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