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