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