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