1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.ratings.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.model.ModelListener;
37  import com.liferay.portal.service.persistence.BatchSessionUtil;
38  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
39  
40  import com.liferay.portlet.ratings.NoSuchEntryException;
41  import com.liferay.portlet.ratings.model.RatingsEntry;
42  import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
43  import com.liferay.portlet.ratings.model.impl.RatingsEntryModelImpl;
44  
45  import java.io.Serializable;
46  
47  import java.util.ArrayList;
48  import java.util.Collections;
49  import java.util.List;
50  
51  /**
52   * <a href="RatingsEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * <p>
55   * ServiceBuilder generated this class. Modifications in this class will be
56   * overwritten the next time is generated.
57   * </p>
58   *
59   * @author    Brian Wing Shun Chan
60   * @see       RatingsEntryPersistence
61   * @see       RatingsEntryUtil
62   * @generated
63   */
64  public class RatingsEntryPersistenceImpl extends BasePersistenceImpl<RatingsEntry>
65      implements RatingsEntryPersistence {
66      public static final String FINDER_CLASS_NAME_ENTITY = RatingsEntryImpl.class.getName();
67      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
68          ".List";
69      public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
70              RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
71              "findByC_C",
72              new String[] { Long.class.getName(), Long.class.getName() });
73      public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
74              RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
75              "findByC_C",
76              new String[] {
77                  Long.class.getName(), Long.class.getName(),
78                  
79              "java.lang.Integer", "java.lang.Integer",
80                  "com.liferay.portal.kernel.util.OrderByComparator"
81              });
82      public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
83              RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
84              "countByC_C",
85              new String[] { Long.class.getName(), Long.class.getName() });
86      public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
87              RatingsEntryModelImpl.FINDER_CACHE_ENABLED,
88              FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
89              new String[] {
90                  Long.class.getName(), Long.class.getName(), Long.class.getName()
91              });
92      public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
93              RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
94              "countByU_C_C",
95              new String[] {
96                  Long.class.getName(), Long.class.getName(), Long.class.getName()
97              });
98      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
99              RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100             "findAll", new String[0]);
101     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
102             RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103             "countAll", new String[0]);
104 
105     public void cacheResult(RatingsEntry ratingsEntry) {
106         EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
107             RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
108 
109         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
110             new Object[] {
111                 new Long(ratingsEntry.getUserId()),
112                 new Long(ratingsEntry.getClassNameId()),
113                 new Long(ratingsEntry.getClassPK())
114             }, ratingsEntry);
115     }
116 
117     public void cacheResult(List<RatingsEntry> ratingsEntries) {
118         for (RatingsEntry ratingsEntry : ratingsEntries) {
119             if (EntityCacheUtil.getResult(
120                         RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
121                         RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(),
122                         this) == null) {
123                 cacheResult(ratingsEntry);
124             }
125         }
126     }
127 
128     public void clearCache() {
129         CacheRegistry.clear(RatingsEntryImpl.class.getName());
130         EntityCacheUtil.clearCache(RatingsEntryImpl.class.getName());
131         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
132         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
133     }
134 
135     public RatingsEntry create(long entryId) {
136         RatingsEntry ratingsEntry = new RatingsEntryImpl();
137 
138         ratingsEntry.setNew(true);
139         ratingsEntry.setPrimaryKey(entryId);
140 
141         return ratingsEntry;
142     }
143 
144     public RatingsEntry remove(Serializable primaryKey)
145         throws NoSuchModelException, SystemException {
146         return remove(((Long)primaryKey).longValue());
147     }
148 
149     public RatingsEntry remove(long entryId)
150         throws NoSuchEntryException, SystemException {
151         Session session = null;
152 
153         try {
154             session = openSession();
155 
156             RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
157                     new Long(entryId));
158 
159             if (ratingsEntry == null) {
160                 if (_log.isWarnEnabled()) {
161                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
162                 }
163 
164                 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
165                     entryId);
166             }
167 
168             return remove(ratingsEntry);
169         }
170         catch (NoSuchEntryException nsee) {
171             throw nsee;
172         }
173         catch (Exception e) {
174             throw processException(e);
175         }
176         finally {
177             closeSession(session);
178         }
179     }
180 
181     public RatingsEntry remove(RatingsEntry ratingsEntry)
182         throws SystemException {
183         for (ModelListener<RatingsEntry> listener : listeners) {
184             listener.onBeforeRemove(ratingsEntry);
185         }
186 
187         ratingsEntry = removeImpl(ratingsEntry);
188 
189         for (ModelListener<RatingsEntry> listener : listeners) {
190             listener.onAfterRemove(ratingsEntry);
191         }
192 
193         return ratingsEntry;
194     }
195 
196     protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
197         throws SystemException {
198         ratingsEntry = toUnwrappedModel(ratingsEntry);
199 
200         Session session = null;
201 
202         try {
203             session = openSession();
204 
205             if (ratingsEntry.isCachedModel() || BatchSessionUtil.isEnabled()) {
206                 Object staleObject = session.get(RatingsEntryImpl.class,
207                         ratingsEntry.getPrimaryKeyObj());
208 
209                 if (staleObject != null) {
210                     session.evict(staleObject);
211                 }
212             }
213 
214             session.delete(ratingsEntry);
215 
216             session.flush();
217         }
218         catch (Exception e) {
219             throw processException(e);
220         }
221         finally {
222             closeSession(session);
223         }
224 
225         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
226 
227         RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
228 
229         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
230             new Object[] {
231                 new Long(ratingsEntryModelImpl.getOriginalUserId()),
232                 new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
233                 new Long(ratingsEntryModelImpl.getOriginalClassPK())
234             });
235 
236         EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
237             RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
238 
239         return ratingsEntry;
240     }
241 
242     /**
243      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
244      */
245     public RatingsEntry update(RatingsEntry ratingsEntry)
246         throws SystemException {
247         if (_log.isWarnEnabled()) {
248             _log.warn(
249                 "Using the deprecated update(RatingsEntry ratingsEntry) method. Use update(RatingsEntry ratingsEntry, boolean merge) instead.");
250         }
251 
252         return update(ratingsEntry, false);
253     }
254 
255     public RatingsEntry updateImpl(
256         com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
257         boolean merge) throws SystemException {
258         ratingsEntry = toUnwrappedModel(ratingsEntry);
259 
260         boolean isNew = ratingsEntry.isNew();
261 
262         RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
263 
264         Session session = null;
265 
266         try {
267             session = openSession();
268 
269             BatchSessionUtil.update(session, ratingsEntry, merge);
270 
271             ratingsEntry.setNew(false);
272         }
273         catch (Exception e) {
274             throw processException(e);
275         }
276         finally {
277             closeSession(session);
278         }
279 
280         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
281 
282         EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
283             RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
284 
285         if (!isNew &&
286                 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
287                 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
288                 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
289             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
290                 new Object[] {
291                     new Long(ratingsEntryModelImpl.getOriginalUserId()),
292                     new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
293                     new Long(ratingsEntryModelImpl.getOriginalClassPK())
294                 });
295         }
296 
297         if (isNew ||
298                 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
299                 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
300                 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
301             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
302                 new Object[] {
303                     new Long(ratingsEntry.getUserId()),
304                     new Long(ratingsEntry.getClassNameId()),
305                     new Long(ratingsEntry.getClassPK())
306                 }, ratingsEntry);
307         }
308 
309         return ratingsEntry;
310     }
311 
312     protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
313         if (ratingsEntry instanceof RatingsEntryImpl) {
314             return ratingsEntry;
315         }
316 
317         RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
318 
319         ratingsEntryImpl.setNew(ratingsEntry.isNew());
320         ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
321 
322         ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
323         ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
324         ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
325         ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
326         ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
327         ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
328         ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
329         ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
330         ratingsEntryImpl.setScore(ratingsEntry.getScore());
331 
332         return ratingsEntryImpl;
333     }
334 
335     public RatingsEntry findByPrimaryKey(Serializable primaryKey)
336         throws NoSuchModelException, SystemException {
337         return findByPrimaryKey(((Long)primaryKey).longValue());
338     }
339 
340     public RatingsEntry findByPrimaryKey(long entryId)
341         throws NoSuchEntryException, SystemException {
342         RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
343 
344         if (ratingsEntry == null) {
345             if (_log.isWarnEnabled()) {
346                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
347             }
348 
349             throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
350                 entryId);
351         }
352 
353         return ratingsEntry;
354     }
355 
356     public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
357         throws SystemException {
358         return fetchByPrimaryKey(((Long)primaryKey).longValue());
359     }
360 
361     public RatingsEntry fetchByPrimaryKey(long entryId)
362         throws SystemException {
363         RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
364                 RatingsEntryImpl.class, entryId, this);
365 
366         if (ratingsEntry == null) {
367             Session session = null;
368 
369             try {
370                 session = openSession();
371 
372                 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
373                         new Long(entryId));
374             }
375             catch (Exception e) {
376                 throw processException(e);
377             }
378             finally {
379                 if (ratingsEntry != null) {
380                     cacheResult(ratingsEntry);
381                 }
382 
383                 closeSession(session);
384             }
385         }
386 
387         return ratingsEntry;
388     }
389 
390     public List<RatingsEntry> findByC_C(long classNameId, long classPK)
391         throws SystemException {
392         Object[] finderArgs = new Object[] {
393                 new Long(classNameId), new Long(classPK)
394             };
395 
396         List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
397                 finderArgs, this);
398 
399         if (list == null) {
400             Session session = null;
401 
402             try {
403                 session = openSession();
404 
405                 StringBundler query = new StringBundler(3);
406 
407                 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
408 
409                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
410 
411                 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
412 
413                 String sql = query.toString();
414 
415                 Query q = session.createQuery(sql);
416 
417                 QueryPos qPos = QueryPos.getInstance(q);
418 
419                 qPos.add(classNameId);
420 
421                 qPos.add(classPK);
422 
423                 list = q.list();
424             }
425             catch (Exception e) {
426                 throw processException(e);
427             }
428             finally {
429                 if (list == null) {
430                     list = new ArrayList<RatingsEntry>();
431                 }
432 
433                 cacheResult(list);
434 
435                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
436                     list);
437 
438                 closeSession(session);
439             }
440         }
441 
442         return list;
443     }
444 
445     public List<RatingsEntry> findByC_C(long classNameId, long classPK,
446         int start, int end) throws SystemException {
447         return findByC_C(classNameId, classPK, start, end, null);
448     }
449 
450     public List<RatingsEntry> findByC_C(long classNameId, long classPK,
451         int start, int end, OrderByComparator obc) throws SystemException {
452         Object[] finderArgs = new Object[] {
453                 new Long(classNameId), new Long(classPK),
454                 
455                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
456             };
457 
458         List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C,
459                 finderArgs, this);
460 
461         if (list == null) {
462             Session session = null;
463 
464             try {
465                 session = openSession();
466 
467                 StringBundler query = null;
468 
469                 if (obc != null) {
470                     query = new StringBundler(4 +
471                             (obc.getOrderByFields().length * 3));
472                 }
473                 else {
474                     query = new StringBundler(3);
475                 }
476 
477                 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
478 
479                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
480 
481                 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
482 
483                 if (obc != null) {
484                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
485                 }
486 
487                 String sql = query.toString();
488 
489                 Query q = session.createQuery(sql);
490 
491                 QueryPos qPos = QueryPos.getInstance(q);
492 
493                 qPos.add(classNameId);
494 
495                 qPos.add(classPK);
496 
497                 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
498                         start, end);
499             }
500             catch (Exception e) {
501                 throw processException(e);
502             }
503             finally {
504                 if (list == null) {
505                     list = new ArrayList<RatingsEntry>();
506                 }
507 
508                 cacheResult(list);
509 
510                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C,
511                     finderArgs, list);
512 
513                 closeSession(session);
514             }
515         }
516 
517         return list;
518     }
519 
520     public RatingsEntry findByC_C_First(long classNameId, long classPK,
521         OrderByComparator obc) throws NoSuchEntryException, SystemException {
522         List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1, obc);
523 
524         if (list.isEmpty()) {
525             StringBundler msg = new StringBundler(6);
526 
527             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
528 
529             msg.append("classNameId=");
530             msg.append(classNameId);
531 
532             msg.append(", classPK=");
533             msg.append(classPK);
534 
535             msg.append(StringPool.CLOSE_CURLY_BRACE);
536 
537             throw new NoSuchEntryException(msg.toString());
538         }
539         else {
540             return list.get(0);
541         }
542     }
543 
544     public RatingsEntry findByC_C_Last(long classNameId, long classPK,
545         OrderByComparator obc) throws NoSuchEntryException, SystemException {
546         int count = countByC_C(classNameId, classPK);
547 
548         List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
549                 count, obc);
550 
551         if (list.isEmpty()) {
552             StringBundler msg = new StringBundler(6);
553 
554             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
555 
556             msg.append("classNameId=");
557             msg.append(classNameId);
558 
559             msg.append(", classPK=");
560             msg.append(classPK);
561 
562             msg.append(StringPool.CLOSE_CURLY_BRACE);
563 
564             throw new NoSuchEntryException(msg.toString());
565         }
566         else {
567             return list.get(0);
568         }
569     }
570 
571     public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
572         long classPK, OrderByComparator obc)
573         throws NoSuchEntryException, SystemException {
574         RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
575 
576         int count = countByC_C(classNameId, classPK);
577 
578         Session session = null;
579 
580         try {
581             session = openSession();
582 
583             StringBundler query = null;
584 
585             if (obc != null) {
586                 query = new StringBundler(4 +
587                         (obc.getOrderByFields().length * 3));
588             }
589             else {
590                 query = new StringBundler(3);
591             }
592 
593             query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
594 
595             query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
596 
597             query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
598 
599             if (obc != null) {
600                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
601             }
602 
603             String sql = query.toString();
604 
605             Query q = session.createQuery(sql);
606 
607             QueryPos qPos = QueryPos.getInstance(q);
608 
609             qPos.add(classNameId);
610 
611             qPos.add(classPK);
612 
613             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
614                     ratingsEntry);
615 
616             RatingsEntry[] array = new RatingsEntryImpl[3];
617 
618             array[0] = (RatingsEntry)objArray[0];
619             array[1] = (RatingsEntry)objArray[1];
620             array[2] = (RatingsEntry)objArray[2];
621 
622             return array;
623         }
624         catch (Exception e) {
625             throw processException(e);
626         }
627         finally {
628             closeSession(session);
629         }
630     }
631 
632     public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
633         throws NoSuchEntryException, SystemException {
634         RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
635 
636         if (ratingsEntry == null) {
637             StringBundler msg = new StringBundler(8);
638 
639             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
640 
641             msg.append("userId=");
642             msg.append(userId);
643 
644             msg.append(", classNameId=");
645             msg.append(classNameId);
646 
647             msg.append(", classPK=");
648             msg.append(classPK);
649 
650             msg.append(StringPool.CLOSE_CURLY_BRACE);
651 
652             if (_log.isWarnEnabled()) {
653                 _log.warn(msg.toString());
654             }
655 
656             throw new NoSuchEntryException(msg.toString());
657         }
658 
659         return ratingsEntry;
660     }
661 
662     public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
663         throws SystemException {
664         return fetchByU_C_C(userId, classNameId, classPK, true);
665     }
666 
667     public RatingsEntry fetchByU_C_C(long userId, long classNameId,
668         long classPK, boolean retrieveFromCache) throws SystemException {
669         Object[] finderArgs = new Object[] {
670                 new Long(userId), new Long(classNameId), new Long(classPK)
671             };
672 
673         Object result = null;
674 
675         if (retrieveFromCache) {
676             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
677                     finderArgs, this);
678         }
679 
680         if (result == null) {
681             Session session = null;
682 
683             try {
684                 session = openSession();
685 
686                 StringBundler query = new StringBundler(4);
687 
688                 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
689 
690                 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
691 
692                 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
693 
694                 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
695 
696                 String sql = query.toString();
697 
698                 Query q = session.createQuery(sql);
699 
700                 QueryPos qPos = QueryPos.getInstance(q);
701 
702                 qPos.add(userId);
703 
704                 qPos.add(classNameId);
705 
706                 qPos.add(classPK);
707 
708                 List<RatingsEntry> list = q.list();
709 
710                 result = list;
711 
712                 RatingsEntry ratingsEntry = null;
713 
714                 if (list.isEmpty()) {
715                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
716                         finderArgs, list);
717                 }
718                 else {
719                     ratingsEntry = list.get(0);
720 
721                     cacheResult(ratingsEntry);
722 
723                     if ((ratingsEntry.getUserId() != userId) ||
724                             (ratingsEntry.getClassNameId() != classNameId) ||
725                             (ratingsEntry.getClassPK() != classPK)) {
726                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
727                             finderArgs, ratingsEntry);
728                     }
729                 }
730 
731                 return ratingsEntry;
732             }
733             catch (Exception e) {
734                 throw processException(e);
735             }
736             finally {
737                 if (result == null) {
738                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
739                         finderArgs, new ArrayList<RatingsEntry>());
740                 }
741 
742                 closeSession(session);
743             }
744         }
745         else {
746             if (result instanceof List<?>) {
747                 return null;
748             }
749             else {
750                 return (RatingsEntry)result;
751             }
752         }
753     }
754 
755     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
756         throws SystemException {
757         Session session = null;
758 
759         try {
760             session = openSession();
761 
762             dynamicQuery.compile(session);
763 
764             return dynamicQuery.list();
765         }
766         catch (Exception e) {
767             throw processException(e);
768         }
769         finally {
770             closeSession(session);
771         }
772     }
773 
774     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
775         int start, int end) throws SystemException {
776         Session session = null;
777 
778         try {
779             session = openSession();
780 
781             dynamicQuery.setLimit(start, end);
782 
783             dynamicQuery.compile(session);
784 
785             return dynamicQuery.list();
786         }
787         catch (Exception e) {
788             throw processException(e);
789         }
790         finally {
791             closeSession(session);
792         }
793     }
794 
795     public List<RatingsEntry> findAll() throws SystemException {
796         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
797     }
798 
799     public List<RatingsEntry> findAll(int start, int end)
800         throws SystemException {
801         return findAll(start, end, null);
802     }
803 
804     public List<RatingsEntry> findAll(int start, int end, OrderByComparator obc)
805         throws SystemException {
806         Object[] finderArgs = new Object[] {
807                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
808             };
809 
810         List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
811                 finderArgs, this);
812 
813         if (list == null) {
814             Session session = null;
815 
816             try {
817                 session = openSession();
818 
819                 StringBundler query = null;
820                 String sql = null;
821 
822                 if (obc != null) {
823                     query = new StringBundler(2 +
824                             (obc.getOrderByFields().length * 3));
825 
826                     query.append(_SQL_SELECT_RATINGSENTRY);
827 
828                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
829 
830                     sql = query.toString();
831                 }
832 
833                 sql = _SQL_SELECT_RATINGSENTRY;
834 
835                 Query q = session.createQuery(sql);
836 
837                 if (obc == null) {
838                     list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
839                             start, end, false);
840 
841                     Collections.sort(list);
842                 }
843                 else {
844                     list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
845                             start, end);
846                 }
847             }
848             catch (Exception e) {
849                 throw processException(e);
850             }
851             finally {
852                 if (list == null) {
853                     list = new ArrayList<RatingsEntry>();
854                 }
855 
856                 cacheResult(list);
857 
858                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
859 
860                 closeSession(session);
861             }
862         }
863 
864         return list;
865     }
866 
867     public void removeByC_C(long classNameId, long classPK)
868         throws SystemException {
869         for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
870             remove(ratingsEntry);
871         }
872     }
873 
874     public void removeByU_C_C(long userId, long classNameId, long classPK)
875         throws NoSuchEntryException, SystemException {
876         RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
877 
878         remove(ratingsEntry);
879     }
880 
881     public void removeAll() throws SystemException {
882         for (RatingsEntry ratingsEntry : findAll()) {
883             remove(ratingsEntry);
884         }
885     }
886 
887     public int countByC_C(long classNameId, long classPK)
888         throws SystemException {
889         Object[] finderArgs = new Object[] {
890                 new Long(classNameId), new Long(classPK)
891             };
892 
893         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
894                 finderArgs, this);
895 
896         if (count == null) {
897             Session session = null;
898 
899             try {
900                 session = openSession();
901 
902                 StringBundler query = new StringBundler(3);
903 
904                 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
905 
906                 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
907 
908                 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
909 
910                 String sql = query.toString();
911 
912                 Query q = session.createQuery(sql);
913 
914                 QueryPos qPos = QueryPos.getInstance(q);
915 
916                 qPos.add(classNameId);
917 
918                 qPos.add(classPK);
919 
920                 count = (Long)q.uniqueResult();
921             }
922             catch (Exception e) {
923                 throw processException(e);
924             }
925             finally {
926                 if (count == null) {
927                     count = Long.valueOf(0);
928                 }
929 
930                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
931                     count);
932 
933                 closeSession(session);
934             }
935         }
936 
937         return count.intValue();
938     }
939 
940     public int countByU_C_C(long userId, long classNameId, long classPK)
941         throws SystemException {
942         Object[] finderArgs = new Object[] {
943                 new Long(userId), new Long(classNameId), new Long(classPK)
944             };
945 
946         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
947                 finderArgs, this);
948 
949         if (count == null) {
950             Session session = null;
951 
952             try {
953                 session = openSession();
954 
955                 StringBundler query = new StringBundler(4);
956 
957                 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
958 
959                 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
960 
961                 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
962 
963                 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
964 
965                 String sql = query.toString();
966 
967                 Query q = session.createQuery(sql);
968 
969                 QueryPos qPos = QueryPos.getInstance(q);
970 
971                 qPos.add(userId);
972 
973                 qPos.add(classNameId);
974 
975                 qPos.add(classPK);
976 
977                 count = (Long)q.uniqueResult();
978             }
979             catch (Exception e) {
980                 throw processException(e);
981             }
982             finally {
983                 if (count == null) {
984                     count = Long.valueOf(0);
985                 }
986 
987                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
988                     finderArgs, count);
989 
990                 closeSession(session);
991             }
992         }
993 
994         return count.intValue();
995     }
996 
997     public int countAll() throws SystemException {
998         Object[] finderArgs = new Object[0];
999 
1000        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1001                finderArgs, this);
1002
1003        if (count == null) {
1004            Session session = null;
1005
1006            try {
1007                session = openSession();
1008
1009                Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
1010
1011                count = (Long)q.uniqueResult();
1012            }
1013            catch (Exception e) {
1014                throw processException(e);
1015            }
1016            finally {
1017                if (count == null) {
1018                    count = Long.valueOf(0);
1019                }
1020
1021                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1022                    count);
1023
1024                closeSession(session);
1025            }
1026        }
1027
1028        return count.intValue();
1029    }
1030
1031    public void afterPropertiesSet() {
1032        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1033                    com.liferay.portal.util.PropsUtil.get(
1034                        "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1035
1036        if (listenerClassNames.length > 0) {
1037            try {
1038                List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1039
1040                for (String listenerClassName : listenerClassNames) {
1041                    listenersList.add((ModelListener<RatingsEntry>)Class.forName(
1042                            listenerClassName).newInstance());
1043                }
1044
1045                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1046            }
1047            catch (Exception e) {
1048                _log.error(e);
1049            }
1050        }
1051    }
1052
1053    @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence")
1054    protected com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence ratingsEntryPersistence;
1055    @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence")
1056    protected com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence ratingsStatsPersistence;
1057    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1058    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1059    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1060    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1061    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence")
1062    protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
1063    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence")
1064    protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
1065    private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1066    private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1067    private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1068    private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1069    private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1070    private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1071    private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1072    private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1073    private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1074    private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1075    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1076    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1077    private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1078}