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