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