1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    *
5    *
6    *
7    * The contents of this file are subject to the terms of the Liferay Enterprise
8    * Subscription License ("License"). You may not use this file except in
9    * compliance with the License. You can obtain a copy of the License by
10   * contacting Liferay, Inc. See the License for the specific language governing
11   * permissions and limitations under the License, including but not limited to
12   * distribution rights of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.softwarecatalog.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.annotation.BeanReference;
27  import com.liferay.portal.kernel.cache.CacheRegistry;
28  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
29  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
30  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
31  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
32  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
33  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
34  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
35  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
36  import com.liferay.portal.kernel.dao.orm.FinderPath;
37  import com.liferay.portal.kernel.dao.orm.Query;
38  import com.liferay.portal.kernel.dao.orm.QueryPos;
39  import com.liferay.portal.kernel.dao.orm.QueryUtil;
40  import com.liferay.portal.kernel.dao.orm.SQLQuery;
41  import com.liferay.portal.kernel.dao.orm.Session;
42  import com.liferay.portal.kernel.dao.orm.Type;
43  import com.liferay.portal.kernel.log.Log;
44  import com.liferay.portal.kernel.log.LogFactoryUtil;
45  import com.liferay.portal.kernel.util.GetterUtil;
46  import com.liferay.portal.kernel.util.OrderByComparator;
47  import com.liferay.portal.kernel.util.SetUtil;
48  import com.liferay.portal.kernel.util.StringPool;
49  import com.liferay.portal.kernel.util.StringUtil;
50  import com.liferay.portal.kernel.util.Validator;
51  import com.liferay.portal.model.ModelListener;
52  import com.liferay.portal.service.persistence.BatchSessionUtil;
53  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
54  
55  import com.liferay.portlet.softwarecatalog.NoSuchProductVersionException;
56  import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
57  import com.liferay.portlet.softwarecatalog.model.impl.SCProductVersionImpl;
58  import com.liferay.portlet.softwarecatalog.model.impl.SCProductVersionModelImpl;
59  
60  import java.sql.Types;
61  
62  import java.util.ArrayList;
63  import java.util.Collections;
64  import java.util.List;
65  import java.util.Set;
66  
67  /**
68   * <a href="SCProductVersionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
69   *
70   * <p>
71   * ServiceBuilder generated this class. Modifications in this class will be
72   * overwritten the next time is generated.
73   * </p>
74   *
75   * @author    Brian Wing Shun Chan
76   * @see       SCProductVersionPersistence
77   * @see       SCProductVersionUtil
78   * @generated
79   */
80  public class SCProductVersionPersistenceImpl extends BasePersistenceImpl
81      implements SCProductVersionPersistence {
82      public static final String FINDER_CLASS_NAME_ENTITY = SCProductVersionImpl.class.getName();
83      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
84          ".List";
85      public static final FinderPath FINDER_PATH_FIND_BY_PRODUCTENTRYID = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
86              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
87              FINDER_CLASS_NAME_LIST, "findByProductEntryId",
88              new String[] { Long.class.getName() });
89      public static final FinderPath FINDER_PATH_FIND_BY_OBC_PRODUCTENTRYID = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
90              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
91              FINDER_CLASS_NAME_LIST, "findByProductEntryId",
92              new String[] {
93                  Long.class.getName(),
94                  
95              "java.lang.Integer", "java.lang.Integer",
96                  "com.liferay.portal.kernel.util.OrderByComparator"
97              });
98      public static final FinderPath FINDER_PATH_COUNT_BY_PRODUCTENTRYID = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
99              SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
100             FINDER_CLASS_NAME_LIST, "countByProductEntryId",
101             new String[] { Long.class.getName() });
102     public static final FinderPath FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
103             SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
104             FINDER_CLASS_NAME_ENTITY, "fetchByDirectDownloadURL",
105             new String[] { String.class.getName() });
106     public static final FinderPath FINDER_PATH_COUNT_BY_DIRECTDOWNLOADURL = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
107             SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
108             FINDER_CLASS_NAME_LIST, "countByDirectDownloadURL",
109             new String[] { String.class.getName() });
110     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
111             SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
112             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
113     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
114             SCProductVersionModelImpl.FINDER_CACHE_ENABLED,
115             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
116 
117     public void cacheResult(SCProductVersion scProductVersion) {
118         EntityCacheUtil.putResult(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
119             SCProductVersionImpl.class, scProductVersion.getPrimaryKey(),
120             scProductVersion);
121 
122         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
123             new Object[] { scProductVersion.getDirectDownloadURL() },
124             scProductVersion);
125     }
126 
127     public void cacheResult(List<SCProductVersion> scProductVersions) {
128         for (SCProductVersion scProductVersion : scProductVersions) {
129             if (EntityCacheUtil.getResult(
130                         SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
131                         SCProductVersionImpl.class,
132                         scProductVersion.getPrimaryKey(), this) == null) {
133                 cacheResult(scProductVersion);
134             }
135         }
136     }
137 
138     public void clearCache() {
139         CacheRegistry.clear(SCProductVersionImpl.class.getName());
140         EntityCacheUtil.clearCache(SCProductVersionImpl.class.getName());
141         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
142         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
143     }
144 
145     public SCProductVersion create(long productVersionId) {
146         SCProductVersion scProductVersion = new SCProductVersionImpl();
147 
148         scProductVersion.setNew(true);
149         scProductVersion.setPrimaryKey(productVersionId);
150 
151         return scProductVersion;
152     }
153 
154     public SCProductVersion remove(long productVersionId)
155         throws NoSuchProductVersionException, SystemException {
156         Session session = null;
157 
158         try {
159             session = openSession();
160 
161             SCProductVersion scProductVersion = (SCProductVersion)session.get(SCProductVersionImpl.class,
162                     new Long(productVersionId));
163 
164             if (scProductVersion == null) {
165                 if (_log.isWarnEnabled()) {
166                     _log.warn(
167                         "No SCProductVersion exists with the primary key " +
168                         productVersionId);
169                 }
170 
171                 throw new NoSuchProductVersionException(
172                     "No SCProductVersion exists with the primary key " +
173                     productVersionId);
174             }
175 
176             return remove(scProductVersion);
177         }
178         catch (NoSuchProductVersionException nsee) {
179             throw nsee;
180         }
181         catch (Exception e) {
182             throw processException(e);
183         }
184         finally {
185             closeSession(session);
186         }
187     }
188 
189     public SCProductVersion remove(SCProductVersion scProductVersion)
190         throws SystemException {
191         for (ModelListener<SCProductVersion> listener : listeners) {
192             listener.onBeforeRemove(scProductVersion);
193         }
194 
195         scProductVersion = removeImpl(scProductVersion);
196 
197         for (ModelListener<SCProductVersion> listener : listeners) {
198             listener.onAfterRemove(scProductVersion);
199         }
200 
201         return scProductVersion;
202     }
203 
204     protected SCProductVersion removeImpl(SCProductVersion scProductVersion)
205         throws SystemException {
206         try {
207             clearSCFrameworkVersions.clear(scProductVersion.getPrimaryKey());
208         }
209         catch (Exception e) {
210             throw processException(e);
211         }
212         finally {
213             FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
214         }
215 
216         Session session = null;
217 
218         try {
219             session = openSession();
220 
221             if (scProductVersion.isCachedModel() ||
222                     BatchSessionUtil.isEnabled()) {
223                 Object staleObject = session.get(SCProductVersionImpl.class,
224                         scProductVersion.getPrimaryKeyObj());
225 
226                 if (staleObject != null) {
227                     session.evict(staleObject);
228                 }
229             }
230 
231             session.delete(scProductVersion);
232 
233             session.flush();
234         }
235         catch (Exception e) {
236             throw processException(e);
237         }
238         finally {
239             closeSession(session);
240         }
241 
242         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
243 
244         SCProductVersionModelImpl scProductVersionModelImpl = (SCProductVersionModelImpl)scProductVersion;
245 
246         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
247             new Object[] {
248                 scProductVersionModelImpl.getOriginalDirectDownloadURL()
249             });
250 
251         EntityCacheUtil.removeResult(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
252             SCProductVersionImpl.class, scProductVersion.getPrimaryKey());
253 
254         return scProductVersion;
255     }
256 
257     /**
258      * @deprecated Use {@link #update(SCProductVersion, boolean merge)}.
259      */
260     public SCProductVersion update(SCProductVersion scProductVersion)
261         throws SystemException {
262         if (_log.isWarnEnabled()) {
263             _log.warn(
264                 "Using the deprecated update(SCProductVersion scProductVersion) method. Use update(SCProductVersion scProductVersion, boolean merge) instead.");
265         }
266 
267         return update(scProductVersion, false);
268     }
269 
270     /**
271      * Add, update, or merge, the entity. This method also calls the model
272      * listeners to trigger the proper events associated with adding, deleting,
273      * or updating an entity.
274      *
275      * @param  scProductVersion the entity to add, update, or merge
276      * @param  merge boolean value for whether to merge the entity. The default
277      *         value is false. Setting merge to true is more expensive and
278      *         should only be true when scProductVersion is transient. See
279      *         LEP-5473 for a detailed discussion of this method.
280      * @return the entity that was added, updated, or merged
281      */
282     public SCProductVersion update(SCProductVersion scProductVersion,
283         boolean merge) throws SystemException {
284         boolean isNew = scProductVersion.isNew();
285 
286         for (ModelListener<SCProductVersion> listener : listeners) {
287             if (isNew) {
288                 listener.onBeforeCreate(scProductVersion);
289             }
290             else {
291                 listener.onBeforeUpdate(scProductVersion);
292             }
293         }
294 
295         scProductVersion = updateImpl(scProductVersion, merge);
296 
297         for (ModelListener<SCProductVersion> listener : listeners) {
298             if (isNew) {
299                 listener.onAfterCreate(scProductVersion);
300             }
301             else {
302                 listener.onAfterUpdate(scProductVersion);
303             }
304         }
305 
306         return scProductVersion;
307     }
308 
309     public SCProductVersion updateImpl(
310         com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion,
311         boolean merge) throws SystemException {
312         boolean isNew = scProductVersion.isNew();
313 
314         SCProductVersionModelImpl scProductVersionModelImpl = (SCProductVersionModelImpl)scProductVersion;
315 
316         Session session = null;
317 
318         try {
319             session = openSession();
320 
321             BatchSessionUtil.update(session, scProductVersion, merge);
322 
323             scProductVersion.setNew(false);
324         }
325         catch (Exception e) {
326             throw processException(e);
327         }
328         finally {
329             closeSession(session);
330         }
331 
332         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
333 
334         EntityCacheUtil.putResult(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
335             SCProductVersionImpl.class, scProductVersion.getPrimaryKey(),
336             scProductVersion);
337 
338         if (!isNew &&
339                 (!Validator.equals(scProductVersion.getDirectDownloadURL(),
340                     scProductVersionModelImpl.getOriginalDirectDownloadURL()))) {
341             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
342                 new Object[] {
343                     scProductVersionModelImpl.getOriginalDirectDownloadURL()
344                 });
345         }
346 
347         if (isNew ||
348                 (!Validator.equals(scProductVersion.getDirectDownloadURL(),
349                     scProductVersionModelImpl.getOriginalDirectDownloadURL()))) {
350             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
351                 new Object[] { scProductVersion.getDirectDownloadURL() },
352                 scProductVersion);
353         }
354 
355         return scProductVersion;
356     }
357 
358     public SCProductVersion findByPrimaryKey(long productVersionId)
359         throws NoSuchProductVersionException, SystemException {
360         SCProductVersion scProductVersion = fetchByPrimaryKey(productVersionId);
361 
362         if (scProductVersion == null) {
363             if (_log.isWarnEnabled()) {
364                 _log.warn("No SCProductVersion exists with the primary key " +
365                     productVersionId);
366             }
367 
368             throw new NoSuchProductVersionException(
369                 "No SCProductVersion exists with the primary key " +
370                 productVersionId);
371         }
372 
373         return scProductVersion;
374     }
375 
376     public SCProductVersion fetchByPrimaryKey(long productVersionId)
377         throws SystemException {
378         SCProductVersion scProductVersion = (SCProductVersion)EntityCacheUtil.getResult(SCProductVersionModelImpl.ENTITY_CACHE_ENABLED,
379                 SCProductVersionImpl.class, productVersionId, this);
380 
381         if (scProductVersion == null) {
382             Session session = null;
383 
384             try {
385                 session = openSession();
386 
387                 scProductVersion = (SCProductVersion)session.get(SCProductVersionImpl.class,
388                         new Long(productVersionId));
389             }
390             catch (Exception e) {
391                 throw processException(e);
392             }
393             finally {
394                 if (scProductVersion != null) {
395                     cacheResult(scProductVersion);
396                 }
397 
398                 closeSession(session);
399             }
400         }
401 
402         return scProductVersion;
403     }
404 
405     public List<SCProductVersion> findByProductEntryId(long productEntryId)
406         throws SystemException {
407         Object[] finderArgs = new Object[] { new Long(productEntryId) };
408 
409         List<SCProductVersion> list = (List<SCProductVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
410                 finderArgs, this);
411 
412         if (list == null) {
413             Session session = null;
414 
415             try {
416                 session = openSession();
417 
418                 StringBuilder query = new StringBuilder();
419 
420                 query.append(
421                     "SELECT scProductVersion FROM SCProductVersion scProductVersion WHERE ");
422 
423                 query.append("scProductVersion.productEntryId = ?");
424 
425                 query.append(" ");
426 
427                 query.append("ORDER BY ");
428 
429                 query.append("scProductVersion.createDate DESC");
430 
431                 Query q = session.createQuery(query.toString());
432 
433                 QueryPos qPos = QueryPos.getInstance(q);
434 
435                 qPos.add(productEntryId);
436 
437                 list = q.list();
438             }
439             catch (Exception e) {
440                 throw processException(e);
441             }
442             finally {
443                 if (list == null) {
444                     list = new ArrayList<SCProductVersion>();
445                 }
446 
447                 cacheResult(list);
448 
449                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
450                     finderArgs, list);
451 
452                 closeSession(session);
453             }
454         }
455 
456         return list;
457     }
458 
459     public List<SCProductVersion> findByProductEntryId(long productEntryId,
460         int start, int end) throws SystemException {
461         return findByProductEntryId(productEntryId, start, end, null);
462     }
463 
464     public List<SCProductVersion> findByProductEntryId(long productEntryId,
465         int start, int end, OrderByComparator obc) throws SystemException {
466         Object[] finderArgs = new Object[] {
467                 new Long(productEntryId),
468                 
469                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
470             };
471 
472         List<SCProductVersion> list = (List<SCProductVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_PRODUCTENTRYID,
473                 finderArgs, this);
474 
475         if (list == null) {
476             Session session = null;
477 
478             try {
479                 session = openSession();
480 
481                 StringBuilder query = new StringBuilder();
482 
483                 query.append(
484                     "SELECT scProductVersion FROM SCProductVersion scProductVersion WHERE ");
485 
486                 query.append("scProductVersion.productEntryId = ?");
487 
488                 query.append(" ");
489 
490                 if (obc != null) {
491                     query.append("ORDER BY ");
492 
493                     String[] orderByFields = obc.getOrderByFields();
494 
495                     for (int i = 0; i < orderByFields.length; i++) {
496                         query.append("scProductVersion.");
497                         query.append(orderByFields[i]);
498 
499                         if (obc.isAscending()) {
500                             query.append(" ASC");
501                         }
502                         else {
503                             query.append(" DESC");
504                         }
505 
506                         if ((i + 1) < orderByFields.length) {
507                             query.append(", ");
508                         }
509                     }
510                 }
511 
512                 else {
513                     query.append("ORDER BY ");
514 
515                     query.append("scProductVersion.createDate DESC");
516                 }
517 
518                 Query q = session.createQuery(query.toString());
519 
520                 QueryPos qPos = QueryPos.getInstance(q);
521 
522                 qPos.add(productEntryId);
523 
524                 list = (List<SCProductVersion>)QueryUtil.list(q, getDialect(),
525                         start, end);
526             }
527             catch (Exception e) {
528                 throw processException(e);
529             }
530             finally {
531                 if (list == null) {
532                     list = new ArrayList<SCProductVersion>();
533                 }
534 
535                 cacheResult(list);
536 
537                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_PRODUCTENTRYID,
538                     finderArgs, list);
539 
540                 closeSession(session);
541             }
542         }
543 
544         return list;
545     }
546 
547     public SCProductVersion findByProductEntryId_First(long productEntryId,
548         OrderByComparator obc)
549         throws NoSuchProductVersionException, SystemException {
550         List<SCProductVersion> list = findByProductEntryId(productEntryId, 0,
551                 1, obc);
552 
553         if (list.isEmpty()) {
554             StringBuilder msg = new StringBuilder();
555 
556             msg.append("No SCProductVersion exists with the key {");
557 
558             msg.append("productEntryId=" + productEntryId);
559 
560             msg.append(StringPool.CLOSE_CURLY_BRACE);
561 
562             throw new NoSuchProductVersionException(msg.toString());
563         }
564         else {
565             return list.get(0);
566         }
567     }
568 
569     public SCProductVersion findByProductEntryId_Last(long productEntryId,
570         OrderByComparator obc)
571         throws NoSuchProductVersionException, SystemException {
572         int count = countByProductEntryId(productEntryId);
573 
574         List<SCProductVersion> list = findByProductEntryId(productEntryId,
575                 count - 1, count, obc);
576 
577         if (list.isEmpty()) {
578             StringBuilder msg = new StringBuilder();
579 
580             msg.append("No SCProductVersion exists with the key {");
581 
582             msg.append("productEntryId=" + productEntryId);
583 
584             msg.append(StringPool.CLOSE_CURLY_BRACE);
585 
586             throw new NoSuchProductVersionException(msg.toString());
587         }
588         else {
589             return list.get(0);
590         }
591     }
592 
593     public SCProductVersion[] findByProductEntryId_PrevAndNext(
594         long productVersionId, long productEntryId, OrderByComparator obc)
595         throws NoSuchProductVersionException, SystemException {
596         SCProductVersion scProductVersion = findByPrimaryKey(productVersionId);
597 
598         int count = countByProductEntryId(productEntryId);
599 
600         Session session = null;
601 
602         try {
603             session = openSession();
604 
605             StringBuilder query = new StringBuilder();
606 
607             query.append(
608                 "SELECT scProductVersion FROM SCProductVersion scProductVersion WHERE ");
609 
610             query.append("scProductVersion.productEntryId = ?");
611 
612             query.append(" ");
613 
614             if (obc != null) {
615                 query.append("ORDER BY ");
616 
617                 String[] orderByFields = obc.getOrderByFields();
618 
619                 for (int i = 0; i < orderByFields.length; i++) {
620                     query.append("scProductVersion.");
621                     query.append(orderByFields[i]);
622 
623                     if (obc.isAscending()) {
624                         query.append(" ASC");
625                     }
626                     else {
627                         query.append(" DESC");
628                     }
629 
630                     if ((i + 1) < orderByFields.length) {
631                         query.append(", ");
632                     }
633                 }
634             }
635 
636             else {
637                 query.append("ORDER BY ");
638 
639                 query.append("scProductVersion.createDate DESC");
640             }
641 
642             Query q = session.createQuery(query.toString());
643 
644             QueryPos qPos = QueryPos.getInstance(q);
645 
646             qPos.add(productEntryId);
647 
648             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
649                     scProductVersion);
650 
651             SCProductVersion[] array = new SCProductVersionImpl[3];
652 
653             array[0] = (SCProductVersion)objArray[0];
654             array[1] = (SCProductVersion)objArray[1];
655             array[2] = (SCProductVersion)objArray[2];
656 
657             return array;
658         }
659         catch (Exception e) {
660             throw processException(e);
661         }
662         finally {
663             closeSession(session);
664         }
665     }
666 
667     public SCProductVersion findByDirectDownloadURL(String directDownloadURL)
668         throws NoSuchProductVersionException, SystemException {
669         SCProductVersion scProductVersion = fetchByDirectDownloadURL(directDownloadURL);
670 
671         if (scProductVersion == null) {
672             StringBuilder msg = new StringBuilder();
673 
674             msg.append("No SCProductVersion exists with the key {");
675 
676             msg.append("directDownloadURL=" + directDownloadURL);
677 
678             msg.append(StringPool.CLOSE_CURLY_BRACE);
679 
680             if (_log.isWarnEnabled()) {
681                 _log.warn(msg.toString());
682             }
683 
684             throw new NoSuchProductVersionException(msg.toString());
685         }
686 
687         return scProductVersion;
688     }
689 
690     public SCProductVersion fetchByDirectDownloadURL(String directDownloadURL)
691         throws SystemException {
692         return fetchByDirectDownloadURL(directDownloadURL, true);
693     }
694 
695     public SCProductVersion fetchByDirectDownloadURL(String directDownloadURL,
696         boolean retrieveFromCache) throws SystemException {
697         Object[] finderArgs = new Object[] { directDownloadURL };
698 
699         Object result = null;
700 
701         if (retrieveFromCache) {
702             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
703                     finderArgs, this);
704         }
705 
706         if (result == null) {
707             Session session = null;
708 
709             try {
710                 session = openSession();
711 
712                 StringBuilder query = new StringBuilder();
713 
714                 query.append(
715                     "SELECT scProductVersion FROM SCProductVersion scProductVersion WHERE ");
716 
717                 if (directDownloadURL == null) {
718                     query.append("scProductVersion.directDownloadURL IS NULL");
719                 }
720                 else {
721                     query.append(
722                         "scProductVersion.lower(directDownloadURL) = ?");
723                 }
724 
725                 query.append(" ");
726 
727                 query.append("ORDER BY ");
728 
729                 query.append("scProductVersion.createDate DESC");
730 
731                 Query q = session.createQuery(query.toString());
732 
733                 QueryPos qPos = QueryPos.getInstance(q);
734 
735                 if (directDownloadURL != null) {
736                     qPos.add(directDownloadURL);
737                 }
738 
739                 List<SCProductVersion> list = q.list();
740 
741                 result = list;
742 
743                 SCProductVersion scProductVersion = null;
744 
745                 if (list.isEmpty()) {
746                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
747                         finderArgs, list);
748                 }
749                 else {
750                     scProductVersion = list.get(0);
751 
752                     cacheResult(scProductVersion);
753 
754                     if ((scProductVersion.getDirectDownloadURL() == null) ||
755                             !scProductVersion.getDirectDownloadURL()
756                                                  .equals(directDownloadURL)) {
757                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
758                             finderArgs, scProductVersion);
759                     }
760                 }
761 
762                 return scProductVersion;
763             }
764             catch (Exception e) {
765                 throw processException(e);
766             }
767             finally {
768                 if (result == null) {
769                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_DIRECTDOWNLOADURL,
770                         finderArgs, new ArrayList<SCProductVersion>());
771                 }
772 
773                 closeSession(session);
774             }
775         }
776         else {
777             if (result instanceof List<?>) {
778                 return null;
779             }
780             else {
781                 return (SCProductVersion)result;
782             }
783         }
784     }
785 
786     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
787         throws SystemException {
788         Session session = null;
789 
790         try {
791             session = openSession();
792 
793             dynamicQuery.compile(session);
794 
795             return dynamicQuery.list();
796         }
797         catch (Exception e) {
798             throw processException(e);
799         }
800         finally {
801             closeSession(session);
802         }
803     }
804 
805     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
806         int start, int end) throws SystemException {
807         Session session = null;
808 
809         try {
810             session = openSession();
811 
812             dynamicQuery.setLimit(start, end);
813 
814             dynamicQuery.compile(session);
815 
816             return dynamicQuery.list();
817         }
818         catch (Exception e) {
819             throw processException(e);
820         }
821         finally {
822             closeSession(session);
823         }
824     }
825 
826     public List<SCProductVersion> findAll() throws SystemException {
827         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
828     }
829 
830     public List<SCProductVersion> findAll(int start, int end)
831         throws SystemException {
832         return findAll(start, end, null);
833     }
834 
835     public List<SCProductVersion> findAll(int start, int end,
836         OrderByComparator obc) throws SystemException {
837         Object[] finderArgs = new Object[] {
838                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
839             };
840 
841         List<SCProductVersion> list = (List<SCProductVersion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
842                 finderArgs, this);
843 
844         if (list == null) {
845             Session session = null;
846 
847             try {
848                 session = openSession();
849 
850                 StringBuilder query = new StringBuilder();
851 
852                 query.append(
853                     "SELECT scProductVersion FROM SCProductVersion scProductVersion ");
854 
855                 if (obc != null) {
856                     query.append("ORDER BY ");
857 
858                     String[] orderByFields = obc.getOrderByFields();
859 
860                     for (int i = 0; i < orderByFields.length; i++) {
861                         query.append("scProductVersion.");
862                         query.append(orderByFields[i]);
863 
864                         if (obc.isAscending()) {
865                             query.append(" ASC");
866                         }
867                         else {
868                             query.append(" DESC");
869                         }
870 
871                         if ((i + 1) < orderByFields.length) {
872                             query.append(", ");
873                         }
874                     }
875                 }
876 
877                 else {
878                     query.append("ORDER BY ");
879 
880                     query.append("scProductVersion.createDate DESC");
881                 }
882 
883                 Query q = session.createQuery(query.toString());
884 
885                 if (obc == null) {
886                     list = (List<SCProductVersion>)QueryUtil.list(q,
887                             getDialect(), start, end, false);
888 
889                     Collections.sort(list);
890                 }
891                 else {
892                     list = (List<SCProductVersion>)QueryUtil.list(q,
893                             getDialect(), start, end);
894                 }
895             }
896             catch (Exception e) {
897                 throw processException(e);
898             }
899             finally {
900                 if (list == null) {
901                     list = new ArrayList<SCProductVersion>();
902                 }
903 
904                 cacheResult(list);
905 
906                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
907 
908                 closeSession(session);
909             }
910         }
911 
912         return list;
913     }
914 
915     public void removeByProductEntryId(long productEntryId)
916         throws SystemException {
917         for (SCProductVersion scProductVersion : findByProductEntryId(
918                 productEntryId)) {
919             remove(scProductVersion);
920         }
921     }
922 
923     public void removeByDirectDownloadURL(String directDownloadURL)
924         throws NoSuchProductVersionException, SystemException {
925         SCProductVersion scProductVersion = findByDirectDownloadURL(directDownloadURL);
926 
927         remove(scProductVersion);
928     }
929 
930     public void removeAll() throws SystemException {
931         for (SCProductVersion scProductVersion : findAll()) {
932             remove(scProductVersion);
933         }
934     }
935 
936     public int countByProductEntryId(long productEntryId)
937         throws SystemException {
938         Object[] finderArgs = new Object[] { new Long(productEntryId) };
939 
940         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
941                 finderArgs, this);
942 
943         if (count == null) {
944             Session session = null;
945 
946             try {
947                 session = openSession();
948 
949                 StringBuilder query = new StringBuilder();
950 
951                 query.append("SELECT COUNT(scProductVersion) ");
952                 query.append("FROM SCProductVersion scProductVersion WHERE ");
953 
954                 query.append("scProductVersion.productEntryId = ?");
955 
956                 query.append(" ");
957 
958                 Query q = session.createQuery(query.toString());
959 
960                 QueryPos qPos = QueryPos.getInstance(q);
961 
962                 qPos.add(productEntryId);
963 
964                 count = (Long)q.uniqueResult();
965             }
966             catch (Exception e) {
967                 throw processException(e);
968             }
969             finally {
970                 if (count == null) {
971                     count = Long.valueOf(0);
972                 }
973 
974                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
975                     finderArgs, count);
976 
977                 closeSession(session);
978             }
979         }
980 
981         return count.intValue();
982     }
983 
984     public int countByDirectDownloadURL(String directDownloadURL)
985         throws SystemException {
986         Object[] finderArgs = new Object[] { directDownloadURL };
987 
988         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_DIRECTDOWNLOADURL,
989                 finderArgs, this);
990 
991         if (count == null) {
992             Session session = null;
993 
994             try {
995                 session = openSession();
996 
997                 StringBuilder query = new StringBuilder();
998 
999                 query.append("SELECT COUNT(scProductVersion) ");
1000                query.append("FROM SCProductVersion scProductVersion WHERE ");
1001
1002                if (directDownloadURL == null) {
1003                    query.append("scProductVersion.directDownloadURL IS NULL");
1004                }
1005                else {
1006                    query.append(
1007                        "scProductVersion.lower(directDownloadURL) = ?");
1008                }
1009
1010                query.append(" ");
1011
1012                Query q = session.createQuery(query.toString());
1013
1014                QueryPos qPos = QueryPos.getInstance(q);
1015
1016                if (directDownloadURL != null) {
1017                    qPos.add(directDownloadURL);
1018                }
1019
1020                count = (Long)q.uniqueResult();
1021            }
1022            catch (Exception e) {
1023                throw processException(e);
1024            }
1025            finally {
1026                if (count == null) {
1027                    count = Long.valueOf(0);
1028                }
1029
1030                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_DIRECTDOWNLOADURL,
1031                    finderArgs, count);
1032
1033                closeSession(session);
1034            }
1035        }
1036
1037        return count.intValue();
1038    }
1039
1040    public int countAll() throws SystemException {
1041        Object[] finderArgs = new Object[0];
1042
1043        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1044                finderArgs, this);
1045
1046        if (count == null) {
1047            Session session = null;
1048
1049            try {
1050                session = openSession();
1051
1052                Query q = session.createQuery(
1053                        "SELECT COUNT(scProductVersion) FROM SCProductVersion scProductVersion");
1054
1055                count = (Long)q.uniqueResult();
1056            }
1057            catch (Exception e) {
1058                throw processException(e);
1059            }
1060            finally {
1061                if (count == null) {
1062                    count = Long.valueOf(0);
1063                }
1064
1065                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1066                    count);
1067
1068                closeSession(session);
1069            }
1070        }
1071
1072        return count.intValue();
1073    }
1074
1075    public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
1076        long pk) throws SystemException {
1077        return getSCFrameworkVersions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1078    }
1079
1080    public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
1081        long pk, int start, int end) throws SystemException {
1082        return getSCFrameworkVersions(pk, start, end, null);
1083    }
1084
1085    public static final FinderPath FINDER_PATH_GET_SCFRAMEWORKVERSIONS = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionModelImpl.ENTITY_CACHE_ENABLED,
1086            SCProductVersionModelImpl.FINDER_CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS,
1087            "SCFrameworkVersi_SCProductVers", "getSCFrameworkVersions",
1088            new String[] {
1089                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1090                "com.liferay.portal.kernel.util.OrderByComparator"
1091            });
1092
1093    public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
1094        long pk, int start, int end, OrderByComparator obc)
1095        throws SystemException {
1096        Object[] finderArgs = new Object[] {
1097                new Long(pk), String.valueOf(start), String.valueOf(end),
1098                String.valueOf(obc)
1099            };
1100
1101        List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> list = (List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>)FinderCacheUtil.getResult(FINDER_PATH_GET_SCFRAMEWORKVERSIONS,
1102                finderArgs, this);
1103
1104        if (list == null) {
1105            Session session = null;
1106
1107            try {
1108                session = openSession();
1109
1110                StringBuilder sb = new StringBuilder();
1111
1112                sb.append(_SQL_GETSCFRAMEWORKVERSIONS);
1113
1114                if (obc != null) {
1115                    sb.append("ORDER BY ");
1116                    sb.append(obc.getOrderBy());
1117                }
1118
1119                else {
1120                    sb.append("ORDER BY ");
1121
1122                    sb.append("SCFrameworkVersion.name DESC");
1123                }
1124
1125                String sql = sb.toString();
1126
1127                SQLQuery q = session.createSQLQuery(sql);
1128
1129                q.addEntity("SCFrameworkVersion",
1130                    com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionImpl.class);
1131
1132                QueryPos qPos = QueryPos.getInstance(q);
1133
1134                qPos.add(pk);
1135
1136                list = (List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>)QueryUtil.list(q,
1137                        getDialect(), start, end);
1138            }
1139            catch (Exception e) {
1140                throw processException(e);
1141            }
1142            finally {
1143                if (list == null) {
1144                    list = new ArrayList<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>();
1145                }
1146
1147                scFrameworkVersionPersistence.cacheResult(list);
1148
1149                FinderCacheUtil.putResult(FINDER_PATH_GET_SCFRAMEWORKVERSIONS,
1150                    finderArgs, list);
1151
1152                closeSession(session);
1153            }
1154        }
1155
1156        return list;
1157    }
1158
1159    public static final FinderPath FINDER_PATH_GET_SCFRAMEWORKVERSIONS_SIZE = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionModelImpl.ENTITY_CACHE_ENABLED,
1160            SCProductVersionModelImpl.FINDER_CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS,
1161            "SCFrameworkVersi_SCProductVers", "getSCFrameworkVersionsSize",
1162            new String[] { Long.class.getName() });
1163
1164    public int getSCFrameworkVersionsSize(long pk) throws SystemException {
1165        Object[] finderArgs = new Object[] { new Long(pk) };
1166
1167        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_SCFRAMEWORKVERSIONS_SIZE,
1168                finderArgs, this);
1169
1170        if (count == null) {
1171            Session session = null;
1172
1173            try {
1174                session = openSession();
1175
1176                SQLQuery q = session.createSQLQuery(_SQL_GETSCFRAMEWORKVERSIONSSIZE);
1177
1178                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1179
1180                QueryPos qPos = QueryPos.getInstance(q);
1181
1182                qPos.add(pk);
1183
1184                count = (Long)q.uniqueResult();
1185            }
1186            catch (Exception e) {
1187                throw processException(e);
1188            }
1189            finally {
1190                if (count == null) {
1191                    count = Long.valueOf(0);
1192                }
1193
1194                FinderCacheUtil.putResult(FINDER_PATH_GET_SCFRAMEWORKVERSIONS_SIZE,
1195                    finderArgs, count);
1196
1197                closeSession(session);
1198            }
1199        }
1200
1201        return count.intValue();
1202    }
1203
1204    public static final FinderPath FINDER_PATH_CONTAINS_SCFRAMEWORKVERSION = new FinderPath(com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionModelImpl.ENTITY_CACHE_ENABLED,
1205            SCProductVersionModelImpl.FINDER_CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS,
1206            "SCFrameworkVersi_SCProductVers", "containsSCFrameworkVersion",
1207            new String[] { Long.class.getName(), Long.class.getName() });
1208
1209    public boolean containsSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1210        throws SystemException {
1211        Object[] finderArgs = new Object[] {
1212                new Long(pk),
1213                
1214                new Long(scFrameworkVersionPK)
1215            };
1216
1217        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_SCFRAMEWORKVERSION,
1218                finderArgs, this);
1219
1220        if (value == null) {
1221            try {
1222                value = Boolean.valueOf(containsSCFrameworkVersion.contains(
1223                            pk, scFrameworkVersionPK));
1224            }
1225            catch (Exception e) {
1226                throw processException(e);
1227            }
1228            finally {
1229                if (value == null) {
1230                    value = Boolean.FALSE;
1231                }
1232
1233                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_SCFRAMEWORKVERSION,
1234                    finderArgs, value);
1235            }
1236        }
1237
1238        return value.booleanValue();
1239    }
1240
1241    public boolean containsSCFrameworkVersions(long pk)
1242        throws SystemException {
1243        if (getSCFrameworkVersionsSize(pk) > 0) {
1244            return true;
1245        }
1246        else {
1247            return false;
1248        }
1249    }
1250
1251    public void addSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1252        throws SystemException {
1253        try {
1254            addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1255        }
1256        catch (Exception e) {
1257            throw processException(e);
1258        }
1259        finally {
1260            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1261        }
1262    }
1263
1264    public void addSCFrameworkVersion(long pk,
1265        com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion)
1266        throws SystemException {
1267        try {
1268            addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1269        }
1270        catch (Exception e) {
1271            throw processException(e);
1272        }
1273        finally {
1274            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1275        }
1276    }
1277
1278    public void addSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1279        throws SystemException {
1280        try {
1281            for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1282                addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1283            }
1284        }
1285        catch (Exception e) {
1286            throw processException(e);
1287        }
1288        finally {
1289            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1290        }
1291    }
1292
1293    public void addSCFrameworkVersions(long pk,
1294        List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1295        throws SystemException {
1296        try {
1297            for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1298                addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1299            }
1300        }
1301        catch (Exception e) {
1302            throw processException(e);
1303        }
1304        finally {
1305            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1306        }
1307    }
1308
1309    public void clearSCFrameworkVersions(long pk) throws SystemException {
1310        try {
1311            clearSCFrameworkVersions.clear(pk);
1312        }
1313        catch (Exception e) {
1314            throw processException(e);
1315        }
1316        finally {
1317            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1318        }
1319    }
1320
1321    public void removeSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1322        throws SystemException {
1323        try {
1324            removeSCFrameworkVersion.remove(pk, scFrameworkVersionPK);
1325        }
1326        catch (Exception e) {
1327            throw processException(e);
1328        }
1329        finally {
1330            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1331        }
1332    }
1333
1334    public void removeSCFrameworkVersion(long pk,
1335        com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion)
1336        throws SystemException {
1337        try {
1338            removeSCFrameworkVersion.remove(pk,
1339                scFrameworkVersion.getPrimaryKey());
1340        }
1341        catch (Exception e) {
1342            throw processException(e);
1343        }
1344        finally {
1345            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1346        }
1347    }
1348
1349    public void removeSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1350        throws SystemException {
1351        try {
1352            for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1353                removeSCFrameworkVersion.remove(pk, scFrameworkVersionPK);
1354            }
1355        }
1356        catch (Exception e) {
1357            throw processException(e);
1358        }
1359        finally {
1360            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1361        }
1362    }
1363
1364    public void removeSCFrameworkVersions(long pk,
1365        List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1366        throws SystemException {
1367        try {
1368            for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1369                removeSCFrameworkVersion.remove(pk,
1370                    scFrameworkVersion.getPrimaryKey());
1371            }
1372        }
1373        catch (Exception e) {
1374            throw processException(e);
1375        }
1376        finally {
1377            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1378        }
1379    }
1380
1381    public void setSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1382        throws SystemException {
1383        try {
1384            Set<Long> scFrameworkVersionPKSet = SetUtil.fromArray(scFrameworkVersionPKs);
1385
1386            List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions =
1387                getSCFrameworkVersions(pk);
1388
1389            for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1390                if (!scFrameworkVersionPKSet.contains(
1391                            scFrameworkVersion.getPrimaryKey())) {
1392                    removeSCFrameworkVersion.remove(pk,
1393                        scFrameworkVersion.getPrimaryKey());
1394                }
1395                else {
1396                    scFrameworkVersionPKSet.remove(scFrameworkVersion.getPrimaryKey());
1397                }
1398            }
1399
1400            for (Long scFrameworkVersionPK : scFrameworkVersionPKSet) {
1401                addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1402            }
1403        }
1404        catch (Exception e) {
1405            throw processException(e);
1406        }
1407        finally {
1408            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1409        }
1410    }
1411
1412    public void setSCFrameworkVersions(long pk,
1413        List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1414        throws SystemException {
1415        try {
1416            long[] scFrameworkVersionPKs = new long[scFrameworkVersions.size()];
1417
1418            for (int i = 0; i < scFrameworkVersions.size(); i++) {
1419                com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion =
1420                    scFrameworkVersions.get(i);
1421
1422                scFrameworkVersionPKs[i] = scFrameworkVersion.getPrimaryKey();
1423            }
1424
1425            setSCFrameworkVersions(pk, scFrameworkVersionPKs);
1426        }
1427        catch (Exception e) {
1428            throw processException(e);
1429        }
1430        finally {
1431            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1432        }
1433    }
1434
1435    public void afterPropertiesSet() {
1436        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1437                    com.liferay.portal.util.PropsUtil.get(
1438                        "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductVersion")));
1439
1440        if (listenerClassNames.length > 0) {
1441            try {
1442                List<ModelListener<SCProductVersion>> listenersList = new ArrayList<ModelListener<SCProductVersion>>();
1443
1444                for (String listenerClassName : listenerClassNames) {
1445                    listenersList.add((ModelListener<SCProductVersion>)Class.forName(
1446                            listenerClassName).newInstance());
1447                }
1448
1449                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1450            }
1451            catch (Exception e) {
1452                _log.error(e);
1453            }
1454        }
1455
1456        containsSCFrameworkVersion = new ContainsSCFrameworkVersion(this);
1457
1458        addSCFrameworkVersion = new AddSCFrameworkVersion(this);
1459        clearSCFrameworkVersions = new ClearSCFrameworkVersions(this);
1460        removeSCFrameworkVersion = new RemoveSCFrameworkVersion(this);
1461    }
1462
1463    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCLicensePersistence.impl")
1464    protected com.liferay.portlet.softwarecatalog.service.persistence.SCLicensePersistence scLicensePersistence;
1465    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCFrameworkVersionPersistence.impl")
1466    protected com.liferay.portlet.softwarecatalog.service.persistence.SCFrameworkVersionPersistence scFrameworkVersionPersistence;
1467    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence.impl")
1468    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence scProductEntryPersistence;
1469    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductScreenshotPersistence.impl")
1470    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductScreenshotPersistence scProductScreenshotPersistence;
1471    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductVersionPersistence.impl")
1472    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductVersionPersistence scProductVersionPersistence;
1473    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1474    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1475    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1476    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1477    protected ContainsSCFrameworkVersion containsSCFrameworkVersion;
1478    protected AddSCFrameworkVersion addSCFrameworkVersion;
1479    protected ClearSCFrameworkVersions clearSCFrameworkVersions;
1480    protected RemoveSCFrameworkVersion removeSCFrameworkVersion;
1481
1482    protected class ContainsSCFrameworkVersion {
1483        protected ContainsSCFrameworkVersion(
1484            SCProductVersionPersistenceImpl persistenceImpl) {
1485            super();
1486
1487            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1488                    _SQL_CONTAINSSCFRAMEWORKVERSION,
1489                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1490        }
1491
1492        protected boolean contains(long productVersionId,
1493            long frameworkVersionId) {
1494            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1495                        new Long(productVersionId), new Long(frameworkVersionId)
1496                    });
1497
1498            if (results.size() > 0) {
1499                Integer count = results.get(0);
1500
1501                if (count.intValue() > 0) {
1502                    return true;
1503                }
1504            }
1505
1506            return false;
1507        }
1508
1509        private MappingSqlQuery _mappingSqlQuery;
1510    }
1511
1512    protected class AddSCFrameworkVersion {
1513        protected AddSCFrameworkVersion(
1514            SCProductVersionPersistenceImpl persistenceImpl) {
1515            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1516                    "INSERT INTO SCFrameworkVersi_SCProductVers (productVersionId, frameworkVersionId) VALUES (?, ?)",
1517                    new int[] { Types.BIGINT, Types.BIGINT });
1518            _persistenceImpl = persistenceImpl;
1519        }
1520
1521        protected void add(long productVersionId, long frameworkVersionId) {
1522            if (!_persistenceImpl.containsSCFrameworkVersion.contains(
1523                        productVersionId, frameworkVersionId)) {
1524                _sqlUpdate.update(new Object[] {
1525                        new Long(productVersionId), new Long(frameworkVersionId)
1526                    });
1527            }
1528        }
1529
1530        private SqlUpdate _sqlUpdate;
1531        private SCProductVersionPersistenceImpl _persistenceImpl;
1532    }
1533
1534    protected class ClearSCFrameworkVersions {
1535        protected ClearSCFrameworkVersions(
1536            SCProductVersionPersistenceImpl persistenceImpl) {
1537            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1538                    "DELETE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ?",
1539                    new int[] { Types.BIGINT });
1540        }
1541
1542        protected void clear(long productVersionId) {
1543            _sqlUpdate.update(new Object[] { new Long(productVersionId) });
1544        }
1545
1546        private SqlUpdate _sqlUpdate;
1547    }
1548
1549    protected class RemoveSCFrameworkVersion {
1550        protected RemoveSCFrameworkVersion(
1551            SCProductVersionPersistenceImpl persistenceImpl) {
1552            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1553                    "DELETE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ? AND frameworkVersionId = ?",
1554                    new int[] { Types.BIGINT, Types.BIGINT });
1555        }
1556
1557        protected void remove(long productVersionId, long frameworkVersionId) {
1558            _sqlUpdate.update(new Object[] {
1559                    new Long(productVersionId), new Long(frameworkVersionId)
1560                });
1561        }
1562
1563        private SqlUpdate _sqlUpdate;
1564    }
1565
1566    private static final String _SQL_GETSCFRAMEWORKVERSIONS = "SELECT {SCFrameworkVersion.*} FROM SCFrameworkVersion INNER JOIN SCFrameworkVersi_SCProductVers ON (SCFrameworkVersi_SCProductVers.frameworkVersionId = SCFrameworkVersion.frameworkVersionId) WHERE (SCFrameworkVersi_SCProductVers.productVersionId = ?)";
1567    private static final String _SQL_GETSCFRAMEWORKVERSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ?";
1568    private static final String _SQL_CONTAINSSCFRAMEWORKVERSION = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ? AND frameworkVersionId = ?";
1569    private static Log _log = LogFactoryUtil.getLog(SCProductVersionPersistenceImpl.class);
1570}