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