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