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