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