001    /**
002     * Copyright (c) 2000-2011 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     * The persistence implementation for the s c product screenshot service.
056     *
057     * <p>
058     * Never modify or reference this class directly. Always use {@link SCProductScreenshotUtil} to access the s c product screenshot persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
059     * </p>
060     *
061     * <p>
062     * Caching information and settings can be found in <code>portal.properties</code>
063     * </p>
064     *
065     * @author Brian Wing Shun Chan
066     * @see SCProductScreenshotPersistence
067     * @see SCProductScreenshotUtil
068     * @generated
069     */
070    public class SCProductScreenshotPersistenceImpl extends BasePersistenceImpl<SCProductScreenshot>
071            implements SCProductScreenshotPersistence {
072            public static final String FINDER_CLASS_NAME_ENTITY = SCProductScreenshotImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
074                    ".List";
075            public static final FinderPath FINDER_PATH_FIND_BY_PRODUCTENTRYID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
076                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
077                            FINDER_CLASS_NAME_LIST, "findByProductEntryId",
078                            new String[] {
079                                    Long.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_COUNT_BY_PRODUCTENTRYID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
085                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
086                            FINDER_CLASS_NAME_LIST, "countByProductEntryId",
087                            new String[] { Long.class.getName() });
088            public static final FinderPath FINDER_PATH_FETCH_BY_THUMBNAILID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
089                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
090                            FINDER_CLASS_NAME_ENTITY, "fetchByThumbnailId",
091                            new String[] { Long.class.getName() });
092            public static final FinderPath FINDER_PATH_COUNT_BY_THUMBNAILID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
093                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
094                            FINDER_CLASS_NAME_LIST, "countByThumbnailId",
095                            new String[] { Long.class.getName() });
096            public static final FinderPath FINDER_PATH_FETCH_BY_FULLIMAGEID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
097                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
098                            FINDER_CLASS_NAME_ENTITY, "fetchByFullImageId",
099                            new String[] { Long.class.getName() });
100            public static final FinderPath FINDER_PATH_COUNT_BY_FULLIMAGEID = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
101                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
102                            FINDER_CLASS_NAME_LIST, "countByFullImageId",
103                            new String[] { Long.class.getName() });
104            public static final FinderPath FINDER_PATH_FETCH_BY_P_P = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
105                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
106                            FINDER_CLASS_NAME_ENTITY, "fetchByP_P",
107                            new String[] { Long.class.getName(), Integer.class.getName() });
108            public static final FinderPath FINDER_PATH_COUNT_BY_P_P = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
109                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
110                            FINDER_CLASS_NAME_LIST, "countByP_P",
111                            new String[] { Long.class.getName(), Integer.class.getName() });
112            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
113                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
114                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
115            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
116                            SCProductScreenshotModelImpl.FINDER_CACHE_ENABLED,
117                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
118    
119            /**
120             * Caches the s c product screenshot in the entity cache if it is enabled.
121             *
122             * @param scProductScreenshot the s c product screenshot to cache
123             */
124            public void cacheResult(SCProductScreenshot scProductScreenshot) {
125                    EntityCacheUtil.putResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
126                            SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey(),
127                            scProductScreenshot);
128    
129                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
130                            new Object[] { new Long(scProductScreenshot.getThumbnailId()) },
131                            scProductScreenshot);
132    
133                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
134                            new Object[] { new Long(scProductScreenshot.getFullImageId()) },
135                            scProductScreenshot);
136    
137                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
138                            new Object[] {
139                                    new Long(scProductScreenshot.getProductEntryId()),
140                                    new Integer(scProductScreenshot.getPriority())
141                            }, scProductScreenshot);
142            }
143    
144            /**
145             * Caches the s c product screenshots in the entity cache if it is enabled.
146             *
147             * @param scProductScreenshots the s c product screenshots to cache
148             */
149            public void cacheResult(List<SCProductScreenshot> scProductScreenshots) {
150                    for (SCProductScreenshot scProductScreenshot : scProductScreenshots) {
151                            if (EntityCacheUtil.getResult(
152                                                    SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
153                                                    SCProductScreenshotImpl.class,
154                                                    scProductScreenshot.getPrimaryKey(), this) == null) {
155                                    cacheResult(scProductScreenshot);
156                            }
157                    }
158            }
159    
160            /**
161             * Clears the cache for all s c product screenshots.
162             *
163             * <p>
164             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
165             * </p>
166             */
167            public void clearCache() {
168                    CacheRegistryUtil.clear(SCProductScreenshotImpl.class.getName());
169                    EntityCacheUtil.clearCache(SCProductScreenshotImpl.class.getName());
170                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
171                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
172            }
173    
174            /**
175             * Clears the cache for the s c product screenshot.
176             *
177             * <p>
178             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
179             * </p>
180             */
181            public void clearCache(SCProductScreenshot scProductScreenshot) {
182                    EntityCacheUtil.removeResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
183                            SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey());
184    
185                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
186                            new Object[] { new Long(scProductScreenshot.getThumbnailId()) });
187    
188                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
189                            new Object[] { new Long(scProductScreenshot.getFullImageId()) });
190    
191                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P,
192                            new Object[] {
193                                    new Long(scProductScreenshot.getProductEntryId()),
194                                    new Integer(scProductScreenshot.getPriority())
195                            });
196            }
197    
198            /**
199             * Creates a new s c product screenshot with the primary key. Does not add the s c product screenshot to the database.
200             *
201             * @param productScreenshotId the primary key for the new s c product screenshot
202             * @return the new s c product screenshot
203             */
204            public SCProductScreenshot create(long productScreenshotId) {
205                    SCProductScreenshot scProductScreenshot = new SCProductScreenshotImpl();
206    
207                    scProductScreenshot.setNew(true);
208                    scProductScreenshot.setPrimaryKey(productScreenshotId);
209    
210                    return scProductScreenshot;
211            }
212    
213            /**
214             * Removes the s c product screenshot with the primary key from the database. Also notifies the appropriate model listeners.
215             *
216             * @param primaryKey the primary key of the s c product screenshot to remove
217             * @return the s c product screenshot that was removed
218             * @throws com.liferay.portal.NoSuchModelException if a s c product screenshot with the primary key could not be found
219             * @throws SystemException if a system exception occurred
220             */
221            public SCProductScreenshot remove(Serializable primaryKey)
222                    throws NoSuchModelException, SystemException {
223                    return remove(((Long)primaryKey).longValue());
224            }
225    
226            /**
227             * Removes the s c product screenshot with the primary key from the database. Also notifies the appropriate model listeners.
228             *
229             * @param productScreenshotId the primary key of the s c product screenshot to remove
230             * @return the s c product screenshot that was removed
231             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException if a s c product screenshot with the primary key could not be found
232             * @throws SystemException if a system exception occurred
233             */
234            public SCProductScreenshot remove(long productScreenshotId)
235                    throws NoSuchProductScreenshotException, SystemException {
236                    Session session = null;
237    
238                    try {
239                            session = openSession();
240    
241                            SCProductScreenshot scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
242                                            new Long(productScreenshotId));
243    
244                            if (scProductScreenshot == null) {
245                                    if (_log.isWarnEnabled()) {
246                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
247                                                    productScreenshotId);
248                                    }
249    
250                                    throw new NoSuchProductScreenshotException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
251                                            productScreenshotId);
252                            }
253    
254                            return remove(scProductScreenshot);
255                    }
256                    catch (NoSuchProductScreenshotException nsee) {
257                            throw nsee;
258                    }
259                    catch (Exception e) {
260                            throw processException(e);
261                    }
262                    finally {
263                            closeSession(session);
264                    }
265            }
266    
267            protected SCProductScreenshot removeImpl(
268                    SCProductScreenshot scProductScreenshot) throws SystemException {
269                    scProductScreenshot = toUnwrappedModel(scProductScreenshot);
270    
271                    Session session = null;
272    
273                    try {
274                            session = openSession();
275    
276                            BatchSessionUtil.delete(session, scProductScreenshot);
277                    }
278                    catch (Exception e) {
279                            throw processException(e);
280                    }
281                    finally {
282                            closeSession(session);
283                    }
284    
285                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
286    
287                    SCProductScreenshotModelImpl scProductScreenshotModelImpl = (SCProductScreenshotModelImpl)scProductScreenshot;
288    
289                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
290                            new Object[] { new Long(scProductScreenshotModelImpl.getThumbnailId()) });
291    
292                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
293                            new Object[] { new Long(scProductScreenshotModelImpl.getFullImageId()) });
294    
295                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P,
296                            new Object[] {
297                                    new Long(scProductScreenshotModelImpl.getProductEntryId()),
298                                    new Integer(scProductScreenshotModelImpl.getPriority())
299                            });
300    
301                    EntityCacheUtil.removeResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
302                            SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey());
303    
304                    return scProductScreenshot;
305            }
306    
307            public SCProductScreenshot updateImpl(
308                    com.liferay.portlet.softwarecatalog.model.SCProductScreenshot scProductScreenshot,
309                    boolean merge) throws SystemException {
310                    scProductScreenshot = toUnwrappedModel(scProductScreenshot);
311    
312                    boolean isNew = scProductScreenshot.isNew();
313    
314                    SCProductScreenshotModelImpl scProductScreenshotModelImpl = (SCProductScreenshotModelImpl)scProductScreenshot;
315    
316                    Session session = null;
317    
318                    try {
319                            session = openSession();
320    
321                            BatchSessionUtil.update(session, scProductScreenshot, merge);
322    
323                            scProductScreenshot.setNew(false);
324                    }
325                    catch (Exception e) {
326                            throw processException(e);
327                    }
328                    finally {
329                            closeSession(session);
330                    }
331    
332                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
333    
334                    EntityCacheUtil.putResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
335                            SCProductScreenshotImpl.class, scProductScreenshot.getPrimaryKey(),
336                            scProductScreenshot);
337    
338                    if (!isNew &&
339                                    (scProductScreenshot.getThumbnailId() != scProductScreenshotModelImpl.getOriginalThumbnailId())) {
340                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
341                                    new Object[] {
342                                            new Long(scProductScreenshotModelImpl.getOriginalThumbnailId())
343                                    });
344                    }
345    
346                    if (isNew ||
347                                    (scProductScreenshot.getThumbnailId() != scProductScreenshotModelImpl.getOriginalThumbnailId())) {
348                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
349                                    new Object[] { new Long(scProductScreenshot.getThumbnailId()) },
350                                    scProductScreenshot);
351                    }
352    
353                    if (!isNew &&
354                                    (scProductScreenshot.getFullImageId() != scProductScreenshotModelImpl.getOriginalFullImageId())) {
355                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
356                                    new Object[] {
357                                            new Long(scProductScreenshotModelImpl.getOriginalFullImageId())
358                                    });
359                    }
360    
361                    if (isNew ||
362                                    (scProductScreenshot.getFullImageId() != scProductScreenshotModelImpl.getOriginalFullImageId())) {
363                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
364                                    new Object[] { new Long(scProductScreenshot.getFullImageId()) },
365                                    scProductScreenshot);
366                    }
367    
368                    if (!isNew &&
369                                    ((scProductScreenshot.getProductEntryId() != scProductScreenshotModelImpl.getOriginalProductEntryId()) ||
370                                    (scProductScreenshot.getPriority() != scProductScreenshotModelImpl.getOriginalPriority()))) {
371                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P,
372                                    new Object[] {
373                                            new Long(scProductScreenshotModelImpl.getOriginalProductEntryId()),
374                                            new Integer(scProductScreenshotModelImpl.getOriginalPriority())
375                                    });
376                    }
377    
378                    if (isNew ||
379                                    ((scProductScreenshot.getProductEntryId() != scProductScreenshotModelImpl.getOriginalProductEntryId()) ||
380                                    (scProductScreenshot.getPriority() != scProductScreenshotModelImpl.getOriginalPriority()))) {
381                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
382                                    new Object[] {
383                                            new Long(scProductScreenshot.getProductEntryId()),
384                                            new Integer(scProductScreenshot.getPriority())
385                                    }, scProductScreenshot);
386                    }
387    
388                    return scProductScreenshot;
389            }
390    
391            protected SCProductScreenshot toUnwrappedModel(
392                    SCProductScreenshot scProductScreenshot) {
393                    if (scProductScreenshot instanceof SCProductScreenshotImpl) {
394                            return scProductScreenshot;
395                    }
396    
397                    SCProductScreenshotImpl scProductScreenshotImpl = new SCProductScreenshotImpl();
398    
399                    scProductScreenshotImpl.setNew(scProductScreenshot.isNew());
400                    scProductScreenshotImpl.setPrimaryKey(scProductScreenshot.getPrimaryKey());
401    
402                    scProductScreenshotImpl.setProductScreenshotId(scProductScreenshot.getProductScreenshotId());
403                    scProductScreenshotImpl.setCompanyId(scProductScreenshot.getCompanyId());
404                    scProductScreenshotImpl.setGroupId(scProductScreenshot.getGroupId());
405                    scProductScreenshotImpl.setProductEntryId(scProductScreenshot.getProductEntryId());
406                    scProductScreenshotImpl.setThumbnailId(scProductScreenshot.getThumbnailId());
407                    scProductScreenshotImpl.setFullImageId(scProductScreenshot.getFullImageId());
408                    scProductScreenshotImpl.setPriority(scProductScreenshot.getPriority());
409    
410                    return scProductScreenshotImpl;
411            }
412    
413            /**
414             * Finds the s c product screenshot with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
415             *
416             * @param primaryKey the primary key of the s c product screenshot to find
417             * @return the s c product screenshot
418             * @throws com.liferay.portal.NoSuchModelException if a s c product screenshot with the primary key could not be found
419             * @throws SystemException if a system exception occurred
420             */
421            public SCProductScreenshot findByPrimaryKey(Serializable primaryKey)
422                    throws NoSuchModelException, SystemException {
423                    return findByPrimaryKey(((Long)primaryKey).longValue());
424            }
425    
426            /**
427             * Finds the s c product screenshot with the primary key or throws a {@link com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException} if it could not be found.
428             *
429             * @param productScreenshotId the primary key of the s c product screenshot to find
430             * @return the s c product screenshot
431             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException if a s c product screenshot with the primary key could not be found
432             * @throws SystemException if a system exception occurred
433             */
434            public SCProductScreenshot findByPrimaryKey(long productScreenshotId)
435                    throws NoSuchProductScreenshotException, SystemException {
436                    SCProductScreenshot scProductScreenshot = fetchByPrimaryKey(productScreenshotId);
437    
438                    if (scProductScreenshot == null) {
439                            if (_log.isWarnEnabled()) {
440                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
441                                            productScreenshotId);
442                            }
443    
444                            throw new NoSuchProductScreenshotException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
445                                    productScreenshotId);
446                    }
447    
448                    return scProductScreenshot;
449            }
450    
451            /**
452             * Finds the s c product screenshot with the primary key or returns <code>null</code> if it could not be found.
453             *
454             * @param primaryKey the primary key of the s c product screenshot to find
455             * @return the s c product screenshot, or <code>null</code> if a s c product screenshot with the primary key could not be found
456             * @throws SystemException if a system exception occurred
457             */
458            public SCProductScreenshot fetchByPrimaryKey(Serializable primaryKey)
459                    throws SystemException {
460                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
461            }
462    
463            /**
464             * Finds the s c product screenshot with the primary key or returns <code>null</code> if it could not be found.
465             *
466             * @param productScreenshotId the primary key of the s c product screenshot to find
467             * @return the s c product screenshot, or <code>null</code> if a s c product screenshot with the primary key could not be found
468             * @throws SystemException if a system exception occurred
469             */
470            public SCProductScreenshot fetchByPrimaryKey(long productScreenshotId)
471                    throws SystemException {
472                    SCProductScreenshot scProductScreenshot = (SCProductScreenshot)EntityCacheUtil.getResult(SCProductScreenshotModelImpl.ENTITY_CACHE_ENABLED,
473                                    SCProductScreenshotImpl.class, productScreenshotId, this);
474    
475                    if (scProductScreenshot == null) {
476                            Session session = null;
477    
478                            try {
479                                    session = openSession();
480    
481                                    scProductScreenshot = (SCProductScreenshot)session.get(SCProductScreenshotImpl.class,
482                                                    new Long(productScreenshotId));
483                            }
484                            catch (Exception e) {
485                                    throw processException(e);
486                            }
487                            finally {
488                                    if (scProductScreenshot != null) {
489                                            cacheResult(scProductScreenshot);
490                                    }
491    
492                                    closeSession(session);
493                            }
494                    }
495    
496                    return scProductScreenshot;
497            }
498    
499            /**
500             * Finds all the s c product screenshots where productEntryId = &#63;.
501             *
502             * @param productEntryId the product entry id to search with
503             * @return the matching s c product screenshots
504             * @throws SystemException if a system exception occurred
505             */
506            public List<SCProductScreenshot> findByProductEntryId(long productEntryId)
507                    throws SystemException {
508                    return findByProductEntryId(productEntryId, QueryUtil.ALL_POS,
509                            QueryUtil.ALL_POS, null);
510            }
511    
512            /**
513             * Finds a range of all the s c product screenshots where productEntryId = &#63;.
514             *
515             * <p>
516             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
517             * </p>
518             *
519             * @param productEntryId the product entry id to search with
520             * @param start the lower bound of the range of s c product screenshots to return
521             * @param end the upper bound of the range of s c product screenshots to return (not inclusive)
522             * @return the range of matching s c product screenshots
523             * @throws SystemException if a system exception occurred
524             */
525            public List<SCProductScreenshot> findByProductEntryId(long productEntryId,
526                    int start, int end) throws SystemException {
527                    return findByProductEntryId(productEntryId, start, end, null);
528            }
529    
530            /**
531             * Finds an ordered range of all the s c product screenshots where productEntryId = &#63;.
532             *
533             * <p>
534             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
535             * </p>
536             *
537             * @param productEntryId the product entry id to search with
538             * @param start the lower bound of the range of s c product screenshots to return
539             * @param end the upper bound of the range of s c product screenshots to return (not inclusive)
540             * @param orderByComparator the comparator to order the results by
541             * @return the ordered range of matching s c product screenshots
542             * @throws SystemException if a system exception occurred
543             */
544            public List<SCProductScreenshot> findByProductEntryId(long productEntryId,
545                    int start, int end, OrderByComparator orderByComparator)
546                    throws SystemException {
547                    Object[] finderArgs = new Object[] {
548                                    productEntryId,
549                                    
550                                    String.valueOf(start), String.valueOf(end),
551                                    String.valueOf(orderByComparator)
552                            };
553    
554                    List<SCProductScreenshot> list = (List<SCProductScreenshot>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
555                                    finderArgs, this);
556    
557                    if (list == null) {
558                            StringBundler query = null;
559    
560                            if (orderByComparator != null) {
561                                    query = new StringBundler(3 +
562                                                    (orderByComparator.getOrderByFields().length * 3));
563                            }
564                            else {
565                                    query = new StringBundler(3);
566                            }
567    
568                            query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
569    
570                            query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
571    
572                            if (orderByComparator != null) {
573                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
574                                            orderByComparator);
575                            }
576    
577                            else {
578                                    query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
579                            }
580    
581                            String sql = query.toString();
582    
583                            Session session = null;
584    
585                            try {
586                                    session = openSession();
587    
588                                    Query q = session.createQuery(sql);
589    
590                                    QueryPos qPos = QueryPos.getInstance(q);
591    
592                                    qPos.add(productEntryId);
593    
594                                    list = (List<SCProductScreenshot>)QueryUtil.list(q,
595                                                    getDialect(), start, end);
596                            }
597                            catch (Exception e) {
598                                    throw processException(e);
599                            }
600                            finally {
601                                    if (list == null) {
602                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
603                                                    finderArgs);
604                                    }
605                                    else {
606                                            cacheResult(list);
607    
608                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PRODUCTENTRYID,
609                                                    finderArgs, list);
610                                    }
611    
612                                    closeSession(session);
613                            }
614                    }
615    
616                    return list;
617            }
618    
619            /**
620             * Finds the first s c product screenshot in the ordered set where productEntryId = &#63;.
621             *
622             * <p>
623             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
624             * </p>
625             *
626             * @param productEntryId the product entry id to search with
627             * @param orderByComparator the comparator to order the set by
628             * @return the first matching s c product screenshot
629             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException if a matching s c product screenshot could not be found
630             * @throws SystemException if a system exception occurred
631             */
632            public SCProductScreenshot findByProductEntryId_First(long productEntryId,
633                    OrderByComparator orderByComparator)
634                    throws NoSuchProductScreenshotException, SystemException {
635                    List<SCProductScreenshot> list = findByProductEntryId(productEntryId,
636                                    0, 1, orderByComparator);
637    
638                    if (list.isEmpty()) {
639                            StringBundler msg = new StringBundler(4);
640    
641                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
642    
643                            msg.append("productEntryId=");
644                            msg.append(productEntryId);
645    
646                            msg.append(StringPool.CLOSE_CURLY_BRACE);
647    
648                            throw new NoSuchProductScreenshotException(msg.toString());
649                    }
650                    else {
651                            return list.get(0);
652                    }
653            }
654    
655            /**
656             * Finds the last s c product screenshot in the ordered set where productEntryId = &#63;.
657             *
658             * <p>
659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
660             * </p>
661             *
662             * @param productEntryId the product entry id to search with
663             * @param orderByComparator the comparator to order the set by
664             * @return the last matching s c product screenshot
665             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException if a matching s c product screenshot could not be found
666             * @throws SystemException if a system exception occurred
667             */
668            public SCProductScreenshot findByProductEntryId_Last(long productEntryId,
669                    OrderByComparator orderByComparator)
670                    throws NoSuchProductScreenshotException, SystemException {
671                    int count = countByProductEntryId(productEntryId);
672    
673                    List<SCProductScreenshot> list = findByProductEntryId(productEntryId,
674                                    count - 1, count, orderByComparator);
675    
676                    if (list.isEmpty()) {
677                            StringBundler msg = new StringBundler(4);
678    
679                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
680    
681                            msg.append("productEntryId=");
682                            msg.append(productEntryId);
683    
684                            msg.append(StringPool.CLOSE_CURLY_BRACE);
685    
686                            throw new NoSuchProductScreenshotException(msg.toString());
687                    }
688                    else {
689                            return list.get(0);
690                    }
691            }
692    
693            /**
694             * Finds the s c product screenshots before and after the current s c product screenshot in the ordered set where productEntryId = &#63;.
695             *
696             * <p>
697             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
698             * </p>
699             *
700             * @param productScreenshotId the primary key of the current s c product screenshot
701             * @param productEntryId the product entry id to search with
702             * @param orderByComparator the comparator to order the set by
703             * @return the previous, current, and next s c product screenshot
704             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException if a s c product screenshot with the primary key could not be found
705             * @throws SystemException if a system exception occurred
706             */
707            public SCProductScreenshot[] findByProductEntryId_PrevAndNext(
708                    long productScreenshotId, long productEntryId,
709                    OrderByComparator orderByComparator)
710                    throws NoSuchProductScreenshotException, SystemException {
711                    SCProductScreenshot scProductScreenshot = findByPrimaryKey(productScreenshotId);
712    
713                    Session session = null;
714    
715                    try {
716                            session = openSession();
717    
718                            SCProductScreenshot[] array = new SCProductScreenshotImpl[3];
719    
720                            array[0] = getByProductEntryId_PrevAndNext(session,
721                                            scProductScreenshot, productEntryId, orderByComparator, true);
722    
723                            array[1] = scProductScreenshot;
724    
725                            array[2] = getByProductEntryId_PrevAndNext(session,
726                                            scProductScreenshot, productEntryId, orderByComparator,
727                                            false);
728    
729                            return array;
730                    }
731                    catch (Exception e) {
732                            throw processException(e);
733                    }
734                    finally {
735                            closeSession(session);
736                    }
737            }
738    
739            protected SCProductScreenshot getByProductEntryId_PrevAndNext(
740                    Session session, SCProductScreenshot scProductScreenshot,
741                    long productEntryId, OrderByComparator orderByComparator,
742                    boolean previous) {
743                    StringBundler query = null;
744    
745                    if (orderByComparator != null) {
746                            query = new StringBundler(6 +
747                                            (orderByComparator.getOrderByFields().length * 6));
748                    }
749                    else {
750                            query = new StringBundler(3);
751                    }
752    
753                    query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
754    
755                    query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
756    
757                    if (orderByComparator != null) {
758                            String[] orderByFields = orderByComparator.getOrderByFields();
759    
760                            if (orderByFields.length > 0) {
761                                    query.append(WHERE_AND);
762                            }
763    
764                            for (int i = 0; i < orderByFields.length; i++) {
765                                    query.append(_ORDER_BY_ENTITY_ALIAS);
766                                    query.append(orderByFields[i]);
767    
768                                    if ((i + 1) < orderByFields.length) {
769                                            if (orderByComparator.isAscending() ^ previous) {
770                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
771                                            }
772                                            else {
773                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
774                                            }
775                                    }
776                                    else {
777                                            if (orderByComparator.isAscending() ^ previous) {
778                                                    query.append(WHERE_GREATER_THAN);
779                                            }
780                                            else {
781                                                    query.append(WHERE_LESSER_THAN);
782                                            }
783                                    }
784                            }
785    
786                            query.append(ORDER_BY_CLAUSE);
787    
788                            for (int i = 0; i < orderByFields.length; i++) {
789                                    query.append(_ORDER_BY_ENTITY_ALIAS);
790                                    query.append(orderByFields[i]);
791    
792                                    if ((i + 1) < orderByFields.length) {
793                                            if (orderByComparator.isAscending() ^ previous) {
794                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
795                                            }
796                                            else {
797                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
798                                            }
799                                    }
800                                    else {
801                                            if (orderByComparator.isAscending() ^ previous) {
802                                                    query.append(ORDER_BY_ASC);
803                                            }
804                                            else {
805                                                    query.append(ORDER_BY_DESC);
806                                            }
807                                    }
808                            }
809                    }
810    
811                    else {
812                            query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
813                    }
814    
815                    String sql = query.toString();
816    
817                    Query q = session.createQuery(sql);
818    
819                    q.setFirstResult(0);
820                    q.setMaxResults(2);
821    
822                    QueryPos qPos = QueryPos.getInstance(q);
823    
824                    qPos.add(productEntryId);
825    
826                    if (orderByComparator != null) {
827                            Object[] values = orderByComparator.getOrderByValues(scProductScreenshot);
828    
829                            for (Object value : values) {
830                                    qPos.add(value);
831                            }
832                    }
833    
834                    List<SCProductScreenshot> list = q.list();
835    
836                    if (list.size() == 2) {
837                            return list.get(1);
838                    }
839                    else {
840                            return null;
841                    }
842            }
843    
844            /**
845             * Finds the s c product screenshot where thumbnailId = &#63; or throws a {@link com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException} if it could not be found.
846             *
847             * @param thumbnailId the thumbnail id to search with
848             * @return the matching s c product screenshot
849             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException if a matching s c product screenshot could not be found
850             * @throws SystemException if a system exception occurred
851             */
852            public SCProductScreenshot findByThumbnailId(long thumbnailId)
853                    throws NoSuchProductScreenshotException, SystemException {
854                    SCProductScreenshot scProductScreenshot = fetchByThumbnailId(thumbnailId);
855    
856                    if (scProductScreenshot == null) {
857                            StringBundler msg = new StringBundler(4);
858    
859                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
860    
861                            msg.append("thumbnailId=");
862                            msg.append(thumbnailId);
863    
864                            msg.append(StringPool.CLOSE_CURLY_BRACE);
865    
866                            if (_log.isWarnEnabled()) {
867                                    _log.warn(msg.toString());
868                            }
869    
870                            throw new NoSuchProductScreenshotException(msg.toString());
871                    }
872    
873                    return scProductScreenshot;
874            }
875    
876            /**
877             * Finds the s c product screenshot where thumbnailId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
878             *
879             * @param thumbnailId the thumbnail id to search with
880             * @return the matching s c product screenshot, or <code>null</code> if a matching s c product screenshot could not be found
881             * @throws SystemException if a system exception occurred
882             */
883            public SCProductScreenshot fetchByThumbnailId(long thumbnailId)
884                    throws SystemException {
885                    return fetchByThumbnailId(thumbnailId, true);
886            }
887    
888            /**
889             * Finds the s c product screenshot where thumbnailId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
890             *
891             * @param thumbnailId the thumbnail id to search with
892             * @return the matching s c product screenshot, or <code>null</code> if a matching s c product screenshot could not be found
893             * @throws SystemException if a system exception occurred
894             */
895            public SCProductScreenshot fetchByThumbnailId(long thumbnailId,
896                    boolean retrieveFromCache) throws SystemException {
897                    Object[] finderArgs = new Object[] { thumbnailId };
898    
899                    Object result = null;
900    
901                    if (retrieveFromCache) {
902                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
903                                            finderArgs, this);
904                    }
905    
906                    if (result == null) {
907                            StringBundler query = new StringBundler(3);
908    
909                            query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
910    
911                            query.append(_FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2);
912    
913                            query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
914    
915                            String sql = query.toString();
916    
917                            Session session = null;
918    
919                            try {
920                                    session = openSession();
921    
922                                    Query q = session.createQuery(sql);
923    
924                                    QueryPos qPos = QueryPos.getInstance(q);
925    
926                                    qPos.add(thumbnailId);
927    
928                                    List<SCProductScreenshot> list = q.list();
929    
930                                    result = list;
931    
932                                    SCProductScreenshot scProductScreenshot = null;
933    
934                                    if (list.isEmpty()) {
935                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
936                                                    finderArgs, list);
937                                    }
938                                    else {
939                                            scProductScreenshot = list.get(0);
940    
941                                            cacheResult(scProductScreenshot);
942    
943                                            if ((scProductScreenshot.getThumbnailId() != thumbnailId)) {
944                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
945                                                            finderArgs, scProductScreenshot);
946                                            }
947                                    }
948    
949                                    return scProductScreenshot;
950                            }
951                            catch (Exception e) {
952                                    throw processException(e);
953                            }
954                            finally {
955                                    if (result == null) {
956                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THUMBNAILID,
957                                                    finderArgs);
958                                    }
959    
960                                    closeSession(session);
961                            }
962                    }
963                    else {
964                            if (result instanceof List<?>) {
965                                    return null;
966                            }
967                            else {
968                                    return (SCProductScreenshot)result;
969                            }
970                    }
971            }
972    
973            /**
974             * Finds the s c product screenshot where fullImageId = &#63; or throws a {@link com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException} if it could not be found.
975             *
976             * @param fullImageId the full image id to search with
977             * @return the matching s c product screenshot
978             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException if a matching s c product screenshot could not be found
979             * @throws SystemException if a system exception occurred
980             */
981            public SCProductScreenshot findByFullImageId(long fullImageId)
982                    throws NoSuchProductScreenshotException, SystemException {
983                    SCProductScreenshot scProductScreenshot = fetchByFullImageId(fullImageId);
984    
985                    if (scProductScreenshot == null) {
986                            StringBundler msg = new StringBundler(4);
987    
988                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
989    
990                            msg.append("fullImageId=");
991                            msg.append(fullImageId);
992    
993                            msg.append(StringPool.CLOSE_CURLY_BRACE);
994    
995                            if (_log.isWarnEnabled()) {
996                                    _log.warn(msg.toString());
997                            }
998    
999                            throw new NoSuchProductScreenshotException(msg.toString());
1000                    }
1001    
1002                    return scProductScreenshot;
1003            }
1004    
1005            /**
1006             * Finds the s c product screenshot where fullImageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1007             *
1008             * @param fullImageId the full image id to search with
1009             * @return the matching s c product screenshot, or <code>null</code> if a matching s c product screenshot could not be found
1010             * @throws SystemException if a system exception occurred
1011             */
1012            public SCProductScreenshot fetchByFullImageId(long fullImageId)
1013                    throws SystemException {
1014                    return fetchByFullImageId(fullImageId, true);
1015            }
1016    
1017            /**
1018             * Finds the s c product screenshot where fullImageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1019             *
1020             * @param fullImageId the full image id to search with
1021             * @return the matching s c product screenshot, or <code>null</code> if a matching s c product screenshot could not be found
1022             * @throws SystemException if a system exception occurred
1023             */
1024            public SCProductScreenshot fetchByFullImageId(long fullImageId,
1025                    boolean retrieveFromCache) throws SystemException {
1026                    Object[] finderArgs = new Object[] { fullImageId };
1027    
1028                    Object result = null;
1029    
1030                    if (retrieveFromCache) {
1031                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
1032                                            finderArgs, this);
1033                    }
1034    
1035                    if (result == null) {
1036                            StringBundler query = new StringBundler(3);
1037    
1038                            query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
1039    
1040                            query.append(_FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2);
1041    
1042                            query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
1043    
1044                            String sql = query.toString();
1045    
1046                            Session session = null;
1047    
1048                            try {
1049                                    session = openSession();
1050    
1051                                    Query q = session.createQuery(sql);
1052    
1053                                    QueryPos qPos = QueryPos.getInstance(q);
1054    
1055                                    qPos.add(fullImageId);
1056    
1057                                    List<SCProductScreenshot> list = q.list();
1058    
1059                                    result = list;
1060    
1061                                    SCProductScreenshot scProductScreenshot = null;
1062    
1063                                    if (list.isEmpty()) {
1064                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
1065                                                    finderArgs, list);
1066                                    }
1067                                    else {
1068                                            scProductScreenshot = list.get(0);
1069    
1070                                            cacheResult(scProductScreenshot);
1071    
1072                                            if ((scProductScreenshot.getFullImageId() != fullImageId)) {
1073                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
1074                                                            finderArgs, scProductScreenshot);
1075                                            }
1076                                    }
1077    
1078                                    return scProductScreenshot;
1079                            }
1080                            catch (Exception e) {
1081                                    throw processException(e);
1082                            }
1083                            finally {
1084                                    if (result == null) {
1085                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_FULLIMAGEID,
1086                                                    finderArgs);
1087                                    }
1088    
1089                                    closeSession(session);
1090                            }
1091                    }
1092                    else {
1093                            if (result instanceof List<?>) {
1094                                    return null;
1095                            }
1096                            else {
1097                                    return (SCProductScreenshot)result;
1098                            }
1099                    }
1100            }
1101    
1102            /**
1103             * Finds the s c product screenshot where productEntryId = &#63; and priority = &#63; or throws a {@link com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException} if it could not be found.
1104             *
1105             * @param productEntryId the product entry id to search with
1106             * @param priority the priority to search with
1107             * @return the matching s c product screenshot
1108             * @throws com.liferay.portlet.softwarecatalog.NoSuchProductScreenshotException if a matching s c product screenshot could not be found
1109             * @throws SystemException if a system exception occurred
1110             */
1111            public SCProductScreenshot findByP_P(long productEntryId, int priority)
1112                    throws NoSuchProductScreenshotException, SystemException {
1113                    SCProductScreenshot scProductScreenshot = fetchByP_P(productEntryId,
1114                                    priority);
1115    
1116                    if (scProductScreenshot == null) {
1117                            StringBundler msg = new StringBundler(6);
1118    
1119                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1120    
1121                            msg.append("productEntryId=");
1122                            msg.append(productEntryId);
1123    
1124                            msg.append(", priority=");
1125                            msg.append(priority);
1126    
1127                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1128    
1129                            if (_log.isWarnEnabled()) {
1130                                    _log.warn(msg.toString());
1131                            }
1132    
1133                            throw new NoSuchProductScreenshotException(msg.toString());
1134                    }
1135    
1136                    return scProductScreenshot;
1137            }
1138    
1139            /**
1140             * Finds the s c product screenshot where productEntryId = &#63; and priority = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1141             *
1142             * @param productEntryId the product entry id to search with
1143             * @param priority the priority to search with
1144             * @return the matching s c product screenshot, or <code>null</code> if a matching s c product screenshot could not be found
1145             * @throws SystemException if a system exception occurred
1146             */
1147            public SCProductScreenshot fetchByP_P(long productEntryId, int priority)
1148                    throws SystemException {
1149                    return fetchByP_P(productEntryId, priority, true);
1150            }
1151    
1152            /**
1153             * Finds the s c product screenshot where productEntryId = &#63; and priority = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1154             *
1155             * @param productEntryId the product entry id to search with
1156             * @param priority the priority to search with
1157             * @return the matching s c product screenshot, or <code>null</code> if a matching s c product screenshot could not be found
1158             * @throws SystemException if a system exception occurred
1159             */
1160            public SCProductScreenshot fetchByP_P(long productEntryId, int priority,
1161                    boolean retrieveFromCache) throws SystemException {
1162                    Object[] finderArgs = new Object[] { productEntryId, priority };
1163    
1164                    Object result = null;
1165    
1166                    if (retrieveFromCache) {
1167                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_P_P,
1168                                            finderArgs, this);
1169                    }
1170    
1171                    if (result == null) {
1172                            StringBundler query = new StringBundler(4);
1173    
1174                            query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE);
1175    
1176                            query.append(_FINDER_COLUMN_P_P_PRODUCTENTRYID_2);
1177    
1178                            query.append(_FINDER_COLUMN_P_P_PRIORITY_2);
1179    
1180                            query.append(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
1181    
1182                            String sql = query.toString();
1183    
1184                            Session session = null;
1185    
1186                            try {
1187                                    session = openSession();
1188    
1189                                    Query q = session.createQuery(sql);
1190    
1191                                    QueryPos qPos = QueryPos.getInstance(q);
1192    
1193                                    qPos.add(productEntryId);
1194    
1195                                    qPos.add(priority);
1196    
1197                                    List<SCProductScreenshot> list = q.list();
1198    
1199                                    result = list;
1200    
1201                                    SCProductScreenshot scProductScreenshot = null;
1202    
1203                                    if (list.isEmpty()) {
1204                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
1205                                                    finderArgs, list);
1206                                    }
1207                                    else {
1208                                            scProductScreenshot = list.get(0);
1209    
1210                                            cacheResult(scProductScreenshot);
1211    
1212                                            if ((scProductScreenshot.getProductEntryId() != productEntryId) ||
1213                                                            (scProductScreenshot.getPriority() != priority)) {
1214                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_P_P,
1215                                                            finderArgs, scProductScreenshot);
1216                                            }
1217                                    }
1218    
1219                                    return scProductScreenshot;
1220                            }
1221                            catch (Exception e) {
1222                                    throw processException(e);
1223                            }
1224                            finally {
1225                                    if (result == null) {
1226                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_P_P,
1227                                                    finderArgs);
1228                                    }
1229    
1230                                    closeSession(session);
1231                            }
1232                    }
1233                    else {
1234                            if (result instanceof List<?>) {
1235                                    return null;
1236                            }
1237                            else {
1238                                    return (SCProductScreenshot)result;
1239                            }
1240                    }
1241            }
1242    
1243            /**
1244             * Finds all the s c product screenshots.
1245             *
1246             * @return the s c product screenshots
1247             * @throws SystemException if a system exception occurred
1248             */
1249            public List<SCProductScreenshot> findAll() throws SystemException {
1250                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1251            }
1252    
1253            /**
1254             * Finds a range of all the s c product screenshots.
1255             *
1256             * <p>
1257             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1258             * </p>
1259             *
1260             * @param start the lower bound of the range of s c product screenshots to return
1261             * @param end the upper bound of the range of s c product screenshots to return (not inclusive)
1262             * @return the range of s c product screenshots
1263             * @throws SystemException if a system exception occurred
1264             */
1265            public List<SCProductScreenshot> findAll(int start, int end)
1266                    throws SystemException {
1267                    return findAll(start, end, null);
1268            }
1269    
1270            /**
1271             * Finds an ordered range of all the s c product screenshots.
1272             *
1273             * <p>
1274             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1275             * </p>
1276             *
1277             * @param start the lower bound of the range of s c product screenshots to return
1278             * @param end the upper bound of the range of s c product screenshots to return (not inclusive)
1279             * @param orderByComparator the comparator to order the results by
1280             * @return the ordered range of s c product screenshots
1281             * @throws SystemException if a system exception occurred
1282             */
1283            public List<SCProductScreenshot> findAll(int start, int end,
1284                    OrderByComparator orderByComparator) throws SystemException {
1285                    Object[] finderArgs = new Object[] {
1286                                    String.valueOf(start), String.valueOf(end),
1287                                    String.valueOf(orderByComparator)
1288                            };
1289    
1290                    List<SCProductScreenshot> list = (List<SCProductScreenshot>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1291                                    finderArgs, this);
1292    
1293                    if (list == null) {
1294                            StringBundler query = null;
1295                            String sql = null;
1296    
1297                            if (orderByComparator != null) {
1298                                    query = new StringBundler(2 +
1299                                                    (orderByComparator.getOrderByFields().length * 3));
1300    
1301                                    query.append(_SQL_SELECT_SCPRODUCTSCREENSHOT);
1302    
1303                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1304                                            orderByComparator);
1305    
1306                                    sql = query.toString();
1307                            }
1308                            else {
1309                                    sql = _SQL_SELECT_SCPRODUCTSCREENSHOT.concat(SCProductScreenshotModelImpl.ORDER_BY_JPQL);
1310                            }
1311    
1312                            Session session = null;
1313    
1314                            try {
1315                                    session = openSession();
1316    
1317                                    Query q = session.createQuery(sql);
1318    
1319                                    if (orderByComparator == null) {
1320                                            list = (List<SCProductScreenshot>)QueryUtil.list(q,
1321                                                            getDialect(), start, end, false);
1322    
1323                                            Collections.sort(list);
1324                                    }
1325                                    else {
1326                                            list = (List<SCProductScreenshot>)QueryUtil.list(q,
1327                                                            getDialect(), start, end);
1328                                    }
1329                            }
1330                            catch (Exception e) {
1331                                    throw processException(e);
1332                            }
1333                            finally {
1334                                    if (list == null) {
1335                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1336                                                    finderArgs);
1337                                    }
1338                                    else {
1339                                            cacheResult(list);
1340    
1341                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1342                                                    list);
1343                                    }
1344    
1345                                    closeSession(session);
1346                            }
1347                    }
1348    
1349                    return list;
1350            }
1351    
1352            /**
1353             * Removes all the s c product screenshots where productEntryId = &#63; from the database.
1354             *
1355             * @param productEntryId the product entry id to search with
1356             * @throws SystemException if a system exception occurred
1357             */
1358            public void removeByProductEntryId(long productEntryId)
1359                    throws SystemException {
1360                    for (SCProductScreenshot scProductScreenshot : findByProductEntryId(
1361                                    productEntryId)) {
1362                            remove(scProductScreenshot);
1363                    }
1364            }
1365    
1366            /**
1367             * Removes the s c product screenshot where thumbnailId = &#63; from the database.
1368             *
1369             * @param thumbnailId the thumbnail id to search with
1370             * @throws SystemException if a system exception occurred
1371             */
1372            public void removeByThumbnailId(long thumbnailId)
1373                    throws NoSuchProductScreenshotException, SystemException {
1374                    SCProductScreenshot scProductScreenshot = findByThumbnailId(thumbnailId);
1375    
1376                    remove(scProductScreenshot);
1377            }
1378    
1379            /**
1380             * Removes the s c product screenshot where fullImageId = &#63; from the database.
1381             *
1382             * @param fullImageId the full image id to search with
1383             * @throws SystemException if a system exception occurred
1384             */
1385            public void removeByFullImageId(long fullImageId)
1386                    throws NoSuchProductScreenshotException, SystemException {
1387                    SCProductScreenshot scProductScreenshot = findByFullImageId(fullImageId);
1388    
1389                    remove(scProductScreenshot);
1390            }
1391    
1392            /**
1393             * Removes the s c product screenshot where productEntryId = &#63; and priority = &#63; from the database.
1394             *
1395             * @param productEntryId the product entry id to search with
1396             * @param priority the priority to search with
1397             * @throws SystemException if a system exception occurred
1398             */
1399            public void removeByP_P(long productEntryId, int priority)
1400                    throws NoSuchProductScreenshotException, SystemException {
1401                    SCProductScreenshot scProductScreenshot = findByP_P(productEntryId,
1402                                    priority);
1403    
1404                    remove(scProductScreenshot);
1405            }
1406    
1407            /**
1408             * Removes all the s c product screenshots from the database.
1409             *
1410             * @throws SystemException if a system exception occurred
1411             */
1412            public void removeAll() throws SystemException {
1413                    for (SCProductScreenshot scProductScreenshot : findAll()) {
1414                            remove(scProductScreenshot);
1415                    }
1416            }
1417    
1418            /**
1419             * Counts all the s c product screenshots where productEntryId = &#63;.
1420             *
1421             * @param productEntryId the product entry id to search with
1422             * @return the number of matching s c product screenshots
1423             * @throws SystemException if a system exception occurred
1424             */
1425            public int countByProductEntryId(long productEntryId)
1426                    throws SystemException {
1427                    Object[] finderArgs = new Object[] { productEntryId };
1428    
1429                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
1430                                    finderArgs, this);
1431    
1432                    if (count == null) {
1433                            StringBundler query = new StringBundler(2);
1434    
1435                            query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1436    
1437                            query.append(_FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2);
1438    
1439                            String sql = query.toString();
1440    
1441                            Session session = null;
1442    
1443                            try {
1444                                    session = openSession();
1445    
1446                                    Query q = session.createQuery(sql);
1447    
1448                                    QueryPos qPos = QueryPos.getInstance(q);
1449    
1450                                    qPos.add(productEntryId);
1451    
1452                                    count = (Long)q.uniqueResult();
1453                            }
1454                            catch (Exception e) {
1455                                    throw processException(e);
1456                            }
1457                            finally {
1458                                    if (count == null) {
1459                                            count = Long.valueOf(0);
1460                                    }
1461    
1462                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PRODUCTENTRYID,
1463                                            finderArgs, count);
1464    
1465                                    closeSession(session);
1466                            }
1467                    }
1468    
1469                    return count.intValue();
1470            }
1471    
1472            /**
1473             * Counts all the s c product screenshots where thumbnailId = &#63;.
1474             *
1475             * @param thumbnailId the thumbnail id to search with
1476             * @return the number of matching s c product screenshots
1477             * @throws SystemException if a system exception occurred
1478             */
1479            public int countByThumbnailId(long thumbnailId) throws SystemException {
1480                    Object[] finderArgs = new Object[] { thumbnailId };
1481    
1482                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THUMBNAILID,
1483                                    finderArgs, this);
1484    
1485                    if (count == null) {
1486                            StringBundler query = new StringBundler(2);
1487    
1488                            query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1489    
1490                            query.append(_FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2);
1491    
1492                            String sql = query.toString();
1493    
1494                            Session session = null;
1495    
1496                            try {
1497                                    session = openSession();
1498    
1499                                    Query q = session.createQuery(sql);
1500    
1501                                    QueryPos qPos = QueryPos.getInstance(q);
1502    
1503                                    qPos.add(thumbnailId);
1504    
1505                                    count = (Long)q.uniqueResult();
1506                            }
1507                            catch (Exception e) {
1508                                    throw processException(e);
1509                            }
1510                            finally {
1511                                    if (count == null) {
1512                                            count = Long.valueOf(0);
1513                                    }
1514    
1515                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THUMBNAILID,
1516                                            finderArgs, count);
1517    
1518                                    closeSession(session);
1519                            }
1520                    }
1521    
1522                    return count.intValue();
1523            }
1524    
1525            /**
1526             * Counts all the s c product screenshots where fullImageId = &#63;.
1527             *
1528             * @param fullImageId the full image id to search with
1529             * @return the number of matching s c product screenshots
1530             * @throws SystemException if a system exception occurred
1531             */
1532            public int countByFullImageId(long fullImageId) throws SystemException {
1533                    Object[] finderArgs = new Object[] { fullImageId };
1534    
1535                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_FULLIMAGEID,
1536                                    finderArgs, this);
1537    
1538                    if (count == null) {
1539                            StringBundler query = new StringBundler(2);
1540    
1541                            query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1542    
1543                            query.append(_FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2);
1544    
1545                            String sql = query.toString();
1546    
1547                            Session session = null;
1548    
1549                            try {
1550                                    session = openSession();
1551    
1552                                    Query q = session.createQuery(sql);
1553    
1554                                    QueryPos qPos = QueryPos.getInstance(q);
1555    
1556                                    qPos.add(fullImageId);
1557    
1558                                    count = (Long)q.uniqueResult();
1559                            }
1560                            catch (Exception e) {
1561                                    throw processException(e);
1562                            }
1563                            finally {
1564                                    if (count == null) {
1565                                            count = Long.valueOf(0);
1566                                    }
1567    
1568                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_FULLIMAGEID,
1569                                            finderArgs, count);
1570    
1571                                    closeSession(session);
1572                            }
1573                    }
1574    
1575                    return count.intValue();
1576            }
1577    
1578            /**
1579             * Counts all the s c product screenshots where productEntryId = &#63; and priority = &#63;.
1580             *
1581             * @param productEntryId the product entry id to search with
1582             * @param priority the priority to search with
1583             * @return the number of matching s c product screenshots
1584             * @throws SystemException if a system exception occurred
1585             */
1586            public int countByP_P(long productEntryId, int priority)
1587                    throws SystemException {
1588                    Object[] finderArgs = new Object[] { productEntryId, priority };
1589    
1590                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_P_P,
1591                                    finderArgs, this);
1592    
1593                    if (count == null) {
1594                            StringBundler query = new StringBundler(3);
1595    
1596                            query.append(_SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE);
1597    
1598                            query.append(_FINDER_COLUMN_P_P_PRODUCTENTRYID_2);
1599    
1600                            query.append(_FINDER_COLUMN_P_P_PRIORITY_2);
1601    
1602                            String sql = query.toString();
1603    
1604                            Session session = null;
1605    
1606                            try {
1607                                    session = openSession();
1608    
1609                                    Query q = session.createQuery(sql);
1610    
1611                                    QueryPos qPos = QueryPos.getInstance(q);
1612    
1613                                    qPos.add(productEntryId);
1614    
1615                                    qPos.add(priority);
1616    
1617                                    count = (Long)q.uniqueResult();
1618                            }
1619                            catch (Exception e) {
1620                                    throw processException(e);
1621                            }
1622                            finally {
1623                                    if (count == null) {
1624                                            count = Long.valueOf(0);
1625                                    }
1626    
1627                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_P_P, finderArgs,
1628                                            count);
1629    
1630                                    closeSession(session);
1631                            }
1632                    }
1633    
1634                    return count.intValue();
1635            }
1636    
1637            /**
1638             * Counts all the s c product screenshots.
1639             *
1640             * @return the number of s c product screenshots
1641             * @throws SystemException if a system exception occurred
1642             */
1643            public int countAll() throws SystemException {
1644                    Object[] finderArgs = new Object[0];
1645    
1646                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1647                                    finderArgs, this);
1648    
1649                    if (count == null) {
1650                            Session session = null;
1651    
1652                            try {
1653                                    session = openSession();
1654    
1655                                    Query q = session.createQuery(_SQL_COUNT_SCPRODUCTSCREENSHOT);
1656    
1657                                    count = (Long)q.uniqueResult();
1658                            }
1659                            catch (Exception e) {
1660                                    throw processException(e);
1661                            }
1662                            finally {
1663                                    if (count == null) {
1664                                            count = Long.valueOf(0);
1665                                    }
1666    
1667                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1668                                            count);
1669    
1670                                    closeSession(session);
1671                            }
1672                    }
1673    
1674                    return count.intValue();
1675            }
1676    
1677            /**
1678             * Initializes the s c product screenshot persistence.
1679             */
1680            public void afterPropertiesSet() {
1681                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1682                                            com.liferay.portal.util.PropsUtil.get(
1683                                                    "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductScreenshot")));
1684    
1685                    if (listenerClassNames.length > 0) {
1686                            try {
1687                                    List<ModelListener<SCProductScreenshot>> listenersList = new ArrayList<ModelListener<SCProductScreenshot>>();
1688    
1689                                    for (String listenerClassName : listenerClassNames) {
1690                                            listenersList.add((ModelListener<SCProductScreenshot>)InstanceFactory.newInstance(
1691                                                            listenerClassName));
1692                                    }
1693    
1694                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1695                            }
1696                            catch (Exception e) {
1697                                    _log.error(e);
1698                            }
1699                    }
1700            }
1701    
1702            public void destroy() {
1703                    EntityCacheUtil.removeCache(SCProductScreenshotImpl.class.getName());
1704                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1705                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1706            }
1707    
1708            @BeanReference(type = SCLicensePersistence.class)
1709            protected SCLicensePersistence scLicensePersistence;
1710            @BeanReference(type = SCFrameworkVersionPersistence.class)
1711            protected SCFrameworkVersionPersistence scFrameworkVersionPersistence;
1712            @BeanReference(type = SCProductEntryPersistence.class)
1713            protected SCProductEntryPersistence scProductEntryPersistence;
1714            @BeanReference(type = SCProductScreenshotPersistence.class)
1715            protected SCProductScreenshotPersistence scProductScreenshotPersistence;
1716            @BeanReference(type = SCProductVersionPersistence.class)
1717            protected SCProductVersionPersistence scProductVersionPersistence;
1718            @BeanReference(type = ImagePersistence.class)
1719            protected ImagePersistence imagePersistence;
1720            @BeanReference(type = ResourcePersistence.class)
1721            protected ResourcePersistence resourcePersistence;
1722            @BeanReference(type = UserPersistence.class)
1723            protected UserPersistence userPersistence;
1724            private static final String _SQL_SELECT_SCPRODUCTSCREENSHOT = "SELECT scProductScreenshot FROM SCProductScreenshot scProductScreenshot";
1725            private static final String _SQL_SELECT_SCPRODUCTSCREENSHOT_WHERE = "SELECT scProductScreenshot FROM SCProductScreenshot scProductScreenshot WHERE ";
1726            private static final String _SQL_COUNT_SCPRODUCTSCREENSHOT = "SELECT COUNT(scProductScreenshot) FROM SCProductScreenshot scProductScreenshot";
1727            private static final String _SQL_COUNT_SCPRODUCTSCREENSHOT_WHERE = "SELECT COUNT(scProductScreenshot) FROM SCProductScreenshot scProductScreenshot WHERE ";
1728            private static final String _FINDER_COLUMN_PRODUCTENTRYID_PRODUCTENTRYID_2 = "scProductScreenshot.productEntryId = ?";
1729            private static final String _FINDER_COLUMN_THUMBNAILID_THUMBNAILID_2 = "scProductScreenshot.thumbnailId = ?";
1730            private static final String _FINDER_COLUMN_FULLIMAGEID_FULLIMAGEID_2 = "scProductScreenshot.fullImageId = ?";
1731            private static final String _FINDER_COLUMN_P_P_PRODUCTENTRYID_2 = "scProductScreenshot.productEntryId = ? AND ";
1732            private static final String _FINDER_COLUMN_P_P_PRIORITY_2 = "scProductScreenshot.priority = ?";
1733            private static final String _ORDER_BY_ENTITY_ALIAS = "scProductScreenshot.";
1734            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SCProductScreenshot exists with the primary key ";
1735            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SCProductScreenshot exists with the key {";
1736            private static Log _log = LogFactoryUtil.getLog(SCProductScreenshotPersistenceImpl.class);
1737    }