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