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