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