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