001    /**
002     * Copyright (c) 2000-2012 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.ratings.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.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.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
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.asset.service.persistence.AssetEntryPersistence;
044    import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
045    import com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence;
046    import com.liferay.portlet.ratings.NoSuchEntryException;
047    import com.liferay.portlet.ratings.model.RatingsEntry;
048    import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
049    import com.liferay.portlet.ratings.model.impl.RatingsEntryModelImpl;
050    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    
058    /**
059     * The persistence implementation for the ratings entry service.
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 RatingsEntryPersistence
067     * @see RatingsEntryUtil
068     * @generated
069     */
070    public class RatingsEntryPersistenceImpl extends BasePersistenceImpl<RatingsEntry>
071            implements RatingsEntryPersistence {
072            /*
073             * NOTE FOR DEVELOPERS:
074             *
075             * Never modify or reference this class directly. Always use {@link RatingsEntryUtil} to access the ratings entry persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
076             */
077            public static final String FINDER_CLASS_NAME_ENTITY = RatingsEntryImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List1";
080            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List2";
082            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
083                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
084                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
085                            new String[] {
086                                    Long.class.getName(), Long.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
092                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
094                            new String[] { Long.class.getName(), Long.class.getName() },
095                            RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
096                            RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
097            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
098                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
099                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
100                            new String[] { Long.class.getName(), Long.class.getName() });
101            public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
102                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
103                            FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
104                            new String[] {
105                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
106                            },
107                            RatingsEntryModelImpl.USERID_COLUMN_BITMASK |
108                            RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
109                            RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
110            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
111                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
113                            new String[] {
114                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
115                            });
116            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
117                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
118                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
119                            new String[] {
120                                    Long.class.getName(), Long.class.getName(),
121                                    Double.class.getName(),
122                                    
123                            "java.lang.Integer", "java.lang.Integer",
124                                    "com.liferay.portal.kernel.util.OrderByComparator"
125                            });
126            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
127                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
128                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
129                            new String[] {
130                                    Long.class.getName(), Long.class.getName(),
131                                    Double.class.getName()
132                            },
133                            RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
134                            RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK |
135                            RatingsEntryModelImpl.SCORE_COLUMN_BITMASK);
136            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
137                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
138                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
139                            new String[] {
140                                    Long.class.getName(), Long.class.getName(),
141                                    Double.class.getName()
142                            });
143            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
144                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
145                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
146            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
147                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
148                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
149            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
150                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
151                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
152    
153            /**
154             * Caches the ratings entry in the entity cache if it is enabled.
155             *
156             * @param ratingsEntry the ratings entry
157             */
158            public void cacheResult(RatingsEntry ratingsEntry) {
159                    EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
160                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
161    
162                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
163                            new Object[] {
164                                    Long.valueOf(ratingsEntry.getUserId()),
165                                    Long.valueOf(ratingsEntry.getClassNameId()),
166                                    Long.valueOf(ratingsEntry.getClassPK())
167                            }, ratingsEntry);
168    
169                    ratingsEntry.resetOriginalValues();
170            }
171    
172            /**
173             * Caches the ratings entries in the entity cache if it is enabled.
174             *
175             * @param ratingsEntries the ratings entries
176             */
177            public void cacheResult(List<RatingsEntry> ratingsEntries) {
178                    for (RatingsEntry ratingsEntry : ratingsEntries) {
179                            if (EntityCacheUtil.getResult(
180                                                    RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
181                                                    RatingsEntryImpl.class, ratingsEntry.getPrimaryKey()) == null) {
182                                    cacheResult(ratingsEntry);
183                            }
184                            else {
185                                    ratingsEntry.resetOriginalValues();
186                            }
187                    }
188            }
189    
190            /**
191             * Clears the cache for all ratings entries.
192             *
193             * <p>
194             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
195             * </p>
196             */
197            @Override
198            public void clearCache() {
199                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
200                            CacheRegistryUtil.clear(RatingsEntryImpl.class.getName());
201                    }
202    
203                    EntityCacheUtil.clearCache(RatingsEntryImpl.class.getName());
204    
205                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
206                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
207                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
208            }
209    
210            /**
211             * Clears the cache for the ratings entry.
212             *
213             * <p>
214             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
215             * </p>
216             */
217            @Override
218            public void clearCache(RatingsEntry ratingsEntry) {
219                    EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
220                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
221    
222                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
223                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
224    
225                    clearUniqueFindersCache(ratingsEntry);
226            }
227    
228            @Override
229            public void clearCache(List<RatingsEntry> ratingsEntries) {
230                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
231                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
232    
233                    for (RatingsEntry ratingsEntry : ratingsEntries) {
234                            EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
235                                    RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
236    
237                            clearUniqueFindersCache(ratingsEntry);
238                    }
239            }
240    
241            protected void clearUniqueFindersCache(RatingsEntry ratingsEntry) {
242                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
243                            new Object[] {
244                                    Long.valueOf(ratingsEntry.getUserId()),
245                                    Long.valueOf(ratingsEntry.getClassNameId()),
246                                    Long.valueOf(ratingsEntry.getClassPK())
247                            });
248            }
249    
250            /**
251             * Creates a new ratings entry with the primary key. Does not add the ratings entry to the database.
252             *
253             * @param entryId the primary key for the new ratings entry
254             * @return the new ratings entry
255             */
256            public RatingsEntry create(long entryId) {
257                    RatingsEntry ratingsEntry = new RatingsEntryImpl();
258    
259                    ratingsEntry.setNew(true);
260                    ratingsEntry.setPrimaryKey(entryId);
261    
262                    return ratingsEntry;
263            }
264    
265            /**
266             * Removes the ratings entry with the primary key from the database. Also notifies the appropriate model listeners.
267             *
268             * @param entryId the primary key of the ratings entry
269             * @return the ratings entry that was removed
270             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
271             * @throws SystemException if a system exception occurred
272             */
273            public RatingsEntry remove(long entryId)
274                    throws NoSuchEntryException, SystemException {
275                    return remove(Long.valueOf(entryId));
276            }
277    
278            /**
279             * Removes the ratings entry with the primary key from the database. Also notifies the appropriate model listeners.
280             *
281             * @param primaryKey the primary key of the ratings entry
282             * @return the ratings entry that was removed
283             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
284             * @throws SystemException if a system exception occurred
285             */
286            @Override
287            public RatingsEntry remove(Serializable primaryKey)
288                    throws NoSuchEntryException, SystemException {
289                    Session session = null;
290    
291                    try {
292                            session = openSession();
293    
294                            RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
295                                            primaryKey);
296    
297                            if (ratingsEntry == null) {
298                                    if (_log.isWarnEnabled()) {
299                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
300                                    }
301    
302                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
303                                            primaryKey);
304                            }
305    
306                            return remove(ratingsEntry);
307                    }
308                    catch (NoSuchEntryException nsee) {
309                            throw nsee;
310                    }
311                    catch (Exception e) {
312                            throw processException(e);
313                    }
314                    finally {
315                            closeSession(session);
316                    }
317            }
318    
319            @Override
320            protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
321                    throws SystemException {
322                    ratingsEntry = toUnwrappedModel(ratingsEntry);
323    
324                    Session session = null;
325    
326                    try {
327                            session = openSession();
328    
329                            BatchSessionUtil.delete(session, ratingsEntry);
330                    }
331                    catch (Exception e) {
332                            throw processException(e);
333                    }
334                    finally {
335                            closeSession(session);
336                    }
337    
338                    clearCache(ratingsEntry);
339    
340                    return ratingsEntry;
341            }
342    
343            @Override
344            public RatingsEntry updateImpl(
345                    com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
346                    boolean merge) throws SystemException {
347                    ratingsEntry = toUnwrappedModel(ratingsEntry);
348    
349                    boolean isNew = ratingsEntry.isNew();
350    
351                    RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
352    
353                    Session session = null;
354    
355                    try {
356                            session = openSession();
357    
358                            BatchSessionUtil.update(session, ratingsEntry, merge);
359    
360                            ratingsEntry.setNew(false);
361                    }
362                    catch (Exception e) {
363                            throw processException(e);
364                    }
365                    finally {
366                            closeSession(session);
367                    }
368    
369                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
370    
371                    if (isNew || !RatingsEntryModelImpl.COLUMN_BITMASK_ENABLED) {
372                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
373                    }
374                    else {
375                            if ((ratingsEntryModelImpl.getColumnBitmask() &
376                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
377                                    Object[] args = new Object[] {
378                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
379                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK())
380                                            };
381    
382                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
383                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
384                                            args);
385    
386                                    args = new Object[] {
387                                                    Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
388                                                    Long.valueOf(ratingsEntryModelImpl.getClassPK())
389                                            };
390    
391                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
392                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
393                                            args);
394                            }
395    
396                            if ((ratingsEntryModelImpl.getColumnBitmask() &
397                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
398                                    Object[] args = new Object[] {
399                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
400                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK()),
401                                                    Double.valueOf(ratingsEntryModelImpl.getOriginalScore())
402                                            };
403    
404                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
405                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
406                                            args);
407    
408                                    args = new Object[] {
409                                                    Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
410                                                    Long.valueOf(ratingsEntryModelImpl.getClassPK()),
411                                                    Double.valueOf(ratingsEntryModelImpl.getScore())
412                                            };
413    
414                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
415                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
416                                            args);
417                            }
418                    }
419    
420                    EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
421                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
422    
423                    if (isNew) {
424                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
425                                    new Object[] {
426                                            Long.valueOf(ratingsEntry.getUserId()),
427                                            Long.valueOf(ratingsEntry.getClassNameId()),
428                                            Long.valueOf(ratingsEntry.getClassPK())
429                                    }, ratingsEntry);
430                    }
431                    else {
432                            if ((ratingsEntryModelImpl.getColumnBitmask() &
433                                            FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
434                                    Object[] args = new Object[] {
435                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalUserId()),
436                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
437                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK())
438                                            };
439    
440                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
441                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
442    
443                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
444                                            new Object[] {
445                                                    Long.valueOf(ratingsEntry.getUserId()),
446                                                    Long.valueOf(ratingsEntry.getClassNameId()),
447                                                    Long.valueOf(ratingsEntry.getClassPK())
448                                            }, ratingsEntry);
449                            }
450                    }
451    
452                    return ratingsEntry;
453            }
454    
455            protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
456                    if (ratingsEntry instanceof RatingsEntryImpl) {
457                            return ratingsEntry;
458                    }
459    
460                    RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
461    
462                    ratingsEntryImpl.setNew(ratingsEntry.isNew());
463                    ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
464    
465                    ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
466                    ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
467                    ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
468                    ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
469                    ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
470                    ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
471                    ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
472                    ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
473                    ratingsEntryImpl.setScore(ratingsEntry.getScore());
474    
475                    return ratingsEntryImpl;
476            }
477    
478            /**
479             * Returns the ratings entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
480             *
481             * @param primaryKey the primary key of the ratings entry
482             * @return the ratings entry
483             * @throws com.liferay.portal.NoSuchModelException if a ratings entry with the primary key could not be found
484             * @throws SystemException if a system exception occurred
485             */
486            @Override
487            public RatingsEntry findByPrimaryKey(Serializable primaryKey)
488                    throws NoSuchModelException, SystemException {
489                    return findByPrimaryKey(((Long)primaryKey).longValue());
490            }
491    
492            /**
493             * Returns the ratings entry with the primary key or throws a {@link com.liferay.portlet.ratings.NoSuchEntryException} if it could not be found.
494             *
495             * @param entryId the primary key of the ratings entry
496             * @return the ratings entry
497             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
498             * @throws SystemException if a system exception occurred
499             */
500            public RatingsEntry findByPrimaryKey(long entryId)
501                    throws NoSuchEntryException, SystemException {
502                    RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
503    
504                    if (ratingsEntry == null) {
505                            if (_log.isWarnEnabled()) {
506                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
507                            }
508    
509                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
510                                    entryId);
511                    }
512    
513                    return ratingsEntry;
514            }
515    
516            /**
517             * Returns the ratings entry with the primary key or returns <code>null</code> if it could not be found.
518             *
519             * @param primaryKey the primary key of the ratings entry
520             * @return the ratings entry, or <code>null</code> if a ratings entry with the primary key could not be found
521             * @throws SystemException if a system exception occurred
522             */
523            @Override
524            public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
525                    throws SystemException {
526                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
527            }
528    
529            /**
530             * Returns the ratings entry with the primary key or returns <code>null</code> if it could not be found.
531             *
532             * @param entryId the primary key of the ratings entry
533             * @return the ratings entry, or <code>null</code> if a ratings entry with the primary key could not be found
534             * @throws SystemException if a system exception occurred
535             */
536            public RatingsEntry fetchByPrimaryKey(long entryId)
537                    throws SystemException {
538                    RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
539                                    RatingsEntryImpl.class, entryId);
540    
541                    if (ratingsEntry == _nullRatingsEntry) {
542                            return null;
543                    }
544    
545                    if (ratingsEntry == null) {
546                            Session session = null;
547    
548                            boolean hasException = false;
549    
550                            try {
551                                    session = openSession();
552    
553                                    ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
554                                                    Long.valueOf(entryId));
555                            }
556                            catch (Exception e) {
557                                    hasException = true;
558    
559                                    throw processException(e);
560                            }
561                            finally {
562                                    if (ratingsEntry != null) {
563                                            cacheResult(ratingsEntry);
564                                    }
565                                    else if (!hasException) {
566                                            EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
567                                                    RatingsEntryImpl.class, entryId, _nullRatingsEntry);
568                                    }
569    
570                                    closeSession(session);
571                            }
572                    }
573    
574                    return ratingsEntry;
575            }
576    
577            /**
578             * Returns all the ratings entries where classNameId = &#63; and classPK = &#63;.
579             *
580             * @param classNameId the class name ID
581             * @param classPK the class p k
582             * @return the matching ratings entries
583             * @throws SystemException if a system exception occurred
584             */
585            public List<RatingsEntry> findByC_C(long classNameId, long classPK)
586                    throws SystemException {
587                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
588                            QueryUtil.ALL_POS, null);
589            }
590    
591            /**
592             * Returns a range of all the ratings entries where classNameId = &#63; and classPK = &#63;.
593             *
594             * <p>
595             * 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.
596             * </p>
597             *
598             * @param classNameId the class name ID
599             * @param classPK the class p k
600             * @param start the lower bound of the range of ratings entries
601             * @param end the upper bound of the range of ratings entries (not inclusive)
602             * @return the range of matching ratings entries
603             * @throws SystemException if a system exception occurred
604             */
605            public List<RatingsEntry> findByC_C(long classNameId, long classPK,
606                    int start, int end) throws SystemException {
607                    return findByC_C(classNameId, classPK, start, end, null);
608            }
609    
610            /**
611             * Returns an ordered range of all the ratings entries where classNameId = &#63; and classPK = &#63;.
612             *
613             * <p>
614             * 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.
615             * </p>
616             *
617             * @param classNameId the class name ID
618             * @param classPK the class p k
619             * @param start the lower bound of the range of ratings entries
620             * @param end the upper bound of the range of ratings entries (not inclusive)
621             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
622             * @return the ordered range of matching ratings entries
623             * @throws SystemException if a system exception occurred
624             */
625            public List<RatingsEntry> findByC_C(long classNameId, long classPK,
626                    int start, int end, OrderByComparator orderByComparator)
627                    throws SystemException {
628                    FinderPath finderPath = null;
629                    Object[] finderArgs = null;
630    
631                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
632                                    (orderByComparator == null)) {
633                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
634                            finderArgs = new Object[] { classNameId, classPK };
635                    }
636                    else {
637                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
638                            finderArgs = new Object[] {
639                                            classNameId, classPK,
640                                            
641                                            start, end, orderByComparator
642                                    };
643                    }
644    
645                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
646                                    finderArgs, this);
647    
648                    if ((list != null) && !list.isEmpty()) {
649                            for (RatingsEntry ratingsEntry : list) {
650                                    if ((classNameId != ratingsEntry.getClassNameId()) ||
651                                                    (classPK != ratingsEntry.getClassPK())) {
652                                            list = null;
653    
654                                            break;
655                                    }
656                            }
657                    }
658    
659                    if (list == null) {
660                            StringBundler query = null;
661    
662                            if (orderByComparator != null) {
663                                    query = new StringBundler(4 +
664                                                    (orderByComparator.getOrderByFields().length * 3));
665                            }
666                            else {
667                                    query = new StringBundler(3);
668                            }
669    
670                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
671    
672                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
673    
674                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
675    
676                            if (orderByComparator != null) {
677                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
678                                            orderByComparator);
679                            }
680    
681                            String sql = query.toString();
682    
683                            Session session = null;
684    
685                            try {
686                                    session = openSession();
687    
688                                    Query q = session.createQuery(sql);
689    
690                                    QueryPos qPos = QueryPos.getInstance(q);
691    
692                                    qPos.add(classNameId);
693    
694                                    qPos.add(classPK);
695    
696                                    list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
697                                                    start, end);
698                            }
699                            catch (Exception e) {
700                                    throw processException(e);
701                            }
702                            finally {
703                                    if (list == null) {
704                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
705                                    }
706                                    else {
707                                            cacheResult(list);
708    
709                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
710                                    }
711    
712                                    closeSession(session);
713                            }
714                    }
715    
716                    return list;
717            }
718    
719            /**
720             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
721             *
722             * <p>
723             * 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.
724             * </p>
725             *
726             * @param classNameId the class name ID
727             * @param classPK the class p k
728             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
729             * @return the first matching ratings entry
730             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
731             * @throws SystemException if a system exception occurred
732             */
733            public RatingsEntry findByC_C_First(long classNameId, long classPK,
734                    OrderByComparator orderByComparator)
735                    throws NoSuchEntryException, SystemException {
736                    List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
737                                    orderByComparator);
738    
739                    if (list.isEmpty()) {
740                            StringBundler msg = new StringBundler(6);
741    
742                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
743    
744                            msg.append("classNameId=");
745                            msg.append(classNameId);
746    
747                            msg.append(", classPK=");
748                            msg.append(classPK);
749    
750                            msg.append(StringPool.CLOSE_CURLY_BRACE);
751    
752                            throw new NoSuchEntryException(msg.toString());
753                    }
754                    else {
755                            return list.get(0);
756                    }
757            }
758    
759            /**
760             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
761             *
762             * <p>
763             * 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.
764             * </p>
765             *
766             * @param classNameId the class name ID
767             * @param classPK the class p k
768             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
769             * @return the last matching ratings entry
770             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
771             * @throws SystemException if a system exception occurred
772             */
773            public RatingsEntry findByC_C_Last(long classNameId, long classPK,
774                    OrderByComparator orderByComparator)
775                    throws NoSuchEntryException, SystemException {
776                    int count = countByC_C(classNameId, classPK);
777    
778                    List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
779                                    count, orderByComparator);
780    
781                    if (list.isEmpty()) {
782                            StringBundler msg = new StringBundler(6);
783    
784                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
785    
786                            msg.append("classNameId=");
787                            msg.append(classNameId);
788    
789                            msg.append(", classPK=");
790                            msg.append(classPK);
791    
792                            msg.append(StringPool.CLOSE_CURLY_BRACE);
793    
794                            throw new NoSuchEntryException(msg.toString());
795                    }
796                    else {
797                            return list.get(0);
798                    }
799            }
800    
801            /**
802             * Returns the ratings entries before and after the current ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
803             *
804             * <p>
805             * 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.
806             * </p>
807             *
808             * @param entryId the primary key of the current ratings entry
809             * @param classNameId the class name ID
810             * @param classPK the class p k
811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
812             * @return the previous, current, and next ratings entry
813             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
814             * @throws SystemException if a system exception occurred
815             */
816            public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
817                    long classPK, OrderByComparator orderByComparator)
818                    throws NoSuchEntryException, SystemException {
819                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
820    
821                    Session session = null;
822    
823                    try {
824                            session = openSession();
825    
826                            RatingsEntry[] array = new RatingsEntryImpl[3];
827    
828                            array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
829                                            classPK, orderByComparator, true);
830    
831                            array[1] = ratingsEntry;
832    
833                            array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
834                                            classPK, orderByComparator, false);
835    
836                            return array;
837                    }
838                    catch (Exception e) {
839                            throw processException(e);
840                    }
841                    finally {
842                            closeSession(session);
843                    }
844            }
845    
846            protected RatingsEntry getByC_C_PrevAndNext(Session session,
847                    RatingsEntry ratingsEntry, long classNameId, long classPK,
848                    OrderByComparator orderByComparator, boolean previous) {
849                    StringBundler query = null;
850    
851                    if (orderByComparator != null) {
852                            query = new StringBundler(6 +
853                                            (orderByComparator.getOrderByFields().length * 6));
854                    }
855                    else {
856                            query = new StringBundler(3);
857                    }
858    
859                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
860    
861                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
862    
863                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
864    
865                    if (orderByComparator != null) {
866                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
867    
868                            if (orderByConditionFields.length > 0) {
869                                    query.append(WHERE_AND);
870                            }
871    
872                            for (int i = 0; i < orderByConditionFields.length; i++) {
873                                    query.append(_ORDER_BY_ENTITY_ALIAS);
874                                    query.append(orderByConditionFields[i]);
875    
876                                    if ((i + 1) < orderByConditionFields.length) {
877                                            if (orderByComparator.isAscending() ^ previous) {
878                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
879                                            }
880                                            else {
881                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
882                                            }
883                                    }
884                                    else {
885                                            if (orderByComparator.isAscending() ^ previous) {
886                                                    query.append(WHERE_GREATER_THAN);
887                                            }
888                                            else {
889                                                    query.append(WHERE_LESSER_THAN);
890                                            }
891                                    }
892                            }
893    
894                            query.append(ORDER_BY_CLAUSE);
895    
896                            String[] orderByFields = orderByComparator.getOrderByFields();
897    
898                            for (int i = 0; i < orderByFields.length; i++) {
899                                    query.append(_ORDER_BY_ENTITY_ALIAS);
900                                    query.append(orderByFields[i]);
901    
902                                    if ((i + 1) < orderByFields.length) {
903                                            if (orderByComparator.isAscending() ^ previous) {
904                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
905                                            }
906                                            else {
907                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
908                                            }
909                                    }
910                                    else {
911                                            if (orderByComparator.isAscending() ^ previous) {
912                                                    query.append(ORDER_BY_ASC);
913                                            }
914                                            else {
915                                                    query.append(ORDER_BY_DESC);
916                                            }
917                                    }
918                            }
919                    }
920    
921                    String sql = query.toString();
922    
923                    Query q = session.createQuery(sql);
924    
925                    q.setFirstResult(0);
926                    q.setMaxResults(2);
927    
928                    QueryPos qPos = QueryPos.getInstance(q);
929    
930                    qPos.add(classNameId);
931    
932                    qPos.add(classPK);
933    
934                    if (orderByComparator != null) {
935                            Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
936    
937                            for (Object value : values) {
938                                    qPos.add(value);
939                            }
940                    }
941    
942                    List<RatingsEntry> list = q.list();
943    
944                    if (list.size() == 2) {
945                            return list.get(1);
946                    }
947                    else {
948                            return null;
949                    }
950            }
951    
952            /**
953             * Returns the ratings entry where userId = &#63; and classNameId = &#63; and classPK = &#63; or throws a {@link com.liferay.portlet.ratings.NoSuchEntryException} if it could not be found.
954             *
955             * @param userId the user ID
956             * @param classNameId the class name ID
957             * @param classPK the class p k
958             * @return the matching ratings entry
959             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
960             * @throws SystemException if a system exception occurred
961             */
962            public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
963                    throws NoSuchEntryException, SystemException {
964                    RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
965    
966                    if (ratingsEntry == null) {
967                            StringBundler msg = new StringBundler(8);
968    
969                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
970    
971                            msg.append("userId=");
972                            msg.append(userId);
973    
974                            msg.append(", classNameId=");
975                            msg.append(classNameId);
976    
977                            msg.append(", classPK=");
978                            msg.append(classPK);
979    
980                            msg.append(StringPool.CLOSE_CURLY_BRACE);
981    
982                            if (_log.isWarnEnabled()) {
983                                    _log.warn(msg.toString());
984                            }
985    
986                            throw new NoSuchEntryException(msg.toString());
987                    }
988    
989                    return ratingsEntry;
990            }
991    
992            /**
993             * Returns the ratings entry where userId = &#63; and classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
994             *
995             * @param userId the user ID
996             * @param classNameId the class name ID
997             * @param classPK the class p k
998             * @return the matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
999             * @throws SystemException if a system exception occurred
1000             */
1001            public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
1002                    throws SystemException {
1003                    return fetchByU_C_C(userId, classNameId, classPK, true);
1004            }
1005    
1006            /**
1007             * Returns the ratings entry where userId = &#63; and classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1008             *
1009             * @param userId the user ID
1010             * @param classNameId the class name ID
1011             * @param classPK the class p k
1012             * @param retrieveFromCache whether to use the finder cache
1013             * @return the matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1014             * @throws SystemException if a system exception occurred
1015             */
1016            public RatingsEntry fetchByU_C_C(long userId, long classNameId,
1017                    long classPK, boolean retrieveFromCache) throws SystemException {
1018                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1019    
1020                    Object result = null;
1021    
1022                    if (retrieveFromCache) {
1023                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
1024                                            finderArgs, this);
1025                    }
1026    
1027                    if (result instanceof RatingsEntry) {
1028                            RatingsEntry ratingsEntry = (RatingsEntry)result;
1029    
1030                            if ((userId != ratingsEntry.getUserId()) ||
1031                                            (classNameId != ratingsEntry.getClassNameId()) ||
1032                                            (classPK != ratingsEntry.getClassPK())) {
1033                                    result = null;
1034                            }
1035                    }
1036    
1037                    if (result == null) {
1038                            StringBundler query = new StringBundler(4);
1039    
1040                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1041    
1042                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1043    
1044                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1045    
1046                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1047    
1048                            String sql = query.toString();
1049    
1050                            Session session = null;
1051    
1052                            try {
1053                                    session = openSession();
1054    
1055                                    Query q = session.createQuery(sql);
1056    
1057                                    QueryPos qPos = QueryPos.getInstance(q);
1058    
1059                                    qPos.add(userId);
1060    
1061                                    qPos.add(classNameId);
1062    
1063                                    qPos.add(classPK);
1064    
1065                                    List<RatingsEntry> list = q.list();
1066    
1067                                    result = list;
1068    
1069                                    RatingsEntry ratingsEntry = null;
1070    
1071                                    if (list.isEmpty()) {
1072                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1073                                                    finderArgs, list);
1074                                    }
1075                                    else {
1076                                            ratingsEntry = list.get(0);
1077    
1078                                            cacheResult(ratingsEntry);
1079    
1080                                            if ((ratingsEntry.getUserId() != userId) ||
1081                                                            (ratingsEntry.getClassNameId() != classNameId) ||
1082                                                            (ratingsEntry.getClassPK() != classPK)) {
1083                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1084                                                            finderArgs, ratingsEntry);
1085                                            }
1086                                    }
1087    
1088                                    return ratingsEntry;
1089                            }
1090                            catch (Exception e) {
1091                                    throw processException(e);
1092                            }
1093                            finally {
1094                                    if (result == null) {
1095                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
1096                                                    finderArgs);
1097                                    }
1098    
1099                                    closeSession(session);
1100                            }
1101                    }
1102                    else {
1103                            if (result instanceof List<?>) {
1104                                    return null;
1105                            }
1106                            else {
1107                                    return (RatingsEntry)result;
1108                            }
1109                    }
1110            }
1111    
1112            /**
1113             * Returns all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1114             *
1115             * @param classNameId the class name ID
1116             * @param classPK the class p k
1117             * @param score the score
1118             * @return the matching ratings entries
1119             * @throws SystemException if a system exception occurred
1120             */
1121            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1122                    double score) throws SystemException {
1123                    return findByC_C_S(classNameId, classPK, score, QueryUtil.ALL_POS,
1124                            QueryUtil.ALL_POS, null);
1125            }
1126    
1127            /**
1128             * Returns a range of all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1129             *
1130             * <p>
1131             * 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.
1132             * </p>
1133             *
1134             * @param classNameId the class name ID
1135             * @param classPK the class p k
1136             * @param score the score
1137             * @param start the lower bound of the range of ratings entries
1138             * @param end the upper bound of the range of ratings entries (not inclusive)
1139             * @return the range of matching ratings entries
1140             * @throws SystemException if a system exception occurred
1141             */
1142            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1143                    double score, int start, int end) throws SystemException {
1144                    return findByC_C_S(classNameId, classPK, score, start, end, null);
1145            }
1146    
1147            /**
1148             * Returns an ordered range of all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1149             *
1150             * <p>
1151             * 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.
1152             * </p>
1153             *
1154             * @param classNameId the class name ID
1155             * @param classPK the class p k
1156             * @param score the score
1157             * @param start the lower bound of the range of ratings entries
1158             * @param end the upper bound of the range of ratings entries (not inclusive)
1159             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1160             * @return the ordered range of matching ratings entries
1161             * @throws SystemException if a system exception occurred
1162             */
1163            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1164                    double score, int start, int end, OrderByComparator orderByComparator)
1165                    throws SystemException {
1166                    FinderPath finderPath = null;
1167                    Object[] finderArgs = null;
1168    
1169                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1170                                    (orderByComparator == null)) {
1171                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
1172                            finderArgs = new Object[] { classNameId, classPK, score };
1173                    }
1174                    else {
1175                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
1176                            finderArgs = new Object[] {
1177                                            classNameId, classPK, score,
1178                                            
1179                                            start, end, orderByComparator
1180                                    };
1181                    }
1182    
1183                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1184                                    finderArgs, this);
1185    
1186                    if ((list != null) && !list.isEmpty()) {
1187                            for (RatingsEntry ratingsEntry : list) {
1188                                    if ((classNameId != ratingsEntry.getClassNameId()) ||
1189                                                    (classPK != ratingsEntry.getClassPK()) ||
1190                                                    (score != ratingsEntry.getScore())) {
1191                                            list = null;
1192    
1193                                            break;
1194                                    }
1195                            }
1196                    }
1197    
1198                    if (list == null) {
1199                            StringBundler query = null;
1200    
1201                            if (orderByComparator != null) {
1202                                    query = new StringBundler(5 +
1203                                                    (orderByComparator.getOrderByFields().length * 3));
1204                            }
1205                            else {
1206                                    query = new StringBundler(4);
1207                            }
1208    
1209                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1210    
1211                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1212    
1213                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1214    
1215                            query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1216    
1217                            if (orderByComparator != null) {
1218                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1219                                            orderByComparator);
1220                            }
1221    
1222                            String sql = query.toString();
1223    
1224                            Session session = null;
1225    
1226                            try {
1227                                    session = openSession();
1228    
1229                                    Query q = session.createQuery(sql);
1230    
1231                                    QueryPos qPos = QueryPos.getInstance(q);
1232    
1233                                    qPos.add(classNameId);
1234    
1235                                    qPos.add(classPK);
1236    
1237                                    qPos.add(score);
1238    
1239                                    list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1240                                                    start, end);
1241                            }
1242                            catch (Exception e) {
1243                                    throw processException(e);
1244                            }
1245                            finally {
1246                                    if (list == null) {
1247                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1248                                    }
1249                                    else {
1250                                            cacheResult(list);
1251    
1252                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1253                                    }
1254    
1255                                    closeSession(session);
1256                            }
1257                    }
1258    
1259                    return list;
1260            }
1261    
1262            /**
1263             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
1264             *
1265             * <p>
1266             * 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.
1267             * </p>
1268             *
1269             * @param classNameId the class name ID
1270             * @param classPK the class p k
1271             * @param score the score
1272             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1273             * @return the first matching ratings entry
1274             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
1275             * @throws SystemException if a system exception occurred
1276             */
1277            public RatingsEntry findByC_C_S_First(long classNameId, long classPK,
1278                    double score, OrderByComparator orderByComparator)
1279                    throws NoSuchEntryException, SystemException {
1280                    List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score, 0,
1281                                    1, orderByComparator);
1282    
1283                    if (list.isEmpty()) {
1284                            StringBundler msg = new StringBundler(8);
1285    
1286                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1287    
1288                            msg.append("classNameId=");
1289                            msg.append(classNameId);
1290    
1291                            msg.append(", classPK=");
1292                            msg.append(classPK);
1293    
1294                            msg.append(", score=");
1295                            msg.append(score);
1296    
1297                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1298    
1299                            throw new NoSuchEntryException(msg.toString());
1300                    }
1301                    else {
1302                            return list.get(0);
1303                    }
1304            }
1305    
1306            /**
1307             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
1308             *
1309             * <p>
1310             * 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.
1311             * </p>
1312             *
1313             * @param classNameId the class name ID
1314             * @param classPK the class p k
1315             * @param score the score
1316             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1317             * @return the last matching ratings entry
1318             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
1319             * @throws SystemException if a system exception occurred
1320             */
1321            public RatingsEntry findByC_C_S_Last(long classNameId, long classPK,
1322                    double score, OrderByComparator orderByComparator)
1323                    throws NoSuchEntryException, SystemException {
1324                    int count = countByC_C_S(classNameId, classPK, score);
1325    
1326                    List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score,
1327                                    count - 1, count, orderByComparator);
1328    
1329                    if (list.isEmpty()) {
1330                            StringBundler msg = new StringBundler(8);
1331    
1332                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1333    
1334                            msg.append("classNameId=");
1335                            msg.append(classNameId);
1336    
1337                            msg.append(", classPK=");
1338                            msg.append(classPK);
1339    
1340                            msg.append(", score=");
1341                            msg.append(score);
1342    
1343                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1344    
1345                            throw new NoSuchEntryException(msg.toString());
1346                    }
1347                    else {
1348                            return list.get(0);
1349                    }
1350            }
1351    
1352            /**
1353             * Returns the ratings entries before and after the current ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
1354             *
1355             * <p>
1356             * 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.
1357             * </p>
1358             *
1359             * @param entryId the primary key of the current ratings entry
1360             * @param classNameId the class name ID
1361             * @param classPK the class p k
1362             * @param score the score
1363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1364             * @return the previous, current, and next ratings entry
1365             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
1366             * @throws SystemException if a system exception occurred
1367             */
1368            public RatingsEntry[] findByC_C_S_PrevAndNext(long entryId,
1369                    long classNameId, long classPK, double score,
1370                    OrderByComparator orderByComparator)
1371                    throws NoSuchEntryException, SystemException {
1372                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
1373    
1374                    Session session = null;
1375    
1376                    try {
1377                            session = openSession();
1378    
1379                            RatingsEntry[] array = new RatingsEntryImpl[3];
1380    
1381                            array[0] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1382                                            classNameId, classPK, score, orderByComparator, true);
1383    
1384                            array[1] = ratingsEntry;
1385    
1386                            array[2] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1387                                            classNameId, classPK, score, orderByComparator, false);
1388    
1389                            return array;
1390                    }
1391                    catch (Exception e) {
1392                            throw processException(e);
1393                    }
1394                    finally {
1395                            closeSession(session);
1396                    }
1397            }
1398    
1399            protected RatingsEntry getByC_C_S_PrevAndNext(Session session,
1400                    RatingsEntry ratingsEntry, long classNameId, long classPK,
1401                    double score, OrderByComparator orderByComparator, boolean previous) {
1402                    StringBundler query = null;
1403    
1404                    if (orderByComparator != null) {
1405                            query = new StringBundler(6 +
1406                                            (orderByComparator.getOrderByFields().length * 6));
1407                    }
1408                    else {
1409                            query = new StringBundler(3);
1410                    }
1411    
1412                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1413    
1414                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1415    
1416                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1417    
1418                    query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1419    
1420                    if (orderByComparator != null) {
1421                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1422    
1423                            if (orderByConditionFields.length > 0) {
1424                                    query.append(WHERE_AND);
1425                            }
1426    
1427                            for (int i = 0; i < orderByConditionFields.length; i++) {
1428                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1429                                    query.append(orderByConditionFields[i]);
1430    
1431                                    if ((i + 1) < orderByConditionFields.length) {
1432                                            if (orderByComparator.isAscending() ^ previous) {
1433                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1434                                            }
1435                                            else {
1436                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1437                                            }
1438                                    }
1439                                    else {
1440                                            if (orderByComparator.isAscending() ^ previous) {
1441                                                    query.append(WHERE_GREATER_THAN);
1442                                            }
1443                                            else {
1444                                                    query.append(WHERE_LESSER_THAN);
1445                                            }
1446                                    }
1447                            }
1448    
1449                            query.append(ORDER_BY_CLAUSE);
1450    
1451                            String[] orderByFields = orderByComparator.getOrderByFields();
1452    
1453                            for (int i = 0; i < orderByFields.length; i++) {
1454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1455                                    query.append(orderByFields[i]);
1456    
1457                                    if ((i + 1) < orderByFields.length) {
1458                                            if (orderByComparator.isAscending() ^ previous) {
1459                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1460                                            }
1461                                            else {
1462                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1463                                            }
1464                                    }
1465                                    else {
1466                                            if (orderByComparator.isAscending() ^ previous) {
1467                                                    query.append(ORDER_BY_ASC);
1468                                            }
1469                                            else {
1470                                                    query.append(ORDER_BY_DESC);
1471                                            }
1472                                    }
1473                            }
1474                    }
1475    
1476                    String sql = query.toString();
1477    
1478                    Query q = session.createQuery(sql);
1479    
1480                    q.setFirstResult(0);
1481                    q.setMaxResults(2);
1482    
1483                    QueryPos qPos = QueryPos.getInstance(q);
1484    
1485                    qPos.add(classNameId);
1486    
1487                    qPos.add(classPK);
1488    
1489                    qPos.add(score);
1490    
1491                    if (orderByComparator != null) {
1492                            Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
1493    
1494                            for (Object value : values) {
1495                                    qPos.add(value);
1496                            }
1497                    }
1498    
1499                    List<RatingsEntry> list = q.list();
1500    
1501                    if (list.size() == 2) {
1502                            return list.get(1);
1503                    }
1504                    else {
1505                            return null;
1506                    }
1507            }
1508    
1509            /**
1510             * Returns all the ratings entries.
1511             *
1512             * @return the ratings entries
1513             * @throws SystemException if a system exception occurred
1514             */
1515            public List<RatingsEntry> findAll() throws SystemException {
1516                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1517            }
1518    
1519            /**
1520             * Returns a range of all the ratings entries.
1521             *
1522             * <p>
1523             * 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.
1524             * </p>
1525             *
1526             * @param start the lower bound of the range of ratings entries
1527             * @param end the upper bound of the range of ratings entries (not inclusive)
1528             * @return the range of ratings entries
1529             * @throws SystemException if a system exception occurred
1530             */
1531            public List<RatingsEntry> findAll(int start, int end)
1532                    throws SystemException {
1533                    return findAll(start, end, null);
1534            }
1535    
1536            /**
1537             * Returns an ordered range of all the ratings entries.
1538             *
1539             * <p>
1540             * 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.
1541             * </p>
1542             *
1543             * @param start the lower bound of the range of ratings entries
1544             * @param end the upper bound of the range of ratings entries (not inclusive)
1545             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1546             * @return the ordered range of ratings entries
1547             * @throws SystemException if a system exception occurred
1548             */
1549            public List<RatingsEntry> findAll(int start, int end,
1550                    OrderByComparator orderByComparator) throws SystemException {
1551                    FinderPath finderPath = null;
1552                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1553    
1554                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1555                                    (orderByComparator == null)) {
1556                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1557                            finderArgs = FINDER_ARGS_EMPTY;
1558                    }
1559                    else {
1560                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1561                            finderArgs = new Object[] { start, end, orderByComparator };
1562                    }
1563    
1564                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1565                                    finderArgs, this);
1566    
1567                    if (list == null) {
1568                            StringBundler query = null;
1569                            String sql = null;
1570    
1571                            if (orderByComparator != null) {
1572                                    query = new StringBundler(2 +
1573                                                    (orderByComparator.getOrderByFields().length * 3));
1574    
1575                                    query.append(_SQL_SELECT_RATINGSENTRY);
1576    
1577                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1578                                            orderByComparator);
1579    
1580                                    sql = query.toString();
1581                            }
1582                            else {
1583                                    sql = _SQL_SELECT_RATINGSENTRY;
1584                            }
1585    
1586                            Session session = null;
1587    
1588                            try {
1589                                    session = openSession();
1590    
1591                                    Query q = session.createQuery(sql);
1592    
1593                                    if (orderByComparator == null) {
1594                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1595                                                            start, end, false);
1596    
1597                                            Collections.sort(list);
1598                                    }
1599                                    else {
1600                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1601                                                            start, end);
1602                                    }
1603                            }
1604                            catch (Exception e) {
1605                                    throw processException(e);
1606                            }
1607                            finally {
1608                                    if (list == null) {
1609                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1610                                    }
1611                                    else {
1612                                            cacheResult(list);
1613    
1614                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1615                                    }
1616    
1617                                    closeSession(session);
1618                            }
1619                    }
1620    
1621                    return list;
1622            }
1623    
1624            /**
1625             * Removes all the ratings entries where classNameId = &#63; and classPK = &#63; from the database.
1626             *
1627             * @param classNameId the class name ID
1628             * @param classPK the class p k
1629             * @throws SystemException if a system exception occurred
1630             */
1631            public void removeByC_C(long classNameId, long classPK)
1632                    throws SystemException {
1633                    for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
1634                            remove(ratingsEntry);
1635                    }
1636            }
1637    
1638            /**
1639             * Removes the ratings entry where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1640             *
1641             * @param userId the user ID
1642             * @param classNameId the class name ID
1643             * @param classPK the class p k
1644             * @throws SystemException if a system exception occurred
1645             */
1646            public void removeByU_C_C(long userId, long classNameId, long classPK)
1647                    throws NoSuchEntryException, SystemException {
1648                    RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
1649    
1650                    remove(ratingsEntry);
1651            }
1652    
1653            /**
1654             * Removes all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63; from the database.
1655             *
1656             * @param classNameId the class name ID
1657             * @param classPK the class p k
1658             * @param score the score
1659             * @throws SystemException if a system exception occurred
1660             */
1661            public void removeByC_C_S(long classNameId, long classPK, double score)
1662                    throws SystemException {
1663                    for (RatingsEntry ratingsEntry : findByC_C_S(classNameId, classPK, score)) {
1664                            remove(ratingsEntry);
1665                    }
1666            }
1667    
1668            /**
1669             * Removes all the ratings entries from the database.
1670             *
1671             * @throws SystemException if a system exception occurred
1672             */
1673            public void removeAll() throws SystemException {
1674                    for (RatingsEntry ratingsEntry : findAll()) {
1675                            remove(ratingsEntry);
1676                    }
1677            }
1678    
1679            /**
1680             * Returns the number of ratings entries where classNameId = &#63; and classPK = &#63;.
1681             *
1682             * @param classNameId the class name ID
1683             * @param classPK the class p k
1684             * @return the number of matching ratings entries
1685             * @throws SystemException if a system exception occurred
1686             */
1687            public int countByC_C(long classNameId, long classPK)
1688                    throws SystemException {
1689                    Object[] finderArgs = new Object[] { classNameId, classPK };
1690    
1691                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1692                                    finderArgs, this);
1693    
1694                    if (count == null) {
1695                            StringBundler query = new StringBundler(3);
1696    
1697                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1698    
1699                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1700    
1701                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1702    
1703                            String sql = query.toString();
1704    
1705                            Session session = null;
1706    
1707                            try {
1708                                    session = openSession();
1709    
1710                                    Query q = session.createQuery(sql);
1711    
1712                                    QueryPos qPos = QueryPos.getInstance(q);
1713    
1714                                    qPos.add(classNameId);
1715    
1716                                    qPos.add(classPK);
1717    
1718                                    count = (Long)q.uniqueResult();
1719                            }
1720                            catch (Exception e) {
1721                                    throw processException(e);
1722                            }
1723                            finally {
1724                                    if (count == null) {
1725                                            count = Long.valueOf(0);
1726                                    }
1727    
1728                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1729                                            count);
1730    
1731                                    closeSession(session);
1732                            }
1733                    }
1734    
1735                    return count.intValue();
1736            }
1737    
1738            /**
1739             * Returns the number of ratings entries where userId = &#63; and classNameId = &#63; and classPK = &#63;.
1740             *
1741             * @param userId the user ID
1742             * @param classNameId the class name ID
1743             * @param classPK the class p k
1744             * @return the number of matching ratings entries
1745             * @throws SystemException if a system exception occurred
1746             */
1747            public int countByU_C_C(long userId, long classNameId, long classPK)
1748                    throws SystemException {
1749                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1750    
1751                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
1752                                    finderArgs, this);
1753    
1754                    if (count == null) {
1755                            StringBundler query = new StringBundler(4);
1756    
1757                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1758    
1759                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1760    
1761                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1762    
1763                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1764    
1765                            String sql = query.toString();
1766    
1767                            Session session = null;
1768    
1769                            try {
1770                                    session = openSession();
1771    
1772                                    Query q = session.createQuery(sql);
1773    
1774                                    QueryPos qPos = QueryPos.getInstance(q);
1775    
1776                                    qPos.add(userId);
1777    
1778                                    qPos.add(classNameId);
1779    
1780                                    qPos.add(classPK);
1781    
1782                                    count = (Long)q.uniqueResult();
1783                            }
1784                            catch (Exception e) {
1785                                    throw processException(e);
1786                            }
1787                            finally {
1788                                    if (count == null) {
1789                                            count = Long.valueOf(0);
1790                                    }
1791    
1792                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
1793                                            finderArgs, count);
1794    
1795                                    closeSession(session);
1796                            }
1797                    }
1798    
1799                    return count.intValue();
1800            }
1801    
1802            /**
1803             * Returns the number of ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1804             *
1805             * @param classNameId the class name ID
1806             * @param classPK the class p k
1807             * @param score the score
1808             * @return the number of matching ratings entries
1809             * @throws SystemException if a system exception occurred
1810             */
1811            public int countByC_C_S(long classNameId, long classPK, double score)
1812                    throws SystemException {
1813                    Object[] finderArgs = new Object[] { classNameId, classPK, score };
1814    
1815                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
1816                                    finderArgs, this);
1817    
1818                    if (count == null) {
1819                            StringBundler query = new StringBundler(4);
1820    
1821                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1822    
1823                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1824    
1825                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1826    
1827                            query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1828    
1829                            String sql = query.toString();
1830    
1831                            Session session = null;
1832    
1833                            try {
1834                                    session = openSession();
1835    
1836                                    Query q = session.createQuery(sql);
1837    
1838                                    QueryPos qPos = QueryPos.getInstance(q);
1839    
1840                                    qPos.add(classNameId);
1841    
1842                                    qPos.add(classPK);
1843    
1844                                    qPos.add(score);
1845    
1846                                    count = (Long)q.uniqueResult();
1847                            }
1848                            catch (Exception e) {
1849                                    throw processException(e);
1850                            }
1851                            finally {
1852                                    if (count == null) {
1853                                            count = Long.valueOf(0);
1854                                    }
1855    
1856                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
1857                                            finderArgs, count);
1858    
1859                                    closeSession(session);
1860                            }
1861                    }
1862    
1863                    return count.intValue();
1864            }
1865    
1866            /**
1867             * Returns the number of ratings entries.
1868             *
1869             * @return the number of ratings entries
1870             * @throws SystemException if a system exception occurred
1871             */
1872            public int countAll() throws SystemException {
1873                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1874                                    FINDER_ARGS_EMPTY, this);
1875    
1876                    if (count == null) {
1877                            Session session = null;
1878    
1879                            try {
1880                                    session = openSession();
1881    
1882                                    Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
1883    
1884                                    count = (Long)q.uniqueResult();
1885                            }
1886                            catch (Exception e) {
1887                                    throw processException(e);
1888                            }
1889                            finally {
1890                                    if (count == null) {
1891                                            count = Long.valueOf(0);
1892                                    }
1893    
1894                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1895                                            FINDER_ARGS_EMPTY, count);
1896    
1897                                    closeSession(session);
1898                            }
1899                    }
1900    
1901                    return count.intValue();
1902            }
1903    
1904            /**
1905             * Initializes the ratings entry persistence.
1906             */
1907            public void afterPropertiesSet() {
1908                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1909                                            com.liferay.portal.util.PropsUtil.get(
1910                                                    "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1911    
1912                    if (listenerClassNames.length > 0) {
1913                            try {
1914                                    List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1915    
1916                                    for (String listenerClassName : listenerClassNames) {
1917                                            listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
1918                                                            listenerClassName));
1919                                    }
1920    
1921                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1922                            }
1923                            catch (Exception e) {
1924                                    _log.error(e);
1925                            }
1926                    }
1927            }
1928    
1929            public void destroy() {
1930                    EntityCacheUtil.removeCache(RatingsEntryImpl.class.getName());
1931                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1932                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1933            }
1934    
1935            @BeanReference(type = RatingsEntryPersistence.class)
1936            protected RatingsEntryPersistence ratingsEntryPersistence;
1937            @BeanReference(type = RatingsStatsPersistence.class)
1938            protected RatingsStatsPersistence ratingsStatsPersistence;
1939            @BeanReference(type = ResourcePersistence.class)
1940            protected ResourcePersistence resourcePersistence;
1941            @BeanReference(type = UserPersistence.class)
1942            protected UserPersistence userPersistence;
1943            @BeanReference(type = AssetEntryPersistence.class)
1944            protected AssetEntryPersistence assetEntryPersistence;
1945            @BeanReference(type = BlogsEntryPersistence.class)
1946            protected BlogsEntryPersistence blogsEntryPersistence;
1947            @BeanReference(type = BlogsStatsUserPersistence.class)
1948            protected BlogsStatsUserPersistence blogsStatsUserPersistence;
1949            @BeanReference(type = SocialActivityPersistence.class)
1950            protected SocialActivityPersistence socialActivityPersistence;
1951            private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1952            private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1953            private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1954            private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1955            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1956            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1957            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1958            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1959            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1960            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1961            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "ratingsEntry.classPK = ? AND ";
1962            private static final String _FINDER_COLUMN_C_C_S_SCORE_2 = "ratingsEntry.score = ?";
1963            private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1964            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1965            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1966            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1967            private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1968            private static RatingsEntry _nullRatingsEntry = new RatingsEntryImpl() {
1969                            @Override
1970                            public Object clone() {
1971                                    return this;
1972                            }
1973    
1974                            @Override
1975                            public CacheModel<RatingsEntry> toCacheModel() {
1976                                    return _nullRatingsEntryCacheModel;
1977                            }
1978                    };
1979    
1980            private static CacheModel<RatingsEntry> _nullRatingsEntryCacheModel = new CacheModel<RatingsEntry>() {
1981                            public RatingsEntry toEntityModel() {
1982                                    return _nullRatingsEntry;
1983                            }
1984                    };
1985    }