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