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