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