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