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