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