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