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