001    /**
002     * Copyright (c) 2000-2010 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.annotation.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.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
043    import com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence;
044    import com.liferay.portlet.ratings.NoSuchEntryException;
045    import com.liferay.portlet.ratings.model.RatingsEntry;
046    import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
047    import com.liferay.portlet.ratings.model.impl.RatingsEntryModelImpl;
048    import com.liferay.portlet.social.service.persistence.SocialEquityLogPersistence;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the ratings entry service.
058     *
059     * <p>
060     * 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.
061     * </p>
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see RatingsEntryPersistence
069     * @see RatingsEntryUtil
070     * @generated
071     */
072    public class RatingsEntryPersistenceImpl extends BasePersistenceImpl<RatingsEntry>
073            implements RatingsEntryPersistence {
074            public static final String FINDER_CLASS_NAME_ENTITY = RatingsEntryImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
076                    ".List";
077            public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
078                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
079                            "findByC_C",
080                            new String[] {
081                                    Long.class.getName(), Long.class.getName(),
082                                    
083                            "java.lang.Integer", "java.lang.Integer",
084                                    "com.liferay.portal.kernel.util.OrderByComparator"
085                            });
086            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
087                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088                            "countByC_C",
089                            new String[] { Long.class.getName(), Long.class.getName() });
090            public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
091                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED,
092                            FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
093                            new String[] {
094                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
097                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
098                            "countByU_C_C",
099                            new String[] {
100                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
103                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "findAll", new String[0]);
105            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
106                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107                            "countAll", new String[0]);
108    
109            /**
110             * Caches the ratings entry in the entity cache if it is enabled.
111             *
112             * @param ratingsEntry the ratings entry to cache
113             */
114            public void cacheResult(RatingsEntry ratingsEntry) {
115                    EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
116                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
117    
118                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
119                            new Object[] {
120                                    new Long(ratingsEntry.getUserId()),
121                                    new Long(ratingsEntry.getClassNameId()),
122                                    new Long(ratingsEntry.getClassPK())
123                            }, ratingsEntry);
124            }
125    
126            /**
127             * Caches the ratings entries in the entity cache if it is enabled.
128             *
129             * @param ratingsEntries the ratings entries to cache
130             */
131            public void cacheResult(List<RatingsEntry> ratingsEntries) {
132                    for (RatingsEntry ratingsEntry : ratingsEntries) {
133                            if (EntityCacheUtil.getResult(
134                                                    RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
135                                                    RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(),
136                                                    this) == null) {
137                                    cacheResult(ratingsEntry);
138                            }
139                    }
140            }
141    
142            /**
143             * Clears the cache for all ratings entries.
144             *
145             * <p>
146             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
147             * </p>
148             */
149            public void clearCache() {
150                    CacheRegistryUtil.clear(RatingsEntryImpl.class.getName());
151                    EntityCacheUtil.clearCache(RatingsEntryImpl.class.getName());
152                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
153                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
154            }
155    
156            /**
157             * Clears the cache for the ratings entry.
158             *
159             * <p>
160             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
161             * </p>
162             */
163            public void clearCache(RatingsEntry ratingsEntry) {
164                    EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
165                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
166    
167                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
168                            new Object[] {
169                                    new Long(ratingsEntry.getUserId()),
170                                    new Long(ratingsEntry.getClassNameId()),
171                                    new Long(ratingsEntry.getClassPK())
172                            });
173            }
174    
175            /**
176             * Creates a new ratings entry with the primary key. Does not add the ratings entry to the database.
177             *
178             * @param entryId the primary key for the new ratings entry
179             * @return the new ratings entry
180             */
181            public RatingsEntry create(long entryId) {
182                    RatingsEntry ratingsEntry = new RatingsEntryImpl();
183    
184                    ratingsEntry.setNew(true);
185                    ratingsEntry.setPrimaryKey(entryId);
186    
187                    return ratingsEntry;
188            }
189    
190            /**
191             * Removes the ratings entry with the primary key from the database. Also notifies the appropriate model listeners.
192             *
193             * @param primaryKey the primary key of the ratings entry to remove
194             * @return the ratings entry that was removed
195             * @throws com.liferay.portal.NoSuchModelException if a ratings entry with the primary key could not be found
196             * @throws SystemException if a system exception occurred
197             */
198            public RatingsEntry remove(Serializable primaryKey)
199                    throws NoSuchModelException, SystemException {
200                    return remove(((Long)primaryKey).longValue());
201            }
202    
203            /**
204             * Removes the ratings entry with the primary key from the database. Also notifies the appropriate model listeners.
205             *
206             * @param entryId the primary key of the ratings entry to remove
207             * @return the ratings entry that was removed
208             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
209             * @throws SystemException if a system exception occurred
210             */
211            public RatingsEntry remove(long entryId)
212                    throws NoSuchEntryException, SystemException {
213                    Session session = null;
214    
215                    try {
216                            session = openSession();
217    
218                            RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
219                                            new Long(entryId));
220    
221                            if (ratingsEntry == null) {
222                                    if (_log.isWarnEnabled()) {
223                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
224                                    }
225    
226                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
227                                            entryId);
228                            }
229    
230                            return remove(ratingsEntry);
231                    }
232                    catch (NoSuchEntryException nsee) {
233                            throw nsee;
234                    }
235                    catch (Exception e) {
236                            throw processException(e);
237                    }
238                    finally {
239                            closeSession(session);
240                    }
241            }
242    
243            protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
244                    throws SystemException {
245                    ratingsEntry = toUnwrappedModel(ratingsEntry);
246    
247                    Session session = null;
248    
249                    try {
250                            session = openSession();
251    
252                            if (ratingsEntry.isCachedModel() || BatchSessionUtil.isEnabled()) {
253                                    Object staleObject = session.get(RatingsEntryImpl.class,
254                                                    ratingsEntry.getPrimaryKeyObj());
255    
256                                    if (staleObject != null) {
257                                            session.evict(staleObject);
258                                    }
259                            }
260    
261                            session.delete(ratingsEntry);
262    
263                            session.flush();
264                    }
265                    catch (Exception e) {
266                            throw processException(e);
267                    }
268                    finally {
269                            closeSession(session);
270                    }
271    
272                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
273    
274                    RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
275    
276                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
277                            new Object[] {
278                                    new Long(ratingsEntryModelImpl.getOriginalUserId()),
279                                    new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
280                                    new Long(ratingsEntryModelImpl.getOriginalClassPK())
281                            });
282    
283                    EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
284                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
285    
286                    return ratingsEntry;
287            }
288    
289            public RatingsEntry updateImpl(
290                    com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
291                    boolean merge) throws SystemException {
292                    ratingsEntry = toUnwrappedModel(ratingsEntry);
293    
294                    boolean isNew = ratingsEntry.isNew();
295    
296                    RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
297    
298                    Session session = null;
299    
300                    try {
301                            session = openSession();
302    
303                            BatchSessionUtil.update(session, ratingsEntry, merge);
304    
305                            ratingsEntry.setNew(false);
306                    }
307                    catch (Exception e) {
308                            throw processException(e);
309                    }
310                    finally {
311                            closeSession(session);
312                    }
313    
314                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
315    
316                    EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
317                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
318    
319                    if (!isNew &&
320                                    ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
321                                    (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
322                                    (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
323                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
324                                    new Object[] {
325                                            new Long(ratingsEntryModelImpl.getOriginalUserId()),
326                                            new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
327                                            new Long(ratingsEntryModelImpl.getOriginalClassPK())
328                                    });
329                    }
330    
331                    if (isNew ||
332                                    ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
333                                    (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
334                                    (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
335                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
336                                    new Object[] {
337                                            new Long(ratingsEntry.getUserId()),
338                                            new Long(ratingsEntry.getClassNameId()),
339                                            new Long(ratingsEntry.getClassPK())
340                                    }, ratingsEntry);
341                    }
342    
343                    return ratingsEntry;
344            }
345    
346            protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
347                    if (ratingsEntry instanceof RatingsEntryImpl) {
348                            return ratingsEntry;
349                    }
350    
351                    RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
352    
353                    ratingsEntryImpl.setNew(ratingsEntry.isNew());
354                    ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
355    
356                    ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
357                    ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
358                    ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
359                    ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
360                    ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
361                    ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
362                    ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
363                    ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
364                    ratingsEntryImpl.setScore(ratingsEntry.getScore());
365    
366                    return ratingsEntryImpl;
367            }
368    
369            /**
370             * Finds the ratings entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
371             *
372             * @param primaryKey the primary key of the ratings entry to find
373             * @return the ratings entry
374             * @throws com.liferay.portal.NoSuchModelException if a ratings entry with the primary key could not be found
375             * @throws SystemException if a system exception occurred
376             */
377            public RatingsEntry findByPrimaryKey(Serializable primaryKey)
378                    throws NoSuchModelException, SystemException {
379                    return findByPrimaryKey(((Long)primaryKey).longValue());
380            }
381    
382            /**
383             * Finds the ratings entry with the primary key or throws a {@link com.liferay.portlet.ratings.NoSuchEntryException} if it could not be found.
384             *
385             * @param entryId the primary key of the ratings entry to find
386             * @return the ratings entry
387             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
388             * @throws SystemException if a system exception occurred
389             */
390            public RatingsEntry findByPrimaryKey(long entryId)
391                    throws NoSuchEntryException, SystemException {
392                    RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
393    
394                    if (ratingsEntry == null) {
395                            if (_log.isWarnEnabled()) {
396                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
397                            }
398    
399                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
400                                    entryId);
401                    }
402    
403                    return ratingsEntry;
404            }
405    
406            /**
407             * Finds the ratings entry with the primary key or returns <code>null</code> if it could not be found.
408             *
409             * @param primaryKey the primary key of the ratings entry to find
410             * @return the ratings entry, or <code>null</code> if a ratings entry with the primary key could not be found
411             * @throws SystemException if a system exception occurred
412             */
413            public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
414                    throws SystemException {
415                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
416            }
417    
418            /**
419             * Finds the ratings entry with the primary key or returns <code>null</code> if it could not be found.
420             *
421             * @param entryId the primary key of the ratings entry to find
422             * @return the ratings entry, or <code>null</code> if a ratings entry with the primary key could not be found
423             * @throws SystemException if a system exception occurred
424             */
425            public RatingsEntry fetchByPrimaryKey(long entryId)
426                    throws SystemException {
427                    RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
428                                    RatingsEntryImpl.class, entryId, this);
429    
430                    if (ratingsEntry == null) {
431                            Session session = null;
432    
433                            try {
434                                    session = openSession();
435    
436                                    ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
437                                                    new Long(entryId));
438                            }
439                            catch (Exception e) {
440                                    throw processException(e);
441                            }
442                            finally {
443                                    if (ratingsEntry != null) {
444                                            cacheResult(ratingsEntry);
445                                    }
446    
447                                    closeSession(session);
448                            }
449                    }
450    
451                    return ratingsEntry;
452            }
453    
454            /**
455             * Finds all the ratings entries where classNameId = &#63; and classPK = &#63;.
456             *
457             * @param classNameId the class name id to search with
458             * @param classPK the class p k to search with
459             * @return the matching ratings entries
460             * @throws SystemException if a system exception occurred
461             */
462            public List<RatingsEntry> findByC_C(long classNameId, long classPK)
463                    throws SystemException {
464                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
465                            QueryUtil.ALL_POS, null);
466            }
467    
468            /**
469             * Finds a range of all the ratings entries where classNameId = &#63; and classPK = &#63;.
470             *
471             * <p>
472             * 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.
473             * </p>
474             *
475             * @param classNameId the class name id to search with
476             * @param classPK the class p k to search with
477             * @param start the lower bound of the range of ratings entries to return
478             * @param end the upper bound of the range of ratings entries to return (not inclusive)
479             * @return the range of matching ratings entries
480             * @throws SystemException if a system exception occurred
481             */
482            public List<RatingsEntry> findByC_C(long classNameId, long classPK,
483                    int start, int end) throws SystemException {
484                    return findByC_C(classNameId, classPK, start, end, null);
485            }
486    
487            /**
488             * Finds an ordered range of all the ratings entries where classNameId = &#63; and classPK = &#63;.
489             *
490             * <p>
491             * 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.
492             * </p>
493             *
494             * @param classNameId the class name id to search with
495             * @param classPK the class p k to search with
496             * @param start the lower bound of the range of ratings entries to return
497             * @param end the upper bound of the range of ratings entries to return (not inclusive)
498             * @param orderByComparator the comparator to order the results by
499             * @return the ordered range of matching ratings entries
500             * @throws SystemException if a system exception occurred
501             */
502            public List<RatingsEntry> findByC_C(long classNameId, long classPK,
503                    int start, int end, OrderByComparator orderByComparator)
504                    throws SystemException {
505                    Object[] finderArgs = new Object[] {
506                                    classNameId, classPK,
507                                    
508                                    String.valueOf(start), String.valueOf(end),
509                                    String.valueOf(orderByComparator)
510                            };
511    
512                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
513                                    finderArgs, this);
514    
515                    if (list == null) {
516                            Session session = null;
517    
518                            try {
519                                    session = openSession();
520    
521                                    StringBundler query = null;
522    
523                                    if (orderByComparator != null) {
524                                            query = new StringBundler(4 +
525                                                            (orderByComparator.getOrderByFields().length * 3));
526                                    }
527                                    else {
528                                            query = new StringBundler(3);
529                                    }
530    
531                                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
532    
533                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
534    
535                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
536    
537                                    if (orderByComparator != null) {
538                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
539                                                    orderByComparator);
540                                    }
541    
542                                    String sql = query.toString();
543    
544                                    Query q = session.createQuery(sql);
545    
546                                    QueryPos qPos = QueryPos.getInstance(q);
547    
548                                    qPos.add(classNameId);
549    
550                                    qPos.add(classPK);
551    
552                                    list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
553                                                    start, end);
554                            }
555                            catch (Exception e) {
556                                    throw processException(e);
557                            }
558                            finally {
559                                    if (list == null) {
560                                            list = new ArrayList<RatingsEntry>();
561                                    }
562    
563                                    cacheResult(list);
564    
565                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
566                                            list);
567    
568                                    closeSession(session);
569                            }
570                    }
571    
572                    return list;
573            }
574    
575            /**
576             * Finds the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
577             *
578             * <p>
579             * 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.
580             * </p>
581             *
582             * @param classNameId the class name id to search with
583             * @param classPK the class p k to search with
584             * @param orderByComparator the comparator to order the set by
585             * @return the first matching ratings entry
586             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
587             * @throws SystemException if a system exception occurred
588             */
589            public RatingsEntry findByC_C_First(long classNameId, long classPK,
590                    OrderByComparator orderByComparator)
591                    throws NoSuchEntryException, SystemException {
592                    List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
593                                    orderByComparator);
594    
595                    if (list.isEmpty()) {
596                            StringBundler msg = new StringBundler(6);
597    
598                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
599    
600                            msg.append("classNameId=");
601                            msg.append(classNameId);
602    
603                            msg.append(", classPK=");
604                            msg.append(classPK);
605    
606                            msg.append(StringPool.CLOSE_CURLY_BRACE);
607    
608                            throw new NoSuchEntryException(msg.toString());
609                    }
610                    else {
611                            return list.get(0);
612                    }
613            }
614    
615            /**
616             * Finds the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
617             *
618             * <p>
619             * 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.
620             * </p>
621             *
622             * @param classNameId the class name id to search with
623             * @param classPK the class p k to search with
624             * @param orderByComparator the comparator to order the set by
625             * @return the last matching ratings entry
626             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
627             * @throws SystemException if a system exception occurred
628             */
629            public RatingsEntry findByC_C_Last(long classNameId, long classPK,
630                    OrderByComparator orderByComparator)
631                    throws NoSuchEntryException, SystemException {
632                    int count = countByC_C(classNameId, classPK);
633    
634                    List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
635                                    count, orderByComparator);
636    
637                    if (list.isEmpty()) {
638                            StringBundler msg = new StringBundler(6);
639    
640                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
641    
642                            msg.append("classNameId=");
643                            msg.append(classNameId);
644    
645                            msg.append(", classPK=");
646                            msg.append(classPK);
647    
648                            msg.append(StringPool.CLOSE_CURLY_BRACE);
649    
650                            throw new NoSuchEntryException(msg.toString());
651                    }
652                    else {
653                            return list.get(0);
654                    }
655            }
656    
657            /**
658             * Finds the ratings entries before and after the current ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
659             *
660             * <p>
661             * 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.
662             * </p>
663             *
664             * @param entryId the primary key of the current ratings entry
665             * @param classNameId the class name id to search with
666             * @param classPK the class p k to search with
667             * @param orderByComparator the comparator to order the set by
668             * @return the previous, current, and next ratings entry
669             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a ratings entry with the primary key could not be found
670             * @throws SystemException if a system exception occurred
671             */
672            public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
673                    long classPK, OrderByComparator orderByComparator)
674                    throws NoSuchEntryException, SystemException {
675                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
676    
677                    Session session = null;
678    
679                    try {
680                            session = openSession();
681    
682                            RatingsEntry[] array = new RatingsEntryImpl[3];
683    
684                            array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
685                                            classPK, orderByComparator, true);
686    
687                            array[1] = ratingsEntry;
688    
689                            array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
690                                            classPK, orderByComparator, false);
691    
692                            return array;
693                    }
694                    catch (Exception e) {
695                            throw processException(e);
696                    }
697                    finally {
698                            closeSession(session);
699                    }
700            }
701    
702            protected RatingsEntry getByC_C_PrevAndNext(Session session,
703                    RatingsEntry ratingsEntry, long classNameId, long classPK,
704                    OrderByComparator orderByComparator, boolean previous) {
705                    StringBundler query = null;
706    
707                    if (orderByComparator != null) {
708                            query = new StringBundler(6 +
709                                            (orderByComparator.getOrderByFields().length * 6));
710                    }
711                    else {
712                            query = new StringBundler(3);
713                    }
714    
715                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
716    
717                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
718    
719                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
720    
721                    if (orderByComparator != null) {
722                            String[] orderByFields = orderByComparator.getOrderByFields();
723    
724                            if (orderByFields.length > 0) {
725                                    query.append(WHERE_AND);
726                            }
727    
728                            for (int i = 0; i < orderByFields.length; i++) {
729                                    query.append(_ORDER_BY_ENTITY_ALIAS);
730                                    query.append(orderByFields[i]);
731    
732                                    if ((i + 1) < orderByFields.length) {
733                                            if (orderByComparator.isAscending() ^ previous) {
734                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
735                                            }
736                                            else {
737                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
738                                            }
739                                    }
740                                    else {
741                                            if (orderByComparator.isAscending() ^ previous) {
742                                                    query.append(WHERE_GREATER_THAN);
743                                            }
744                                            else {
745                                                    query.append(WHERE_LESSER_THAN);
746                                            }
747                                    }
748                            }
749    
750                            query.append(ORDER_BY_CLAUSE);
751    
752                            for (int i = 0; i < orderByFields.length; i++) {
753                                    query.append(_ORDER_BY_ENTITY_ALIAS);
754                                    query.append(orderByFields[i]);
755    
756                                    if ((i + 1) < orderByFields.length) {
757                                            if (orderByComparator.isAscending() ^ previous) {
758                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
759                                            }
760                                            else {
761                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
762                                            }
763                                    }
764                                    else {
765                                            if (orderByComparator.isAscending() ^ previous) {
766                                                    query.append(ORDER_BY_ASC);
767                                            }
768                                            else {
769                                                    query.append(ORDER_BY_DESC);
770                                            }
771                                    }
772                            }
773                    }
774    
775                    String sql = query.toString();
776    
777                    Query q = session.createQuery(sql);
778    
779                    q.setFirstResult(0);
780                    q.setMaxResults(2);
781    
782                    QueryPos qPos = QueryPos.getInstance(q);
783    
784                    qPos.add(classNameId);
785    
786                    qPos.add(classPK);
787    
788                    if (orderByComparator != null) {
789                            Object[] values = orderByComparator.getOrderByValues(ratingsEntry);
790    
791                            for (Object value : values) {
792                                    qPos.add(value);
793                            }
794                    }
795    
796                    List<RatingsEntry> list = q.list();
797    
798                    if (list.size() == 2) {
799                            return list.get(1);
800                    }
801                    else {
802                            return null;
803                    }
804            }
805    
806            /**
807             * Finds 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.
808             *
809             * @param userId the user id to search with
810             * @param classNameId the class name id to search with
811             * @param classPK the class p k to search with
812             * @return the matching ratings entry
813             * @throws com.liferay.portlet.ratings.NoSuchEntryException if a matching ratings entry could not be found
814             * @throws SystemException if a system exception occurred
815             */
816            public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
817                    throws NoSuchEntryException, SystemException {
818                    RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
819    
820                    if (ratingsEntry == null) {
821                            StringBundler msg = new StringBundler(8);
822    
823                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
824    
825                            msg.append("userId=");
826                            msg.append(userId);
827    
828                            msg.append(", classNameId=");
829                            msg.append(classNameId);
830    
831                            msg.append(", classPK=");
832                            msg.append(classPK);
833    
834                            msg.append(StringPool.CLOSE_CURLY_BRACE);
835    
836                            if (_log.isWarnEnabled()) {
837                                    _log.warn(msg.toString());
838                            }
839    
840                            throw new NoSuchEntryException(msg.toString());
841                    }
842    
843                    return ratingsEntry;
844            }
845    
846            /**
847             * Finds 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.
848             *
849             * @param userId the user id to search with
850             * @param classNameId the class name id to search with
851             * @param classPK the class p k to search with
852             * @return the matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
853             * @throws SystemException if a system exception occurred
854             */
855            public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
856                    throws SystemException {
857                    return fetchByU_C_C(userId, classNameId, classPK, true);
858            }
859    
860            /**
861             * Finds 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.
862             *
863             * @param userId the user id to search with
864             * @param classNameId the class name id to search with
865             * @param classPK the class p k to search with
866             * @return the matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
867             * @throws SystemException if a system exception occurred
868             */
869            public RatingsEntry fetchByU_C_C(long userId, long classNameId,
870                    long classPK, boolean retrieveFromCache) throws SystemException {
871                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
872    
873                    Object result = null;
874    
875                    if (retrieveFromCache) {
876                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
877                                            finderArgs, this);
878                    }
879    
880                    if (result == null) {
881                            Session session = null;
882    
883                            try {
884                                    session = openSession();
885    
886                                    StringBundler query = new StringBundler(4);
887    
888                                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
889    
890                                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
891    
892                                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
893    
894                                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
895    
896                                    String sql = query.toString();
897    
898                                    Query q = session.createQuery(sql);
899    
900                                    QueryPos qPos = QueryPos.getInstance(q);
901    
902                                    qPos.add(userId);
903    
904                                    qPos.add(classNameId);
905    
906                                    qPos.add(classPK);
907    
908                                    List<RatingsEntry> list = q.list();
909    
910                                    result = list;
911    
912                                    RatingsEntry ratingsEntry = null;
913    
914                                    if (list.isEmpty()) {
915                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
916                                                    finderArgs, list);
917                                    }
918                                    else {
919                                            ratingsEntry = list.get(0);
920    
921                                            cacheResult(ratingsEntry);
922    
923                                            if ((ratingsEntry.getUserId() != userId) ||
924                                                            (ratingsEntry.getClassNameId() != classNameId) ||
925                                                            (ratingsEntry.getClassPK() != classPK)) {
926                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
927                                                            finderArgs, ratingsEntry);
928                                            }
929                                    }
930    
931                                    return ratingsEntry;
932                            }
933                            catch (Exception e) {
934                                    throw processException(e);
935                            }
936                            finally {
937                                    if (result == null) {
938                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
939                                                    finderArgs, new ArrayList<RatingsEntry>());
940                                    }
941    
942                                    closeSession(session);
943                            }
944                    }
945                    else {
946                            if (result instanceof List<?>) {
947                                    return null;
948                            }
949                            else {
950                                    return (RatingsEntry)result;
951                            }
952                    }
953            }
954    
955            /**
956             * Finds all the ratings entries.
957             *
958             * @return the ratings entries
959             * @throws SystemException if a system exception occurred
960             */
961            public List<RatingsEntry> findAll() throws SystemException {
962                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
963            }
964    
965            /**
966             * Finds a range of all the ratings entries.
967             *
968             * <p>
969             * 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.
970             * </p>
971             *
972             * @param start the lower bound of the range of ratings entries to return
973             * @param end the upper bound of the range of ratings entries to return (not inclusive)
974             * @return the range of ratings entries
975             * @throws SystemException if a system exception occurred
976             */
977            public List<RatingsEntry> findAll(int start, int end)
978                    throws SystemException {
979                    return findAll(start, end, null);
980            }
981    
982            /**
983             * Finds an ordered range of all the ratings entries.
984             *
985             * <p>
986             * 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.
987             * </p>
988             *
989             * @param start the lower bound of the range of ratings entries to return
990             * @param end the upper bound of the range of ratings entries to return (not inclusive)
991             * @param orderByComparator the comparator to order the results by
992             * @return the ordered range of ratings entries
993             * @throws SystemException if a system exception occurred
994             */
995            public List<RatingsEntry> findAll(int start, int end,
996                    OrderByComparator orderByComparator) throws SystemException {
997                    Object[] finderArgs = new Object[] {
998                                    String.valueOf(start), String.valueOf(end),
999                                    String.valueOf(orderByComparator)
1000                            };
1001    
1002                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1003                                    finderArgs, this);
1004    
1005                    if (list == null) {
1006                            Session session = null;
1007    
1008                            try {
1009                                    session = openSession();
1010    
1011                                    StringBundler query = null;
1012                                    String sql = null;
1013    
1014                                    if (orderByComparator != null) {
1015                                            query = new StringBundler(2 +
1016                                                            (orderByComparator.getOrderByFields().length * 3));
1017    
1018                                            query.append(_SQL_SELECT_RATINGSENTRY);
1019    
1020                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1021                                                    orderByComparator);
1022    
1023                                            sql = query.toString();
1024                                    }
1025                                    else {
1026                                            sql = _SQL_SELECT_RATINGSENTRY;
1027                                    }
1028    
1029                                    Query q = session.createQuery(sql);
1030    
1031                                    if (orderByComparator == null) {
1032                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1033                                                            start, end, false);
1034    
1035                                            Collections.sort(list);
1036                                    }
1037                                    else {
1038                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1039                                                            start, end);
1040                                    }
1041                            }
1042                            catch (Exception e) {
1043                                    throw processException(e);
1044                            }
1045                            finally {
1046                                    if (list == null) {
1047                                            list = new ArrayList<RatingsEntry>();
1048                                    }
1049    
1050                                    cacheResult(list);
1051    
1052                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1053    
1054                                    closeSession(session);
1055                            }
1056                    }
1057    
1058                    return list;
1059            }
1060    
1061            /**
1062             * Removes all the ratings entries where classNameId = &#63; and classPK = &#63; from the database.
1063             *
1064             * @param classNameId the class name id to search with
1065             * @param classPK the class p k to search with
1066             * @throws SystemException if a system exception occurred
1067             */
1068            public void removeByC_C(long classNameId, long classPK)
1069                    throws SystemException {
1070                    for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
1071                            remove(ratingsEntry);
1072                    }
1073            }
1074    
1075            /**
1076             * Removes the ratings entry where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1077             *
1078             * @param userId the user id to search with
1079             * @param classNameId the class name id to search with
1080             * @param classPK the class p k to search with
1081             * @throws SystemException if a system exception occurred
1082             */
1083            public void removeByU_C_C(long userId, long classNameId, long classPK)
1084                    throws NoSuchEntryException, SystemException {
1085                    RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
1086    
1087                    remove(ratingsEntry);
1088            }
1089    
1090            /**
1091             * Removes all the ratings entries from the database.
1092             *
1093             * @throws SystemException if a system exception occurred
1094             */
1095            public void removeAll() throws SystemException {
1096                    for (RatingsEntry ratingsEntry : findAll()) {
1097                            remove(ratingsEntry);
1098                    }
1099            }
1100    
1101            /**
1102             * Counts all the ratings entries where classNameId = &#63; and classPK = &#63;.
1103             *
1104             * @param classNameId the class name id to search with
1105             * @param classPK the class p k to search with
1106             * @return the number of matching ratings entries
1107             * @throws SystemException if a system exception occurred
1108             */
1109            public int countByC_C(long classNameId, long classPK)
1110                    throws SystemException {
1111                    Object[] finderArgs = new Object[] { classNameId, classPK };
1112    
1113                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1114                                    finderArgs, this);
1115    
1116                    if (count == null) {
1117                            Session session = null;
1118    
1119                            try {
1120                                    session = openSession();
1121    
1122                                    StringBundler query = new StringBundler(3);
1123    
1124                                    query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1125    
1126                                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1127    
1128                                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1129    
1130                                    String sql = query.toString();
1131    
1132                                    Query q = session.createQuery(sql);
1133    
1134                                    QueryPos qPos = QueryPos.getInstance(q);
1135    
1136                                    qPos.add(classNameId);
1137    
1138                                    qPos.add(classPK);
1139    
1140                                    count = (Long)q.uniqueResult();
1141                            }
1142                            catch (Exception e) {
1143                                    throw processException(e);
1144                            }
1145                            finally {
1146                                    if (count == null) {
1147                                            count = Long.valueOf(0);
1148                                    }
1149    
1150                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1151                                            count);
1152    
1153                                    closeSession(session);
1154                            }
1155                    }
1156    
1157                    return count.intValue();
1158            }
1159    
1160            /**
1161             * Counts all the ratings entries where userId = &#63; and classNameId = &#63; and classPK = &#63;.
1162             *
1163             * @param userId the user id to search with
1164             * @param classNameId the class name id to search with
1165             * @param classPK the class p k to search with
1166             * @return the number of matching ratings entries
1167             * @throws SystemException if a system exception occurred
1168             */
1169            public int countByU_C_C(long userId, long classNameId, long classPK)
1170                    throws SystemException {
1171                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1172    
1173                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
1174                                    finderArgs, this);
1175    
1176                    if (count == null) {
1177                            Session session = null;
1178    
1179                            try {
1180                                    session = openSession();
1181    
1182                                    StringBundler query = new StringBundler(4);
1183    
1184                                    query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1185    
1186                                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1187    
1188                                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1189    
1190                                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1191    
1192                                    String sql = query.toString();
1193    
1194                                    Query q = session.createQuery(sql);
1195    
1196                                    QueryPos qPos = QueryPos.getInstance(q);
1197    
1198                                    qPos.add(userId);
1199    
1200                                    qPos.add(classNameId);
1201    
1202                                    qPos.add(classPK);
1203    
1204                                    count = (Long)q.uniqueResult();
1205                            }
1206                            catch (Exception e) {
1207                                    throw processException(e);
1208                            }
1209                            finally {
1210                                    if (count == null) {
1211                                            count = Long.valueOf(0);
1212                                    }
1213    
1214                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
1215                                            finderArgs, count);
1216    
1217                                    closeSession(session);
1218                            }
1219                    }
1220    
1221                    return count.intValue();
1222            }
1223    
1224            /**
1225             * Counts all the ratings entries.
1226             *
1227             * @return the number of ratings entries
1228             * @throws SystemException if a system exception occurred
1229             */
1230            public int countAll() throws SystemException {
1231                    Object[] finderArgs = new Object[0];
1232    
1233                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1234                                    finderArgs, this);
1235    
1236                    if (count == null) {
1237                            Session session = null;
1238    
1239                            try {
1240                                    session = openSession();
1241    
1242                                    Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
1243    
1244                                    count = (Long)q.uniqueResult();
1245                            }
1246                            catch (Exception e) {
1247                                    throw processException(e);
1248                            }
1249                            finally {
1250                                    if (count == null) {
1251                                            count = Long.valueOf(0);
1252                                    }
1253    
1254                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1255                                            count);
1256    
1257                                    closeSession(session);
1258                            }
1259                    }
1260    
1261                    return count.intValue();
1262            }
1263    
1264            /**
1265             * Initializes the ratings entry persistence.
1266             */
1267            public void afterPropertiesSet() {
1268                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1269                                            com.liferay.portal.util.PropsUtil.get(
1270                                                    "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1271    
1272                    if (listenerClassNames.length > 0) {
1273                            try {
1274                                    List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1275    
1276                                    for (String listenerClassName : listenerClassNames) {
1277                                            listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
1278                                                            listenerClassName));
1279                                    }
1280    
1281                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1282                            }
1283                            catch (Exception e) {
1284                                    _log.error(e);
1285                            }
1286                    }
1287            }
1288    
1289            @BeanReference(type = RatingsEntryPersistence.class)
1290            protected RatingsEntryPersistence ratingsEntryPersistence;
1291            @BeanReference(type = RatingsStatsPersistence.class)
1292            protected RatingsStatsPersistence ratingsStatsPersistence;
1293            @BeanReference(type = ResourcePersistence.class)
1294            protected ResourcePersistence resourcePersistence;
1295            @BeanReference(type = UserPersistence.class)
1296            protected UserPersistence userPersistence;
1297            @BeanReference(type = BlogsEntryPersistence.class)
1298            protected BlogsEntryPersistence blogsEntryPersistence;
1299            @BeanReference(type = BlogsStatsUserPersistence.class)
1300            protected BlogsStatsUserPersistence blogsStatsUserPersistence;
1301            @BeanReference(type = SocialEquityLogPersistence.class)
1302            protected SocialEquityLogPersistence socialEquityLogPersistence;
1303            private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1304            private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1305            private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1306            private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1307            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1308            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1309            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1310            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1311            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1312            private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1313            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1314            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1315            private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1316    }