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