1   /**
2    * Copyright (c) 2000-2008 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.bean.InitializingBean;
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.util.GetterUtil;
41  import com.liferay.portal.kernel.util.ListUtil;
42  import com.liferay.portal.kernel.util.OrderByComparator;
43  import com.liferay.portal.kernel.util.StringPool;
44  import com.liferay.portal.kernel.util.StringUtil;
45  import com.liferay.portal.model.ModelListener;
46  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
47  
48  import com.liferay.portlet.softwarecatalog.NoSuchFrameworkVersionException;
49  import com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion;
50  import com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionImpl;
51  import com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionModelImpl;
52  
53  import org.apache.commons.logging.Log;
54  import org.apache.commons.logging.LogFactory;
55  
56  import java.sql.Types;
57  
58  import java.util.ArrayList;
59  import java.util.Collections;
60  import java.util.Iterator;
61  import java.util.List;
62  
63  /**
64   * <a href="SCFrameworkVersionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
65   *
66   * @author Brian Wing Shun Chan
67   *
68   */
69  public class SCFrameworkVersionPersistenceImpl extends BasePersistenceImpl
70      implements SCFrameworkVersionPersistence, InitializingBean {
71      public SCFrameworkVersion create(long frameworkVersionId) {
72          SCFrameworkVersion scFrameworkVersion = new SCFrameworkVersionImpl();
73  
74          scFrameworkVersion.setNew(true);
75          scFrameworkVersion.setPrimaryKey(frameworkVersionId);
76  
77          return scFrameworkVersion;
78      }
79  
80      public SCFrameworkVersion remove(long frameworkVersionId)
81          throws NoSuchFrameworkVersionException, SystemException {
82          Session session = null;
83  
84          try {
85              session = openSession();
86  
87              SCFrameworkVersion scFrameworkVersion = (SCFrameworkVersion)session.get(SCFrameworkVersionImpl.class,
88                      new Long(frameworkVersionId));
89  
90              if (scFrameworkVersion == null) {
91                  if (_log.isWarnEnabled()) {
92                      _log.warn(
93                          "No SCFrameworkVersion exists with the primary key " +
94                          frameworkVersionId);
95                  }
96  
97                  throw new NoSuchFrameworkVersionException(
98                      "No SCFrameworkVersion exists with the primary key " +
99                      frameworkVersionId);
100             }
101 
102             return remove(scFrameworkVersion);
103         }
104         catch (NoSuchFrameworkVersionException nsee) {
105             throw nsee;
106         }
107         catch (Exception e) {
108             throw processException(e);
109         }
110         finally {
111             closeSession(session);
112         }
113     }
114 
115     public SCFrameworkVersion remove(SCFrameworkVersion scFrameworkVersion)
116         throws SystemException {
117         if (_listeners.length > 0) {
118             for (ModelListener listener : _listeners) {
119                 listener.onBeforeRemove(scFrameworkVersion);
120             }
121         }
122 
123         scFrameworkVersion = removeImpl(scFrameworkVersion);
124 
125         if (_listeners.length > 0) {
126             for (ModelListener listener : _listeners) {
127                 listener.onAfterRemove(scFrameworkVersion);
128             }
129         }
130 
131         return scFrameworkVersion;
132     }
133 
134     protected SCFrameworkVersion removeImpl(
135         SCFrameworkVersion scFrameworkVersion) throws SystemException {
136         try {
137             clearSCProductVersions.clear(scFrameworkVersion.getPrimaryKey());
138         }
139         catch (Exception e) {
140             throw processException(e);
141         }
142         finally {
143             FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
144         }
145 
146         Session session = null;
147 
148         try {
149             session = openSession();
150 
151             session.delete(scFrameworkVersion);
152 
153             session.flush();
154 
155             return scFrameworkVersion;
156         }
157         catch (Exception e) {
158             throw processException(e);
159         }
160         finally {
161             closeSession(session);
162 
163             FinderCacheUtil.clearCache(SCFrameworkVersion.class.getName());
164         }
165     }
166 
167     /**
168      * @deprecated Use <code>update(SCFrameworkVersion scFrameworkVersion, boolean merge)</code>.
169      */
170     public SCFrameworkVersion update(SCFrameworkVersion scFrameworkVersion)
171         throws SystemException {
172         if (_log.isWarnEnabled()) {
173             _log.warn(
174                 "Using the deprecated update(SCFrameworkVersion scFrameworkVersion) method. Use update(SCFrameworkVersion scFrameworkVersion, boolean merge) instead.");
175         }
176 
177         return update(scFrameworkVersion, false);
178     }
179 
180     /**
181      * Add, update, or merge, the entity. This method also calls the model
182      * listeners to trigger the proper events associated with adding, deleting,
183      * or updating an entity.
184      *
185      * @param        scFrameworkVersion the entity to add, update, or merge
186      * @param        merge boolean value for whether to merge the entity. The
187      *                default value is false. Setting merge to true is more
188      *                expensive and should only be true when scFrameworkVersion is
189      *                transient. See LEP-5473 for a detailed discussion of this
190      *                method.
191      * @return        true if the portlet can be displayed via Ajax
192      */
193     public SCFrameworkVersion update(SCFrameworkVersion scFrameworkVersion,
194         boolean merge) throws SystemException {
195         boolean isNew = scFrameworkVersion.isNew();
196 
197         if (_listeners.length > 0) {
198             for (ModelListener listener : _listeners) {
199                 if (isNew) {
200                     listener.onBeforeCreate(scFrameworkVersion);
201                 }
202                 else {
203                     listener.onBeforeUpdate(scFrameworkVersion);
204                 }
205             }
206         }
207 
208         scFrameworkVersion = updateImpl(scFrameworkVersion, merge);
209 
210         if (_listeners.length > 0) {
211             for (ModelListener listener : _listeners) {
212                 if (isNew) {
213                     listener.onAfterCreate(scFrameworkVersion);
214                 }
215                 else {
216                     listener.onAfterUpdate(scFrameworkVersion);
217                 }
218             }
219         }
220 
221         return scFrameworkVersion;
222     }
223 
224     public SCFrameworkVersion updateImpl(
225         com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion,
226         boolean merge) throws SystemException {
227         FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
228 
229         Session session = null;
230 
231         try {
232             session = openSession();
233 
234             if (merge) {
235                 session.merge(scFrameworkVersion);
236             }
237             else {
238                 if (scFrameworkVersion.isNew()) {
239                     session.save(scFrameworkVersion);
240                 }
241             }
242 
243             session.flush();
244 
245             scFrameworkVersion.setNew(false);
246 
247             return scFrameworkVersion;
248         }
249         catch (Exception e) {
250             throw processException(e);
251         }
252         finally {
253             closeSession(session);
254 
255             FinderCacheUtil.clearCache(SCFrameworkVersion.class.getName());
256         }
257     }
258 
259     public SCFrameworkVersion findByPrimaryKey(long frameworkVersionId)
260         throws NoSuchFrameworkVersionException, SystemException {
261         SCFrameworkVersion scFrameworkVersion = fetchByPrimaryKey(frameworkVersionId);
262 
263         if (scFrameworkVersion == null) {
264             if (_log.isWarnEnabled()) {
265                 _log.warn("No SCFrameworkVersion exists with the primary key " +
266                     frameworkVersionId);
267             }
268 
269             throw new NoSuchFrameworkVersionException(
270                 "No SCFrameworkVersion exists with the primary key " +
271                 frameworkVersionId);
272         }
273 
274         return scFrameworkVersion;
275     }
276 
277     public SCFrameworkVersion fetchByPrimaryKey(long frameworkVersionId)
278         throws SystemException {
279         Session session = null;
280 
281         try {
282             session = openSession();
283 
284             return (SCFrameworkVersion)session.get(SCFrameworkVersionImpl.class,
285                 new Long(frameworkVersionId));
286         }
287         catch (Exception e) {
288             throw processException(e);
289         }
290         finally {
291             closeSession(session);
292         }
293     }
294 
295     public List<SCFrameworkVersion> findByGroupId(long groupId)
296         throws SystemException {
297         boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
298         String finderClassName = SCFrameworkVersion.class.getName();
299         String finderMethodName = "findByGroupId";
300         String[] finderParams = new String[] { Long.class.getName() };
301         Object[] finderArgs = new Object[] { new Long(groupId) };
302 
303         Object result = null;
304 
305         if (finderClassNameCacheEnabled) {
306             result = FinderCacheUtil.getResult(finderClassName,
307                     finderMethodName, finderParams, finderArgs, this);
308         }
309 
310         if (result == null) {
311             Session session = null;
312 
313             try {
314                 session = openSession();
315 
316                 StringBuilder query = new StringBuilder();
317 
318                 query.append(
319                     "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
320 
321                 query.append("groupId = ?");
322 
323                 query.append(" ");
324 
325                 query.append("ORDER BY ");
326 
327                 query.append("priority ASC, ");
328                 query.append("name ASC");
329 
330                 Query q = session.createQuery(query.toString());
331 
332                 QueryPos qPos = QueryPos.getInstance(q);
333 
334                 qPos.add(groupId);
335 
336                 List<SCFrameworkVersion> list = q.list();
337 
338                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
339                     finderClassName, finderMethodName, finderParams,
340                     finderArgs, list);
341 
342                 return list;
343             }
344             catch (Exception e) {
345                 throw processException(e);
346             }
347             finally {
348                 closeSession(session);
349             }
350         }
351         else {
352             return (List<SCFrameworkVersion>)result;
353         }
354     }
355 
356     public List<SCFrameworkVersion> findByGroupId(long groupId, int start,
357         int end) throws SystemException {
358         return findByGroupId(groupId, start, end, null);
359     }
360 
361     public List<SCFrameworkVersion> findByGroupId(long groupId, int start,
362         int end, OrderByComparator obc) throws SystemException {
363         boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
364         String finderClassName = SCFrameworkVersion.class.getName();
365         String finderMethodName = "findByGroupId";
366         String[] finderParams = new String[] {
367                 Long.class.getName(),
368                 
369                 "java.lang.Integer", "java.lang.Integer",
370                 "com.liferay.portal.kernel.util.OrderByComparator"
371             };
372         Object[] finderArgs = new Object[] {
373                 new Long(groupId),
374                 
375                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
376             };
377 
378         Object result = null;
379 
380         if (finderClassNameCacheEnabled) {
381             result = FinderCacheUtil.getResult(finderClassName,
382                     finderMethodName, finderParams, finderArgs, this);
383         }
384 
385         if (result == null) {
386             Session session = null;
387 
388             try {
389                 session = openSession();
390 
391                 StringBuilder query = new StringBuilder();
392 
393                 query.append(
394                     "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
395 
396                 query.append("groupId = ?");
397 
398                 query.append(" ");
399 
400                 if (obc != null) {
401                     query.append("ORDER BY ");
402                     query.append(obc.getOrderBy());
403                 }
404 
405                 else {
406                     query.append("ORDER BY ");
407 
408                     query.append("priority ASC, ");
409                     query.append("name ASC");
410                 }
411 
412                 Query q = session.createQuery(query.toString());
413 
414                 QueryPos qPos = QueryPos.getInstance(q);
415 
416                 qPos.add(groupId);
417 
418                 List<SCFrameworkVersion> list = (List<SCFrameworkVersion>)QueryUtil.list(q,
419                         getDialect(), start, end);
420 
421                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
422                     finderClassName, finderMethodName, finderParams,
423                     finderArgs, list);
424 
425                 return list;
426             }
427             catch (Exception e) {
428                 throw processException(e);
429             }
430             finally {
431                 closeSession(session);
432             }
433         }
434         else {
435             return (List<SCFrameworkVersion>)result;
436         }
437     }
438 
439     public SCFrameworkVersion findByGroupId_First(long groupId,
440         OrderByComparator obc)
441         throws NoSuchFrameworkVersionException, SystemException {
442         List<SCFrameworkVersion> list = findByGroupId(groupId, 0, 1, obc);
443 
444         if (list.size() == 0) {
445             StringBuilder msg = new StringBuilder();
446 
447             msg.append("No SCFrameworkVersion exists with the key {");
448 
449             msg.append("groupId=" + groupId);
450 
451             msg.append(StringPool.CLOSE_CURLY_BRACE);
452 
453             throw new NoSuchFrameworkVersionException(msg.toString());
454         }
455         else {
456             return list.get(0);
457         }
458     }
459 
460     public SCFrameworkVersion findByGroupId_Last(long groupId,
461         OrderByComparator obc)
462         throws NoSuchFrameworkVersionException, SystemException {
463         int count = countByGroupId(groupId);
464 
465         List<SCFrameworkVersion> list = findByGroupId(groupId, count - 1,
466                 count, obc);
467 
468         if (list.size() == 0) {
469             StringBuilder msg = new StringBuilder();
470 
471             msg.append("No SCFrameworkVersion exists with the key {");
472 
473             msg.append("groupId=" + groupId);
474 
475             msg.append(StringPool.CLOSE_CURLY_BRACE);
476 
477             throw new NoSuchFrameworkVersionException(msg.toString());
478         }
479         else {
480             return list.get(0);
481         }
482     }
483 
484     public SCFrameworkVersion[] findByGroupId_PrevAndNext(
485         long frameworkVersionId, long groupId, OrderByComparator obc)
486         throws NoSuchFrameworkVersionException, SystemException {
487         SCFrameworkVersion scFrameworkVersion = findByPrimaryKey(frameworkVersionId);
488 
489         int count = countByGroupId(groupId);
490 
491         Session session = null;
492 
493         try {
494             session = openSession();
495 
496             StringBuilder query = new StringBuilder();
497 
498             query.append(
499                 "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
500 
501             query.append("groupId = ?");
502 
503             query.append(" ");
504 
505             if (obc != null) {
506                 query.append("ORDER BY ");
507                 query.append(obc.getOrderBy());
508             }
509 
510             else {
511                 query.append("ORDER BY ");
512 
513                 query.append("priority ASC, ");
514                 query.append("name ASC");
515             }
516 
517             Query q = session.createQuery(query.toString());
518 
519             QueryPos qPos = QueryPos.getInstance(q);
520 
521             qPos.add(groupId);
522 
523             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
524                     scFrameworkVersion);
525 
526             SCFrameworkVersion[] array = new SCFrameworkVersionImpl[3];
527 
528             array[0] = (SCFrameworkVersion)objArray[0];
529             array[1] = (SCFrameworkVersion)objArray[1];
530             array[2] = (SCFrameworkVersion)objArray[2];
531 
532             return array;
533         }
534         catch (Exception e) {
535             throw processException(e);
536         }
537         finally {
538             closeSession(session);
539         }
540     }
541 
542     public List<SCFrameworkVersion> findByCompanyId(long companyId)
543         throws SystemException {
544         boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
545         String finderClassName = SCFrameworkVersion.class.getName();
546         String finderMethodName = "findByCompanyId";
547         String[] finderParams = new String[] { Long.class.getName() };
548         Object[] finderArgs = new Object[] { new Long(companyId) };
549 
550         Object result = null;
551 
552         if (finderClassNameCacheEnabled) {
553             result = FinderCacheUtil.getResult(finderClassName,
554                     finderMethodName, finderParams, finderArgs, this);
555         }
556 
557         if (result == null) {
558             Session session = null;
559 
560             try {
561                 session = openSession();
562 
563                 StringBuilder query = new StringBuilder();
564 
565                 query.append(
566                     "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
567 
568                 query.append("companyId = ?");
569 
570                 query.append(" ");
571 
572                 query.append("ORDER BY ");
573 
574                 query.append("priority ASC, ");
575                 query.append("name ASC");
576 
577                 Query q = session.createQuery(query.toString());
578 
579                 QueryPos qPos = QueryPos.getInstance(q);
580 
581                 qPos.add(companyId);
582 
583                 List<SCFrameworkVersion> list = q.list();
584 
585                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
586                     finderClassName, finderMethodName, finderParams,
587                     finderArgs, list);
588 
589                 return list;
590             }
591             catch (Exception e) {
592                 throw processException(e);
593             }
594             finally {
595                 closeSession(session);
596             }
597         }
598         else {
599             return (List<SCFrameworkVersion>)result;
600         }
601     }
602 
603     public List<SCFrameworkVersion> findByCompanyId(long companyId, int start,
604         int end) throws SystemException {
605         return findByCompanyId(companyId, start, end, null);
606     }
607 
608     public List<SCFrameworkVersion> findByCompanyId(long companyId, int start,
609         int end, OrderByComparator obc) throws SystemException {
610         boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
611         String finderClassName = SCFrameworkVersion.class.getName();
612         String finderMethodName = "findByCompanyId";
613         String[] finderParams = new String[] {
614                 Long.class.getName(),
615                 
616                 "java.lang.Integer", "java.lang.Integer",
617                 "com.liferay.portal.kernel.util.OrderByComparator"
618             };
619         Object[] finderArgs = new Object[] {
620                 new Long(companyId),
621                 
622                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
623             };
624 
625         Object result = null;
626 
627         if (finderClassNameCacheEnabled) {
628             result = FinderCacheUtil.getResult(finderClassName,
629                     finderMethodName, finderParams, finderArgs, this);
630         }
631 
632         if (result == null) {
633             Session session = null;
634 
635             try {
636                 session = openSession();
637 
638                 StringBuilder query = new StringBuilder();
639 
640                 query.append(
641                     "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
642 
643                 query.append("companyId = ?");
644 
645                 query.append(" ");
646 
647                 if (obc != null) {
648                     query.append("ORDER BY ");
649                     query.append(obc.getOrderBy());
650                 }
651 
652                 else {
653                     query.append("ORDER BY ");
654 
655                     query.append("priority ASC, ");
656                     query.append("name ASC");
657                 }
658 
659                 Query q = session.createQuery(query.toString());
660 
661                 QueryPos qPos = QueryPos.getInstance(q);
662 
663                 qPos.add(companyId);
664 
665                 List<SCFrameworkVersion> list = (List<SCFrameworkVersion>)QueryUtil.list(q,
666                         getDialect(), start, end);
667 
668                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
669                     finderClassName, finderMethodName, finderParams,
670                     finderArgs, list);
671 
672                 return list;
673             }
674             catch (Exception e) {
675                 throw processException(e);
676             }
677             finally {
678                 closeSession(session);
679             }
680         }
681         else {
682             return (List<SCFrameworkVersion>)result;
683         }
684     }
685 
686     public SCFrameworkVersion findByCompanyId_First(long companyId,
687         OrderByComparator obc)
688         throws NoSuchFrameworkVersionException, SystemException {
689         List<SCFrameworkVersion> list = findByCompanyId(companyId, 0, 1, obc);
690 
691         if (list.size() == 0) {
692             StringBuilder msg = new StringBuilder();
693 
694             msg.append("No SCFrameworkVersion exists with the key {");
695 
696             msg.append("companyId=" + companyId);
697 
698             msg.append(StringPool.CLOSE_CURLY_BRACE);
699 
700             throw new NoSuchFrameworkVersionException(msg.toString());
701         }
702         else {
703             return list.get(0);
704         }
705     }
706 
707     public SCFrameworkVersion findByCompanyId_Last(long companyId,
708         OrderByComparator obc)
709         throws NoSuchFrameworkVersionException, SystemException {
710         int count = countByCompanyId(companyId);
711 
712         List<SCFrameworkVersion> list = findByCompanyId(companyId, count - 1,
713                 count, obc);
714 
715         if (list.size() == 0) {
716             StringBuilder msg = new StringBuilder();
717 
718             msg.append("No SCFrameworkVersion exists with the key {");
719 
720             msg.append("companyId=" + companyId);
721 
722             msg.append(StringPool.CLOSE_CURLY_BRACE);
723 
724             throw new NoSuchFrameworkVersionException(msg.toString());
725         }
726         else {
727             return list.get(0);
728         }
729     }
730 
731     public SCFrameworkVersion[] findByCompanyId_PrevAndNext(
732         long frameworkVersionId, long companyId, OrderByComparator obc)
733         throws NoSuchFrameworkVersionException, SystemException {
734         SCFrameworkVersion scFrameworkVersion = findByPrimaryKey(frameworkVersionId);
735 
736         int count = countByCompanyId(companyId);
737 
738         Session session = null;
739 
740         try {
741             session = openSession();
742 
743             StringBuilder query = new StringBuilder();
744 
745             query.append(
746                 "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
747 
748             query.append("companyId = ?");
749 
750             query.append(" ");
751 
752             if (obc != null) {
753                 query.append("ORDER BY ");
754                 query.append(obc.getOrderBy());
755             }
756 
757             else {
758                 query.append("ORDER BY ");
759 
760                 query.append("priority ASC, ");
761                 query.append("name ASC");
762             }
763 
764             Query q = session.createQuery(query.toString());
765 
766             QueryPos qPos = QueryPos.getInstance(q);
767 
768             qPos.add(companyId);
769 
770             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
771                     scFrameworkVersion);
772 
773             SCFrameworkVersion[] array = new SCFrameworkVersionImpl[3];
774 
775             array[0] = (SCFrameworkVersion)objArray[0];
776             array[1] = (SCFrameworkVersion)objArray[1];
777             array[2] = (SCFrameworkVersion)objArray[2];
778 
779             return array;
780         }
781         catch (Exception e) {
782             throw processException(e);
783         }
784         finally {
785             closeSession(session);
786         }
787     }
788 
789     public List<SCFrameworkVersion> findByG_A(long groupId, boolean active)
790         throws SystemException {
791         boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
792         String finderClassName = SCFrameworkVersion.class.getName();
793         String finderMethodName = "findByG_A";
794         String[] finderParams = new String[] {
795                 Long.class.getName(), Boolean.class.getName()
796             };
797         Object[] finderArgs = new Object[] {
798                 new Long(groupId), Boolean.valueOf(active)
799             };
800 
801         Object result = null;
802 
803         if (finderClassNameCacheEnabled) {
804             result = FinderCacheUtil.getResult(finderClassName,
805                     finderMethodName, finderParams, finderArgs, this);
806         }
807 
808         if (result == null) {
809             Session session = null;
810 
811             try {
812                 session = openSession();
813 
814                 StringBuilder query = new StringBuilder();
815 
816                 query.append(
817                     "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
818 
819                 query.append("groupId = ?");
820 
821                 query.append(" AND ");
822 
823                 query.append("active_ = ?");
824 
825                 query.append(" ");
826 
827                 query.append("ORDER BY ");
828 
829                 query.append("priority ASC, ");
830                 query.append("name ASC");
831 
832                 Query q = session.createQuery(query.toString());
833 
834                 QueryPos qPos = QueryPos.getInstance(q);
835 
836                 qPos.add(groupId);
837 
838                 qPos.add(active);
839 
840                 List<SCFrameworkVersion> list = q.list();
841 
842                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
843                     finderClassName, finderMethodName, finderParams,
844                     finderArgs, list);
845 
846                 return list;
847             }
848             catch (Exception e) {
849                 throw processException(e);
850             }
851             finally {
852                 closeSession(session);
853             }
854         }
855         else {
856             return (List<SCFrameworkVersion>)result;
857         }
858     }
859 
860     public List<SCFrameworkVersion> findByG_A(long groupId, boolean active,
861         int start, int end) throws SystemException {
862         return findByG_A(groupId, active, start, end, null);
863     }
864 
865     public List<SCFrameworkVersion> findByG_A(long groupId, boolean active,
866         int start, int end, OrderByComparator obc) throws SystemException {
867         boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
868         String finderClassName = SCFrameworkVersion.class.getName();
869         String finderMethodName = "findByG_A";
870         String[] finderParams = new String[] {
871                 Long.class.getName(), Boolean.class.getName(),
872                 
873                 "java.lang.Integer", "java.lang.Integer",
874                 "com.liferay.portal.kernel.util.OrderByComparator"
875             };
876         Object[] finderArgs = new Object[] {
877                 new Long(groupId), Boolean.valueOf(active),
878                 
879                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
880             };
881 
882         Object result = null;
883 
884         if (finderClassNameCacheEnabled) {
885             result = FinderCacheUtil.getResult(finderClassName,
886                     finderMethodName, finderParams, finderArgs, this);
887         }
888 
889         if (result == null) {
890             Session session = null;
891 
892             try {
893                 session = openSession();
894 
895                 StringBuilder query = new StringBuilder();
896 
897                 query.append(
898                     "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
899 
900                 query.append("groupId = ?");
901 
902                 query.append(" AND ");
903 
904                 query.append("active_ = ?");
905 
906                 query.append(" ");
907 
908                 if (obc != null) {
909                     query.append("ORDER BY ");
910                     query.append(obc.getOrderBy());
911                 }
912 
913                 else {
914                     query.append("ORDER BY ");
915 
916                     query.append("priority ASC, ");
917                     query.append("name ASC");
918                 }
919 
920                 Query q = session.createQuery(query.toString());
921 
922                 QueryPos qPos = QueryPos.getInstance(q);
923 
924                 qPos.add(groupId);
925 
926                 qPos.add(active);
927 
928                 List<SCFrameworkVersion> list = (List<SCFrameworkVersion>)QueryUtil.list(q,
929                         getDialect(), start, end);
930 
931                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
932                     finderClassName, finderMethodName, finderParams,
933                     finderArgs, list);
934 
935                 return list;
936             }
937             catch (Exception e) {
938                 throw processException(e);
939             }
940             finally {
941                 closeSession(session);
942             }
943         }
944         else {
945             return (List<SCFrameworkVersion>)result;
946         }
947     }
948 
949     public SCFrameworkVersion findByG_A_First(long groupId, boolean active,
950         OrderByComparator obc)
951         throws NoSuchFrameworkVersionException, SystemException {
952         List<SCFrameworkVersion> list = findByG_A(groupId, active, 0, 1, obc);
953 
954         if (list.size() == 0) {
955             StringBuilder msg = new StringBuilder();
956 
957             msg.append("No SCFrameworkVersion exists with the key {");
958 
959             msg.append("groupId=" + groupId);
960 
961             msg.append(", ");
962             msg.append("active=" + active);
963 
964             msg.append(StringPool.CLOSE_CURLY_BRACE);
965 
966             throw new NoSuchFrameworkVersionException(msg.toString());
967         }
968         else {
969             return list.get(0);
970         }
971     }
972 
973     public SCFrameworkVersion findByG_A_Last(long groupId, boolean active,
974         OrderByComparator obc)
975         throws NoSuchFrameworkVersionException, SystemException {
976         int count = countByG_A(groupId, active);
977 
978         List<SCFrameworkVersion> list = findByG_A(groupId, active, count - 1,
979                 count, obc);
980 
981         if (list.size() == 0) {
982             StringBuilder msg = new StringBuilder();
983 
984             msg.append("No SCFrameworkVersion exists with the key {");
985 
986             msg.append("groupId=" + groupId);
987 
988             msg.append(", ");
989             msg.append("active=" + active);
990 
991             msg.append(StringPool.CLOSE_CURLY_BRACE);
992 
993             throw new NoSuchFrameworkVersionException(msg.toString());
994         }
995         else {
996             return list.get(0);
997         }
998     }
999 
1000    public SCFrameworkVersion[] findByG_A_PrevAndNext(long frameworkVersionId,
1001        long groupId, boolean active, OrderByComparator obc)
1002        throws NoSuchFrameworkVersionException, SystemException {
1003        SCFrameworkVersion scFrameworkVersion = findByPrimaryKey(frameworkVersionId);
1004
1005        int count = countByG_A(groupId, active);
1006
1007        Session session = null;
1008
1009        try {
1010            session = openSession();
1011
1012            StringBuilder query = new StringBuilder();
1013
1014            query.append(
1015                "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
1016
1017            query.append("groupId = ?");
1018
1019            query.append(" AND ");
1020
1021            query.append("active_ = ?");
1022
1023            query.append(" ");
1024
1025            if (obc != null) {
1026                query.append("ORDER BY ");
1027                query.append(obc.getOrderBy());
1028            }
1029
1030            else {
1031                query.append("ORDER BY ");
1032
1033                query.append("priority ASC, ");
1034                query.append("name ASC");
1035            }
1036
1037            Query q = session.createQuery(query.toString());
1038
1039            QueryPos qPos = QueryPos.getInstance(q);
1040
1041            qPos.add(groupId);
1042
1043            qPos.add(active);
1044
1045            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1046                    scFrameworkVersion);
1047
1048            SCFrameworkVersion[] array = new SCFrameworkVersionImpl[3];
1049
1050            array[0] = (SCFrameworkVersion)objArray[0];
1051            array[1] = (SCFrameworkVersion)objArray[1];
1052            array[2] = (SCFrameworkVersion)objArray[2];
1053
1054            return array;
1055        }
1056        catch (Exception e) {
1057            throw processException(e);
1058        }
1059        finally {
1060            closeSession(session);
1061        }
1062    }
1063
1064    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1065        throws SystemException {
1066        Session session = null;
1067
1068        try {
1069            session = openSession();
1070
1071            dynamicQuery.compile(session);
1072
1073            return dynamicQuery.list();
1074        }
1075        catch (Exception e) {
1076            throw processException(e);
1077        }
1078        finally {
1079            closeSession(session);
1080        }
1081    }
1082
1083    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1084        int start, int end) throws SystemException {
1085        Session session = null;
1086
1087        try {
1088            session = openSession();
1089
1090            dynamicQuery.setLimit(start, end);
1091
1092            dynamicQuery.compile(session);
1093
1094            return dynamicQuery.list();
1095        }
1096        catch (Exception e) {
1097            throw processException(e);
1098        }
1099        finally {
1100            closeSession(session);
1101        }
1102    }
1103
1104    public List<SCFrameworkVersion> findAll() throws SystemException {
1105        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1106    }
1107
1108    public List<SCFrameworkVersion> findAll(int start, int end)
1109        throws SystemException {
1110        return findAll(start, end, null);
1111    }
1112
1113    public List<SCFrameworkVersion> findAll(int start, int end,
1114        OrderByComparator obc) throws SystemException {
1115        boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
1116        String finderClassName = SCFrameworkVersion.class.getName();
1117        String finderMethodName = "findAll";
1118        String[] finderParams = new String[] {
1119                "java.lang.Integer", "java.lang.Integer",
1120                "com.liferay.portal.kernel.util.OrderByComparator"
1121            };
1122        Object[] finderArgs = new Object[] {
1123                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1124            };
1125
1126        Object result = null;
1127
1128        if (finderClassNameCacheEnabled) {
1129            result = FinderCacheUtil.getResult(finderClassName,
1130                    finderMethodName, finderParams, finderArgs, this);
1131        }
1132
1133        if (result == null) {
1134            Session session = null;
1135
1136            try {
1137                session = openSession();
1138
1139                StringBuilder query = new StringBuilder();
1140
1141                query.append(
1142                    "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion ");
1143
1144                if (obc != null) {
1145                    query.append("ORDER BY ");
1146                    query.append(obc.getOrderBy());
1147                }
1148
1149                else {
1150                    query.append("ORDER BY ");
1151
1152                    query.append("priority ASC, ");
1153                    query.append("name ASC");
1154                }
1155
1156                Query q = session.createQuery(query.toString());
1157
1158                List<SCFrameworkVersion> list = (List<SCFrameworkVersion>)QueryUtil.list(q,
1159                        getDialect(), start, end);
1160
1161                if (obc == null) {
1162                    Collections.sort(list);
1163                }
1164
1165                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1166                    finderClassName, finderMethodName, finderParams,
1167                    finderArgs, list);
1168
1169                return list;
1170            }
1171            catch (Exception e) {
1172                throw processException(e);
1173            }
1174            finally {
1175                closeSession(session);
1176            }
1177        }
1178        else {
1179            return (List<SCFrameworkVersion>)result;
1180        }
1181    }
1182
1183    public void removeByGroupId(long groupId) throws SystemException {
1184        for (SCFrameworkVersion scFrameworkVersion : findByGroupId(groupId)) {
1185            remove(scFrameworkVersion);
1186        }
1187    }
1188
1189    public void removeByCompanyId(long companyId) throws SystemException {
1190        for (SCFrameworkVersion scFrameworkVersion : findByCompanyId(companyId)) {
1191            remove(scFrameworkVersion);
1192        }
1193    }
1194
1195    public void removeByG_A(long groupId, boolean active)
1196        throws SystemException {
1197        for (SCFrameworkVersion scFrameworkVersion : findByG_A(groupId, active)) {
1198            remove(scFrameworkVersion);
1199        }
1200    }
1201
1202    public void removeAll() throws SystemException {
1203        for (SCFrameworkVersion scFrameworkVersion : findAll()) {
1204            remove(scFrameworkVersion);
1205        }
1206    }
1207
1208    public int countByGroupId(long groupId) throws SystemException {
1209        boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
1210        String finderClassName = SCFrameworkVersion.class.getName();
1211        String finderMethodName = "countByGroupId";
1212        String[] finderParams = new String[] { Long.class.getName() };
1213        Object[] finderArgs = new Object[] { new Long(groupId) };
1214
1215        Object result = null;
1216
1217        if (finderClassNameCacheEnabled) {
1218            result = FinderCacheUtil.getResult(finderClassName,
1219                    finderMethodName, finderParams, finderArgs, this);
1220        }
1221
1222        if (result == null) {
1223            Session session = null;
1224
1225            try {
1226                session = openSession();
1227
1228                StringBuilder query = new StringBuilder();
1229
1230                query.append("SELECT COUNT(*) ");
1231                query.append(
1232                    "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
1233
1234                query.append("groupId = ?");
1235
1236                query.append(" ");
1237
1238                Query q = session.createQuery(query.toString());
1239
1240                QueryPos qPos = QueryPos.getInstance(q);
1241
1242                qPos.add(groupId);
1243
1244                Long count = null;
1245
1246                Iterator<Long> itr = q.list().iterator();
1247
1248                if (itr.hasNext()) {
1249                    count = itr.next();
1250                }
1251
1252                if (count == null) {
1253                    count = new Long(0);
1254                }
1255
1256                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1257                    finderClassName, finderMethodName, finderParams,
1258                    finderArgs, count);
1259
1260                return count.intValue();
1261            }
1262            catch (Exception e) {
1263                throw processException(e);
1264            }
1265            finally {
1266                closeSession(session);
1267            }
1268        }
1269        else {
1270            return ((Long)result).intValue();
1271        }
1272    }
1273
1274    public int countByCompanyId(long companyId) throws SystemException {
1275        boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
1276        String finderClassName = SCFrameworkVersion.class.getName();
1277        String finderMethodName = "countByCompanyId";
1278        String[] finderParams = new String[] { Long.class.getName() };
1279        Object[] finderArgs = new Object[] { new Long(companyId) };
1280
1281        Object result = null;
1282
1283        if (finderClassNameCacheEnabled) {
1284            result = FinderCacheUtil.getResult(finderClassName,
1285                    finderMethodName, finderParams, finderArgs, this);
1286        }
1287
1288        if (result == null) {
1289            Session session = null;
1290
1291            try {
1292                session = openSession();
1293
1294                StringBuilder query = new StringBuilder();
1295
1296                query.append("SELECT COUNT(*) ");
1297                query.append(
1298                    "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
1299
1300                query.append("companyId = ?");
1301
1302                query.append(" ");
1303
1304                Query q = session.createQuery(query.toString());
1305
1306                QueryPos qPos = QueryPos.getInstance(q);
1307
1308                qPos.add(companyId);
1309
1310                Long count = null;
1311
1312                Iterator<Long> itr = q.list().iterator();
1313
1314                if (itr.hasNext()) {
1315                    count = itr.next();
1316                }
1317
1318                if (count == null) {
1319                    count = new Long(0);
1320                }
1321
1322                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1323                    finderClassName, finderMethodName, finderParams,
1324                    finderArgs, count);
1325
1326                return count.intValue();
1327            }
1328            catch (Exception e) {
1329                throw processException(e);
1330            }
1331            finally {
1332                closeSession(session);
1333            }
1334        }
1335        else {
1336            return ((Long)result).intValue();
1337        }
1338    }
1339
1340    public int countByG_A(long groupId, boolean active)
1341        throws SystemException {
1342        boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
1343        String finderClassName = SCFrameworkVersion.class.getName();
1344        String finderMethodName = "countByG_A";
1345        String[] finderParams = new String[] {
1346                Long.class.getName(), Boolean.class.getName()
1347            };
1348        Object[] finderArgs = new Object[] {
1349                new Long(groupId), Boolean.valueOf(active)
1350            };
1351
1352        Object result = null;
1353
1354        if (finderClassNameCacheEnabled) {
1355            result = FinderCacheUtil.getResult(finderClassName,
1356                    finderMethodName, finderParams, finderArgs, this);
1357        }
1358
1359        if (result == null) {
1360            Session session = null;
1361
1362            try {
1363                session = openSession();
1364
1365                StringBuilder query = new StringBuilder();
1366
1367                query.append("SELECT COUNT(*) ");
1368                query.append(
1369                    "FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion WHERE ");
1370
1371                query.append("groupId = ?");
1372
1373                query.append(" AND ");
1374
1375                query.append("active_ = ?");
1376
1377                query.append(" ");
1378
1379                Query q = session.createQuery(query.toString());
1380
1381                QueryPos qPos = QueryPos.getInstance(q);
1382
1383                qPos.add(groupId);
1384
1385                qPos.add(active);
1386
1387                Long count = null;
1388
1389                Iterator<Long> itr = q.list().iterator();
1390
1391                if (itr.hasNext()) {
1392                    count = itr.next();
1393                }
1394
1395                if (count == null) {
1396                    count = new Long(0);
1397                }
1398
1399                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1400                    finderClassName, finderMethodName, finderParams,
1401                    finderArgs, count);
1402
1403                return count.intValue();
1404            }
1405            catch (Exception e) {
1406                throw processException(e);
1407            }
1408            finally {
1409                closeSession(session);
1410            }
1411        }
1412        else {
1413            return ((Long)result).intValue();
1414        }
1415    }
1416
1417    public int countAll() throws SystemException {
1418        boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED;
1419        String finderClassName = SCFrameworkVersion.class.getName();
1420        String finderMethodName = "countAll";
1421        String[] finderParams = new String[] {  };
1422        Object[] finderArgs = new Object[] {  };
1423
1424        Object result = null;
1425
1426        if (finderClassNameCacheEnabled) {
1427            result = FinderCacheUtil.getResult(finderClassName,
1428                    finderMethodName, finderParams, finderArgs, this);
1429        }
1430
1431        if (result == null) {
1432            Session session = null;
1433
1434            try {
1435                session = openSession();
1436
1437                Query q = session.createQuery(
1438                        "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion");
1439
1440                Long count = null;
1441
1442                Iterator<Long> itr = q.list().iterator();
1443
1444                if (itr.hasNext()) {
1445                    count = itr.next();
1446                }
1447
1448                if (count == null) {
1449                    count = new Long(0);
1450                }
1451
1452                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1453                    finderClassName, finderMethodName, finderParams,
1454                    finderArgs, count);
1455
1456                return count.intValue();
1457            }
1458            catch (Exception e) {
1459                throw processException(e);
1460            }
1461            finally {
1462                closeSession(session);
1463            }
1464        }
1465        else {
1466            return ((Long)result).intValue();
1467        }
1468    }
1469
1470    public List<com.liferay.portlet.softwarecatalog.model.SCProductVersion> getSCProductVersions(
1471        long pk) throws SystemException {
1472        return getSCProductVersions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1473    }
1474
1475    public List<com.liferay.portlet.softwarecatalog.model.SCProductVersion> getSCProductVersions(
1476        long pk, int start, int end) throws SystemException {
1477        return getSCProductVersions(pk, start, end, null);
1478    }
1479
1480    public List<com.liferay.portlet.softwarecatalog.model.SCProductVersion> getSCProductVersions(
1481        long pk, int start, int end, OrderByComparator obc)
1482        throws SystemException {
1483        boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
1484
1485        String finderClassName = "SCFrameworkVersi_SCProductVers";
1486
1487        String finderMethodName = "getSCProductVersions";
1488        String[] finderParams = new String[] {
1489                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1490                "com.liferay.portal.kernel.util.OrderByComparator"
1491            };
1492        Object[] finderArgs = new Object[] {
1493                new Long(pk), String.valueOf(start), String.valueOf(end),
1494                String.valueOf(obc)
1495            };
1496
1497        Object result = null;
1498
1499        if (finderClassNameCacheEnabled) {
1500            result = FinderCacheUtil.getResult(finderClassName,
1501                    finderMethodName, finderParams, finderArgs, this);
1502        }
1503
1504        if (result == null) {
1505            Session session = null;
1506
1507            try {
1508                session = openSession();
1509
1510                StringBuilder sb = new StringBuilder();
1511
1512                sb.append(_SQL_GETSCPRODUCTVERSIONS);
1513
1514                if (obc != null) {
1515                    sb.append("ORDER BY ");
1516                    sb.append(obc.getOrderBy());
1517                }
1518
1519                else {
1520                    sb.append("ORDER BY ");
1521
1522                    sb.append("SCProductVersion.createDate DESC");
1523                }
1524
1525                String sql = sb.toString();
1526
1527                SQLQuery q = session.createSQLQuery(sql);
1528
1529                q.addEntity("SCProductVersion",
1530                    com.liferay.portlet.softwarecatalog.model.impl.SCProductVersionImpl.class);
1531
1532                QueryPos qPos = QueryPos.getInstance(q);
1533
1534                qPos.add(pk);
1535
1536                List<com.liferay.portlet.softwarecatalog.model.SCProductVersion> list =
1537                    (List<com.liferay.portlet.softwarecatalog.model.SCProductVersion>)QueryUtil.list(q,
1538                        getDialect(), start, end);
1539
1540                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1541                    finderClassName, finderMethodName, finderParams,
1542                    finderArgs, list);
1543
1544                return list;
1545            }
1546            catch (Exception e) {
1547                throw processException(e);
1548            }
1549            finally {
1550                closeSession(session);
1551            }
1552        }
1553        else {
1554            return (List<com.liferay.portlet.softwarecatalog.model.SCProductVersion>)result;
1555        }
1556    }
1557
1558    public int getSCProductVersionsSize(long pk) throws SystemException {
1559        boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
1560
1561        String finderClassName = "SCFrameworkVersi_SCProductVers";
1562
1563        String finderMethodName = "getSCProductVersionsSize";
1564        String[] finderParams = new String[] { Long.class.getName() };
1565        Object[] finderArgs = new Object[] { new Long(pk) };
1566
1567        Object result = null;
1568
1569        if (finderClassNameCacheEnabled) {
1570            result = FinderCacheUtil.getResult(finderClassName,
1571                    finderMethodName, finderParams, finderArgs, this);
1572        }
1573
1574        if (result == null) {
1575            Session session = null;
1576
1577            try {
1578                session = openSession();
1579
1580                SQLQuery q = session.createSQLQuery(_SQL_GETSCPRODUCTVERSIONSSIZE);
1581
1582                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1583
1584                QueryPos qPos = QueryPos.getInstance(q);
1585
1586                qPos.add(pk);
1587
1588                Long count = null;
1589
1590                Iterator<Long> itr = q.list().iterator();
1591
1592                if (itr.hasNext()) {
1593                    count = itr.next();
1594                }
1595
1596                if (count == null) {
1597                    count = new Long(0);
1598                }
1599
1600                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1601                    finderClassName, finderMethodName, finderParams,
1602                    finderArgs, count);
1603
1604                return count.intValue();
1605            }
1606            catch (Exception e) {
1607                throw processException(e);
1608            }
1609            finally {
1610                closeSession(session);
1611            }
1612        }
1613        else {
1614            return ((Long)result).intValue();
1615        }
1616    }
1617
1618    public boolean containsSCProductVersion(long pk, long scProductVersionPK)
1619        throws SystemException {
1620        boolean finderClassNameCacheEnabled = SCFrameworkVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
1621
1622        String finderClassName = "SCFrameworkVersi_SCProductVers";
1623
1624        String finderMethodName = "containsSCProductVersions";
1625        String[] finderParams = new String[] {
1626                Long.class.getName(),
1627                
1628                Long.class.getName()
1629            };
1630        Object[] finderArgs = new Object[] {
1631                new Long(pk),
1632                
1633                new Long(scProductVersionPK)
1634            };
1635
1636        Object result = null;
1637
1638        if (finderClassNameCacheEnabled) {
1639            result = FinderCacheUtil.getResult(finderClassName,
1640                    finderMethodName, finderParams, finderArgs, this);
1641        }
1642
1643        if (result == null) {
1644            try {
1645                Boolean value = Boolean.valueOf(containsSCProductVersion.contains(
1646                            pk, scProductVersionPK));
1647
1648                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1649                    finderClassName, finderMethodName, finderParams,
1650                    finderArgs, value);
1651
1652                return value.booleanValue();
1653            }
1654            catch (Exception e) {
1655                throw processException(e);
1656            }
1657        }
1658        else {
1659            return ((Boolean)result).booleanValue();
1660        }
1661    }
1662
1663    public boolean containsSCProductVersions(long pk) throws SystemException {
1664        if (getSCProductVersionsSize(pk) > 0) {
1665            return true;
1666        }
1667        else {
1668            return false;
1669        }
1670    }
1671
1672    public void addSCProductVersion(long pk, long scProductVersionPK)
1673        throws SystemException {
1674        try {
1675            addSCProductVersion.add(pk, scProductVersionPK);
1676        }
1677        catch (Exception e) {
1678            throw processException(e);
1679        }
1680        finally {
1681            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1682        }
1683    }
1684
1685    public void addSCProductVersion(long pk,
1686        com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion)
1687        throws SystemException {
1688        try {
1689            addSCProductVersion.add(pk, scProductVersion.getPrimaryKey());
1690        }
1691        catch (Exception e) {
1692            throw processException(e);
1693        }
1694        finally {
1695            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1696        }
1697    }
1698
1699    public void addSCProductVersions(long pk, long[] scProductVersionPKs)
1700        throws SystemException {
1701        try {
1702            for (long scProductVersionPK : scProductVersionPKs) {
1703                addSCProductVersion.add(pk, scProductVersionPK);
1704            }
1705        }
1706        catch (Exception e) {
1707            throw processException(e);
1708        }
1709        finally {
1710            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1711        }
1712    }
1713
1714    public void addSCProductVersions(long pk,
1715        List<com.liferay.portlet.softwarecatalog.model.SCProductVersion> scProductVersions)
1716        throws SystemException {
1717        try {
1718            for (com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion : scProductVersions) {
1719                addSCProductVersion.add(pk, scProductVersion.getPrimaryKey());
1720            }
1721        }
1722        catch (Exception e) {
1723            throw processException(e);
1724        }
1725        finally {
1726            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1727        }
1728    }
1729
1730    public void clearSCProductVersions(long pk) throws SystemException {
1731        try {
1732            clearSCProductVersions.clear(pk);
1733        }
1734        catch (Exception e) {
1735            throw processException(e);
1736        }
1737        finally {
1738            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1739        }
1740    }
1741
1742    public void removeSCProductVersion(long pk, long scProductVersionPK)
1743        throws SystemException {
1744        try {
1745            removeSCProductVersion.remove(pk, scProductVersionPK);
1746        }
1747        catch (Exception e) {
1748            throw processException(e);
1749        }
1750        finally {
1751            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1752        }
1753    }
1754
1755    public void removeSCProductVersion(long pk,
1756        com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion)
1757        throws SystemException {
1758        try {
1759            removeSCProductVersion.remove(pk, scProductVersion.getPrimaryKey());
1760        }
1761        catch (Exception e) {
1762            throw processException(e);
1763        }
1764        finally {
1765            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1766        }
1767    }
1768
1769    public void removeSCProductVersions(long pk, long[] scProductVersionPKs)
1770        throws SystemException {
1771        try {
1772            for (long scProductVersionPK : scProductVersionPKs) {
1773                removeSCProductVersion.remove(pk, scProductVersionPK);
1774            }
1775        }
1776        catch (Exception e) {
1777            throw processException(e);
1778        }
1779        finally {
1780            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1781        }
1782    }
1783
1784    public void removeSCProductVersions(long pk,
1785        List<com.liferay.portlet.softwarecatalog.model.SCProductVersion> scProductVersions)
1786        throws SystemException {
1787        try {
1788            for (com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion : scProductVersions) {
1789                removeSCProductVersion.remove(pk,
1790                    scProductVersion.getPrimaryKey());
1791            }
1792        }
1793        catch (Exception e) {
1794            throw processException(e);
1795        }
1796        finally {
1797            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1798        }
1799    }
1800
1801    public void setSCProductVersions(long pk, long[] scProductVersionPKs)
1802        throws SystemException {
1803        try {
1804            clearSCProductVersions.clear(pk);
1805
1806            for (long scProductVersionPK : scProductVersionPKs) {
1807                addSCProductVersion.add(pk, scProductVersionPK);
1808            }
1809        }
1810        catch (Exception e) {
1811            throw processException(e);
1812        }
1813        finally {
1814            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1815        }
1816    }
1817
1818    public void setSCProductVersions(long pk,
1819        List<com.liferay.portlet.softwarecatalog.model.SCProductVersion> scProductVersions)
1820        throws SystemException {
1821        try {
1822            clearSCProductVersions.clear(pk);
1823
1824            for (com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion : scProductVersions) {
1825                addSCProductVersion.add(pk, scProductVersion.getPrimaryKey());
1826            }
1827        }
1828        catch (Exception e) {
1829            throw processException(e);
1830        }
1831        finally {
1832            FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1833        }
1834    }
1835
1836    public void registerListener(ModelListener listener) {
1837        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1838
1839        listeners.add(listener);
1840
1841        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1842    }
1843
1844    public void unregisterListener(ModelListener listener) {
1845        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1846
1847        listeners.remove(listener);
1848
1849        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1850    }
1851
1852    public void afterPropertiesSet() {
1853        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1854                    com.liferay.portal.util.PropsUtil.get(
1855                        "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion")));
1856
1857        if (listenerClassNames.length > 0) {
1858            try {
1859                List<ModelListener> listeners = new ArrayList<ModelListener>();
1860
1861                for (String listenerClassName : listenerClassNames) {
1862                    listeners.add((ModelListener)Class.forName(
1863                            listenerClassName).newInstance());
1864                }
1865
1866                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1867            }
1868            catch (Exception e) {
1869                _log.error(e);
1870            }
1871        }
1872
1873        containsSCProductVersion = new ContainsSCProductVersion(this);
1874
1875        addSCProductVersion = new AddSCProductVersion(this);
1876        clearSCProductVersions = new ClearSCProductVersions(this);
1877        removeSCProductVersion = new RemoveSCProductVersion(this);
1878    }
1879
1880    protected ContainsSCProductVersion containsSCProductVersion;
1881    protected AddSCProductVersion addSCProductVersion;
1882    protected ClearSCProductVersions clearSCProductVersions;
1883    protected RemoveSCProductVersion removeSCProductVersion;
1884
1885    protected class ContainsSCProductVersion {
1886        protected ContainsSCProductVersion(
1887            SCFrameworkVersionPersistenceImpl persistenceImpl) {
1888            super();
1889
1890            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1891                    _SQL_CONTAINSSCPRODUCTVERSION,
1892                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1893        }
1894
1895        protected boolean contains(long frameworkVersionId,
1896            long productVersionId) {
1897            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1898                        new Long(frameworkVersionId), new Long(productVersionId)
1899                    });
1900
1901            if (results.size() > 0) {
1902                Integer count = results.get(0);
1903
1904                if (count.intValue() > 0) {
1905                    return true;
1906                }
1907            }
1908
1909            return false;
1910        }
1911
1912        private MappingSqlQuery _mappingSqlQuery;
1913    }
1914
1915    protected class AddSCProductVersion {
1916        protected AddSCProductVersion(
1917            SCFrameworkVersionPersistenceImpl persistenceImpl) {
1918            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1919                    "INSERT INTO SCFrameworkVersi_SCProductVers (frameworkVersionId, productVersionId) VALUES (?, ?)",
1920                    new int[] { Types.BIGINT, Types.BIGINT });
1921            _persistenceImpl = persistenceImpl;
1922        }
1923
1924        protected void add(long frameworkVersionId, long productVersionId) {
1925            if (!_persistenceImpl.containsSCProductVersion.contains(
1926                        frameworkVersionId, productVersionId)) {
1927                _sqlUpdate.update(new Object[] {
1928                        new Long(frameworkVersionId), new Long(productVersionId)
1929                    });
1930            }
1931        }
1932
1933        private SqlUpdate _sqlUpdate;
1934        private SCFrameworkVersionPersistenceImpl _persistenceImpl;
1935    }
1936
1937    protected class ClearSCProductVersions {
1938        protected ClearSCProductVersions(
1939            SCFrameworkVersionPersistenceImpl persistenceImpl) {
1940            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1941                    "DELETE FROM SCFrameworkVersi_SCProductVers WHERE frameworkVersionId = ?",
1942                    new int[] { Types.BIGINT });
1943        }
1944
1945        protected void clear(long frameworkVersionId) {
1946            _sqlUpdate.update(new Object[] { new Long(frameworkVersionId) });
1947        }
1948
1949        private SqlUpdate _sqlUpdate;
1950    }
1951
1952    protected class RemoveSCProductVersion {
1953        protected RemoveSCProductVersion(
1954            SCFrameworkVersionPersistenceImpl persistenceImpl) {
1955            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1956                    "DELETE FROM SCFrameworkVersi_SCProductVers WHERE frameworkVersionId = ? AND productVersionId = ?",
1957                    new int[] { Types.BIGINT, Types.BIGINT });
1958        }
1959
1960        protected void remove(long frameworkVersionId, long productVersionId) {
1961            _sqlUpdate.update(new Object[] {
1962                    new Long(frameworkVersionId), new Long(productVersionId)
1963                });
1964        }
1965
1966        private SqlUpdate _sqlUpdate;
1967    }
1968
1969    private static final String _SQL_GETSCPRODUCTVERSIONS = "SELECT {SCProductVersion.*} FROM SCProductVersion INNER JOIN SCFrameworkVersi_SCProductVers ON (SCFrameworkVersi_SCProductVers.productVersionId = SCProductVersion.productVersionId) WHERE (SCFrameworkVersi_SCProductVers.frameworkVersionId = ?)";
1970    private static final String _SQL_GETSCPRODUCTVERSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE frameworkVersionId = ?";
1971    private static final String _SQL_CONTAINSSCPRODUCTVERSION = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE frameworkVersionId = ? AND productVersionId = ?";
1972    private static Log _log = LogFactory.getLog(SCFrameworkVersionPersistenceImpl.class);
1973    private ModelListener[] _listeners = new ModelListener[0];
1974}