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