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