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