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