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