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