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