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