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