001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.softwarecatalog.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ImagePersistence;
039    import com.liferay.portal.service.persistence.ResourcePersistence;
040    import com.liferay.portal.service.persistence.UserPersistence;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException;
044    import com.liferay.portlet.softwarecatalog.model.SCProductScreenshot;
045    import com.liferay.portlet.softwarecatalog.model.impl.SCProductScreenshotImpl;
046    import com.liferay.portlet.softwarecatalog.model.impl.SCProductScreenshotModelImpl;
047    
048    import java.io.Serializable;
049    
050    import java.util.ArrayList;
051    import java.util.Collections;
052    import java.util.List;
053    
054    /**
055     * @author    Brian Wing Shun Chan
056     * @see       SCProductScreenshotPersistence
057     * @see       SCProductScreenshotUtil
058     * @generated
059     */
060    public class SCProductScreenshotPersistenceImpl extends BasePersistenceImpl<SCProductScreenshot>
061            implements SCProductScreenshotPersistence {
062            public static final String FINDER_CLASS_NAME_ENTITY = SCProductScreenshotImpl.class.getName();
063            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
064                    ".List";
065            public static final FinderPath FINDER_PATH_FIND_BY_PRODUCTENTRYID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
066                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
067                            FINDER_CLASS_NAME_LIST, "findByProductEntryId",
068                            new String[] {
069                                    Long.class.getName(),
070                                    
071                            "java.lang.Integer", "java.lang.Integer",
072                                    "com.liferay.portal.kernel.util.OrderByComparator"
073                            });
074            public static final FinderPath FINDER_PATH_COUNT_BY_PRODUCTENTRYID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
075                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_LIST, "countByProductEntryId",
077                            new String[] { Long.class.getName() });
078            public static final FinderPath FINDER_PATH_FETCH_BY_THUMBNAILID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
079                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
080                            FINDER_CLASS_NAME_ENTITY, "fetchByThumbnailId",
081                            new String[] { Long.class.getName() });
082            public static final FinderPath FINDER_PATH_COUNT_BY_THUMBNAILID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
083                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
084                            FINDER_CLASS_NAME_LIST, "countByThumbnailId",
085                            new String[] { Long.class.getName() });
086            public static final FinderPath FINDER_PATH_FETCH_BY_FULLIMAGEID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
087                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
088                            FINDER_CLASS_NAME_ENTITY, "fetchByFullImageId",
089                            new String[] { Long.class.getName() });
090            public static final FinderPath FINDER_PATH_COUNT_BY_FULLIMAGEID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
091                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
092                            FINDER_CLASS_NAME_LIST, "countByFullImageId",
093                            new String[] { Long.class.getName() });
094            public static final FinderPath FINDER_PATH_FETCH_BY_P_P = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
095                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
096                            FINDER_CLASS_NAME_ENTITY, "fetchByP_P",
097                            new String[] { Long.class.getName(), Integer.class.getName() });
098            public static final FinderPath FINDER_PATH_COUNT_BY_P_P = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
099                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
100                            FINDER_CLASS_NAME_LIST, "countByP_P",
101                            new String[] { Long.class.getName(), Integer.class.getName() });
102            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
103                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
104                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
105            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
106                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
108    
109            public void cacheResult(SCProductScreenshot scProductScreenshot) {
110                    EntityCacheUtil.putResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
111                            SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey(),
112                            scProductScreenshot);
113    
114                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
115                            new Object[] { new Long(scProductScreenshot.getThumbnailId()) },
116                            scProductScreenshot);
117    
118                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
119                            new Object[] { new Long(scProductScreenshot.getFullImageId()) },
120                            scProductScreenshot);
121    
122                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
123                            new Object[] {
124                                    new Long(scProductScreenshot.getProductEntryId()),
125                                    new Integer(scProductScreenshot.getPriority())
126                            }, scProductScreenshot);
127            }
128    
129            public void cacheResult(List<SCProductScreenshot> scProductScreenshots) {
130                    for (SCProductScreenshot scProductScreenshot : scProductScreenshots) {
131                            if (EntityCacheUtil.getResult(
132                                                    SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
133                                                    SCProductScreenshotImpl.class,
134                                                    scProductScreenshot.getPrimaryKey(), this) == null) {
135                                    cacheResult(scProductScreenshot);
136                            }
137                    }
138            }
139    
140            public void clearCache() {
141                    CacheRegistryUtil.clear(SCProductScreenshotImpl.class.getName());
142                    EntityCacheUtil.clearCache(SCProductScreenshotImpl.class.getName());
143                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
144                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
145            }
146    
147            public void clearCache(SCProductScreenshot scProductScreenshot) {
148                    EntityCacheUtil.removeResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
149                            SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey());
150    
151                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
152                            new Object[] { new Long(scProductScreenshot.getThumbnailId()) });
153    
154                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
155                            new Object[] { new Long(scProductScreenshot.getFullImageId()) });
156    
157                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P,
158                            new Object[] {
159                                    new Long(scProductScreenshot.getProductEntryId()),
160                                    new Integer(scProductScreenshot.getPriority())
161                            });
162            }
163    
164            public SCProductScreenshot create(long productScreenshotId) {
165                    SCProductScreenshot scProductScreenshot = new SCProductScreenshotImpl();
166    
167                    scProductScreenshot.setNew(true);
168                    scProductScreenshot.setPrimaryKey(productScreenshotId);
169    
170                    return scProductScreenshot;
171            }
172    
173            public SCProductScreenshot remove(Serializable primaryKey)
174                    throws NoSuchModelException, SystemException {
175                    return remove(((Long)primaryKey).longValue());
176            }
177    
178            public SCProductScreenshot remove(long productScreenshotId)
179                    throws NoSuchProductScreenshotException, SystemException {
180                    Session session = null;
181    
182                    try {
183                            session = openSession();
184    
185                            SCProductScreenshot scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
186                                            new Long(productScreenshotId));
187    
188                            if (scProductScreenshot == null) {
189                                    if (_log.isWarnEnabled()) {
190                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
191                                                    productScreenshotId);
192                                    }
193    
194                                    throw new NoSuchProductScreenshotException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
195                                            productScreenshotId);
196                            }
197    
198                            return remove(scProductScreenshot);
199                    }
200                    catch (NoSuchProductScreenshotException nsee) {
201                            throw nsee;
202                    }
203                    catch (Exception e) {
204                            throw processException(e);
205                    }
206                    finally {
207                            closeSession(session);
208                    }
209            }
210    
211            protected SCProductScreenshot removeImpl(
212                    SCProductScreenshot scProductScreenshot) throws SystemException {
213                    scProductScreenshot = toUnwrappedModel(scProductScreenshot);
214    
215                    Session session = null;
216    
217                    try {
218                            session = openSession();
219    
220                            if (scProductScreenshot.isCachedModel() ||
221                                            BatchSessionUtil.isEnabled()) {
222                                    Object staleObject = session.get(SCProductScreenshotImpl.class,
223                                                    scProductScreenshot.getPrimaryKeyObj());
224    
225                                    if (staleObject != null) {
226                                            session.evict(staleObject);
227                                    }
228                            }
229    
230                            session.delete(scProductScreenshot);
231    
232                            session.flush();
233                    }
234                    catch (Exception e) {
235                            throw processException(e);
236                    }
237                    finally {
238                            closeSession(session);
239                    }
240    
241                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
242    
243                    SCProductScreenshotModelImpl scProductScreenshotModelImpl = (SCProductScreenshotModelImpl)scProductScreenshot;
244    
245                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
246                            new Object[] {
247                                    new Long(scProductScreenshotModelImpl.getOriginalThumbnailId())
248                            });
249    
250                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
251                            new Object[] {
252                                    new Long(scProductScreenshotModelImpl.getOriginalFullImageId())
253                            });
254    
255                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P,
256                            new Object[] {
257                                    new Long(scProductScreenshotModelImpl.getOriginalProductEntryId()),
258                                    new Integer(scProductScreenshotModelImpl.getOriginalPriority())
259                            });
260    
261                    EntityCacheUtil.removeResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
262                            SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey());
263    
264                    return scProductScreenshot;
265            }
266    
267            public SCProductScreenshot updateImpl(
268                    com.liferay.portlet.softwarecatalog.model.SCProductScreenshot scProductScreenshot,
269                    boolean merge) throws SystemException {
270                    scProductScreenshot = toUnwrappedModel(scProductScreenshot);
271    
272                    boolean isNew = scProductScreenshot.isNew();
273    
274                    SCProductScreenshotModelImpl scProductScreenshotModelImpl = (SCProductScreenshotModelImpl)scProductScreenshot;
275    
276                    Session session = null;
277    
278                    try {
279                            session = openSession();
280    
281                            BatchSessionUtil.update(session, scProductScreenshot, merge);
282    
283                            scProductScreenshot.setNew(false);
284                    }
285                    catch (Exception e) {
286                            throw processException(e);
287                    }
288                    finally {
289                            closeSession(session);
290                    }
291    
292                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
293    
294                    EntityCacheUtil.putResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
295                            SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey(),
296                            scProductScreenshot);
297    
298                    if (!isNew &&
299                                    (scProductScreenshot.getThumbnailId() != scProductScreenshotModelImpl.getOriginalThumbnailId())) {
300                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
301                                    new Object[] {
302                                            new Long(scProductScreenshotModelImpl.getOriginalThumbnailId())
303                                    });
304                    }
305    
306                    if (isNew ||
307                                    (scProductScreenshot.getThumbnailId() != scProductScreenshotModelImpl.getOriginalThumbnailId())) {
308                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
309                                    new Object[] { new Long(scProductScreenshot.getThumbnailId()) },
310                                    scProductScreenshot);
311                    }
312    
313                    if (!isNew &&
314                                    (scProductScreenshot.getFullImageId() != scProductScreenshotModelImpl.getOriginalFullImageId())) {
315                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
316                                    new Object[] {
317                                            new Long(scProductScreenshotModelImpl.getOriginalFullImageId())
318                                    });
319                    }
320    
321                    if (isNew ||
322                                    (scProductScreenshot.getFullImageId() != scProductScreenshotModelImpl.getOriginalFullImageId())) {
323                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
324                                    new Object[] { new Long(scProductScreenshot.getFullImageId()) },
325                                    scProductScreenshot);
326                    }
327    
328                    if (!isNew &&
329                                    ((scProductScreenshot.getProductEntryId() != scProductScreenshotModelImpl.getOriginalProductEntryId()) ||
330                                    (scProductScreenshot.getPriority() != scProductScreenshotModelImpl.getOriginalPriority()))) {
331                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P,
332                                    new Object[] {
333                                            new Long(scProductScreenshotModelImpl.getOriginalProductEntryId()),
334                                            new Integer(scProductScreenshotModelImpl.getOriginalPriority())
335                                    });
336                    }
337    
338                    if (isNew ||
339                                    ((scProductScreenshot.getProductEntryId() != scProductScreenshotModelImpl.getOriginalProductEntryId()) ||
340                                    (scProductScreenshot.getPriority() != scProductScreenshotModelImpl.getOriginalPriority()))) {
341                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
342                                    new Object[] {
343                                            new Long(scProductScreenshot.getProductEntryId()),
344                                            new Integer(scProductScreenshot.getPriority())
345                                    }, scProductScreenshot);
346                    }
347    
348                    return scProductScreenshot;
349            }
350    
351            protected SCProductScreenshot toUnwrappedModel(
352                    SCProductScreenshot scProductScreenshot) {
353                    if (scProductScreenshot instanceof SCProductScreenshotImpl) {
354                            return scProductScreenshot;
355                    }
356    
357                    SCProductScreenshotImpl scProductScreenshotImpl = new SCProductScreenshotImpl();
358    
359                    scProductScreenshotImpl.setNew(scProductScreenshot.isNew());
360                    scProductScreenshotImpl.setPrimaryKey(scProductScreenshot.getPrimaryKey());
361    
362                    scProductScreenshotImpl.setProductScreenshotId(scProductScreenshot.getProductScreenshotId());
363                    scProductScreenshotImpl.setCompanyId(scProductScreenshot.getCompanyId());
364                    scProductScreenshotImpl.setGroupId(scProductScreenshot.getGroupId());
365                    scProductScreenshotImpl.setProductEntryId(scProductScreenshot.getProductEntryId());
366                    scProductScreenshotImpl.setThumbnailId(scProductScreenshot.getThumbnailId());
367                    scProductScreenshotImpl.setFullImageId(scProductScreenshot.getFullImageId());
368                    scProductScreenshotImpl.setPriority(scProductScreenshot.getPriority());
369    
370                    return scProductScreenshotImpl;
371            }
372    
373            public SCProductScreenshot findByPrimaryKey(Serializable primaryKey)
374                    throws NoSuchModelException, SystemException {
375                    return findByPrimaryKey(((Long)primaryKey).longValue());
376            }
377    
378            public SCProductScreenshot findByPrimaryKey(long productScreenshotId)
379                    throws NoSuchProductScreenshotException, SystemException {
380                    SCProductScreenshot scProductScreenshot = fetchByPrimaryKey(productScreenshotId);
381    
382                    if (scProductScreenshot == null) {
383                            if (_log.isWarnEnabled()) {
384                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
385                                            productScreenshotId);
386                            }
387    
388                            throw new NoSuchProductScreenshotException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
389                                    productScreenshotId);
390                    }
391    
392                    return scProductScreenshot;
393            }
394    
395            public SCProductScreenshot fetchByPrimaryKey(Serializable primaryKey)
396                    throws SystemException {
397                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
398            }
399    
400            public SCProductScreenshot fetchByPrimaryKey(long productScreenshotId)
401                    throws SystemException {
402                    SCProductScreenshot scProductScreenshot = (SCProductScreenshot)EntityCacheUtil.getResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
403                                    SCProductScreenshotImpl.class, productScreenshotId, this);
404    
405                    if (scProductScreenshot == null) {
406                            Session session = null;
407    
408                            try {
409                                    session = openSession();
410    
411                                    scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
412                                                    new Long(productScreenshotId));
413                            }
414                            catch (Exception e) {
415                                    throw processException(e);
416                            }
417                            finally {
418                                    if (scProductScreenshot != null) {
419                                            cacheResult(scProductScreenshot);
420                                    }
421    
422                                    closeSession(session);
423                            }
424                    }
425    
426                    return scProductScreenshot;
427            }
428    
429            public List<SCProductScreenshot> findByProductEntryId(long productEntryId)
430                    throws SystemException {
431                    return findByProductEntryId(productEntryId, QueryUtil.ALL_POS,
432                            QueryUtil.ALL_POS, null);
433            }
434    
435            public List<SCProductScreenshot> findByProductEntryId(long productEntryId,
436                    int start, int end) throws SystemException {
437                    return findByProductEntryId(productEntryId, start, end, null);
438            }
439    
440            public List<SCProductScreenshot> findByProductEntryId(long productEntryId,
441                    int start, int end, OrderByComparator orderByComparator)
442                    throws SystemException {
443                    Object[] finderArgs = new Object[] {
444                                    productEntryId,
445                                    
446                                    String.valueOf(start), String.valueOf(end),
447                                    String.valueOf(orderByComparator)
448                            };
449    
450                    List<SCProductScreenshot> list = (List<SCProductScreenshot>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
451                                    finderArgs, this);
452    
453                    if (list == null) {
454                            Session session = null;
455    
456                            try {
457                                    session = openSession();
458    
459                                    StringBundler query = null;
460    
461                                    if (orderByComparator != null) {
462                                            query = new StringBundler(3 +
463                                                            (orderByComparator.getOrderByFields().length * 3));
464                                    }
465                                    else {
466                                            query = new StringBundler(3);
467                                    }
468    
469                                    query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
470    
471                                    query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
472    
473                                    if (orderByComparator != null) {
474                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
475                                                    orderByComparator);
476                                    }
477    
478                                    else {
479                                            query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
480                                    }
481    
482                                    String sql = query.toString();
483    
484                                    Query q = session.createQuery(sql);
485    
486                                    QueryPos qPos = QueryPos.getInstance(q);
487    
488                                    qPos.add(productEntryId);
489    
490                                    list = (List<SCProductScreenshot>)QueryUtil.list(q,
491                                                    getDialect(), start, end);
492                            }
493                            catch (Exception e) {
494                                    throw processException(e);
495                            }
496                            finally {
497                                    if (list == null) {
498                                            list = new ArrayList<SCProductScreenshot>();
499                                    }
500    
501                                    cacheResult(list);
502    
503                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
504                                            finderArgs, list);
505    
506                                    closeSession(session);
507                            }
508                    }
509    
510                    return list;
511            }
512    
513            public SCProductScreenshot findByProductEntryId_First(long productEntryId,
514                    OrderByComparator orderByComparator)
515                    throws NoSuchProductScreenshotException, SystemException {
516                    List<SCProductScreenshot> list = findByProductEntryId(productEntryId,
517                                    0, 1, orderByComparator);
518    
519                    if (list.isEmpty()) {
520                            StringBundler msg = new StringBundler(4);
521    
522                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
523    
524                            msg.append("productEntryId=");
525                            msg.append(productEntryId);
526    
527                            msg.append(StringPool.CLOSE_CURLY_BRACE);
528    
529                            throw new NoSuchProductScreenshotException(msg.toString());
530                    }
531                    else {
532                            return list.get(0);
533                    }
534            }
535    
536            public SCProductScreenshot findByProductEntryId_Last(long productEntryId,
537                    OrderByComparator orderByComparator)
538                    throws NoSuchProductScreenshotException, SystemException {
539                    int count = countByProductEntryId(productEntryId);
540    
541                    List<SCProductScreenshot> list = findByProductEntryId(productEntryId,
542                                    count - 1, count, orderByComparator);
543    
544                    if (list.isEmpty()) {
545                            StringBundler msg = new StringBundler(4);
546    
547                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
548    
549                            msg.append("productEntryId=");
550                            msg.append(productEntryId);
551    
552                            msg.append(StringPool.CLOSE_CURLY_BRACE);
553    
554                            throw new NoSuchProductScreenshotException(msg.toString());
555                    }
556                    else {
557                            return list.get(0);
558                    }
559            }
560    
561            public SCProductScreenshot[] findByProductEntryId_PrevAndNext(
562                    long productScreenshotId, long productEntryId,
563                    OrderByComparator orderByComparator)
564                    throws NoSuchProductScreenshotException, SystemException {
565                    SCProductScreenshot scProductScreenshot = findByPrimaryKey(productScreenshotId);
566    
567                    Session session = null;
568    
569                    try {
570                            session = openSession();
571    
572                            SCProductScreenshot[] array = new SCProductScreenshotImpl[3];
573    
574                            array[0] = getByProductEntryId_PrevAndNext(session,
575                                            scProductScreenshot, productEntryId, orderByComparator, true);
576    
577                            array[1] = scProductScreenshot;
578    
579                            array[2] = getByProductEntryId_PrevAndNext(session,
580                                            scProductScreenshot, productEntryId, orderByComparator,
581                                            false);
582    
583                            return array;
584                    }
585                    catch (Exception e) {
586                            throw processException(e);
587                    }
588                    finally {
589                            closeSession(session);
590                    }
591            }
592    
593            protected SCProductScreenshot getByProductEntryId_PrevAndNext(
594                    Session session, SCProductScreenshot scProductScreenshot,
595                    long productEntryId, OrderByComparator orderByComparator,
596                    boolean previous) {
597                    StringBundler query = null;
598    
599                    if (orderByComparator != null) {
600                            query = new StringBundler(6 +
601                                            (orderByComparator.getOrderByFields().length * 6));
602                    }
603                    else {
604                            query = new StringBundler(3);
605                    }
606    
607                    query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
608    
609                    query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
610    
611                    if (orderByComparator != null) {
612                            String[] orderByFields = orderByComparator.getOrderByFields();
613    
614                            if (orderByFields.length > 0) {
615                                    query.append(WHERE_AND);
616                            }
617    
618                            for (int i = 0; i < orderByFields.length; i++) {
619                                    query.append(_ORDER_BY_ENTITY_ALIAS);
620                                    query.append(orderByFields[i]);
621    
622                                    if ((i + 1) < orderByFields.length) {
623                                            if (orderByComparator.isAscending() ^ previous) {
624                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
625                                            }
626                                            else {
627                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
628                                            }
629                                    }
630                                    else {
631                                            if (orderByComparator.isAscending() ^ previous) {
632                                                    query.append(WHERE_GREATER_THAN);
633                                            }
634                                            else {
635                                                    query.append(WHERE_LESSER_THAN);
636                                            }
637                                    }
638                            }
639    
640                            query.append(ORDER_BY_CLAUSE);
641    
642                            for (int i = 0; i < orderByFields.length; i++) {
643                                    query.append(_ORDER_BY_ENTITY_ALIAS);
644                                    query.append(orderByFields[i]);
645    
646                                    if ((i + 1) < orderByFields.length) {
647                                            if (orderByComparator.isAscending() ^ previous) {
648                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
649                                            }
650                                            else {
651                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
652                                            }
653                                    }
654                                    else {
655                                            if (orderByComparator.isAscending() ^ previous) {
656                                                    query.append(ORDER_BY_ASC);
657                                            }
658                                            else {
659                                                    query.append(ORDER_BY_DESC);
660                                            }
661                                    }
662                            }
663                    }
664    
665                    else {
666                            query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
667                    }
668    
669                    String sql = query.toString();
670    
671                    Query q = session.createQuery(sql);
672    
673                    q.setFirstResult(0);
674                    q.setMaxResults(2);
675    
676                    QueryPos qPos = QueryPos.getInstance(q);
677    
678                    qPos.add(productEntryId);
679    
680                    if (orderByComparator != null) {
681                            Object[] values = orderByComparator.getOrderByValues(scProductScreenshot);
682    
683                            for (Object value : values) {
684                                    qPos.add(value);
685                            }
686                    }
687    
688                    List<SCProductScreenshot> list = q.list();
689    
690                    if (list.size() == 2) {
691                            return list.get(1);
692                    }
693                    else {
694                            return null;
695                    }
696            }
697    
698            public SCProductScreenshot findByThumbnailId(long thumbnailId)
699                    throws NoSuchProductScreenshotException, SystemException {
700                    SCProductScreenshot scProductScreenshot = fetchByThumbnailId(thumbnailId);
701    
702                    if (scProductScreenshot == null) {
703                            StringBundler msg = new StringBundler(4);
704    
705                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
706    
707                            msg.append("thumbnailId=");
708                            msg.append(thumbnailId);
709    
710                            msg.append(StringPool.CLOSE_CURLY_BRACE);
711    
712                            if (_log.isWarnEnabled()) {
713                                    _log.warn(msg.toString());
714                            }
715    
716                            throw new NoSuchProductScreenshotException(msg.toString());
717                    }
718    
719                    return scProductScreenshot;
720            }
721    
722            public SCProductScreenshot fetchByThumbnailId(long thumbnailId)
723                    throws SystemException {
724                    return fetchByThumbnailId(thumbnailId, true);
725            }
726    
727            public SCProductScreenshot fetchByThumbnailId(long thumbnailId,
728                    boolean retrieveFromCache) throws SystemException {
729                    Object[] finderArgs = new Object[] { thumbnailId };
730    
731                    Object result = null;
732    
733                    if (retrieveFromCache) {
734                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
735                                            finderArgs, this);
736                    }
737    
738                    if (result == null) {
739                            Session session = null;
740    
741                            try {
742                                    session = openSession();
743    
744                                    StringBundler query = new StringBundler(3);
745    
746                                    query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
747    
748                                    query.append(_FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2);
749    
750                                    query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
751    
752                                    String sql = query.toString();
753    
754                                    Query q = session.createQuery(sql);
755    
756                                    QueryPos qPos = QueryPos.getInstance(q);
757    
758                                    qPos.add(thumbnailId);
759    
760                                    List<SCProductScreenshot> list = q.list();
761    
762                                    result = list;
763    
764                                    SCProductScreenshot scProductScreenshot = null;
765    
766                                    if (list.isEmpty()) {
767                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
768                                                    finderArgs, list);
769                                    }
770                                    else {
771                                            scProductScreenshot = list.get(0);
772    
773                                            cacheResult(scProductScreenshot);
774    
775                                            if ((scProductScreenshot.getThumbnailId() != thumbnailId)) {
776                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
777                                                            finderArgs, scProductScreenshot);
778                                            }
779                                    }
780    
781                                    return scProductScreenshot;
782                            }
783                            catch (Exception e) {
784                                    throw processException(e);
785                            }
786                            finally {
787                                    if (result == null) {
788                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
789                                                    finderArgs, new ArrayList<SCProductScreenshot>());
790                                    }
791    
792                                    closeSession(session);
793                            }
794                    }
795                    else {
796                            if (result instanceof List<?>) {
797                                    return null;
798                            }
799                            else {
800                                    return (SCProductScreenshot)result;
801                            }
802                    }
803            }
804    
805            public SCProductScreenshot findByFullImageId(long fullImageId)
806                    throws NoSuchProductScreenshotException, SystemException {
807                    SCProductScreenshot scProductScreenshot = fetchByFullImageId(fullImageId);
808    
809                    if (scProductScreenshot == null) {
810                            StringBundler msg = new StringBundler(4);
811    
812                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
813    
814                            msg.append("fullImageId=");
815                            msg.append(fullImageId);
816    
817                            msg.append(StringPool.CLOSE_CURLY_BRACE);
818    
819                            if (_log.isWarnEnabled()) {
820                                    _log.warn(msg.toString());
821                            }
822    
823                            throw new NoSuchProductScreenshotException(msg.toString());
824                    }
825    
826                    return scProductScreenshot;
827            }
828    
829            public SCProductScreenshot fetchByFullImageId(long fullImageId)
830                    throws SystemException {
831                    return fetchByFullImageId(fullImageId, true);
832            }
833    
834            public SCProductScreenshot fetchByFullImageId(long fullImageId,
835                    boolean retrieveFromCache) throws SystemException {
836                    Object[] finderArgs = new Object[] { fullImageId };
837    
838                    Object result = null;
839    
840                    if (retrieveFromCache) {
841                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
842                                            finderArgs, this);
843                    }
844    
845                    if (result == null) {
846                            Session session = null;
847    
848                            try {
849                                    session = openSession();
850    
851                                    StringBundler query = new StringBundler(3);
852    
853                                    query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
854    
855                                    query.append(_FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2);
856    
857                                    query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
858    
859                                    String sql = query.toString();
860    
861                                    Query q = session.createQuery(sql);
862    
863                                    QueryPos qPos = QueryPos.getInstance(q);
864    
865                                    qPos.add(fullImageId);
866    
867                                    List<SCProductScreenshot> list = q.list();
868    
869                                    result = list;
870    
871                                    SCProductScreenshot scProductScreenshot = null;
872    
873                                    if (list.isEmpty()) {
874                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
875                                                    finderArgs, list);
876                                    }
877                                    else {
878                                            scProductScreenshot = list.get(0);
879    
880                                            cacheResult(scProductScreenshot);
881    
882                                            if ((scProductScreenshot.getFullImageId() != fullImageId)) {
883                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
884                                                            finderArgs, scProductScreenshot);
885                                            }
886                                    }
887    
888                                    return scProductScreenshot;
889                            }
890                            catch (Exception e) {
891                                    throw processException(e);
892                            }
893                            finally {
894                                    if (result == null) {
895                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
896                                                    finderArgs, new ArrayList<SCProductScreenshot>());
897                                    }
898    
899                                    closeSession(session);
900                            }
901                    }
902                    else {
903                            if (result instanceof List<?>) {
904                                    return null;
905                            }
906                            else {
907                                    return (SCProductScreenshot)result;
908                            }
909                    }
910            }
911    
912            public SCProductScreenshot findByP_P(long productEntryId, int priority)
913                    throws NoSuchProductScreenshotException, SystemException {
914                    SCProductScreenshot scProductScreenshot = fetchByP_P(productEntryId,
915                                    priority);
916    
917                    if (scProductScreenshot == null) {
918                            StringBundler msg = new StringBundler(6);
919    
920                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
921    
922                            msg.append("productEntryId=");
923                            msg.append(productEntryId);
924    
925                            msg.append(", priority=");
926                            msg.append(priority);
927    
928                            msg.append(StringPool.CLOSE_CURLY_BRACE);
929    
930                            if (_log.isWarnEnabled()) {
931                                    _log.warn(msg.toString());
932                            }
933    
934                            throw new NoSuchProductScreenshotException(msg.toString());
935                    }
936    
937                    return scProductScreenshot;
938            }
939    
940            public SCProductScreenshot fetchByP_P(long productEntryId, int priority)
941                    throws SystemException {
942                    return fetchByP_P(productEntryId, priority, true);
943            }
944    
945            public SCProductScreenshot fetchByP_P(long productEntryId, int priority,
946                    boolean retrieveFromCache) throws SystemException {
947                    Object[] finderArgs = new Object[] { productEntryId, priority };
948    
949                    Object result = null;
950    
951                    if (retrieveFromCache) {
952                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_P_P,
953                                            finderArgs, this);
954                    }
955    
956                    if (result == null) {
957                            Session session = null;
958    
959                            try {
960                                    session = openSession();
961    
962                                    StringBundler query = new StringBundler(4);
963    
964                                    query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
965    
966                                    query.append(_FINDER_COLUMN_P_P_PRODUCTENTRYID_2);
967    
968                                    query.append(_FINDER_COLUMN_P_P_PRIORITY_2);
969    
970                                    query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
971    
972                                    String sql = query.toString();
973    
974                                    Query q = session.createQuery(sql);
975    
976                                    QueryPos qPos = QueryPos.getInstance(q);
977    
978                                    qPos.add(productEntryId);
979    
980                                    qPos.add(priority);
981    
982                                    List<SCProductScreenshot> list = q.list();
983    
984                                    result = list;
985    
986                                    SCProductScreenshot scProductScreenshot = null;
987    
988                                    if (list.isEmpty()) {
989                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
990                                                    finderArgs, list);
991                                    }
992                                    else {
993                                            scProductScreenshot = list.get(0);
994    
995                                            cacheResult(scProductScreenshot);
996    
997                                            if ((scProductScreenshot.getProductEntryId() != productEntryId) ||
998                                                            (scProductScreenshot.getPriority() != priority)) {
999                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
1000                                                            finderArgs, scProductScreenshot);
1001                                            }
1002                                    }
1003    
1004                                    return scProductScreenshot;
1005                            }
1006                            catch (Exception e) {
1007                                    throw processException(e);
1008                            }
1009                            finally {
1010                                    if (result == null) {
1011                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
1012                                                    finderArgs, new ArrayList<SCProductScreenshot>());
1013                                    }
1014    
1015                                    closeSession(session);
1016                            }
1017                    }
1018                    else {
1019                            if (result instanceof List<?>) {
1020                                    return null;
1021                            }
1022                            else {
1023                                    return (SCProductScreenshot)result;
1024                            }
1025                    }
1026            }
1027    
1028            public List<SCProductScreenshot> findAll() throws SystemException {
1029                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1030            }
1031    
1032            public List<SCProductScreenshot> findAll(int start, int end)
1033                    throws SystemException {
1034                    return findAll(start, end, null);
1035            }
1036    
1037            public List<SCProductScreenshot> findAll(int start, int end,
1038                    OrderByComparator orderByComparator) throws SystemException {
1039                    Object[] finderArgs = new Object[] {
1040                                    String.valueOf(start), String.valueOf(end),
1041                                    String.valueOf(orderByComparator)
1042                            };
1043    
1044                    List<SCProductScreenshot> list = (List<SCProductScreenshot>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1045                                    finderArgs, this);
1046    
1047                    if (list == null) {
1048                            Session session = null;
1049    
1050                            try {
1051                                    session = openSession();
1052    
1053                                    StringBundler query = null;
1054                                    String sql = null;
1055    
1056                                    if (orderByComparator != null) {
1057                                            query = new StringBundler(2 +
1058                                                            (orderByComparator.getOrderByFields().length * 3));
1059    
1060                                            query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT);
1061    
1062                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1063                                                    orderByComparator);
1064    
1065                                            sql = query.toString();
1066                                    }
1067                                    else {
1068                                            sql = _SQL_SELECT_SCPRODUCTSCREENSHOT.concat(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
1069                                    }
1070    
1071                                    Query q = session.createQuery(sql);
1072    
1073                                    if (orderByComparator == null) {
1074                                            list = (List<SCProductScreenshot>)QueryUtil.list(q,
1075                                                            getDialect(), start, end, false);
1076    
1077                                            Collections.sort(list);
1078                                    }
1079                                    else {
1080                                            list = (List<SCProductScreenshot>)QueryUtil.list(q,
1081                                                            getDialect(), start, end);
1082                                    }
1083                            }
1084                            catch (Exception e) {
1085                                    throw processException(e);
1086                            }
1087                            finally {
1088                                    if (list == null) {
1089                                            list = new ArrayList<SCProductScreenshot>();
1090                                    }
1091    
1092                                    cacheResult(list);
1093    
1094                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1095    
1096                                    closeSession(session);
1097                            }
1098                    }
1099    
1100                    return list;
1101            }
1102    
1103            public void removeByProductEntryId(long productEntryId)
1104                    throws SystemException {
1105                    for (SCProductScreenshot scProductScreenshot : findByProductEntryId(
1106                                    productEntryId)) {
1107                            remove(scProductScreenshot);
1108                    }
1109            }
1110    
1111            public void removeByThumbnailId(long thumbnailId)
1112                    throws NoSuchProductScreenshotException, SystemException {
1113                    SCProductScreenshot scProductScreenshot = findByThumbnailId(thumbnailId);
1114    
1115                    remove(scProductScreenshot);
1116            }
1117    
1118            public void removeByFullImageId(long fullImageId)
1119                    throws NoSuchProductScreenshotException, SystemException {
1120                    SCProductScreenshot scProductScreenshot = findByFullImageId(fullImageId);
1121    
1122                    remove(scProductScreenshot);
1123            }
1124    
1125            public void removeByP_P(long productEntryId, int priority)
1126                    throws NoSuchProductScreenshotException, SystemException {
1127                    SCProductScreenshot scProductScreenshot = findByP_P(productEntryId,
1128                                    priority);
1129    
1130                    remove(scProductScreenshot);
1131            }
1132    
1133            public void removeAll() throws SystemException {
1134                    for (SCProductScreenshot scProductScreenshot : findAll()) {
1135                            remove(scProductScreenshot);
1136                    }
1137            }
1138    
1139            public int countByProductEntryId(long productEntryId)
1140                    throws SystemException {
1141                    Object[] finderArgs = new Object[] { productEntryId };
1142    
1143                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
1144                                    finderArgs, this);
1145    
1146                    if (count == null) {
1147                            Session session = null;
1148    
1149                            try {
1150                                    session = openSession();
1151    
1152                                    StringBundler query = new StringBundler(2);
1153    
1154                                    query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1155    
1156                                    query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
1157    
1158                                    String sql = query.toString();
1159    
1160                                    Query q = session.createQuery(sql);
1161    
1162                                    QueryPos qPos = QueryPos.getInstance(q);
1163    
1164                                    qPos.add(productEntryId);
1165    
1166                                    count = (Long)q.uniqueResult();
1167                            }
1168                            catch (Exception e) {
1169                                    throw processException(e);
1170                            }
1171                            finally {
1172                                    if (count == null) {
1173                                            count = Long.valueOf(0);
1174                                    }
1175    
1176                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
1177                                            finderArgs, count);
1178    
1179                                    closeSession(session);
1180                            }
1181                    }
1182    
1183                    return count.intValue();
1184            }
1185    
1186            public int countByThumbnailId(long thumbnailId) throws SystemException {
1187                    Object[] finderArgs = new Object[] { thumbnailId };
1188    
1189                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THUMBNAILID,
1190                                    finderArgs, this);
1191    
1192                    if (count == null) {
1193                            Session session = null;
1194    
1195                            try {
1196                                    session = openSession();
1197    
1198                                    StringBundler query = new StringBundler(2);
1199    
1200                                    query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1201    
1202                                    query.append(_FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2);
1203    
1204                                    String sql = query.toString();
1205    
1206                                    Query q = session.createQuery(sql);
1207    
1208                                    QueryPos qPos = QueryPos.getInstance(q);
1209    
1210                                    qPos.add(thumbnailId);
1211    
1212                                    count = (Long)q.uniqueResult();
1213                            }
1214                            catch (Exception e) {
1215                                    throw processException(e);
1216                            }
1217                            finally {
1218                                    if (count == null) {
1219                                            count = Long.valueOf(0);
1220                                    }
1221    
1222                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THUMBNAILID,
1223                                            finderArgs, count);
1224    
1225                                    closeSession(session);
1226                            }
1227                    }
1228    
1229                    return count.intValue();
1230            }
1231    
1232            public int countByFullImageId(long fullImageId) throws SystemException {
1233                    Object[] finderArgs = new Object[] { fullImageId };
1234    
1235                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FULLIMAGEID,
1236                                    finderArgs, this);
1237    
1238                    if (count == null) {
1239                            Session session = null;
1240    
1241                            try {
1242                                    session = openSession();
1243    
1244                                    StringBundler query = new StringBundler(2);
1245    
1246                                    query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1247    
1248                                    query.append(_FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2);
1249    
1250                                    String sql = query.toString();
1251    
1252                                    Query q = session.createQuery(sql);
1253    
1254                                    QueryPos qPos = QueryPos.getInstance(q);
1255    
1256                                    qPos.add(fullImageId);
1257    
1258                                    count = (Long)q.uniqueResult();
1259                            }
1260                            catch (Exception e) {
1261                                    throw processException(e);
1262                            }
1263                            finally {
1264                                    if (count == null) {
1265                                            count = Long.valueOf(0);
1266                                    }
1267    
1268                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FULLIMAGEID,
1269                                            finderArgs, count);
1270    
1271                                    closeSession(session);
1272                            }
1273                    }
1274    
1275                    return count.intValue();
1276            }
1277    
1278            public int countByP_P(long productEntryId, int priority)
1279                    throws SystemException {
1280                    Object[] finderArgs = new Object[] { productEntryId, priority };
1281    
1282                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_P,
1283                                    finderArgs, this);
1284    
1285                    if (count == null) {
1286                            Session session = null;
1287    
1288                            try {
1289                                    session = openSession();
1290    
1291                                    StringBundler query = new StringBundler(3);
1292    
1293                                    query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1294    
1295                                    query.append(_FINDER_COLUMN_P_P_PRODUCTENTRYID_2);
1296    
1297                                    query.append(_FINDER_COLUMN_P_P_PRIORITY_2);
1298    
1299                                    String sql = query.toString();
1300    
1301                                    Query q = session.createQuery(sql);
1302    
1303                                    QueryPos qPos = QueryPos.getInstance(q);
1304    
1305                                    qPos.add(productEntryId);
1306    
1307                                    qPos.add(priority);
1308    
1309                                    count = (Long)q.uniqueResult();
1310                            }
1311                            catch (Exception e) {
1312                                    throw processException(e);
1313                            }
1314                            finally {
1315                                    if (count == null) {
1316                                            count = Long.valueOf(0);
1317                                    }
1318    
1319                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_P, finderArgs,
1320                                            count);
1321    
1322                                    closeSession(session);
1323                            }
1324                    }
1325    
1326                    return count.intValue();
1327            }
1328    
1329            public int countAll() throws SystemException {
1330                    Object[] finderArgs = new Object[0];
1331    
1332                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1333                                    finderArgs, this);
1334    
1335                    if (count == null) {
1336                            Session session = null;
1337    
1338                            try {
1339                                    session = openSession();
1340    
1341                                    Query q = session.createQuery(_SQL_COUNT_SCPRODUCTSCREENSHOT);
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_ALL, finderArgs,
1354                                            count);
1355    
1356                                    closeSession(session);
1357                            }
1358                    }
1359    
1360                    return count.intValue();
1361            }
1362    
1363            public void afterPropertiesSet() {
1364                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1365                                            com.liferay.portal.util.PropsUtil.get(
1366                                                    "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductScreenshot")));
1367    
1368                    if (listenerClassNames.length > 0) {
1369                            try {
1370                                    List<ModelListener<SCProductScreenshot>> listenersList = new ArrayList<ModelListener<SCProductScreenshot>>();
1371    
1372                                    for (String listenerClassName : listenerClassNames) {
1373                                            listenersList.add((ModelListener<SCProductScreenshot>)InstanceFactory.newInstance(
1374                                                            listenerClassName));
1375                                    }
1376    
1377                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1378                            }
1379                            catch (Exception e) {
1380                                    _log.error(e);
1381                            }
1382                    }
1383            }
1384    
1385            @BeanReference(type = SCLicensePersistence.class)
1386            protected SCLicensePersistence scLicensePersistence;
1387            @BeanReference(type = SCFrameworkVersionPersistence.class)
1388            protected SCFrameworkVersionPersistence scFrameworkVersionPersistence;
1389            @BeanReference(type = SCProductEntryPersistence.class)
1390            protected SCProductEntryPersistence scProductEntryPersistence;
1391            @BeanReference(type = SCProductScreenshotPersistence.class)
1392            protected SCProductScreenshotPersistence scProductScreenshotPersistence;
1393            @BeanReference(type = SCProductVersionPersistence.class)
1394            protected SCProductVersionPersistence scProductVersionPersistence;
1395            @BeanReference(type = ImagePersistence.class)
1396            protected ImagePersistence imagePersistence;
1397            @BeanReference(type = ResourcePersistence.class)
1398            protected ResourcePersistence resourcePersistence;
1399            @BeanReference(type = UserPersistence.class)
1400            protected UserPersistence userPersistence;
1401            private static final String _SQL_SELECT_SCPRODUCTSCREENSHOT = "SELECT scProductScreenshot FROM SCProductScreenshot scProductScreenshot";
1402            private static final String _SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE = "SELECT scProductScreenshot FROM SCProductScreenshot scProductScreenshot WHERE ";
1403            private static final String _SQL_COUNT_SCPRODUCTSCREENSHOT = "SELECT COUNT(scProductScreenshot) FROM SCProductScreenshot scProductScreenshot";
1404            private static final String _SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE = "SELECT COUNT(scProductScreenshot) FROM SCProductScreenshot scProductScreenshot WHERE ";
1405            private static final String _FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2 = "scProductScreenshot.productEntryId = ?";
1406            private static final String _FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2 = "scProductScreenshot.thumbnailId = ?";
1407            private static final String _FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2 = "scProductScreenshot.fullImageId = ?";
1408            private static final String _FINDER_COLUMN_P_P_PRODUCTENTRYID_2 = "scProductScreenshot.productEntryId = ? AND ";
1409            private static final String _FINDER_COLUMN_P_P_PRIORITY_2 = "scProductScreenshot.priority = ?";
1410            private static final String _ORDER_BY_ENTITY_ALIAS = "scProductScreenshot.";
1411            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SCProductScreenshot exists with the primary key ";
1412            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SCProductScreenshot exists with the key {";
1413            private static Log _log = LogFactoryUtil.getLog(SCProductScreenshotPersistenceImpl.class);
1414    }