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