001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    
375                    else {
376                            if ((ratingsEntryModelImpl.getColumnBitmask() &
377                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
378                                    Object[] args = new Object[] {
379                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
380                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK())
381                                            };
382    
383                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
384                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
385                                            args);
386    
387                                    args = new Object[] {
388                                                    Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
389                                                    Long.valueOf(ratingsEntryModelImpl.getClassPK())
390                                            };
391    
392                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
393                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
394                                            args);
395                            }
396    
397                            if ((ratingsEntryModelImpl.getColumnBitmask() &
398                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
399                                    Object[] args = new Object[] {
400                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
401                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK()),
402                                                    Double.valueOf(ratingsEntryModelImpl.getOriginalScore())
403                                            };
404    
405                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
406                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
407                                            args);
408    
409                                    args = new Object[] {
410                                                    Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
411                                                    Long.valueOf(ratingsEntryModelImpl.getClassPK()),
412                                                    Double.valueOf(ratingsEntryModelImpl.getScore())
413                                            };
414    
415                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
416                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
417                                            args);
418                            }
419                    }
420    
421                    EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
422                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
423    
424                    if (isNew) {
425                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
426                                    new Object[] {
427                                            Long.valueOf(ratingsEntry.getUserId()),
428                                            Long.valueOf(ratingsEntry.getClassNameId()),
429                                            Long.valueOf(ratingsEntry.getClassPK())
430                                    }, ratingsEntry);
431                    }
432                    else {
433                            if ((ratingsEntryModelImpl.getColumnBitmask() &
434                                            FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
435                                    Object[] args = new Object[] {
436                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalUserId()),
437                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
438                                                    Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK())
439                                            };
440    
441                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
442    
443                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
444    
445                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
446                                            new Object[] {
447                                                    Long.valueOf(ratingsEntry.getUserId()),
448                                                    Long.valueOf(ratingsEntry.getClassNameId()),
449                                                    Long.valueOf(ratingsEntry.getClassPK())
450                                            }, ratingsEntry);
451                            }
452                    }
453    
454                    return ratingsEntry;
455            }
456    
457            protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
458                    if (ratingsEntry instanceof RatingsEntryImpl) {
459                            return ratingsEntry;
460                    }
461    
462                    RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
463    
464                    ratingsEntryImpl.setNew(ratingsEntry.isNew());
465                    ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
466    
467                    ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
468                    ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
469                    ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
470                    ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
471                    ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
472                    ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
473                    ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
474                    ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
475                    ratingsEntryImpl.setScore(ratingsEntry.getScore());
476    
477                    return ratingsEntryImpl;
478            }
479    
480            /**
481             * Returns the ratings entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
482             *
483             * @param primaryKey the primary key of the ratings entry
484             * @return the ratings entry
485             * @throws com.liferay.portal.NoSuchModelException if a ratings entry with the primary key could not be found
486             * @throws SystemException if a system exception occurred
487             */
488            @Override
489            public RatingsEntry findByPrimaryKey(Serializable primaryKey)
490                    throws NoSuchModelException, SystemException {
491                    return findByPrimaryKey(((Long)primaryKey).longValue());
492            }
493    
494            /**
495             * Returns the ratings entry with the primary key or throws a {@link com.liferay.portlet.ratings.NoSuchEntryException} if it could not be found.
496             *
497             * @param entryId the primary key of the ratings entry
498             * @return the ratings entry
499             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
500             * @throws SystemException if a system exception occurred
501             */
502            public RatingsEntry findByPrimaryKey(long entryId)
503                    throws NoSuchEntryException, SystemException {
504                    RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
505    
506                    if (ratingsEntry == null) {
507                            if (_log.isWarnEnabled()) {
508                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
509                            }
510    
511                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
512                                    entryId);
513                    }
514    
515                    return ratingsEntry;
516            }
517    
518            /**
519             * Returns the ratings entry with the primary key or returns <code>null</code> if it could not be found.
520             *
521             * @param primaryKey the primary key of the ratings entry
522             * @return the ratings entry, or <code>null</code> if a ratings entry with the primary key could not be found
523             * @throws SystemException if a system exception occurred
524             */
525            @Override
526            public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
527                    throws SystemException {
528                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
529            }
530    
531            /**
532             * Returns the ratings entry with the primary key or returns <code>null</code> if it could not be found.
533             *
534             * @param entryId the primary key of the ratings entry
535             * @return the ratings entry, or <code>null</code> if a ratings entry with the primary key could not be found
536             * @throws SystemException if a system exception occurred
537             */
538            public RatingsEntry fetchByPrimaryKey(long entryId)
539                    throws SystemException {
540                    RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
541                                    RatingsEntryImpl.class, entryId);
542    
543                    if (ratingsEntry == _nullRatingsEntry) {
544                            return null;
545                    }
546    
547                    if (ratingsEntry == null) {
548                            Session session = null;
549    
550                            boolean hasException = false;
551    
552                            try {
553                                    session = openSession();
554    
555                                    ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
556                                                    Long.valueOf(entryId));
557                            }
558                            catch (Exception e) {
559                                    hasException = true;
560    
561                                    throw processException(e);
562                            }
563                            finally {
564                                    if (ratingsEntry != null) {
565                                            cacheResult(ratingsEntry);
566                                    }
567                                    else if (!hasException) {
568                                            EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
569                                                    RatingsEntryImpl.class, entryId, _nullRatingsEntry);
570                                    }
571    
572                                    closeSession(session);
573                            }
574                    }
575    
576                    return ratingsEntry;
577            }
578    
579            /**
580             * Returns all the ratings entries where classNameId = &#63; and classPK = &#63;.
581             *
582             * @param classNameId the class name ID
583             * @param classPK the class p k
584             * @return the matching ratings entries
585             * @throws SystemException if a system exception occurred
586             */
587            public List<RatingsEntry> findByC_C(long classNameId, long classPK)
588                    throws SystemException {
589                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
590                            QueryUtil.ALL_POS, null);
591            }
592    
593            /**
594             * Returns a range of all the ratings entries where classNameId = &#63; and classPK = &#63;.
595             *
596             * <p>
597             * 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.
598             * </p>
599             *
600             * @param classNameId the class name ID
601             * @param classPK the class p k
602             * @param start the lower bound of the range of ratings entries
603             * @param end the upper bound of the range of ratings entries (not inclusive)
604             * @return the range of matching ratings entries
605             * @throws SystemException if a system exception occurred
606             */
607            public List<RatingsEntry> findByC_C(long classNameId, long classPK,
608                    int start, int end) throws SystemException {
609                    return findByC_C(classNameId, classPK, start, end, null);
610            }
611    
612            /**
613             * Returns an ordered range of all the ratings entries where classNameId = &#63; and classPK = &#63;.
614             *
615             * <p>
616             * 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.
617             * </p>
618             *
619             * @param classNameId the class name ID
620             * @param classPK the class p k
621             * @param start the lower bound of the range of ratings entries
622             * @param end the upper bound of the range of ratings entries (not inclusive)
623             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
624             * @return the ordered range of matching ratings entries
625             * @throws SystemException if a system exception occurred
626             */
627            public List<RatingsEntry> findByC_C(long classNameId, long classPK,
628                    int start, int end, OrderByComparator orderByComparator)
629                    throws SystemException {
630                    FinderPath finderPath = null;
631                    Object[] finderArgs = null;
632    
633                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
634                                    (orderByComparator == null)) {
635                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
636                            finderArgs = new Object[] { classNameId, classPK };
637                    }
638                    else {
639                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
640                            finderArgs = new Object[] {
641                                            classNameId, classPK,
642                                            
643                                            start, end, orderByComparator
644                                    };
645                    }
646    
647                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
648                                    finderArgs, this);
649    
650                    if ((list != null) && !list.isEmpty()) {
651                            for (RatingsEntry ratingsEntry : list) {
652                                    if ((classNameId != ratingsEntry.getClassNameId()) ||
653                                                    (classPK != ratingsEntry.getClassPK())) {
654                                            list = null;
655    
656                                            break;
657                                    }
658                            }
659                    }
660    
661                    if (list == null) {
662                            StringBundler query = null;
663    
664                            if (orderByComparator != null) {
665                                    query = new StringBundler(4 +
666                                                    (orderByComparator.getOrderByFields().length * 3));
667                            }
668                            else {
669                                    query = new StringBundler(3);
670                            }
671    
672                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
673    
674                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
675    
676                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
677    
678                            if (orderByComparator != null) {
679                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
680                                            orderByComparator);
681                            }
682    
683                            String sql = query.toString();
684    
685                            Session session = null;
686    
687                            try {
688                                    session = openSession();
689    
690                                    Query q = session.createQuery(sql);
691    
692                                    QueryPos qPos = QueryPos.getInstance(q);
693    
694                                    qPos.add(classNameId);
695    
696                                    qPos.add(classPK);
697    
698                                    list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
699                                                    start, end);
700                            }
701                            catch (Exception e) {
702                                    throw processException(e);
703                            }
704                            finally {
705                                    if (list == null) {
706                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
707                                    }
708                                    else {
709                                            cacheResult(list);
710    
711                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
712                                    }
713    
714                                    closeSession(session);
715                            }
716                    }
717    
718                    return list;
719            }
720    
721            /**
722             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
723             *
724             * @param classNameId the class name ID
725             * @param classPK the class p k
726             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
727             * @return the first matching ratings entry
728             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
729             * @throws SystemException if a system exception occurred
730             */
731            public RatingsEntry findByC_C_First(long classNameId, long classPK,
732                    OrderByComparator orderByComparator)
733                    throws NoSuchEntryException, SystemException {
734                    RatingsEntry ratingsEntry = fetchByC_C_First(classNameId, classPK,
735                                    orderByComparator);
736    
737                    if (ratingsEntry != null) {
738                            return ratingsEntry;
739                    }
740    
741                    StringBundler msg = new StringBundler(6);
742    
743                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
744    
745                    msg.append("classNameId=");
746                    msg.append(classNameId);
747    
748                    msg.append(", classPK=");
749                    msg.append(classPK);
750    
751                    msg.append(StringPool.CLOSE_CURLY_BRACE);
752    
753                    throw new NoSuchEntryException(msg.toString());
754            }
755    
756            /**
757             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
758             *
759             * @param classNameId the class name ID
760             * @param classPK the class p k
761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
762             * @return the first matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
763             * @throws SystemException if a system exception occurred
764             */
765            public RatingsEntry fetchByC_C_First(long classNameId, long classPK,
766                    OrderByComparator orderByComparator) throws SystemException {
767                    List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
768                                    orderByComparator);
769    
770                    if (!list.isEmpty()) {
771                            return list.get(0);
772                    }
773    
774                    return null;
775            }
776    
777            /**
778             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
779             *
780             * @param classNameId the class name ID
781             * @param classPK the class p k
782             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
783             * @return the last matching ratings entry
784             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
785             * @throws SystemException if a system exception occurred
786             */
787            public RatingsEntry findByC_C_Last(long classNameId, long classPK,
788                    OrderByComparator orderByComparator)
789                    throws NoSuchEntryException, SystemException {
790                    RatingsEntry ratingsEntry = fetchByC_C_Last(classNameId, classPK,
791                                    orderByComparator);
792    
793                    if (ratingsEntry != null) {
794                            return ratingsEntry;
795                    }
796    
797                    StringBundler msg = new StringBundler(6);
798    
799                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
800    
801                    msg.append("classNameId=");
802                    msg.append(classNameId);
803    
804                    msg.append(", classPK=");
805                    msg.append(classPK);
806    
807                    msg.append(StringPool.CLOSE_CURLY_BRACE);
808    
809                    throw new NoSuchEntryException(msg.toString());
810            }
811    
812            /**
813             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
814             *
815             * @param classNameId the class name ID
816             * @param classPK the class p k
817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
818             * @return the last matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
819             * @throws SystemException if a system exception occurred
820             */
821            public RatingsEntry fetchByC_C_Last(long classNameId, long classPK,
822                    OrderByComparator orderByComparator) throws SystemException {
823                    int count = countByC_C(classNameId, classPK);
824    
825                    List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
826                                    count, orderByComparator);
827    
828                    if (!list.isEmpty()) {
829                            return list.get(0);
830                    }
831    
832                    return null;
833            }
834    
835            /**
836             * Returns the ratings entries before and after the current ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
837             *
838             * @param entryId the primary key of the current ratings entry
839             * @param classNameId the class name ID
840             * @param classPK the class p k
841             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
842             * @return the previous, current, and next ratings entry
843             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
844             * @throws SystemException if a system exception occurred
845             */
846            public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
847                    long classPK, OrderByComparator orderByComparator)
848                    throws NoSuchEntryException, SystemException {
849                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
850    
851                    Session session = null;
852    
853                    try {
854                            session = openSession();
855    
856                            RatingsEntry[] array = new RatingsEntryImpl[3];
857    
858                            array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
859                                            classPK, orderByComparator, true);
860    
861                            array[1] = ratingsEntry;
862    
863                            array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
864                                            classPK, orderByComparator, false);
865    
866                            return array;
867                    }
868                    catch (Exception e) {
869                            throw processException(e);
870                    }
871                    finally {
872                            closeSession(session);
873                    }
874            }
875    
876            protected RatingsEntry getByC_C_PrevAndNext(Session session,
877                    RatingsEntry ratingsEntry, long classNameId, long classPK,
878                    OrderByComparator orderByComparator, boolean previous) {
879                    StringBundler query = null;
880    
881                    if (orderByComparator != null) {
882                            query = new StringBundler(6 +
883                                            (orderByComparator.getOrderByFields().length * 6));
884                    }
885                    else {
886                            query = new StringBundler(3);
887                    }
888    
889                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
890    
891                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
892    
893                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
894    
895                    if (orderByComparator != null) {
896                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
897    
898                            if (orderByConditionFields.length > 0) {
899                                    query.append(WHERE_AND);
900                            }
901    
902                            for (int i = 0; i < orderByConditionFields.length; i++) {
903                                    query.append(_ORDER_BY_ENTITY_ALIAS);
904                                    query.append(orderByConditionFields[i]);
905    
906                                    if ((i + 1) < orderByConditionFields.length) {
907                                            if (orderByComparator.isAscending() ^ previous) {
908                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
909                                            }
910                                            else {
911                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
912                                            }
913                                    }
914                                    else {
915                                            if (orderByComparator.isAscending() ^ previous) {
916                                                    query.append(WHERE_GREATER_THAN);
917                                            }
918                                            else {
919                                                    query.append(WHERE_LESSER_THAN);
920                                            }
921                                    }
922                            }
923    
924                            query.append(ORDER_BY_CLAUSE);
925    
926                            String[] orderByFields = orderByComparator.getOrderByFields();
927    
928                            for (int i = 0; i < orderByFields.length; i++) {
929                                    query.append(_ORDER_BY_ENTITY_ALIAS);
930                                    query.append(orderByFields[i]);
931    
932                                    if ((i + 1) < orderByFields.length) {
933                                            if (orderByComparator.isAscending() ^ previous) {
934                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
935                                            }
936                                            else {
937                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
938                                            }
939                                    }
940                                    else {
941                                            if (orderByComparator.isAscending() ^ previous) {
942                                                    query.append(ORDER_BY_ASC);
943                                            }
944                                            else {
945                                                    query.append(ORDER_BY_DESC);
946                                            }
947                                    }
948                            }
949                    }
950    
951                    String sql = query.toString();
952    
953                    Query q = session.createQuery(sql);
954    
955                    q.setFirstResult(0);
956                    q.setMaxResults(2);
957    
958                    QueryPos qPos = QueryPos.getInstance(q);
959    
960                    qPos.add(classNameId);
961    
962                    qPos.add(classPK);
963    
964                    if (orderByComparator != null) {
965                            Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
966    
967                            for (Object value : values) {
968                                    qPos.add(value);
969                            }
970                    }
971    
972                    List<RatingsEntry> list = q.list();
973    
974                    if (list.size() == 2) {
975                            return list.get(1);
976                    }
977                    else {
978                            return null;
979                    }
980            }
981    
982            /**
983             * 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.
984             *
985             * @param userId the user ID
986             * @param classNameId the class name ID
987             * @param classPK the class p k
988             * @return the matching ratings entry
989             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
990             * @throws SystemException if a system exception occurred
991             */
992            public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
993                    throws NoSuchEntryException, SystemException {
994                    RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
995    
996                    if (ratingsEntry == null) {
997                            StringBundler msg = new StringBundler(8);
998    
999                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1000    
1001                            msg.append("userId=");
1002                            msg.append(userId);
1003    
1004                            msg.append(", classNameId=");
1005                            msg.append(classNameId);
1006    
1007                            msg.append(", classPK=");
1008                            msg.append(classPK);
1009    
1010                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1011    
1012                            if (_log.isWarnEnabled()) {
1013                                    _log.warn(msg.toString());
1014                            }
1015    
1016                            throw new NoSuchEntryException(msg.toString());
1017                    }
1018    
1019                    return ratingsEntry;
1020            }
1021    
1022            /**
1023             * 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.
1024             *
1025             * @param userId the user ID
1026             * @param classNameId the class name ID
1027             * @param classPK the class p k
1028             * @return the matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1029             * @throws SystemException if a system exception occurred
1030             */
1031            public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
1032                    throws SystemException {
1033                    return fetchByU_C_C(userId, classNameId, classPK, true);
1034            }
1035    
1036            /**
1037             * 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.
1038             *
1039             * @param userId the user ID
1040             * @param classNameId the class name ID
1041             * @param classPK the class p k
1042             * @param retrieveFromCache whether to use the finder cache
1043             * @return the matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1044             * @throws SystemException if a system exception occurred
1045             */
1046            public RatingsEntry fetchByU_C_C(long userId, long classNameId,
1047                    long classPK, boolean retrieveFromCache) throws SystemException {
1048                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1049    
1050                    Object result = null;
1051    
1052                    if (retrieveFromCache) {
1053                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
1054                                            finderArgs, this);
1055                    }
1056    
1057                    if (result instanceof RatingsEntry) {
1058                            RatingsEntry ratingsEntry = (RatingsEntry)result;
1059    
1060                            if ((userId != ratingsEntry.getUserId()) ||
1061                                            (classNameId != ratingsEntry.getClassNameId()) ||
1062                                            (classPK != ratingsEntry.getClassPK())) {
1063                                    result = null;
1064                            }
1065                    }
1066    
1067                    if (result == null) {
1068                            StringBundler query = new StringBundler(4);
1069    
1070                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1071    
1072                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1073    
1074                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1075    
1076                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1077    
1078                            String sql = query.toString();
1079    
1080                            Session session = null;
1081    
1082                            try {
1083                                    session = openSession();
1084    
1085                                    Query q = session.createQuery(sql);
1086    
1087                                    QueryPos qPos = QueryPos.getInstance(q);
1088    
1089                                    qPos.add(userId);
1090    
1091                                    qPos.add(classNameId);
1092    
1093                                    qPos.add(classPK);
1094    
1095                                    List<RatingsEntry> list = q.list();
1096    
1097                                    result = list;
1098    
1099                                    RatingsEntry ratingsEntry = null;
1100    
1101                                    if (list.isEmpty()) {
1102                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1103                                                    finderArgs, list);
1104                                    }
1105                                    else {
1106                                            ratingsEntry = list.get(0);
1107    
1108                                            cacheResult(ratingsEntry);
1109    
1110                                            if ((ratingsEntry.getUserId() != userId) ||
1111                                                            (ratingsEntry.getClassNameId() != classNameId) ||
1112                                                            (ratingsEntry.getClassPK() != classPK)) {
1113                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1114                                                            finderArgs, ratingsEntry);
1115                                            }
1116                                    }
1117    
1118                                    return ratingsEntry;
1119                            }
1120                            catch (Exception e) {
1121                                    throw processException(e);
1122                            }
1123                            finally {
1124                                    if (result == null) {
1125                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
1126                                                    finderArgs);
1127                                    }
1128    
1129                                    closeSession(session);
1130                            }
1131                    }
1132                    else {
1133                            if (result instanceof List<?>) {
1134                                    return null;
1135                            }
1136                            else {
1137                                    return (RatingsEntry)result;
1138                            }
1139                    }
1140            }
1141    
1142            /**
1143             * Returns all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1144             *
1145             * @param classNameId the class name ID
1146             * @param classPK the class p k
1147             * @param score the score
1148             * @return the matching ratings entries
1149             * @throws SystemException if a system exception occurred
1150             */
1151            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1152                    double score) throws SystemException {
1153                    return findByC_C_S(classNameId, classPK, score, QueryUtil.ALL_POS,
1154                            QueryUtil.ALL_POS, null);
1155            }
1156    
1157            /**
1158             * Returns a range of all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1159             *
1160             * <p>
1161             * 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.
1162             * </p>
1163             *
1164             * @param classNameId the class name ID
1165             * @param classPK the class p k
1166             * @param score the score
1167             * @param start the lower bound of the range of ratings entries
1168             * @param end the upper bound of the range of ratings entries (not inclusive)
1169             * @return the range of matching ratings entries
1170             * @throws SystemException if a system exception occurred
1171             */
1172            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1173                    double score, int start, int end) throws SystemException {
1174                    return findByC_C_S(classNameId, classPK, score, start, end, null);
1175            }
1176    
1177            /**
1178             * Returns an ordered range of all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1179             *
1180             * <p>
1181             * 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.
1182             * </p>
1183             *
1184             * @param classNameId the class name ID
1185             * @param classPK the class p k
1186             * @param score the score
1187             * @param start the lower bound of the range of ratings entries
1188             * @param end the upper bound of the range of ratings entries (not inclusive)
1189             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1190             * @return the ordered range of matching ratings entries
1191             * @throws SystemException if a system exception occurred
1192             */
1193            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1194                    double score, int start, int end, OrderByComparator orderByComparator)
1195                    throws SystemException {
1196                    FinderPath finderPath = null;
1197                    Object[] finderArgs = null;
1198    
1199                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1200                                    (orderByComparator == null)) {
1201                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
1202                            finderArgs = new Object[] { classNameId, classPK, score };
1203                    }
1204                    else {
1205                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
1206                            finderArgs = new Object[] {
1207                                            classNameId, classPK, score,
1208                                            
1209                                            start, end, orderByComparator
1210                                    };
1211                    }
1212    
1213                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1214                                    finderArgs, this);
1215    
1216                    if ((list != null) && !list.isEmpty()) {
1217                            for (RatingsEntry ratingsEntry : list) {
1218                                    if ((classNameId != ratingsEntry.getClassNameId()) ||
1219                                                    (classPK != ratingsEntry.getClassPK()) ||
1220                                                    (score != ratingsEntry.getScore())) {
1221                                            list = null;
1222    
1223                                            break;
1224                                    }
1225                            }
1226                    }
1227    
1228                    if (list == null) {
1229                            StringBundler query = null;
1230    
1231                            if (orderByComparator != null) {
1232                                    query = new StringBundler(5 +
1233                                                    (orderByComparator.getOrderByFields().length * 3));
1234                            }
1235                            else {
1236                                    query = new StringBundler(4);
1237                            }
1238    
1239                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1240    
1241                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1242    
1243                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1244    
1245                            query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1246    
1247                            if (orderByComparator != null) {
1248                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1249                                            orderByComparator);
1250                            }
1251    
1252                            String sql = query.toString();
1253    
1254                            Session session = null;
1255    
1256                            try {
1257                                    session = openSession();
1258    
1259                                    Query q = session.createQuery(sql);
1260    
1261                                    QueryPos qPos = QueryPos.getInstance(q);
1262    
1263                                    qPos.add(classNameId);
1264    
1265                                    qPos.add(classPK);
1266    
1267                                    qPos.add(score);
1268    
1269                                    list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1270                                                    start, end);
1271                            }
1272                            catch (Exception e) {
1273                                    throw processException(e);
1274                            }
1275                            finally {
1276                                    if (list == null) {
1277                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1278                                    }
1279                                    else {
1280                                            cacheResult(list);
1281    
1282                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1283                                    }
1284    
1285                                    closeSession(session);
1286                            }
1287                    }
1288    
1289                    return list;
1290            }
1291    
1292            /**
1293             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
1294             *
1295             * @param classNameId the class name ID
1296             * @param classPK the class p k
1297             * @param score the score
1298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1299             * @return the first matching ratings entry
1300             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
1301             * @throws SystemException if a system exception occurred
1302             */
1303            public RatingsEntry findByC_C_S_First(long classNameId, long classPK,
1304                    double score, OrderByComparator orderByComparator)
1305                    throws NoSuchEntryException, SystemException {
1306                    RatingsEntry ratingsEntry = fetchByC_C_S_First(classNameId, classPK,
1307                                    score, orderByComparator);
1308    
1309                    if (ratingsEntry != null) {
1310                            return ratingsEntry;
1311                    }
1312    
1313                    StringBundler msg = new StringBundler(8);
1314    
1315                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1316    
1317                    msg.append("classNameId=");
1318                    msg.append(classNameId);
1319    
1320                    msg.append(", classPK=");
1321                    msg.append(classPK);
1322    
1323                    msg.append(", score=");
1324                    msg.append(score);
1325    
1326                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1327    
1328                    throw new NoSuchEntryException(msg.toString());
1329            }
1330    
1331            /**
1332             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
1333             *
1334             * @param classNameId the class name ID
1335             * @param classPK the class p k
1336             * @param score the score
1337             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1338             * @return the first matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1339             * @throws SystemException if a system exception occurred
1340             */
1341            public RatingsEntry fetchByC_C_S_First(long classNameId, long classPK,
1342                    double score, OrderByComparator orderByComparator)
1343                    throws SystemException {
1344                    List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score, 0,
1345                                    1, orderByComparator);
1346    
1347                    if (!list.isEmpty()) {
1348                            return list.get(0);
1349                    }
1350    
1351                    return null;
1352            }
1353    
1354            /**
1355             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
1356             *
1357             * @param classNameId the class name ID
1358             * @param classPK the class p k
1359             * @param score the score
1360             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1361             * @return the last matching ratings entry
1362             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
1363             * @throws SystemException if a system exception occurred
1364             */
1365            public RatingsEntry findByC_C_S_Last(long classNameId, long classPK,
1366                    double score, OrderByComparator orderByComparator)
1367                    throws NoSuchEntryException, SystemException {
1368                    RatingsEntry ratingsEntry = fetchByC_C_S_Last(classNameId, classPK,
1369                                    score, orderByComparator);
1370    
1371                    if (ratingsEntry != null) {
1372                            return ratingsEntry;
1373                    }
1374    
1375                    StringBundler msg = new StringBundler(8);
1376    
1377                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1378    
1379                    msg.append("classNameId=");
1380                    msg.append(classNameId);
1381    
1382                    msg.append(", classPK=");
1383                    msg.append(classPK);
1384    
1385                    msg.append(", score=");
1386                    msg.append(score);
1387    
1388                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1389    
1390                    throw new NoSuchEntryException(msg.toString());
1391            }
1392    
1393            /**
1394             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
1395             *
1396             * @param classNameId the class name ID
1397             * @param classPK the class p k
1398             * @param score the score
1399             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1400             * @return the last matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1401             * @throws SystemException if a system exception occurred
1402             */
1403            public RatingsEntry fetchByC_C_S_Last(long classNameId, long classPK,
1404                    double score, OrderByComparator orderByComparator)
1405                    throws SystemException {
1406                    int count = countByC_C_S(classNameId, classPK, score);
1407    
1408                    List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score,
1409                                    count - 1, count, orderByComparator);
1410    
1411                    if (!list.isEmpty()) {
1412                            return list.get(0);
1413                    }
1414    
1415                    return null;
1416            }
1417    
1418            /**
1419             * Returns the ratings entries before and after the current ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
1420             *
1421             * @param entryId the primary key of the current ratings entry
1422             * @param classNameId the class name ID
1423             * @param classPK the class p k
1424             * @param score the score
1425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1426             * @return the previous, current, and next ratings entry
1427             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
1428             * @throws SystemException if a system exception occurred
1429             */
1430            public RatingsEntry[] findByC_C_S_PrevAndNext(long entryId,
1431                    long classNameId, long classPK, double score,
1432                    OrderByComparator orderByComparator)
1433                    throws NoSuchEntryException, SystemException {
1434                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
1435    
1436                    Session session = null;
1437    
1438                    try {
1439                            session = openSession();
1440    
1441                            RatingsEntry[] array = new RatingsEntryImpl[3];
1442    
1443                            array[0] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1444                                            classNameId, classPK, score, orderByComparator, true);
1445    
1446                            array[1] = ratingsEntry;
1447    
1448                            array[2] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1449                                            classNameId, classPK, score, orderByComparator, false);
1450    
1451                            return array;
1452                    }
1453                    catch (Exception e) {
1454                            throw processException(e);
1455                    }
1456                    finally {
1457                            closeSession(session);
1458                    }
1459            }
1460    
1461            protected RatingsEntry getByC_C_S_PrevAndNext(Session session,
1462                    RatingsEntry ratingsEntry, long classNameId, long classPK,
1463                    double score, OrderByComparator orderByComparator, boolean previous) {
1464                    StringBundler query = null;
1465    
1466                    if (orderByComparator != null) {
1467                            query = new StringBundler(6 +
1468                                            (orderByComparator.getOrderByFields().length * 6));
1469                    }
1470                    else {
1471                            query = new StringBundler(3);
1472                    }
1473    
1474                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1475    
1476                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1477    
1478                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1479    
1480                    query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1481    
1482                    if (orderByComparator != null) {
1483                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1484    
1485                            if (orderByConditionFields.length > 0) {
1486                                    query.append(WHERE_AND);
1487                            }
1488    
1489                            for (int i = 0; i < orderByConditionFields.length; i++) {
1490                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1491                                    query.append(orderByConditionFields[i]);
1492    
1493                                    if ((i + 1) < orderByConditionFields.length) {
1494                                            if (orderByComparator.isAscending() ^ previous) {
1495                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1496                                            }
1497                                            else {
1498                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1499                                            }
1500                                    }
1501                                    else {
1502                                            if (orderByComparator.isAscending() ^ previous) {
1503                                                    query.append(WHERE_GREATER_THAN);
1504                                            }
1505                                            else {
1506                                                    query.append(WHERE_LESSER_THAN);
1507                                            }
1508                                    }
1509                            }
1510    
1511                            query.append(ORDER_BY_CLAUSE);
1512    
1513                            String[] orderByFields = orderByComparator.getOrderByFields();
1514    
1515                            for (int i = 0; i < orderByFields.length; i++) {
1516                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1517                                    query.append(orderByFields[i]);
1518    
1519                                    if ((i + 1) < orderByFields.length) {
1520                                            if (orderByComparator.isAscending() ^ previous) {
1521                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1522                                            }
1523                                            else {
1524                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1525                                            }
1526                                    }
1527                                    else {
1528                                            if (orderByComparator.isAscending() ^ previous) {
1529                                                    query.append(ORDER_BY_ASC);
1530                                            }
1531                                            else {
1532                                                    query.append(ORDER_BY_DESC);
1533                                            }
1534                                    }
1535                            }
1536                    }
1537    
1538                    String sql = query.toString();
1539    
1540                    Query q = session.createQuery(sql);
1541    
1542                    q.setFirstResult(0);
1543                    q.setMaxResults(2);
1544    
1545                    QueryPos qPos = QueryPos.getInstance(q);
1546    
1547                    qPos.add(classNameId);
1548    
1549                    qPos.add(classPK);
1550    
1551                    qPos.add(score);
1552    
1553                    if (orderByComparator != null) {
1554                            Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
1555    
1556                            for (Object value : values) {
1557                                    qPos.add(value);
1558                            }
1559                    }
1560    
1561                    List<RatingsEntry> list = q.list();
1562    
1563                    if (list.size() == 2) {
1564                            return list.get(1);
1565                    }
1566                    else {
1567                            return null;
1568                    }
1569            }
1570    
1571            /**
1572             * Returns all the ratings entries.
1573             *
1574             * @return the ratings entries
1575             * @throws SystemException if a system exception occurred
1576             */
1577            public List<RatingsEntry> findAll() throws SystemException {
1578                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1579            }
1580    
1581            /**
1582             * Returns a range of all the ratings entries.
1583             *
1584             * <p>
1585             * 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.
1586             * </p>
1587             *
1588             * @param start the lower bound of the range of ratings entries
1589             * @param end the upper bound of the range of ratings entries (not inclusive)
1590             * @return the range of ratings entries
1591             * @throws SystemException if a system exception occurred
1592             */
1593            public List<RatingsEntry> findAll(int start, int end)
1594                    throws SystemException {
1595                    return findAll(start, end, null);
1596            }
1597    
1598            /**
1599             * Returns an ordered range of all the ratings entries.
1600             *
1601             * <p>
1602             * 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.
1603             * </p>
1604             *
1605             * @param start the lower bound of the range of ratings entries
1606             * @param end the upper bound of the range of ratings entries (not inclusive)
1607             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1608             * @return the ordered range of ratings entries
1609             * @throws SystemException if a system exception occurred
1610             */
1611            public List<RatingsEntry> findAll(int start, int end,
1612                    OrderByComparator orderByComparator) throws SystemException {
1613                    FinderPath finderPath = null;
1614                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1615    
1616                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1617                                    (orderByComparator == null)) {
1618                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1619                            finderArgs = FINDER_ARGS_EMPTY;
1620                    }
1621                    else {
1622                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1623                            finderArgs = new Object[] { start, end, orderByComparator };
1624                    }
1625    
1626                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1627                                    finderArgs, this);
1628    
1629                    if (list == null) {
1630                            StringBundler query = null;
1631                            String sql = null;
1632    
1633                            if (orderByComparator != null) {
1634                                    query = new StringBundler(2 +
1635                                                    (orderByComparator.getOrderByFields().length * 3));
1636    
1637                                    query.append(_SQL_SELECT_RATINGSENTRY);
1638    
1639                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1640                                            orderByComparator);
1641    
1642                                    sql = query.toString();
1643                            }
1644                            else {
1645                                    sql = _SQL_SELECT_RATINGSENTRY;
1646                            }
1647    
1648                            Session session = null;
1649    
1650                            try {
1651                                    session = openSession();
1652    
1653                                    Query q = session.createQuery(sql);
1654    
1655                                    if (orderByComparator == null) {
1656                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1657                                                            start, end, false);
1658    
1659                                            Collections.sort(list);
1660                                    }
1661                                    else {
1662                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1663                                                            start, end);
1664                                    }
1665                            }
1666                            catch (Exception e) {
1667                                    throw processException(e);
1668                            }
1669                            finally {
1670                                    if (list == null) {
1671                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1672                                    }
1673                                    else {
1674                                            cacheResult(list);
1675    
1676                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1677                                    }
1678    
1679                                    closeSession(session);
1680                            }
1681                    }
1682    
1683                    return list;
1684            }
1685    
1686            /**
1687             * Removes all the ratings entries where classNameId = &#63; and classPK = &#63; from the database.
1688             *
1689             * @param classNameId the class name ID
1690             * @param classPK the class p k
1691             * @throws SystemException if a system exception occurred
1692             */
1693            public void removeByC_C(long classNameId, long classPK)
1694                    throws SystemException {
1695                    for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
1696                            remove(ratingsEntry);
1697                    }
1698            }
1699    
1700            /**
1701             * Removes the ratings entry where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1702             *
1703             * @param userId the user ID
1704             * @param classNameId the class name ID
1705             * @param classPK the class p k
1706             * @return the ratings entry that was removed
1707             * @throws SystemException if a system exception occurred
1708             */
1709            public RatingsEntry removeByU_C_C(long userId, long classNameId,
1710                    long classPK) throws NoSuchEntryException, SystemException {
1711                    RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
1712    
1713                    return remove(ratingsEntry);
1714            }
1715    
1716            /**
1717             * Removes all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63; from the database.
1718             *
1719             * @param classNameId the class name ID
1720             * @param classPK the class p k
1721             * @param score the score
1722             * @throws SystemException if a system exception occurred
1723             */
1724            public void removeByC_C_S(long classNameId, long classPK, double score)
1725                    throws SystemException {
1726                    for (RatingsEntry ratingsEntry : findByC_C_S(classNameId, classPK, score)) {
1727                            remove(ratingsEntry);
1728                    }
1729            }
1730    
1731            /**
1732             * Removes all the ratings entries from the database.
1733             *
1734             * @throws SystemException if a system exception occurred
1735             */
1736            public void removeAll() throws SystemException {
1737                    for (RatingsEntry ratingsEntry : findAll()) {
1738                            remove(ratingsEntry);
1739                    }
1740            }
1741    
1742            /**
1743             * Returns the number of ratings entries where classNameId = &#63; and classPK = &#63;.
1744             *
1745             * @param classNameId the class name ID
1746             * @param classPK the class p k
1747             * @return the number of matching ratings entries
1748             * @throws SystemException if a system exception occurred
1749             */
1750            public int countByC_C(long classNameId, long classPK)
1751                    throws SystemException {
1752                    Object[] finderArgs = new Object[] { classNameId, classPK };
1753    
1754                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1755                                    finderArgs, this);
1756    
1757                    if (count == null) {
1758                            StringBundler query = new StringBundler(3);
1759    
1760                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1761    
1762                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1763    
1764                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1765    
1766                            String sql = query.toString();
1767    
1768                            Session session = null;
1769    
1770                            try {
1771                                    session = openSession();
1772    
1773                                    Query q = session.createQuery(sql);
1774    
1775                                    QueryPos qPos = QueryPos.getInstance(q);
1776    
1777                                    qPos.add(classNameId);
1778    
1779                                    qPos.add(classPK);
1780    
1781                                    count = (Long)q.uniqueResult();
1782                            }
1783                            catch (Exception e) {
1784                                    throw processException(e);
1785                            }
1786                            finally {
1787                                    if (count == null) {
1788                                            count = Long.valueOf(0);
1789                                    }
1790    
1791                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1792                                            count);
1793    
1794                                    closeSession(session);
1795                            }
1796                    }
1797    
1798                    return count.intValue();
1799            }
1800    
1801            /**
1802             * Returns the number of ratings entries where userId = &#63; and classNameId = &#63; and classPK = &#63;.
1803             *
1804             * @param userId the user ID
1805             * @param classNameId the class name ID
1806             * @param classPK the class p k
1807             * @return the number of matching ratings entries
1808             * @throws SystemException if a system exception occurred
1809             */
1810            public int countByU_C_C(long userId, long classNameId, long classPK)
1811                    throws SystemException {
1812                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1813    
1814                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
1815                                    finderArgs, this);
1816    
1817                    if (count == null) {
1818                            StringBundler query = new StringBundler(4);
1819    
1820                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1821    
1822                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1823    
1824                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1825    
1826                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1827    
1828                            String sql = query.toString();
1829    
1830                            Session session = null;
1831    
1832                            try {
1833                                    session = openSession();
1834    
1835                                    Query q = session.createQuery(sql);
1836    
1837                                    QueryPos qPos = QueryPos.getInstance(q);
1838    
1839                                    qPos.add(userId);
1840    
1841                                    qPos.add(classNameId);
1842    
1843                                    qPos.add(classPK);
1844    
1845                                    count = (Long)q.uniqueResult();
1846                            }
1847                            catch (Exception e) {
1848                                    throw processException(e);
1849                            }
1850                            finally {
1851                                    if (count == null) {
1852                                            count = Long.valueOf(0);
1853                                    }
1854    
1855                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
1856                                            finderArgs, count);
1857    
1858                                    closeSession(session);
1859                            }
1860                    }
1861    
1862                    return count.intValue();
1863            }
1864    
1865            /**
1866             * Returns the number of ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1867             *
1868             * @param classNameId the class name ID
1869             * @param classPK the class p k
1870             * @param score the score
1871             * @return the number of matching ratings entries
1872             * @throws SystemException if a system exception occurred
1873             */
1874            public int countByC_C_S(long classNameId, long classPK, double score)
1875                    throws SystemException {
1876                    Object[] finderArgs = new Object[] { classNameId, classPK, score };
1877    
1878                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
1879                                    finderArgs, this);
1880    
1881                    if (count == null) {
1882                            StringBundler query = new StringBundler(4);
1883    
1884                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1885    
1886                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1887    
1888                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1889    
1890                            query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1891    
1892                            String sql = query.toString();
1893    
1894                            Session session = null;
1895    
1896                            try {
1897                                    session = openSession();
1898    
1899                                    Query q = session.createQuery(sql);
1900    
1901                                    QueryPos qPos = QueryPos.getInstance(q);
1902    
1903                                    qPos.add(classNameId);
1904    
1905                                    qPos.add(classPK);
1906    
1907                                    qPos.add(score);
1908    
1909                                    count = (Long)q.uniqueResult();
1910                            }
1911                            catch (Exception e) {
1912                                    throw processException(e);
1913                            }
1914                            finally {
1915                                    if (count == null) {
1916                                            count = Long.valueOf(0);
1917                                    }
1918    
1919                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
1920                                            finderArgs, count);
1921    
1922                                    closeSession(session);
1923                            }
1924                    }
1925    
1926                    return count.intValue();
1927            }
1928    
1929            /**
1930             * Returns the number of ratings entries.
1931             *
1932             * @return the number of ratings entries
1933             * @throws SystemException if a system exception occurred
1934             */
1935            public int countAll() throws SystemException {
1936                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1937                                    FINDER_ARGS_EMPTY, this);
1938    
1939                    if (count == null) {
1940                            Session session = null;
1941    
1942                            try {
1943                                    session = openSession();
1944    
1945                                    Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
1946    
1947                                    count = (Long)q.uniqueResult();
1948                            }
1949                            catch (Exception e) {
1950                                    throw processException(e);
1951                            }
1952                            finally {
1953                                    if (count == null) {
1954                                            count = Long.valueOf(0);
1955                                    }
1956    
1957                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1958                                            FINDER_ARGS_EMPTY, count);
1959    
1960                                    closeSession(session);
1961                            }
1962                    }
1963    
1964                    return count.intValue();
1965            }
1966    
1967            /**
1968             * Initializes the ratings entry persistence.
1969             */
1970            public void afterPropertiesSet() {
1971                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1972                                            com.liferay.portal.util.PropsUtil.get(
1973                                                    "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1974    
1975                    if (listenerClassNames.length > 0) {
1976                            try {
1977                                    List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1978    
1979                                    for (String listenerClassName : listenerClassNames) {
1980                                            listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
1981                                                            listenerClassName));
1982                                    }
1983    
1984                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1985                            }
1986                            catch (Exception e) {
1987                                    _log.error(e);
1988                            }
1989                    }
1990            }
1991    
1992            public void destroy() {
1993                    EntityCacheUtil.removeCache(RatingsEntryImpl.class.getName());
1994                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1995                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1996            }
1997    
1998            @BeanReference(type = RatingsEntryPersistence.class)
1999            protected RatingsEntryPersistence ratingsEntryPersistence;
2000            @BeanReference(type = RatingsStatsPersistence.class)
2001            protected RatingsStatsPersistence ratingsStatsPersistence;
2002            @BeanReference(type = ResourcePersistence.class)
2003            protected ResourcePersistence resourcePersistence;
2004            @BeanReference(type = UserPersistence.class)
2005            protected UserPersistence userPersistence;
2006            @BeanReference(type = AssetEntryPersistence.class)
2007            protected AssetEntryPersistence assetEntryPersistence;
2008            @BeanReference(type = BlogsEntryPersistence.class)
2009            protected BlogsEntryPersistence blogsEntryPersistence;
2010            @BeanReference(type = BlogsStatsUserPersistence.class)
2011            protected BlogsStatsUserPersistence blogsStatsUserPersistence;
2012            @BeanReference(type = SocialActivityPersistence.class)
2013            protected SocialActivityPersistence socialActivityPersistence;
2014            private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
2015            private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
2016            private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
2017            private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
2018            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
2019            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
2020            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
2021            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
2022            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
2023            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
2024            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "ratingsEntry.classPK = ? AND ";
2025            private static final String _FINDER_COLUMN_C_C_S_SCORE_2 = "ratingsEntry.score = ?";
2026            private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
2027            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
2028            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
2029            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2030            private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
2031            private static RatingsEntry _nullRatingsEntry = new RatingsEntryImpl() {
2032                            @Override
2033                            public Object clone() {
2034                                    return this;
2035                            }
2036    
2037                            @Override
2038                            public CacheModel<RatingsEntry> toCacheModel() {
2039                                    return _nullRatingsEntryCacheModel;
2040                            }
2041                    };
2042    
2043            private static CacheModel<RatingsEntry> _nullRatingsEntryCacheModel = new CacheModel<RatingsEntry>() {
2044                            public RatingsEntry toEntityModel() {
2045                                    return _nullRatingsEntry;
2046                            }
2047                    };
2048    }