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