001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.SetUtil;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringPool;
032    import com.liferay.portal.kernel.util.Validator;
033    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.service.ServiceContext;
036    import com.liferay.portal.service.ServiceContextThreadLocal;
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    import com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence;
044    
045    import java.io.Serializable;
046    
047    import java.util.Collections;
048    import java.util.Date;
049    import java.util.HashMap;
050    import java.util.HashSet;
051    import java.util.Iterator;
052    import java.util.List;
053    import java.util.Map;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the ratings entry service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see RatingsEntryPersistence
065     * @see com.liferay.portlet.ratings.service.persistence.RatingsEntryUtil
066     * @generated
067     */
068    @ProviderType
069    public class RatingsEntryPersistenceImpl extends BasePersistenceImpl<RatingsEntry>
070            implements RatingsEntryPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * 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.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = RatingsEntryImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
082                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
085                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
088                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
091                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
093                            new String[] {
094                                    String.class.getName(),
095                                    
096                            Integer.class.getName(), Integer.class.getName(),
097                                    OrderByComparator.class.getName()
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
100                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102                            new String[] { String.class.getName() },
103                            RatingsEntryModelImpl.UUID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
105                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107                            new String[] { String.class.getName() });
108    
109            /**
110             * Returns all the ratings entries where uuid = &#63;.
111             *
112             * @param uuid the uuid
113             * @return the matching ratings entries
114             */
115            @Override
116            public List<RatingsEntry> findByUuid(String uuid) {
117                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118            }
119    
120            /**
121             * Returns a range of all the ratings entries where uuid = &#63;.
122             *
123             * <p>
124             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
125             * </p>
126             *
127             * @param uuid the uuid
128             * @param start the lower bound of the range of ratings entries
129             * @param end the upper bound of the range of ratings entries (not inclusive)
130             * @return the range of matching ratings entries
131             */
132            @Override
133            public List<RatingsEntry> findByUuid(String uuid, int start, int end) {
134                    return findByUuid(uuid, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the ratings entries where uuid = &#63;.
139             *
140             * <p>
141             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link RatingsEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
142             * </p>
143             *
144             * @param uuid the uuid
145             * @param start the lower bound of the range of ratings entries
146             * @param end the upper bound of the range of ratings entries (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching ratings entries
149             */
150            @Override
151            public List<RatingsEntry> findByUuid(String uuid, int start, int end,
152                    OrderByComparator<RatingsEntry> orderByComparator) {
153                    boolean pagination = true;
154                    FinderPath finderPath = null;
155                    Object[] finderArgs = null;
156    
157                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158                                    (orderByComparator == null)) {
159                            pagination = false;
160                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
161                            finderArgs = new Object[] { uuid };
162                    }
163                    else {
164                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
165                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
166                    }
167    
168                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
169                                    finderArgs, this);
170    
171                    if ((list != null) && !list.isEmpty()) {
172                            for (RatingsEntry ratingsEntry : list) {
173                                    if (!Validator.equals(uuid, ratingsEntry.getUuid())) {
174                                            list = null;
175    
176                                            break;
177                                    }
178                            }
179                    }
180    
181                    if (list == null) {
182                            StringBundler query = null;
183    
184                            if (orderByComparator != null) {
185                                    query = new StringBundler(3 +
186                                                    (orderByComparator.getOrderByFields().length * 3));
187                            }
188                            else {
189                                    query = new StringBundler(3);
190                            }
191    
192                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
193    
194                            boolean bindUuid = false;
195    
196                            if (uuid == null) {
197                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
198                            }
199                            else if (uuid.equals(StringPool.BLANK)) {
200                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
201                            }
202                            else {
203                                    bindUuid = true;
204    
205                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
206                            }
207    
208                            if (orderByComparator != null) {
209                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210                                            orderByComparator);
211                            }
212                            else
213                             if (pagination) {
214                                    query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
215                            }
216    
217                            String sql = query.toString();
218    
219                            Session session = null;
220    
221                            try {
222                                    session = openSession();
223    
224                                    Query q = session.createQuery(sql);
225    
226                                    QueryPos qPos = QueryPos.getInstance(q);
227    
228                                    if (bindUuid) {
229                                            qPos.add(uuid);
230                                    }
231    
232                                    if (!pagination) {
233                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
234                                                            start, end, false);
235    
236                                            Collections.sort(list);
237    
238                                            list = Collections.unmodifiableList(list);
239                                    }
240                                    else {
241                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
242                                                            start, end);
243                                    }
244    
245                                    cacheResult(list);
246    
247                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
248                            }
249                            catch (Exception e) {
250                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
251    
252                                    throw processException(e);
253                            }
254                            finally {
255                                    closeSession(session);
256                            }
257                    }
258    
259                    return list;
260            }
261    
262            /**
263             * Returns the first ratings entry in the ordered set where uuid = &#63;.
264             *
265             * @param uuid the uuid
266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
267             * @return the first matching ratings entry
268             * @throws NoSuchEntryException if a matching ratings entry could not be found
269             */
270            @Override
271            public RatingsEntry findByUuid_First(String uuid,
272                    OrderByComparator<RatingsEntry> orderByComparator)
273                    throws NoSuchEntryException {
274                    RatingsEntry ratingsEntry = fetchByUuid_First(uuid, orderByComparator);
275    
276                    if (ratingsEntry != null) {
277                            return ratingsEntry;
278                    }
279    
280                    StringBundler msg = new StringBundler(4);
281    
282                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283    
284                    msg.append("uuid=");
285                    msg.append(uuid);
286    
287                    msg.append(StringPool.CLOSE_CURLY_BRACE);
288    
289                    throw new NoSuchEntryException(msg.toString());
290            }
291    
292            /**
293             * Returns the first ratings entry in the ordered set where uuid = &#63;.
294             *
295             * @param uuid the uuid
296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
297             * @return the first matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
298             */
299            @Override
300            public RatingsEntry fetchByUuid_First(String uuid,
301                    OrderByComparator<RatingsEntry> orderByComparator) {
302                    List<RatingsEntry> list = findByUuid(uuid, 0, 1, orderByComparator);
303    
304                    if (!list.isEmpty()) {
305                            return list.get(0);
306                    }
307    
308                    return null;
309            }
310    
311            /**
312             * Returns the last ratings entry in the ordered set where uuid = &#63;.
313             *
314             * @param uuid the uuid
315             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
316             * @return the last matching ratings entry
317             * @throws NoSuchEntryException if a matching ratings entry could not be found
318             */
319            @Override
320            public RatingsEntry findByUuid_Last(String uuid,
321                    OrderByComparator<RatingsEntry> orderByComparator)
322                    throws NoSuchEntryException {
323                    RatingsEntry ratingsEntry = fetchByUuid_Last(uuid, orderByComparator);
324    
325                    if (ratingsEntry != null) {
326                            return ratingsEntry;
327                    }
328    
329                    StringBundler msg = new StringBundler(4);
330    
331                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
332    
333                    msg.append("uuid=");
334                    msg.append(uuid);
335    
336                    msg.append(StringPool.CLOSE_CURLY_BRACE);
337    
338                    throw new NoSuchEntryException(msg.toString());
339            }
340    
341            /**
342             * Returns the last ratings entry in the ordered set where uuid = &#63;.
343             *
344             * @param uuid the uuid
345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
346             * @return the last matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
347             */
348            @Override
349            public RatingsEntry fetchByUuid_Last(String uuid,
350                    OrderByComparator<RatingsEntry> orderByComparator) {
351                    int count = countByUuid(uuid);
352    
353                    if (count == 0) {
354                            return null;
355                    }
356    
357                    List<RatingsEntry> list = findByUuid(uuid, count - 1, count,
358                                    orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the ratings entries before and after the current ratings entry in the ordered set where uuid = &#63;.
369             *
370             * @param entryId the primary key of the current ratings entry
371             * @param uuid the uuid
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next ratings entry
374             * @throws NoSuchEntryException if a ratings entry with the primary key could not be found
375             */
376            @Override
377            public RatingsEntry[] findByUuid_PrevAndNext(long entryId, String uuid,
378                    OrderByComparator<RatingsEntry> orderByComparator)
379                    throws NoSuchEntryException {
380                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
381    
382                    Session session = null;
383    
384                    try {
385                            session = openSession();
386    
387                            RatingsEntry[] array = new RatingsEntryImpl[3];
388    
389                            array[0] = getByUuid_PrevAndNext(session, ratingsEntry, uuid,
390                                            orderByComparator, true);
391    
392                            array[1] = ratingsEntry;
393    
394                            array[2] = getByUuid_PrevAndNext(session, ratingsEntry, uuid,
395                                            orderByComparator, false);
396    
397                            return array;
398                    }
399                    catch (Exception e) {
400                            throw processException(e);
401                    }
402                    finally {
403                            closeSession(session);
404                    }
405            }
406    
407            protected RatingsEntry getByUuid_PrevAndNext(Session session,
408                    RatingsEntry ratingsEntry, String uuid,
409                    OrderByComparator<RatingsEntry> orderByComparator, boolean previous) {
410                    StringBundler query = null;
411    
412                    if (orderByComparator != null) {
413                            query = new StringBundler(6 +
414                                            (orderByComparator.getOrderByFields().length * 6));
415                    }
416                    else {
417                            query = new StringBundler(3);
418                    }
419    
420                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
421    
422                    boolean bindUuid = false;
423    
424                    if (uuid == null) {
425                            query.append(_FINDER_COLUMN_UUID_UUID_1);
426                    }
427                    else if (uuid.equals(StringPool.BLANK)) {
428                            query.append(_FINDER_COLUMN_UUID_UUID_3);
429                    }
430                    else {
431                            bindUuid = true;
432    
433                            query.append(_FINDER_COLUMN_UUID_UUID_2);
434                    }
435    
436                    if (orderByComparator != null) {
437                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438    
439                            if (orderByConditionFields.length > 0) {
440                                    query.append(WHERE_AND);
441                            }
442    
443                            for (int i = 0; i < orderByConditionFields.length; i++) {
444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
445                                    query.append(orderByConditionFields[i]);
446    
447                                    if ((i + 1) < orderByConditionFields.length) {
448                                            if (orderByComparator.isAscending() ^ previous) {
449                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
450                                            }
451                                            else {
452                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
453                                            }
454                                    }
455                                    else {
456                                            if (orderByComparator.isAscending() ^ previous) {
457                                                    query.append(WHERE_GREATER_THAN);
458                                            }
459                                            else {
460                                                    query.append(WHERE_LESSER_THAN);
461                                            }
462                                    }
463                            }
464    
465                            query.append(ORDER_BY_CLAUSE);
466    
467                            String[] orderByFields = orderByComparator.getOrderByFields();
468    
469                            for (int i = 0; i < orderByFields.length; i++) {
470                                    query.append(_ORDER_BY_ENTITY_ALIAS);
471                                    query.append(orderByFields[i]);
472    
473                                    if ((i + 1) < orderByFields.length) {
474                                            if (orderByComparator.isAscending() ^ previous) {
475                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
476                                            }
477                                            else {
478                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
479                                            }
480                                    }
481                                    else {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(ORDER_BY_ASC);
484                                            }
485                                            else {
486                                                    query.append(ORDER_BY_DESC);
487                                            }
488                                    }
489                            }
490                    }
491                    else {
492                            query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
493                    }
494    
495                    String sql = query.toString();
496    
497                    Query q = session.createQuery(sql);
498    
499                    q.setFirstResult(0);
500                    q.setMaxResults(2);
501    
502                    QueryPos qPos = QueryPos.getInstance(q);
503    
504                    if (bindUuid) {
505                            qPos.add(uuid);
506                    }
507    
508                    if (orderByComparator != null) {
509                            Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
510    
511                            for (Object value : values) {
512                                    qPos.add(value);
513                            }
514                    }
515    
516                    List<RatingsEntry> list = q.list();
517    
518                    if (list.size() == 2) {
519                            return list.get(1);
520                    }
521                    else {
522                            return null;
523                    }
524            }
525    
526            /**
527             * Removes all the ratings entries where uuid = &#63; from the database.
528             *
529             * @param uuid the uuid
530             */
531            @Override
532            public void removeByUuid(String uuid) {
533                    for (RatingsEntry ratingsEntry : findByUuid(uuid, QueryUtil.ALL_POS,
534                                    QueryUtil.ALL_POS, null)) {
535                            remove(ratingsEntry);
536                    }
537            }
538    
539            /**
540             * Returns the number of ratings entries where uuid = &#63;.
541             *
542             * @param uuid the uuid
543             * @return the number of matching ratings entries
544             */
545            @Override
546            public int countByUuid(String uuid) {
547                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
548    
549                    Object[] finderArgs = new Object[] { uuid };
550    
551                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
552                                    this);
553    
554                    if (count == null) {
555                            StringBundler query = new StringBundler(2);
556    
557                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
558    
559                            boolean bindUuid = false;
560    
561                            if (uuid == null) {
562                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
563                            }
564                            else if (uuid.equals(StringPool.BLANK)) {
565                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
566                            }
567                            else {
568                                    bindUuid = true;
569    
570                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
571                            }
572    
573                            String sql = query.toString();
574    
575                            Session session = null;
576    
577                            try {
578                                    session = openSession();
579    
580                                    Query q = session.createQuery(sql);
581    
582                                    QueryPos qPos = QueryPos.getInstance(q);
583    
584                                    if (bindUuid) {
585                                            qPos.add(uuid);
586                                    }
587    
588                                    count = (Long)q.uniqueResult();
589    
590                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
591                            }
592                            catch (Exception e) {
593                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
594    
595                                    throw processException(e);
596                            }
597                            finally {
598                                    closeSession(session);
599                            }
600                    }
601    
602                    return count.intValue();
603            }
604    
605            private static final String _FINDER_COLUMN_UUID_UUID_1 = "ratingsEntry.uuid IS NULL";
606            private static final String _FINDER_COLUMN_UUID_UUID_2 = "ratingsEntry.uuid = ?";
607            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(ratingsEntry.uuid IS NULL OR ratingsEntry.uuid = '')";
608            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
609                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
610                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
611                            new String[] {
612                                    String.class.getName(), Long.class.getName(),
613                                    
614                            Integer.class.getName(), Integer.class.getName(),
615                                    OrderByComparator.class.getName()
616                            });
617            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
618                    new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
619                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
620                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
621                            new String[] { String.class.getName(), Long.class.getName() },
622                            RatingsEntryModelImpl.UUID_COLUMN_BITMASK |
623                            RatingsEntryModelImpl.COMPANYID_COLUMN_BITMASK);
624            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
625                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
627                            new String[] { String.class.getName(), Long.class.getName() });
628    
629            /**
630             * Returns all the ratings entries where uuid = &#63; and companyId = &#63;.
631             *
632             * @param uuid the uuid
633             * @param companyId the company ID
634             * @return the matching ratings entries
635             */
636            @Override
637            public List<RatingsEntry> findByUuid_C(String uuid, long companyId) {
638                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
639                            QueryUtil.ALL_POS, null);
640            }
641    
642            /**
643             * Returns a range of all the ratings entries where uuid = &#63; and companyId = &#63;.
644             *
645             * <p>
646             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
647             * </p>
648             *
649             * @param uuid the uuid
650             * @param companyId the company ID
651             * @param start the lower bound of the range of ratings entries
652             * @param end the upper bound of the range of ratings entries (not inclusive)
653             * @return the range of matching ratings entries
654             */
655            @Override
656            public List<RatingsEntry> findByUuid_C(String uuid, long companyId,
657                    int start, int end) {
658                    return findByUuid_C(uuid, companyId, start, end, null);
659            }
660    
661            /**
662             * Returns an ordered range of all the ratings entries where uuid = &#63; and companyId = &#63;.
663             *
664             * <p>
665             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
666             * </p>
667             *
668             * @param uuid the uuid
669             * @param companyId the company ID
670             * @param start the lower bound of the range of ratings entries
671             * @param end the upper bound of the range of ratings entries (not inclusive)
672             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
673             * @return the ordered range of matching ratings entries
674             */
675            @Override
676            public List<RatingsEntry> findByUuid_C(String uuid, long companyId,
677                    int start, int end, OrderByComparator<RatingsEntry> orderByComparator) {
678                    boolean pagination = true;
679                    FinderPath finderPath = null;
680                    Object[] finderArgs = null;
681    
682                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
683                                    (orderByComparator == null)) {
684                            pagination = false;
685                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
686                            finderArgs = new Object[] { uuid, companyId };
687                    }
688                    else {
689                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
690                            finderArgs = new Object[] {
691                                            uuid, companyId,
692                                            
693                                            start, end, orderByComparator
694                                    };
695                    }
696    
697                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
698                                    finderArgs, this);
699    
700                    if ((list != null) && !list.isEmpty()) {
701                            for (RatingsEntry ratingsEntry : list) {
702                                    if (!Validator.equals(uuid, ratingsEntry.getUuid()) ||
703                                                    (companyId != ratingsEntry.getCompanyId())) {
704                                            list = null;
705    
706                                            break;
707                                    }
708                            }
709                    }
710    
711                    if (list == null) {
712                            StringBundler query = null;
713    
714                            if (orderByComparator != null) {
715                                    query = new StringBundler(4 +
716                                                    (orderByComparator.getOrderByFields().length * 3));
717                            }
718                            else {
719                                    query = new StringBundler(4);
720                            }
721    
722                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
723    
724                            boolean bindUuid = false;
725    
726                            if (uuid == null) {
727                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
728                            }
729                            else if (uuid.equals(StringPool.BLANK)) {
730                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
731                            }
732                            else {
733                                    bindUuid = true;
734    
735                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
736                            }
737    
738                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
739    
740                            if (orderByComparator != null) {
741                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
742                                            orderByComparator);
743                            }
744                            else
745                             if (pagination) {
746                                    query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
747                            }
748    
749                            String sql = query.toString();
750    
751                            Session session = null;
752    
753                            try {
754                                    session = openSession();
755    
756                                    Query q = session.createQuery(sql);
757    
758                                    QueryPos qPos = QueryPos.getInstance(q);
759    
760                                    if (bindUuid) {
761                                            qPos.add(uuid);
762                                    }
763    
764                                    qPos.add(companyId);
765    
766                                    if (!pagination) {
767                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
768                                                            start, end, false);
769    
770                                            Collections.sort(list);
771    
772                                            list = Collections.unmodifiableList(list);
773                                    }
774                                    else {
775                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
776                                                            start, end);
777                                    }
778    
779                                    cacheResult(list);
780    
781                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
782                            }
783                            catch (Exception e) {
784                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
785    
786                                    throw processException(e);
787                            }
788                            finally {
789                                    closeSession(session);
790                            }
791                    }
792    
793                    return list;
794            }
795    
796            /**
797             * Returns the first ratings entry in the ordered set where uuid = &#63; and companyId = &#63;.
798             *
799             * @param uuid the uuid
800             * @param companyId the company ID
801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
802             * @return the first matching ratings entry
803             * @throws NoSuchEntryException if a matching ratings entry could not be found
804             */
805            @Override
806            public RatingsEntry findByUuid_C_First(String uuid, long companyId,
807                    OrderByComparator<RatingsEntry> orderByComparator)
808                    throws NoSuchEntryException {
809                    RatingsEntry ratingsEntry = fetchByUuid_C_First(uuid, companyId,
810                                    orderByComparator);
811    
812                    if (ratingsEntry != null) {
813                            return ratingsEntry;
814                    }
815    
816                    StringBundler msg = new StringBundler(6);
817    
818                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
819    
820                    msg.append("uuid=");
821                    msg.append(uuid);
822    
823                    msg.append(", companyId=");
824                    msg.append(companyId);
825    
826                    msg.append(StringPool.CLOSE_CURLY_BRACE);
827    
828                    throw new NoSuchEntryException(msg.toString());
829            }
830    
831            /**
832             * Returns the first ratings entry in the ordered set where uuid = &#63; and companyId = &#63;.
833             *
834             * @param uuid the uuid
835             * @param companyId the company ID
836             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
837             * @return the first matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
838             */
839            @Override
840            public RatingsEntry fetchByUuid_C_First(String uuid, long companyId,
841                    OrderByComparator<RatingsEntry> orderByComparator) {
842                    List<RatingsEntry> list = findByUuid_C(uuid, companyId, 0, 1,
843                                    orderByComparator);
844    
845                    if (!list.isEmpty()) {
846                            return list.get(0);
847                    }
848    
849                    return null;
850            }
851    
852            /**
853             * Returns the last ratings entry in the ordered set where uuid = &#63; and companyId = &#63;.
854             *
855             * @param uuid the uuid
856             * @param companyId the company ID
857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
858             * @return the last matching ratings entry
859             * @throws NoSuchEntryException if a matching ratings entry could not be found
860             */
861            @Override
862            public RatingsEntry findByUuid_C_Last(String uuid, long companyId,
863                    OrderByComparator<RatingsEntry> orderByComparator)
864                    throws NoSuchEntryException {
865                    RatingsEntry ratingsEntry = fetchByUuid_C_Last(uuid, companyId,
866                                    orderByComparator);
867    
868                    if (ratingsEntry != null) {
869                            return ratingsEntry;
870                    }
871    
872                    StringBundler msg = new StringBundler(6);
873    
874                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
875    
876                    msg.append("uuid=");
877                    msg.append(uuid);
878    
879                    msg.append(", companyId=");
880                    msg.append(companyId);
881    
882                    msg.append(StringPool.CLOSE_CURLY_BRACE);
883    
884                    throw new NoSuchEntryException(msg.toString());
885            }
886    
887            /**
888             * Returns the last ratings entry in the ordered set where uuid = &#63; and companyId = &#63;.
889             *
890             * @param uuid the uuid
891             * @param companyId the company ID
892             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
893             * @return the last matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
894             */
895            @Override
896            public RatingsEntry fetchByUuid_C_Last(String uuid, long companyId,
897                    OrderByComparator<RatingsEntry> orderByComparator) {
898                    int count = countByUuid_C(uuid, companyId);
899    
900                    if (count == 0) {
901                            return null;
902                    }
903    
904                    List<RatingsEntry> list = findByUuid_C(uuid, companyId, count - 1,
905                                    count, orderByComparator);
906    
907                    if (!list.isEmpty()) {
908                            return list.get(0);
909                    }
910    
911                    return null;
912            }
913    
914            /**
915             * Returns the ratings entries before and after the current ratings entry in the ordered set where uuid = &#63; and companyId = &#63;.
916             *
917             * @param entryId the primary key of the current ratings entry
918             * @param uuid the uuid
919             * @param companyId the company ID
920             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
921             * @return the previous, current, and next ratings entry
922             * @throws NoSuchEntryException if a ratings entry with the primary key could not be found
923             */
924            @Override
925            public RatingsEntry[] findByUuid_C_PrevAndNext(long entryId, String uuid,
926                    long companyId, OrderByComparator<RatingsEntry> orderByComparator)
927                    throws NoSuchEntryException {
928                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
929    
930                    Session session = null;
931    
932                    try {
933                            session = openSession();
934    
935                            RatingsEntry[] array = new RatingsEntryImpl[3];
936    
937                            array[0] = getByUuid_C_PrevAndNext(session, ratingsEntry, uuid,
938                                            companyId, orderByComparator, true);
939    
940                            array[1] = ratingsEntry;
941    
942                            array[2] = getByUuid_C_PrevAndNext(session, ratingsEntry, uuid,
943                                            companyId, orderByComparator, false);
944    
945                            return array;
946                    }
947                    catch (Exception e) {
948                            throw processException(e);
949                    }
950                    finally {
951                            closeSession(session);
952                    }
953            }
954    
955            protected RatingsEntry getByUuid_C_PrevAndNext(Session session,
956                    RatingsEntry ratingsEntry, String uuid, long companyId,
957                    OrderByComparator<RatingsEntry> orderByComparator, boolean previous) {
958                    StringBundler query = null;
959    
960                    if (orderByComparator != null) {
961                            query = new StringBundler(6 +
962                                            (orderByComparator.getOrderByFields().length * 6));
963                    }
964                    else {
965                            query = new StringBundler(3);
966                    }
967    
968                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
969    
970                    boolean bindUuid = false;
971    
972                    if (uuid == null) {
973                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
974                    }
975                    else if (uuid.equals(StringPool.BLANK)) {
976                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
977                    }
978                    else {
979                            bindUuid = true;
980    
981                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
982                    }
983    
984                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
985    
986                    if (orderByComparator != null) {
987                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
988    
989                            if (orderByConditionFields.length > 0) {
990                                    query.append(WHERE_AND);
991                            }
992    
993                            for (int i = 0; i < orderByConditionFields.length; i++) {
994                                    query.append(_ORDER_BY_ENTITY_ALIAS);
995                                    query.append(orderByConditionFields[i]);
996    
997                                    if ((i + 1) < orderByConditionFields.length) {
998                                            if (orderByComparator.isAscending() ^ previous) {
999                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1000                                            }
1001                                            else {
1002                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1003                                            }
1004                                    }
1005                                    else {
1006                                            if (orderByComparator.isAscending() ^ previous) {
1007                                                    query.append(WHERE_GREATER_THAN);
1008                                            }
1009                                            else {
1010                                                    query.append(WHERE_LESSER_THAN);
1011                                            }
1012                                    }
1013                            }
1014    
1015                            query.append(ORDER_BY_CLAUSE);
1016    
1017                            String[] orderByFields = orderByComparator.getOrderByFields();
1018    
1019                            for (int i = 0; i < orderByFields.length; i++) {
1020                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1021                                    query.append(orderByFields[i]);
1022    
1023                                    if ((i + 1) < orderByFields.length) {
1024                                            if (orderByComparator.isAscending() ^ previous) {
1025                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1026                                            }
1027                                            else {
1028                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1029                                            }
1030                                    }
1031                                    else {
1032                                            if (orderByComparator.isAscending() ^ previous) {
1033                                                    query.append(ORDER_BY_ASC);
1034                                            }
1035                                            else {
1036                                                    query.append(ORDER_BY_DESC);
1037                                            }
1038                                    }
1039                            }
1040                    }
1041                    else {
1042                            query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
1043                    }
1044    
1045                    String sql = query.toString();
1046    
1047                    Query q = session.createQuery(sql);
1048    
1049                    q.setFirstResult(0);
1050                    q.setMaxResults(2);
1051    
1052                    QueryPos qPos = QueryPos.getInstance(q);
1053    
1054                    if (bindUuid) {
1055                            qPos.add(uuid);
1056                    }
1057    
1058                    qPos.add(companyId);
1059    
1060                    if (orderByComparator != null) {
1061                            Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
1062    
1063                            for (Object value : values) {
1064                                    qPos.add(value);
1065                            }
1066                    }
1067    
1068                    List<RatingsEntry> list = q.list();
1069    
1070                    if (list.size() == 2) {
1071                            return list.get(1);
1072                    }
1073                    else {
1074                            return null;
1075                    }
1076            }
1077    
1078            /**
1079             * Removes all the ratings entries where uuid = &#63; and companyId = &#63; from the database.
1080             *
1081             * @param uuid the uuid
1082             * @param companyId the company ID
1083             */
1084            @Override
1085            public void removeByUuid_C(String uuid, long companyId) {
1086                    for (RatingsEntry ratingsEntry : findByUuid_C(uuid, companyId,
1087                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1088                            remove(ratingsEntry);
1089                    }
1090            }
1091    
1092            /**
1093             * Returns the number of ratings entries where uuid = &#63; and companyId = &#63;.
1094             *
1095             * @param uuid the uuid
1096             * @param companyId the company ID
1097             * @return the number of matching ratings entries
1098             */
1099            @Override
1100            public int countByUuid_C(String uuid, long companyId) {
1101                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1102    
1103                    Object[] finderArgs = new Object[] { uuid, companyId };
1104    
1105                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1106                                    this);
1107    
1108                    if (count == null) {
1109                            StringBundler query = new StringBundler(3);
1110    
1111                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1112    
1113                            boolean bindUuid = false;
1114    
1115                            if (uuid == null) {
1116                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1117                            }
1118                            else if (uuid.equals(StringPool.BLANK)) {
1119                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1120                            }
1121                            else {
1122                                    bindUuid = true;
1123    
1124                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1125                            }
1126    
1127                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1128    
1129                            String sql = query.toString();
1130    
1131                            Session session = null;
1132    
1133                            try {
1134                                    session = openSession();
1135    
1136                                    Query q = session.createQuery(sql);
1137    
1138                                    QueryPos qPos = QueryPos.getInstance(q);
1139    
1140                                    if (bindUuid) {
1141                                            qPos.add(uuid);
1142                                    }
1143    
1144                                    qPos.add(companyId);
1145    
1146                                    count = (Long)q.uniqueResult();
1147    
1148                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1149                            }
1150                            catch (Exception e) {
1151                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1152    
1153                                    throw processException(e);
1154                            }
1155                            finally {
1156                                    closeSession(session);
1157                            }
1158                    }
1159    
1160                    return count.intValue();
1161            }
1162    
1163            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "ratingsEntry.uuid IS NULL AND ";
1164            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "ratingsEntry.uuid = ? AND ";
1165            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(ratingsEntry.uuid IS NULL OR ratingsEntry.uuid = '') AND ";
1166            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "ratingsEntry.companyId = ?";
1167            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1168                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
1169                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
1170                            new String[] {
1171                                    Long.class.getName(), Long.class.getName(),
1172                                    
1173                            Integer.class.getName(), Integer.class.getName(),
1174                                    OrderByComparator.class.getName()
1175                            });
1176            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1177                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
1178                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
1179                            new String[] { Long.class.getName(), Long.class.getName() },
1180                            RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1181                            RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
1182            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1183                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1184                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
1185                            new String[] { Long.class.getName(), Long.class.getName() });
1186    
1187            /**
1188             * Returns all the ratings entries where classNameId = &#63; and classPK = &#63;.
1189             *
1190             * @param classNameId the class name ID
1191             * @param classPK the class p k
1192             * @return the matching ratings entries
1193             */
1194            @Override
1195            public List<RatingsEntry> findByC_C(long classNameId, long classPK) {
1196                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
1197                            QueryUtil.ALL_POS, null);
1198            }
1199    
1200            /**
1201             * Returns a range of all the ratings entries where classNameId = &#63; and classPK = &#63;.
1202             *
1203             * <p>
1204             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1205             * </p>
1206             *
1207             * @param classNameId the class name ID
1208             * @param classPK the class p k
1209             * @param start the lower bound of the range of ratings entries
1210             * @param end the upper bound of the range of ratings entries (not inclusive)
1211             * @return the range of matching ratings entries
1212             */
1213            @Override
1214            public List<RatingsEntry> findByC_C(long classNameId, long classPK,
1215                    int start, int end) {
1216                    return findByC_C(classNameId, classPK, start, end, null);
1217            }
1218    
1219            /**
1220             * Returns an ordered range of all the ratings entries where classNameId = &#63; and classPK = &#63;.
1221             *
1222             * <p>
1223             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1224             * </p>
1225             *
1226             * @param classNameId the class name ID
1227             * @param classPK the class p k
1228             * @param start the lower bound of the range of ratings entries
1229             * @param end the upper bound of the range of ratings entries (not inclusive)
1230             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1231             * @return the ordered range of matching ratings entries
1232             */
1233            @Override
1234            public List<RatingsEntry> findByC_C(long classNameId, long classPK,
1235                    int start, int end, OrderByComparator<RatingsEntry> orderByComparator) {
1236                    boolean pagination = true;
1237                    FinderPath finderPath = null;
1238                    Object[] finderArgs = null;
1239    
1240                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1241                                    (orderByComparator == null)) {
1242                            pagination = false;
1243                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
1244                            finderArgs = new Object[] { classNameId, classPK };
1245                    }
1246                    else {
1247                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
1248                            finderArgs = new Object[] {
1249                                            classNameId, classPK,
1250                                            
1251                                            start, end, orderByComparator
1252                                    };
1253                    }
1254    
1255                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1256                                    finderArgs, this);
1257    
1258                    if ((list != null) && !list.isEmpty()) {
1259                            for (RatingsEntry ratingsEntry : list) {
1260                                    if ((classNameId != ratingsEntry.getClassNameId()) ||
1261                                                    (classPK != ratingsEntry.getClassPK())) {
1262                                            list = null;
1263    
1264                                            break;
1265                                    }
1266                            }
1267                    }
1268    
1269                    if (list == null) {
1270                            StringBundler query = null;
1271    
1272                            if (orderByComparator != null) {
1273                                    query = new StringBundler(4 +
1274                                                    (orderByComparator.getOrderByFields().length * 3));
1275                            }
1276                            else {
1277                                    query = new StringBundler(4);
1278                            }
1279    
1280                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1281    
1282                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1283    
1284                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1285    
1286                            if (orderByComparator != null) {
1287                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1288                                            orderByComparator);
1289                            }
1290                            else
1291                             if (pagination) {
1292                                    query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
1293                            }
1294    
1295                            String sql = query.toString();
1296    
1297                            Session session = null;
1298    
1299                            try {
1300                                    session = openSession();
1301    
1302                                    Query q = session.createQuery(sql);
1303    
1304                                    QueryPos qPos = QueryPos.getInstance(q);
1305    
1306                                    qPos.add(classNameId);
1307    
1308                                    qPos.add(classPK);
1309    
1310                                    if (!pagination) {
1311                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1312                                                            start, end, false);
1313    
1314                                            Collections.sort(list);
1315    
1316                                            list = Collections.unmodifiableList(list);
1317                                    }
1318                                    else {
1319                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1320                                                            start, end);
1321                                    }
1322    
1323                                    cacheResult(list);
1324    
1325                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1326                            }
1327                            catch (Exception e) {
1328                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1329    
1330                                    throw processException(e);
1331                            }
1332                            finally {
1333                                    closeSession(session);
1334                            }
1335                    }
1336    
1337                    return list;
1338            }
1339    
1340            /**
1341             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
1342             *
1343             * @param classNameId the class name ID
1344             * @param classPK the class p k
1345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1346             * @return the first matching ratings entry
1347             * @throws NoSuchEntryException if a matching ratings entry could not be found
1348             */
1349            @Override
1350            public RatingsEntry findByC_C_First(long classNameId, long classPK,
1351                    OrderByComparator<RatingsEntry> orderByComparator)
1352                    throws NoSuchEntryException {
1353                    RatingsEntry ratingsEntry = fetchByC_C_First(classNameId, classPK,
1354                                    orderByComparator);
1355    
1356                    if (ratingsEntry != null) {
1357                            return ratingsEntry;
1358                    }
1359    
1360                    StringBundler msg = new StringBundler(6);
1361    
1362                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1363    
1364                    msg.append("classNameId=");
1365                    msg.append(classNameId);
1366    
1367                    msg.append(", classPK=");
1368                    msg.append(classPK);
1369    
1370                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1371    
1372                    throw new NoSuchEntryException(msg.toString());
1373            }
1374    
1375            /**
1376             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
1377             *
1378             * @param classNameId the class name ID
1379             * @param classPK the class p k
1380             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1381             * @return the first matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1382             */
1383            @Override
1384            public RatingsEntry fetchByC_C_First(long classNameId, long classPK,
1385                    OrderByComparator<RatingsEntry> orderByComparator) {
1386                    List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
1387                                    orderByComparator);
1388    
1389                    if (!list.isEmpty()) {
1390                            return list.get(0);
1391                    }
1392    
1393                    return null;
1394            }
1395    
1396            /**
1397             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
1398             *
1399             * @param classNameId the class name ID
1400             * @param classPK the class p k
1401             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1402             * @return the last matching ratings entry
1403             * @throws NoSuchEntryException if a matching ratings entry could not be found
1404             */
1405            @Override
1406            public RatingsEntry findByC_C_Last(long classNameId, long classPK,
1407                    OrderByComparator<RatingsEntry> orderByComparator)
1408                    throws NoSuchEntryException {
1409                    RatingsEntry ratingsEntry = fetchByC_C_Last(classNameId, classPK,
1410                                    orderByComparator);
1411    
1412                    if (ratingsEntry != null) {
1413                            return ratingsEntry;
1414                    }
1415    
1416                    StringBundler msg = new StringBundler(6);
1417    
1418                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1419    
1420                    msg.append("classNameId=");
1421                    msg.append(classNameId);
1422    
1423                    msg.append(", classPK=");
1424                    msg.append(classPK);
1425    
1426                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1427    
1428                    throw new NoSuchEntryException(msg.toString());
1429            }
1430    
1431            /**
1432             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
1433             *
1434             * @param classNameId the class name ID
1435             * @param classPK the class p k
1436             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1437             * @return the last matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1438             */
1439            @Override
1440            public RatingsEntry fetchByC_C_Last(long classNameId, long classPK,
1441                    OrderByComparator<RatingsEntry> orderByComparator) {
1442                    int count = countByC_C(classNameId, classPK);
1443    
1444                    if (count == 0) {
1445                            return null;
1446                    }
1447    
1448                    List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
1449                                    count, orderByComparator);
1450    
1451                    if (!list.isEmpty()) {
1452                            return list.get(0);
1453                    }
1454    
1455                    return null;
1456            }
1457    
1458            /**
1459             * Returns the ratings entries before and after the current ratings entry in the ordered set where classNameId = &#63; and classPK = &#63;.
1460             *
1461             * @param entryId the primary key of the current ratings entry
1462             * @param classNameId the class name ID
1463             * @param classPK the class p k
1464             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1465             * @return the previous, current, and next ratings entry
1466             * @throws NoSuchEntryException if a ratings entry with the primary key could not be found
1467             */
1468            @Override
1469            public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
1470                    long classPK, OrderByComparator<RatingsEntry> orderByComparator)
1471                    throws NoSuchEntryException {
1472                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
1473    
1474                    Session session = null;
1475    
1476                    try {
1477                            session = openSession();
1478    
1479                            RatingsEntry[] array = new RatingsEntryImpl[3];
1480    
1481                            array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
1482                                            classPK, orderByComparator, true);
1483    
1484                            array[1] = ratingsEntry;
1485    
1486                            array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
1487                                            classPK, orderByComparator, false);
1488    
1489                            return array;
1490                    }
1491                    catch (Exception e) {
1492                            throw processException(e);
1493                    }
1494                    finally {
1495                            closeSession(session);
1496                    }
1497            }
1498    
1499            protected RatingsEntry getByC_C_PrevAndNext(Session session,
1500                    RatingsEntry ratingsEntry, long classNameId, long classPK,
1501                    OrderByComparator<RatingsEntry> orderByComparator, boolean previous) {
1502                    StringBundler query = null;
1503    
1504                    if (orderByComparator != null) {
1505                            query = new StringBundler(6 +
1506                                            (orderByComparator.getOrderByFields().length * 6));
1507                    }
1508                    else {
1509                            query = new StringBundler(3);
1510                    }
1511    
1512                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1513    
1514                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1515    
1516                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1517    
1518                    if (orderByComparator != null) {
1519                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1520    
1521                            if (orderByConditionFields.length > 0) {
1522                                    query.append(WHERE_AND);
1523                            }
1524    
1525                            for (int i = 0; i < orderByConditionFields.length; i++) {
1526                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1527                                    query.append(orderByConditionFields[i]);
1528    
1529                                    if ((i + 1) < orderByConditionFields.length) {
1530                                            if (orderByComparator.isAscending() ^ previous) {
1531                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1532                                            }
1533                                            else {
1534                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1535                                            }
1536                                    }
1537                                    else {
1538                                            if (orderByComparator.isAscending() ^ previous) {
1539                                                    query.append(WHERE_GREATER_THAN);
1540                                            }
1541                                            else {
1542                                                    query.append(WHERE_LESSER_THAN);
1543                                            }
1544                                    }
1545                            }
1546    
1547                            query.append(ORDER_BY_CLAUSE);
1548    
1549                            String[] orderByFields = orderByComparator.getOrderByFields();
1550    
1551                            for (int i = 0; i < orderByFields.length; i++) {
1552                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1553                                    query.append(orderByFields[i]);
1554    
1555                                    if ((i + 1) < orderByFields.length) {
1556                                            if (orderByComparator.isAscending() ^ previous) {
1557                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1558                                            }
1559                                            else {
1560                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1561                                            }
1562                                    }
1563                                    else {
1564                                            if (orderByComparator.isAscending() ^ previous) {
1565                                                    query.append(ORDER_BY_ASC);
1566                                            }
1567                                            else {
1568                                                    query.append(ORDER_BY_DESC);
1569                                            }
1570                                    }
1571                            }
1572                    }
1573                    else {
1574                            query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
1575                    }
1576    
1577                    String sql = query.toString();
1578    
1579                    Query q = session.createQuery(sql);
1580    
1581                    q.setFirstResult(0);
1582                    q.setMaxResults(2);
1583    
1584                    QueryPos qPos = QueryPos.getInstance(q);
1585    
1586                    qPos.add(classNameId);
1587    
1588                    qPos.add(classPK);
1589    
1590                    if (orderByComparator != null) {
1591                            Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
1592    
1593                            for (Object value : values) {
1594                                    qPos.add(value);
1595                            }
1596                    }
1597    
1598                    List<RatingsEntry> list = q.list();
1599    
1600                    if (list.size() == 2) {
1601                            return list.get(1);
1602                    }
1603                    else {
1604                            return null;
1605                    }
1606            }
1607    
1608            /**
1609             * Removes all the ratings entries where classNameId = &#63; and classPK = &#63; from the database.
1610             *
1611             * @param classNameId the class name ID
1612             * @param classPK the class p k
1613             */
1614            @Override
1615            public void removeByC_C(long classNameId, long classPK) {
1616                    for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK,
1617                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1618                            remove(ratingsEntry);
1619                    }
1620            }
1621    
1622            /**
1623             * Returns the number of ratings entries where classNameId = &#63; and classPK = &#63;.
1624             *
1625             * @param classNameId the class name ID
1626             * @param classPK the class p k
1627             * @return the number of matching ratings entries
1628             */
1629            @Override
1630            public int countByC_C(long classNameId, long classPK) {
1631                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
1632    
1633                    Object[] finderArgs = new Object[] { classNameId, classPK };
1634    
1635                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1636                                    this);
1637    
1638                    if (count == null) {
1639                            StringBundler query = new StringBundler(3);
1640    
1641                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1642    
1643                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1644    
1645                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1646    
1647                            String sql = query.toString();
1648    
1649                            Session session = null;
1650    
1651                            try {
1652                                    session = openSession();
1653    
1654                                    Query q = session.createQuery(sql);
1655    
1656                                    QueryPos qPos = QueryPos.getInstance(q);
1657    
1658                                    qPos.add(classNameId);
1659    
1660                                    qPos.add(classPK);
1661    
1662                                    count = (Long)q.uniqueResult();
1663    
1664                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1665                            }
1666                            catch (Exception e) {
1667                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1668    
1669                                    throw processException(e);
1670                            }
1671                            finally {
1672                                    closeSession(session);
1673                            }
1674                    }
1675    
1676                    return count.intValue();
1677            }
1678    
1679            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1680            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1681            public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1682                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
1683                            FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
1684                            new String[] {
1685                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1686                            },
1687                            RatingsEntryModelImpl.USERID_COLUMN_BITMASK |
1688                            RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1689                            RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
1690            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1691                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1692                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
1693                            new String[] {
1694                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
1695                            });
1696    
1697            /**
1698             * Returns the ratings entry where userId = &#63; and classNameId = &#63; and classPK = &#63; or throws a {@link NoSuchEntryException} if it could not be found.
1699             *
1700             * @param userId the user ID
1701             * @param classNameId the class name ID
1702             * @param classPK the class p k
1703             * @return the matching ratings entry
1704             * @throws NoSuchEntryException if a matching ratings entry could not be found
1705             */
1706            @Override
1707            public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
1708                    throws NoSuchEntryException {
1709                    RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
1710    
1711                    if (ratingsEntry == null) {
1712                            StringBundler msg = new StringBundler(8);
1713    
1714                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1715    
1716                            msg.append("userId=");
1717                            msg.append(userId);
1718    
1719                            msg.append(", classNameId=");
1720                            msg.append(classNameId);
1721    
1722                            msg.append(", classPK=");
1723                            msg.append(classPK);
1724    
1725                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1726    
1727                            if (_log.isWarnEnabled()) {
1728                                    _log.warn(msg.toString());
1729                            }
1730    
1731                            throw new NoSuchEntryException(msg.toString());
1732                    }
1733    
1734                    return ratingsEntry;
1735            }
1736    
1737            /**
1738             * 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.
1739             *
1740             * @param userId the user ID
1741             * @param classNameId the class name ID
1742             * @param classPK the class p k
1743             * @return the matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1744             */
1745            @Override
1746            public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK) {
1747                    return fetchByU_C_C(userId, classNameId, classPK, true);
1748            }
1749    
1750            /**
1751             * 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.
1752             *
1753             * @param userId the user ID
1754             * @param classNameId the class name ID
1755             * @param classPK the class p k
1756             * @param retrieveFromCache whether to use the finder cache
1757             * @return the matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
1758             */
1759            @Override
1760            public RatingsEntry fetchByU_C_C(long userId, long classNameId,
1761                    long classPK, boolean retrieveFromCache) {
1762                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1763    
1764                    Object result = null;
1765    
1766                    if (retrieveFromCache) {
1767                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
1768                                            finderArgs, this);
1769                    }
1770    
1771                    if (result instanceof RatingsEntry) {
1772                            RatingsEntry ratingsEntry = (RatingsEntry)result;
1773    
1774                            if ((userId != ratingsEntry.getUserId()) ||
1775                                            (classNameId != ratingsEntry.getClassNameId()) ||
1776                                            (classPK != ratingsEntry.getClassPK())) {
1777                                    result = null;
1778                            }
1779                    }
1780    
1781                    if (result == null) {
1782                            StringBundler query = new StringBundler(5);
1783    
1784                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1785    
1786                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1787    
1788                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1789    
1790                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1791    
1792                            String sql = query.toString();
1793    
1794                            Session session = null;
1795    
1796                            try {
1797                                    session = openSession();
1798    
1799                                    Query q = session.createQuery(sql);
1800    
1801                                    QueryPos qPos = QueryPos.getInstance(q);
1802    
1803                                    qPos.add(userId);
1804    
1805                                    qPos.add(classNameId);
1806    
1807                                    qPos.add(classPK);
1808    
1809                                    List<RatingsEntry> list = q.list();
1810    
1811                                    if (list.isEmpty()) {
1812                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1813                                                    finderArgs, list);
1814                                    }
1815                                    else {
1816                                            RatingsEntry ratingsEntry = list.get(0);
1817    
1818                                            result = ratingsEntry;
1819    
1820                                            cacheResult(ratingsEntry);
1821    
1822                                            if ((ratingsEntry.getUserId() != userId) ||
1823                                                            (ratingsEntry.getClassNameId() != classNameId) ||
1824                                                            (ratingsEntry.getClassPK() != classPK)) {
1825                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1826                                                            finderArgs, ratingsEntry);
1827                                            }
1828                                    }
1829                            }
1830                            catch (Exception e) {
1831                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
1832                                            finderArgs);
1833    
1834                                    throw processException(e);
1835                            }
1836                            finally {
1837                                    closeSession(session);
1838                            }
1839                    }
1840    
1841                    if (result instanceof List<?>) {
1842                            return null;
1843                    }
1844                    else {
1845                            return (RatingsEntry)result;
1846                    }
1847            }
1848    
1849            /**
1850             * Removes the ratings entry where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
1851             *
1852             * @param userId the user ID
1853             * @param classNameId the class name ID
1854             * @param classPK the class p k
1855             * @return the ratings entry that was removed
1856             */
1857            @Override
1858            public RatingsEntry removeByU_C_C(long userId, long classNameId,
1859                    long classPK) throws NoSuchEntryException {
1860                    RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
1861    
1862                    return remove(ratingsEntry);
1863            }
1864    
1865            /**
1866             * Returns the number of ratings entries where userId = &#63; and classNameId = &#63; and classPK = &#63;.
1867             *
1868             * @param userId the user ID
1869             * @param classNameId the class name ID
1870             * @param classPK the class p k
1871             * @return the number of matching ratings entries
1872             */
1873            @Override
1874            public int countByU_C_C(long userId, long classNameId, long classPK) {
1875                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
1876    
1877                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1878    
1879                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1880                                    this);
1881    
1882                    if (count == null) {
1883                            StringBundler query = new StringBundler(4);
1884    
1885                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1886    
1887                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1888    
1889                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1890    
1891                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1892    
1893                            String sql = query.toString();
1894    
1895                            Session session = null;
1896    
1897                            try {
1898                                    session = openSession();
1899    
1900                                    Query q = session.createQuery(sql);
1901    
1902                                    QueryPos qPos = QueryPos.getInstance(q);
1903    
1904                                    qPos.add(userId);
1905    
1906                                    qPos.add(classNameId);
1907    
1908                                    qPos.add(classPK);
1909    
1910                                    count = (Long)q.uniqueResult();
1911    
1912                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1913                            }
1914                            catch (Exception e) {
1915                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1916    
1917                                    throw processException(e);
1918                            }
1919                            finally {
1920                                    closeSession(session);
1921                            }
1922                    }
1923    
1924                    return count.intValue();
1925            }
1926    
1927            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1928            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1929            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1930            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1931                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
1932                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
1933                            new String[] {
1934                                    Long.class.getName(), Long.class.getName(),
1935                                    Double.class.getName(),
1936                                    
1937                            Integer.class.getName(), Integer.class.getName(),
1938                                    OrderByComparator.class.getName()
1939                            });
1940            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1941                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
1942                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
1943                            new String[] {
1944                                    Long.class.getName(), Long.class.getName(),
1945                                    Double.class.getName()
1946                            },
1947                            RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
1948                            RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK |
1949                            RatingsEntryModelImpl.SCORE_COLUMN_BITMASK);
1950            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1951                            RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1952                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
1953                            new String[] {
1954                                    Long.class.getName(), Long.class.getName(),
1955                                    Double.class.getName()
1956                            });
1957    
1958            /**
1959             * Returns all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1960             *
1961             * @param classNameId the class name ID
1962             * @param classPK the class p k
1963             * @param score the score
1964             * @return the matching ratings entries
1965             */
1966            @Override
1967            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1968                    double score) {
1969                    return findByC_C_S(classNameId, classPK, score, QueryUtil.ALL_POS,
1970                            QueryUtil.ALL_POS, null);
1971            }
1972    
1973            /**
1974             * Returns a range of all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1975             *
1976             * <p>
1977             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1978             * </p>
1979             *
1980             * @param classNameId the class name ID
1981             * @param classPK the class p k
1982             * @param score the score
1983             * @param start the lower bound of the range of ratings entries
1984             * @param end the upper bound of the range of ratings entries (not inclusive)
1985             * @return the range of matching ratings entries
1986             */
1987            @Override
1988            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1989                    double score, int start, int end) {
1990                    return findByC_C_S(classNameId, classPK, score, start, end, null);
1991            }
1992    
1993            /**
1994             * Returns an ordered range of all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
1995             *
1996             * <p>
1997             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1998             * </p>
1999             *
2000             * @param classNameId the class name ID
2001             * @param classPK the class p k
2002             * @param score the score
2003             * @param start the lower bound of the range of ratings entries
2004             * @param end the upper bound of the range of ratings entries (not inclusive)
2005             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2006             * @return the ordered range of matching ratings entries
2007             */
2008            @Override
2009            public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
2010                    double score, int start, int end,
2011                    OrderByComparator<RatingsEntry> orderByComparator) {
2012                    boolean pagination = true;
2013                    FinderPath finderPath = null;
2014                    Object[] finderArgs = null;
2015    
2016                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2017                                    (orderByComparator == null)) {
2018                            pagination = false;
2019                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
2020                            finderArgs = new Object[] { classNameId, classPK, score };
2021                    }
2022                    else {
2023                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
2024                            finderArgs = new Object[] {
2025                                            classNameId, classPK, score,
2026                                            
2027                                            start, end, orderByComparator
2028                                    };
2029                    }
2030    
2031                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
2032                                    finderArgs, this);
2033    
2034                    if ((list != null) && !list.isEmpty()) {
2035                            for (RatingsEntry ratingsEntry : list) {
2036                                    if ((classNameId != ratingsEntry.getClassNameId()) ||
2037                                                    (classPK != ratingsEntry.getClassPK()) ||
2038                                                    (score != ratingsEntry.getScore())) {
2039                                            list = null;
2040    
2041                                            break;
2042                                    }
2043                            }
2044                    }
2045    
2046                    if (list == null) {
2047                            StringBundler query = null;
2048    
2049                            if (orderByComparator != null) {
2050                                    query = new StringBundler(5 +
2051                                                    (orderByComparator.getOrderByFields().length * 3));
2052                            }
2053                            else {
2054                                    query = new StringBundler(5);
2055                            }
2056    
2057                            query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
2058    
2059                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
2060    
2061                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
2062    
2063                            query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
2064    
2065                            if (orderByComparator != null) {
2066                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2067                                            orderByComparator);
2068                            }
2069                            else
2070                             if (pagination) {
2071                                    query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
2072                            }
2073    
2074                            String sql = query.toString();
2075    
2076                            Session session = null;
2077    
2078                            try {
2079                                    session = openSession();
2080    
2081                                    Query q = session.createQuery(sql);
2082    
2083                                    QueryPos qPos = QueryPos.getInstance(q);
2084    
2085                                    qPos.add(classNameId);
2086    
2087                                    qPos.add(classPK);
2088    
2089                                    qPos.add(score);
2090    
2091                                    if (!pagination) {
2092                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
2093                                                            start, end, false);
2094    
2095                                            Collections.sort(list);
2096    
2097                                            list = Collections.unmodifiableList(list);
2098                                    }
2099                                    else {
2100                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
2101                                                            start, end);
2102                                    }
2103    
2104                                    cacheResult(list);
2105    
2106                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2107                            }
2108                            catch (Exception e) {
2109                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2110    
2111                                    throw processException(e);
2112                            }
2113                            finally {
2114                                    closeSession(session);
2115                            }
2116                    }
2117    
2118                    return list;
2119            }
2120    
2121            /**
2122             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
2123             *
2124             * @param classNameId the class name ID
2125             * @param classPK the class p k
2126             * @param score the score
2127             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2128             * @return the first matching ratings entry
2129             * @throws NoSuchEntryException if a matching ratings entry could not be found
2130             */
2131            @Override
2132            public RatingsEntry findByC_C_S_First(long classNameId, long classPK,
2133                    double score, OrderByComparator<RatingsEntry> orderByComparator)
2134                    throws NoSuchEntryException {
2135                    RatingsEntry ratingsEntry = fetchByC_C_S_First(classNameId, classPK,
2136                                    score, orderByComparator);
2137    
2138                    if (ratingsEntry != null) {
2139                            return ratingsEntry;
2140                    }
2141    
2142                    StringBundler msg = new StringBundler(8);
2143    
2144                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2145    
2146                    msg.append("classNameId=");
2147                    msg.append(classNameId);
2148    
2149                    msg.append(", classPK=");
2150                    msg.append(classPK);
2151    
2152                    msg.append(", score=");
2153                    msg.append(score);
2154    
2155                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2156    
2157                    throw new NoSuchEntryException(msg.toString());
2158            }
2159    
2160            /**
2161             * Returns the first ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
2162             *
2163             * @param classNameId the class name ID
2164             * @param classPK the class p k
2165             * @param score the score
2166             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2167             * @return the first matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
2168             */
2169            @Override
2170            public RatingsEntry fetchByC_C_S_First(long classNameId, long classPK,
2171                    double score, OrderByComparator<RatingsEntry> orderByComparator) {
2172                    List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score, 0,
2173                                    1, orderByComparator);
2174    
2175                    if (!list.isEmpty()) {
2176                            return list.get(0);
2177                    }
2178    
2179                    return null;
2180            }
2181    
2182            /**
2183             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
2184             *
2185             * @param classNameId the class name ID
2186             * @param classPK the class p k
2187             * @param score the score
2188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2189             * @return the last matching ratings entry
2190             * @throws NoSuchEntryException if a matching ratings entry could not be found
2191             */
2192            @Override
2193            public RatingsEntry findByC_C_S_Last(long classNameId, long classPK,
2194                    double score, OrderByComparator<RatingsEntry> orderByComparator)
2195                    throws NoSuchEntryException {
2196                    RatingsEntry ratingsEntry = fetchByC_C_S_Last(classNameId, classPK,
2197                                    score, orderByComparator);
2198    
2199                    if (ratingsEntry != null) {
2200                            return ratingsEntry;
2201                    }
2202    
2203                    StringBundler msg = new StringBundler(8);
2204    
2205                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2206    
2207                    msg.append("classNameId=");
2208                    msg.append(classNameId);
2209    
2210                    msg.append(", classPK=");
2211                    msg.append(classPK);
2212    
2213                    msg.append(", score=");
2214                    msg.append(score);
2215    
2216                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2217    
2218                    throw new NoSuchEntryException(msg.toString());
2219            }
2220    
2221            /**
2222             * Returns the last ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
2223             *
2224             * @param classNameId the class name ID
2225             * @param classPK the class p k
2226             * @param score the score
2227             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2228             * @return the last matching ratings entry, or <code>null</code> if a matching ratings entry could not be found
2229             */
2230            @Override
2231            public RatingsEntry fetchByC_C_S_Last(long classNameId, long classPK,
2232                    double score, OrderByComparator<RatingsEntry> orderByComparator) {
2233                    int count = countByC_C_S(classNameId, classPK, score);
2234    
2235                    if (count == 0) {
2236                            return null;
2237                    }
2238    
2239                    List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score,
2240                                    count - 1, count, orderByComparator);
2241    
2242                    if (!list.isEmpty()) {
2243                            return list.get(0);
2244                    }
2245    
2246                    return null;
2247            }
2248    
2249            /**
2250             * Returns the ratings entries before and after the current ratings entry in the ordered set where classNameId = &#63; and classPK = &#63; and score = &#63;.
2251             *
2252             * @param entryId the primary key of the current ratings entry
2253             * @param classNameId the class name ID
2254             * @param classPK the class p k
2255             * @param score the score
2256             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2257             * @return the previous, current, and next ratings entry
2258             * @throws NoSuchEntryException if a ratings entry with the primary key could not be found
2259             */
2260            @Override
2261            public RatingsEntry[] findByC_C_S_PrevAndNext(long entryId,
2262                    long classNameId, long classPK, double score,
2263                    OrderByComparator<RatingsEntry> orderByComparator)
2264                    throws NoSuchEntryException {
2265                    RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
2266    
2267                    Session session = null;
2268    
2269                    try {
2270                            session = openSession();
2271    
2272                            RatingsEntry[] array = new RatingsEntryImpl[3];
2273    
2274                            array[0] = getByC_C_S_PrevAndNext(session, ratingsEntry,
2275                                            classNameId, classPK, score, orderByComparator, true);
2276    
2277                            array[1] = ratingsEntry;
2278    
2279                            array[2] = getByC_C_S_PrevAndNext(session, ratingsEntry,
2280                                            classNameId, classPK, score, orderByComparator, false);
2281    
2282                            return array;
2283                    }
2284                    catch (Exception e) {
2285                            throw processException(e);
2286                    }
2287                    finally {
2288                            closeSession(session);
2289                    }
2290            }
2291    
2292            protected RatingsEntry getByC_C_S_PrevAndNext(Session session,
2293                    RatingsEntry ratingsEntry, long classNameId, long classPK,
2294                    double score, OrderByComparator<RatingsEntry> orderByComparator,
2295                    boolean previous) {
2296                    StringBundler query = null;
2297    
2298                    if (orderByComparator != null) {
2299                            query = new StringBundler(6 +
2300                                            (orderByComparator.getOrderByFields().length * 6));
2301                    }
2302                    else {
2303                            query = new StringBundler(3);
2304                    }
2305    
2306                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
2307    
2308                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
2309    
2310                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
2311    
2312                    query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
2313    
2314                    if (orderByComparator != null) {
2315                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2316    
2317                            if (orderByConditionFields.length > 0) {
2318                                    query.append(WHERE_AND);
2319                            }
2320    
2321                            for (int i = 0; i < orderByConditionFields.length; i++) {
2322                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2323                                    query.append(orderByConditionFields[i]);
2324    
2325                                    if ((i + 1) < orderByConditionFields.length) {
2326                                            if (orderByComparator.isAscending() ^ previous) {
2327                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2328                                            }
2329                                            else {
2330                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2331                                            }
2332                                    }
2333                                    else {
2334                                            if (orderByComparator.isAscending() ^ previous) {
2335                                                    query.append(WHERE_GREATER_THAN);
2336                                            }
2337                                            else {
2338                                                    query.append(WHERE_LESSER_THAN);
2339                                            }
2340                                    }
2341                            }
2342    
2343                            query.append(ORDER_BY_CLAUSE);
2344    
2345                            String[] orderByFields = orderByComparator.getOrderByFields();
2346    
2347                            for (int i = 0; i < orderByFields.length; i++) {
2348                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2349                                    query.append(orderByFields[i]);
2350    
2351                                    if ((i + 1) < orderByFields.length) {
2352                                            if (orderByComparator.isAscending() ^ previous) {
2353                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2354                                            }
2355                                            else {
2356                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2357                                            }
2358                                    }
2359                                    else {
2360                                            if (orderByComparator.isAscending() ^ previous) {
2361                                                    query.append(ORDER_BY_ASC);
2362                                            }
2363                                            else {
2364                                                    query.append(ORDER_BY_DESC);
2365                                            }
2366                                    }
2367                            }
2368                    }
2369                    else {
2370                            query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
2371                    }
2372    
2373                    String sql = query.toString();
2374    
2375                    Query q = session.createQuery(sql);
2376    
2377                    q.setFirstResult(0);
2378                    q.setMaxResults(2);
2379    
2380                    QueryPos qPos = QueryPos.getInstance(q);
2381    
2382                    qPos.add(classNameId);
2383    
2384                    qPos.add(classPK);
2385    
2386                    qPos.add(score);
2387    
2388                    if (orderByComparator != null) {
2389                            Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
2390    
2391                            for (Object value : values) {
2392                                    qPos.add(value);
2393                            }
2394                    }
2395    
2396                    List<RatingsEntry> list = q.list();
2397    
2398                    if (list.size() == 2) {
2399                            return list.get(1);
2400                    }
2401                    else {
2402                            return null;
2403                    }
2404            }
2405    
2406            /**
2407             * Removes all the ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63; from the database.
2408             *
2409             * @param classNameId the class name ID
2410             * @param classPK the class p k
2411             * @param score the score
2412             */
2413            @Override
2414            public void removeByC_C_S(long classNameId, long classPK, double score) {
2415                    for (RatingsEntry ratingsEntry : findByC_C_S(classNameId, classPK,
2416                                    score, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2417                            remove(ratingsEntry);
2418                    }
2419            }
2420    
2421            /**
2422             * Returns the number of ratings entries where classNameId = &#63; and classPK = &#63; and score = &#63;.
2423             *
2424             * @param classNameId the class name ID
2425             * @param classPK the class p k
2426             * @param score the score
2427             * @return the number of matching ratings entries
2428             */
2429            @Override
2430            public int countByC_C_S(long classNameId, long classPK, double score) {
2431                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
2432    
2433                    Object[] finderArgs = new Object[] { classNameId, classPK, score };
2434    
2435                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2436                                    this);
2437    
2438                    if (count == null) {
2439                            StringBundler query = new StringBundler(4);
2440    
2441                            query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
2442    
2443                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
2444    
2445                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
2446    
2447                            query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
2448    
2449                            String sql = query.toString();
2450    
2451                            Session session = null;
2452    
2453                            try {
2454                                    session = openSession();
2455    
2456                                    Query q = session.createQuery(sql);
2457    
2458                                    QueryPos qPos = QueryPos.getInstance(q);
2459    
2460                                    qPos.add(classNameId);
2461    
2462                                    qPos.add(classPK);
2463    
2464                                    qPos.add(score);
2465    
2466                                    count = (Long)q.uniqueResult();
2467    
2468                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2469                            }
2470                            catch (Exception e) {
2471                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2472    
2473                                    throw processException(e);
2474                            }
2475                            finally {
2476                                    closeSession(session);
2477                            }
2478                    }
2479    
2480                    return count.intValue();
2481            }
2482    
2483            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
2484            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "ratingsEntry.classPK = ? AND ";
2485            private static final String _FINDER_COLUMN_C_C_S_SCORE_2 = "ratingsEntry.score = ?";
2486    
2487            public RatingsEntryPersistenceImpl() {
2488                    setModelClass(RatingsEntry.class);
2489            }
2490    
2491            /**
2492             * Caches the ratings entry in the entity cache if it is enabled.
2493             *
2494             * @param ratingsEntry the ratings entry
2495             */
2496            @Override
2497            public void cacheResult(RatingsEntry ratingsEntry) {
2498                    EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
2499                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
2500    
2501                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
2502                            new Object[] {
2503                                    ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
2504                                    ratingsEntry.getClassPK()
2505                            }, ratingsEntry);
2506    
2507                    ratingsEntry.resetOriginalValues();
2508            }
2509    
2510            /**
2511             * Caches the ratings entries in the entity cache if it is enabled.
2512             *
2513             * @param ratingsEntries the ratings entries
2514             */
2515            @Override
2516            public void cacheResult(List<RatingsEntry> ratingsEntries) {
2517                    for (RatingsEntry ratingsEntry : ratingsEntries) {
2518                            if (EntityCacheUtil.getResult(
2519                                                    RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
2520                                                    RatingsEntryImpl.class, ratingsEntry.getPrimaryKey()) == null) {
2521                                    cacheResult(ratingsEntry);
2522                            }
2523                            else {
2524                                    ratingsEntry.resetOriginalValues();
2525                            }
2526                    }
2527            }
2528    
2529            /**
2530             * Clears the cache for all ratings entries.
2531             *
2532             * <p>
2533             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2534             * </p>
2535             */
2536            @Override
2537            public void clearCache() {
2538                    EntityCacheUtil.clearCache(RatingsEntryImpl.class);
2539    
2540                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2541                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2542                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2543            }
2544    
2545            /**
2546             * Clears the cache for the ratings entry.
2547             *
2548             * <p>
2549             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2550             * </p>
2551             */
2552            @Override
2553            public void clearCache(RatingsEntry ratingsEntry) {
2554                    EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
2555                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
2556    
2557                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2558                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2559    
2560                    clearUniqueFindersCache(ratingsEntry);
2561            }
2562    
2563            @Override
2564            public void clearCache(List<RatingsEntry> ratingsEntries) {
2565                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2566                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2567    
2568                    for (RatingsEntry ratingsEntry : ratingsEntries) {
2569                            EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
2570                                    RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
2571    
2572                            clearUniqueFindersCache(ratingsEntry);
2573                    }
2574            }
2575    
2576            protected void cacheUniqueFindersCache(RatingsEntry ratingsEntry) {
2577                    if (ratingsEntry.isNew()) {
2578                            Object[] args = new Object[] {
2579                                            ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
2580                                            ratingsEntry.getClassPK()
2581                                    };
2582    
2583                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C, args,
2584                                    Long.valueOf(1));
2585                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C, args,
2586                                    ratingsEntry);
2587                    }
2588                    else {
2589                            RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
2590    
2591                            if ((ratingsEntryModelImpl.getColumnBitmask() &
2592                                            FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
2593                                    Object[] args = new Object[] {
2594                                                    ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
2595                                                    ratingsEntry.getClassPK()
2596                                            };
2597    
2598                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C, args,
2599                                            Long.valueOf(1));
2600                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C, args,
2601                                            ratingsEntry);
2602                            }
2603                    }
2604            }
2605    
2606            protected void clearUniqueFindersCache(RatingsEntry ratingsEntry) {
2607                    RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
2608    
2609                    Object[] args = new Object[] {
2610                                    ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
2611                                    ratingsEntry.getClassPK()
2612                            };
2613    
2614                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
2615                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
2616    
2617                    if ((ratingsEntryModelImpl.getColumnBitmask() &
2618                                    FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
2619                            args = new Object[] {
2620                                            ratingsEntryModelImpl.getOriginalUserId(),
2621                                            ratingsEntryModelImpl.getOriginalClassNameId(),
2622                                            ratingsEntryModelImpl.getOriginalClassPK()
2623                                    };
2624    
2625                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
2626                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
2627                    }
2628            }
2629    
2630            /**
2631             * Creates a new ratings entry with the primary key. Does not add the ratings entry to the database.
2632             *
2633             * @param entryId the primary key for the new ratings entry
2634             * @return the new ratings entry
2635             */
2636            @Override
2637            public RatingsEntry create(long entryId) {
2638                    RatingsEntry ratingsEntry = new RatingsEntryImpl();
2639    
2640                    ratingsEntry.setNew(true);
2641                    ratingsEntry.setPrimaryKey(entryId);
2642    
2643                    String uuid = PortalUUIDUtil.generate();
2644    
2645                    ratingsEntry.setUuid(uuid);
2646    
2647                    return ratingsEntry;
2648            }
2649    
2650            /**
2651             * Removes the ratings entry with the primary key from the database. Also notifies the appropriate model listeners.
2652             *
2653             * @param entryId the primary key of the ratings entry
2654             * @return the ratings entry that was removed
2655             * @throws NoSuchEntryException if a ratings entry with the primary key could not be found
2656             */
2657            @Override
2658            public RatingsEntry remove(long entryId) throws NoSuchEntryException {
2659                    return remove((Serializable)entryId);
2660            }
2661    
2662            /**
2663             * Removes the ratings entry with the primary key from the database. Also notifies the appropriate model listeners.
2664             *
2665             * @param primaryKey the primary key of the ratings entry
2666             * @return the ratings entry that was removed
2667             * @throws NoSuchEntryException if a ratings entry with the primary key could not be found
2668             */
2669            @Override
2670            public RatingsEntry remove(Serializable primaryKey)
2671                    throws NoSuchEntryException {
2672                    Session session = null;
2673    
2674                    try {
2675                            session = openSession();
2676    
2677                            RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
2678                                            primaryKey);
2679    
2680                            if (ratingsEntry == null) {
2681                                    if (_log.isWarnEnabled()) {
2682                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2683                                    }
2684    
2685                                    throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2686                                            primaryKey);
2687                            }
2688    
2689                            return remove(ratingsEntry);
2690                    }
2691                    catch (NoSuchEntryException nsee) {
2692                            throw nsee;
2693                    }
2694                    catch (Exception e) {
2695                            throw processException(e);
2696                    }
2697                    finally {
2698                            closeSession(session);
2699                    }
2700            }
2701    
2702            @Override
2703            protected RatingsEntry removeImpl(RatingsEntry ratingsEntry) {
2704                    ratingsEntry = toUnwrappedModel(ratingsEntry);
2705    
2706                    Session session = null;
2707    
2708                    try {
2709                            session = openSession();
2710    
2711                            if (!session.contains(ratingsEntry)) {
2712                                    ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
2713                                                    ratingsEntry.getPrimaryKeyObj());
2714                            }
2715    
2716                            if (ratingsEntry != null) {
2717                                    session.delete(ratingsEntry);
2718                            }
2719                    }
2720                    catch (Exception e) {
2721                            throw processException(e);
2722                    }
2723                    finally {
2724                            closeSession(session);
2725                    }
2726    
2727                    if (ratingsEntry != null) {
2728                            clearCache(ratingsEntry);
2729                    }
2730    
2731                    return ratingsEntry;
2732            }
2733    
2734            @Override
2735            public RatingsEntry updateImpl(RatingsEntry ratingsEntry) {
2736                    ratingsEntry = toUnwrappedModel(ratingsEntry);
2737    
2738                    boolean isNew = ratingsEntry.isNew();
2739    
2740                    RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
2741    
2742                    if (Validator.isNull(ratingsEntry.getUuid())) {
2743                            String uuid = PortalUUIDUtil.generate();
2744    
2745                            ratingsEntry.setUuid(uuid);
2746                    }
2747    
2748                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2749    
2750                    Date now = new Date();
2751    
2752                    if (isNew && (ratingsEntry.getCreateDate() == null)) {
2753                            if (serviceContext == null) {
2754                                    ratingsEntry.setCreateDate(now);
2755                            }
2756                            else {
2757                                    ratingsEntry.setCreateDate(serviceContext.getCreateDate(now));
2758                            }
2759                    }
2760    
2761                    if (!ratingsEntryModelImpl.hasSetModifiedDate()) {
2762                            if (serviceContext == null) {
2763                                    ratingsEntry.setModifiedDate(now);
2764                            }
2765                            else {
2766                                    ratingsEntry.setModifiedDate(serviceContext.getModifiedDate(now));
2767                            }
2768                    }
2769    
2770                    Session session = null;
2771    
2772                    try {
2773                            session = openSession();
2774    
2775                            if (ratingsEntry.isNew()) {
2776                                    session.save(ratingsEntry);
2777    
2778                                    ratingsEntry.setNew(false);
2779                            }
2780                            else {
2781                                    session.merge(ratingsEntry);
2782                            }
2783                    }
2784                    catch (Exception e) {
2785                            throw processException(e);
2786                    }
2787                    finally {
2788                            closeSession(session);
2789                    }
2790    
2791                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2792    
2793                    if (isNew || !RatingsEntryModelImpl.COLUMN_BITMASK_ENABLED) {
2794                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2795                    }
2796    
2797                    else {
2798                            if ((ratingsEntryModelImpl.getColumnBitmask() &
2799                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2800                                    Object[] args = new Object[] {
2801                                                    ratingsEntryModelImpl.getOriginalUuid()
2802                                            };
2803    
2804                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2805                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2806                                            args);
2807    
2808                                    args = new Object[] { ratingsEntryModelImpl.getUuid() };
2809    
2810                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2811                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2812                                            args);
2813                            }
2814    
2815                            if ((ratingsEntryModelImpl.getColumnBitmask() &
2816                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2817                                    Object[] args = new Object[] {
2818                                                    ratingsEntryModelImpl.getOriginalUuid(),
2819                                                    ratingsEntryModelImpl.getOriginalCompanyId()
2820                                            };
2821    
2822                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2823                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2824                                            args);
2825    
2826                                    args = new Object[] {
2827                                                    ratingsEntryModelImpl.getUuid(),
2828                                                    ratingsEntryModelImpl.getCompanyId()
2829                                            };
2830    
2831                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2832                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2833                                            args);
2834                            }
2835    
2836                            if ((ratingsEntryModelImpl.getColumnBitmask() &
2837                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
2838                                    Object[] args = new Object[] {
2839                                                    ratingsEntryModelImpl.getOriginalClassNameId(),
2840                                                    ratingsEntryModelImpl.getOriginalClassPK()
2841                                            };
2842    
2843                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2844                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
2845                                            args);
2846    
2847                                    args = new Object[] {
2848                                                    ratingsEntryModelImpl.getClassNameId(),
2849                                                    ratingsEntryModelImpl.getClassPK()
2850                                            };
2851    
2852                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2853                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
2854                                            args);
2855                            }
2856    
2857                            if ((ratingsEntryModelImpl.getColumnBitmask() &
2858                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
2859                                    Object[] args = new Object[] {
2860                                                    ratingsEntryModelImpl.getOriginalClassNameId(),
2861                                                    ratingsEntryModelImpl.getOriginalClassPK(),
2862                                                    ratingsEntryModelImpl.getOriginalScore()
2863                                            };
2864    
2865                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
2866                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
2867                                            args);
2868    
2869                                    args = new Object[] {
2870                                                    ratingsEntryModelImpl.getClassNameId(),
2871                                                    ratingsEntryModelImpl.getClassPK(),
2872                                                    ratingsEntryModelImpl.getScore()
2873                                            };
2874    
2875                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
2876                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
2877                                            args);
2878                            }
2879                    }
2880    
2881                    EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
2882                            RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry,
2883                            false);
2884    
2885                    clearUniqueFindersCache(ratingsEntry);
2886                    cacheUniqueFindersCache(ratingsEntry);
2887    
2888                    ratingsEntry.resetOriginalValues();
2889    
2890                    return ratingsEntry;
2891            }
2892    
2893            protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
2894                    if (ratingsEntry instanceof RatingsEntryImpl) {
2895                            return ratingsEntry;
2896                    }
2897    
2898                    RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
2899    
2900                    ratingsEntryImpl.setNew(ratingsEntry.isNew());
2901                    ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
2902    
2903                    ratingsEntryImpl.setUuid(ratingsEntry.getUuid());
2904                    ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
2905                    ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
2906                    ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
2907                    ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
2908                    ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
2909                    ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
2910                    ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
2911                    ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
2912                    ratingsEntryImpl.setScore(ratingsEntry.getScore());
2913    
2914                    return ratingsEntryImpl;
2915            }
2916    
2917            /**
2918             * Returns the ratings entry with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2919             *
2920             * @param primaryKey the primary key of the ratings entry
2921             * @return the ratings entry
2922             * @throws NoSuchEntryException if a ratings entry with the primary key could not be found
2923             */
2924            @Override
2925            public RatingsEntry findByPrimaryKey(Serializable primaryKey)
2926                    throws NoSuchEntryException {
2927                    RatingsEntry ratingsEntry = fetchByPrimaryKey(primaryKey);
2928    
2929                    if (ratingsEntry == null) {
2930                            if (_log.isWarnEnabled()) {
2931                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2932                            }
2933    
2934                            throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2935                                    primaryKey);
2936                    }
2937    
2938                    return ratingsEntry;
2939            }
2940    
2941            /**
2942             * Returns the ratings entry with the primary key or throws a {@link NoSuchEntryException} if it could not be found.
2943             *
2944             * @param entryId the primary key of the ratings entry
2945             * @return the ratings entry
2946             * @throws NoSuchEntryException if a ratings entry with the primary key could not be found
2947             */
2948            @Override
2949            public RatingsEntry findByPrimaryKey(long entryId)
2950                    throws NoSuchEntryException {
2951                    return findByPrimaryKey((Serializable)entryId);
2952            }
2953    
2954            /**
2955             * Returns the ratings entry with the primary key or returns <code>null</code> if it could not be found.
2956             *
2957             * @param primaryKey the primary key of the ratings entry
2958             * @return the ratings entry, or <code>null</code> if a ratings entry with the primary key could not be found
2959             */
2960            @Override
2961            public RatingsEntry fetchByPrimaryKey(Serializable primaryKey) {
2962                    RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
2963                                    RatingsEntryImpl.class, primaryKey);
2964    
2965                    if (ratingsEntry == _nullRatingsEntry) {
2966                            return null;
2967                    }
2968    
2969                    if (ratingsEntry == null) {
2970                            Session session = null;
2971    
2972                            try {
2973                                    session = openSession();
2974    
2975                                    ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
2976                                                    primaryKey);
2977    
2978                                    if (ratingsEntry != null) {
2979                                            cacheResult(ratingsEntry);
2980                                    }
2981                                    else {
2982                                            EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
2983                                                    RatingsEntryImpl.class, primaryKey, _nullRatingsEntry);
2984                                    }
2985                            }
2986                            catch (Exception e) {
2987                                    EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
2988                                            RatingsEntryImpl.class, primaryKey);
2989    
2990                                    throw processException(e);
2991                            }
2992                            finally {
2993                                    closeSession(session);
2994                            }
2995                    }
2996    
2997                    return ratingsEntry;
2998            }
2999    
3000            /**
3001             * Returns the ratings entry with the primary key or returns <code>null</code> if it could not be found.
3002             *
3003             * @param entryId the primary key of the ratings entry
3004             * @return the ratings entry, or <code>null</code> if a ratings entry with the primary key could not be found
3005             */
3006            @Override
3007            public RatingsEntry fetchByPrimaryKey(long entryId) {
3008                    return fetchByPrimaryKey((Serializable)entryId);
3009            }
3010    
3011            @Override
3012            public Map<Serializable, RatingsEntry> fetchByPrimaryKeys(
3013                    Set<Serializable> primaryKeys) {
3014                    if (primaryKeys.isEmpty()) {
3015                            return Collections.emptyMap();
3016                    }
3017    
3018                    Map<Serializable, RatingsEntry> map = new HashMap<Serializable, RatingsEntry>();
3019    
3020                    if (primaryKeys.size() == 1) {
3021                            Iterator<Serializable> iterator = primaryKeys.iterator();
3022    
3023                            Serializable primaryKey = iterator.next();
3024    
3025                            RatingsEntry ratingsEntry = fetchByPrimaryKey(primaryKey);
3026    
3027                            if (ratingsEntry != null) {
3028                                    map.put(primaryKey, ratingsEntry);
3029                            }
3030    
3031                            return map;
3032                    }
3033    
3034                    Set<Serializable> uncachedPrimaryKeys = null;
3035    
3036                    for (Serializable primaryKey : primaryKeys) {
3037                            RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
3038                                            RatingsEntryImpl.class, primaryKey);
3039    
3040                            if (ratingsEntry == null) {
3041                                    if (uncachedPrimaryKeys == null) {
3042                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3043                                    }
3044    
3045                                    uncachedPrimaryKeys.add(primaryKey);
3046                            }
3047                            else {
3048                                    map.put(primaryKey, ratingsEntry);
3049                            }
3050                    }
3051    
3052                    if (uncachedPrimaryKeys == null) {
3053                            return map;
3054                    }
3055    
3056                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3057                                    1);
3058    
3059                    query.append(_SQL_SELECT_RATINGSENTRY_WHERE_PKS_IN);
3060    
3061                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3062                            query.append(String.valueOf(primaryKey));
3063    
3064                            query.append(StringPool.COMMA);
3065                    }
3066    
3067                    query.setIndex(query.index() - 1);
3068    
3069                    query.append(StringPool.CLOSE_PARENTHESIS);
3070    
3071                    String sql = query.toString();
3072    
3073                    Session session = null;
3074    
3075                    try {
3076                            session = openSession();
3077    
3078                            Query q = session.createQuery(sql);
3079    
3080                            for (RatingsEntry ratingsEntry : (List<RatingsEntry>)q.list()) {
3081                                    map.put(ratingsEntry.getPrimaryKeyObj(), ratingsEntry);
3082    
3083                                    cacheResult(ratingsEntry);
3084    
3085                                    uncachedPrimaryKeys.remove(ratingsEntry.getPrimaryKeyObj());
3086                            }
3087    
3088                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3089                                    EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
3090                                            RatingsEntryImpl.class, primaryKey, _nullRatingsEntry);
3091                            }
3092                    }
3093                    catch (Exception e) {
3094                            throw processException(e);
3095                    }
3096                    finally {
3097                            closeSession(session);
3098                    }
3099    
3100                    return map;
3101            }
3102    
3103            /**
3104             * Returns all the ratings entries.
3105             *
3106             * @return the ratings entries
3107             */
3108            @Override
3109            public List<RatingsEntry> findAll() {
3110                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3111            }
3112    
3113            /**
3114             * Returns a range of all the ratings entries.
3115             *
3116             * <p>
3117             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3118             * </p>
3119             *
3120             * @param start the lower bound of the range of ratings entries
3121             * @param end the upper bound of the range of ratings entries (not inclusive)
3122             * @return the range of ratings entries
3123             */
3124            @Override
3125            public List<RatingsEntry> findAll(int start, int end) {
3126                    return findAll(start, end, null);
3127            }
3128    
3129            /**
3130             * Returns an ordered range of all the ratings entries.
3131             *
3132             * <p>
3133             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3134             * </p>
3135             *
3136             * @param start the lower bound of the range of ratings entries
3137             * @param end the upper bound of the range of ratings entries (not inclusive)
3138             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3139             * @return the ordered range of ratings entries
3140             */
3141            @Override
3142            public List<RatingsEntry> findAll(int start, int end,
3143                    OrderByComparator<RatingsEntry> orderByComparator) {
3144                    boolean pagination = true;
3145                    FinderPath finderPath = null;
3146                    Object[] finderArgs = null;
3147    
3148                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3149                                    (orderByComparator == null)) {
3150                            pagination = false;
3151                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3152                            finderArgs = FINDER_ARGS_EMPTY;
3153                    }
3154                    else {
3155                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3156                            finderArgs = new Object[] { start, end, orderByComparator };
3157                    }
3158    
3159                    List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
3160                                    finderArgs, this);
3161    
3162                    if (list == null) {
3163                            StringBundler query = null;
3164                            String sql = null;
3165    
3166                            if (orderByComparator != null) {
3167                                    query = new StringBundler(2 +
3168                                                    (orderByComparator.getOrderByFields().length * 3));
3169    
3170                                    query.append(_SQL_SELECT_RATINGSENTRY);
3171    
3172                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3173                                            orderByComparator);
3174    
3175                                    sql = query.toString();
3176                            }
3177                            else {
3178                                    sql = _SQL_SELECT_RATINGSENTRY;
3179    
3180                                    if (pagination) {
3181                                            sql = sql.concat(RatingsEntryModelImpl.ORDER_BY_JPQL);
3182                                    }
3183                            }
3184    
3185                            Session session = null;
3186    
3187                            try {
3188                                    session = openSession();
3189    
3190                                    Query q = session.createQuery(sql);
3191    
3192                                    if (!pagination) {
3193                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
3194                                                            start, end, false);
3195    
3196                                            Collections.sort(list);
3197    
3198                                            list = Collections.unmodifiableList(list);
3199                                    }
3200                                    else {
3201                                            list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
3202                                                            start, end);
3203                                    }
3204    
3205                                    cacheResult(list);
3206    
3207                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3208                            }
3209                            catch (Exception e) {
3210                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3211    
3212                                    throw processException(e);
3213                            }
3214                            finally {
3215                                    closeSession(session);
3216                            }
3217                    }
3218    
3219                    return list;
3220            }
3221    
3222            /**
3223             * Removes all the ratings entries from the database.
3224             *
3225             */
3226            @Override
3227            public void removeAll() {
3228                    for (RatingsEntry ratingsEntry : findAll()) {
3229                            remove(ratingsEntry);
3230                    }
3231            }
3232    
3233            /**
3234             * Returns the number of ratings entries.
3235             *
3236             * @return the number of ratings entries
3237             */
3238            @Override
3239            public int countAll() {
3240                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3241                                    FINDER_ARGS_EMPTY, this);
3242    
3243                    if (count == null) {
3244                            Session session = null;
3245    
3246                            try {
3247                                    session = openSession();
3248    
3249                                    Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
3250    
3251                                    count = (Long)q.uniqueResult();
3252    
3253                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3254                                            FINDER_ARGS_EMPTY, count);
3255                            }
3256                            catch (Exception e) {
3257                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3258                                            FINDER_ARGS_EMPTY);
3259    
3260                                    throw processException(e);
3261                            }
3262                            finally {
3263                                    closeSession(session);
3264                            }
3265                    }
3266    
3267                    return count.intValue();
3268            }
3269    
3270            @Override
3271            protected Set<String> getBadColumnNames() {
3272                    return _badColumnNames;
3273            }
3274    
3275            /**
3276             * Initializes the ratings entry persistence.
3277             */
3278            public void afterPropertiesSet() {
3279            }
3280    
3281            public void destroy() {
3282                    EntityCacheUtil.removeCache(RatingsEntryImpl.class.getName());
3283                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3284                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3285                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3286            }
3287    
3288            private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
3289            private static final String _SQL_SELECT_RATINGSENTRY_WHERE_PKS_IN = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE entryId IN (";
3290            private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
3291            private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
3292            private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
3293            private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
3294            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
3295            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
3296            private static final Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
3297            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3298                                    "uuid"
3299                            });
3300            private static final RatingsEntry _nullRatingsEntry = new RatingsEntryImpl() {
3301                            @Override
3302                            public Object clone() {
3303                                    return this;
3304                            }
3305    
3306                            @Override
3307                            public CacheModel<RatingsEntry> toCacheModel() {
3308                                    return _nullRatingsEntryCacheModel;
3309                            }
3310                    };
3311    
3312            private static final CacheModel<RatingsEntry> _nullRatingsEntryCacheModel = new CacheModel<RatingsEntry>() {
3313                            @Override
3314                            public RatingsEntry toEntityModel() {
3315                                    return _nullRatingsEntry;
3316                            }
3317                    };
3318    }