1
14
15 package com.liferay.portlet.ratings.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.kernel.annotation.BeanReference;
19 import com.liferay.portal.kernel.cache.CacheRegistry;
20 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
21 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderPath;
24 import com.liferay.portal.kernel.dao.orm.Query;
25 import com.liferay.portal.kernel.dao.orm.QueryPos;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.dao.orm.Session;
28 import com.liferay.portal.kernel.exception.SystemException;
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
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 public RatingsEntry updateImpl(
243 com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
244 boolean merge) throws SystemException {
245 ratingsEntry = toUnwrappedModel(ratingsEntry);
246
247 boolean isNew = ratingsEntry.isNew();
248
249 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
250
251 Session session = null;
252
253 try {
254 session = openSession();
255
256 BatchSessionUtil.update(session, ratingsEntry, merge);
257
258 ratingsEntry.setNew(false);
259 }
260 catch (Exception e) {
261 throw processException(e);
262 }
263 finally {
264 closeSession(session);
265 }
266
267 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
268
269 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
270 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
271
272 if (!isNew &&
273 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
274 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
275 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
276 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
277 new Object[] {
278 new Long(ratingsEntryModelImpl.getOriginalUserId()),
279 new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
280 new Long(ratingsEntryModelImpl.getOriginalClassPK())
281 });
282 }
283
284 if (isNew ||
285 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
286 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
287 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
288 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
289 new Object[] {
290 new Long(ratingsEntry.getUserId()),
291 new Long(ratingsEntry.getClassNameId()),
292 new Long(ratingsEntry.getClassPK())
293 }, ratingsEntry);
294 }
295
296 return ratingsEntry;
297 }
298
299 protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
300 if (ratingsEntry instanceof RatingsEntryImpl) {
301 return ratingsEntry;
302 }
303
304 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
305
306 ratingsEntryImpl.setNew(ratingsEntry.isNew());
307 ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
308
309 ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
310 ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
311 ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
312 ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
313 ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
314 ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
315 ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
316 ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
317 ratingsEntryImpl.setScore(ratingsEntry.getScore());
318
319 return ratingsEntryImpl;
320 }
321
322 public RatingsEntry findByPrimaryKey(Serializable primaryKey)
323 throws NoSuchModelException, SystemException {
324 return findByPrimaryKey(((Long)primaryKey).longValue());
325 }
326
327 public RatingsEntry findByPrimaryKey(long entryId)
328 throws NoSuchEntryException, SystemException {
329 RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
330
331 if (ratingsEntry == null) {
332 if (_log.isWarnEnabled()) {
333 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
334 }
335
336 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
337 entryId);
338 }
339
340 return ratingsEntry;
341 }
342
343 public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
344 throws SystemException {
345 return fetchByPrimaryKey(((Long)primaryKey).longValue());
346 }
347
348 public RatingsEntry fetchByPrimaryKey(long entryId)
349 throws SystemException {
350 RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
351 RatingsEntryImpl.class, entryId, this);
352
353 if (ratingsEntry == null) {
354 Session session = null;
355
356 try {
357 session = openSession();
358
359 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
360 new Long(entryId));
361 }
362 catch (Exception e) {
363 throw processException(e);
364 }
365 finally {
366 if (ratingsEntry != null) {
367 cacheResult(ratingsEntry);
368 }
369
370 closeSession(session);
371 }
372 }
373
374 return ratingsEntry;
375 }
376
377 public List<RatingsEntry> findByC_C(long classNameId, long classPK)
378 throws SystemException {
379 Object[] finderArgs = new Object[] {
380 new Long(classNameId), new Long(classPK)
381 };
382
383 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
384 finderArgs, this);
385
386 if (list == null) {
387 Session session = null;
388
389 try {
390 session = openSession();
391
392 StringBundler query = new StringBundler(3);
393
394 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
395
396 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
397
398 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
399
400 String sql = query.toString();
401
402 Query q = session.createQuery(sql);
403
404 QueryPos qPos = QueryPos.getInstance(q);
405
406 qPos.add(classNameId);
407
408 qPos.add(classPK);
409
410 list = q.list();
411 }
412 catch (Exception e) {
413 throw processException(e);
414 }
415 finally {
416 if (list == null) {
417 list = new ArrayList<RatingsEntry>();
418 }
419
420 cacheResult(list);
421
422 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
423 list);
424
425 closeSession(session);
426 }
427 }
428
429 return list;
430 }
431
432 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
433 int start, int end) throws SystemException {
434 return findByC_C(classNameId, classPK, start, end, null);
435 }
436
437 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
438 int start, int end, OrderByComparator obc) throws SystemException {
439 Object[] finderArgs = new Object[] {
440 new Long(classNameId), new Long(classPK),
441
442 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
443 };
444
445 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C,
446 finderArgs, this);
447
448 if (list == null) {
449 Session session = null;
450
451 try {
452 session = openSession();
453
454 StringBundler query = null;
455
456 if (obc != null) {
457 query = new StringBundler(4 +
458 (obc.getOrderByFields().length * 3));
459 }
460 else {
461 query = new StringBundler(3);
462 }
463
464 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
465
466 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
467
468 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
469
470 if (obc != null) {
471 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
472 }
473
474 String sql = query.toString();
475
476 Query q = session.createQuery(sql);
477
478 QueryPos qPos = QueryPos.getInstance(q);
479
480 qPos.add(classNameId);
481
482 qPos.add(classPK);
483
484 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
485 start, end);
486 }
487 catch (Exception e) {
488 throw processException(e);
489 }
490 finally {
491 if (list == null) {
492 list = new ArrayList<RatingsEntry>();
493 }
494
495 cacheResult(list);
496
497 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C,
498 finderArgs, list);
499
500 closeSession(session);
501 }
502 }
503
504 return list;
505 }
506
507 public RatingsEntry findByC_C_First(long classNameId, long classPK,
508 OrderByComparator obc) throws NoSuchEntryException, SystemException {
509 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1, obc);
510
511 if (list.isEmpty()) {
512 StringBundler msg = new StringBundler(6);
513
514 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
515
516 msg.append("classNameId=");
517 msg.append(classNameId);
518
519 msg.append(", classPK=");
520 msg.append(classPK);
521
522 msg.append(StringPool.CLOSE_CURLY_BRACE);
523
524 throw new NoSuchEntryException(msg.toString());
525 }
526 else {
527 return list.get(0);
528 }
529 }
530
531 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
532 OrderByComparator obc) throws NoSuchEntryException, SystemException {
533 int count = countByC_C(classNameId, classPK);
534
535 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
536 count, obc);
537
538 if (list.isEmpty()) {
539 StringBundler msg = new StringBundler(6);
540
541 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
542
543 msg.append("classNameId=");
544 msg.append(classNameId);
545
546 msg.append(", classPK=");
547 msg.append(classPK);
548
549 msg.append(StringPool.CLOSE_CURLY_BRACE);
550
551 throw new NoSuchEntryException(msg.toString());
552 }
553 else {
554 return list.get(0);
555 }
556 }
557
558 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
559 long classPK, OrderByComparator obc)
560 throws NoSuchEntryException, SystemException {
561 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
562
563 int count = countByC_C(classNameId, classPK);
564
565 Session session = null;
566
567 try {
568 session = openSession();
569
570 StringBundler query = null;
571
572 if (obc != null) {
573 query = new StringBundler(4 +
574 (obc.getOrderByFields().length * 3));
575 }
576 else {
577 query = new StringBundler(3);
578 }
579
580 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
581
582 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
583
584 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
585
586 if (obc != null) {
587 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
588 }
589
590 String sql = query.toString();
591
592 Query q = session.createQuery(sql);
593
594 QueryPos qPos = QueryPos.getInstance(q);
595
596 qPos.add(classNameId);
597
598 qPos.add(classPK);
599
600 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
601 ratingsEntry);
602
603 RatingsEntry[] array = new RatingsEntryImpl[3];
604
605 array[0] = (RatingsEntry)objArray[0];
606 array[1] = (RatingsEntry)objArray[1];
607 array[2] = (RatingsEntry)objArray[2];
608
609 return array;
610 }
611 catch (Exception e) {
612 throw processException(e);
613 }
614 finally {
615 closeSession(session);
616 }
617 }
618
619 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
620 throws NoSuchEntryException, SystemException {
621 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
622
623 if (ratingsEntry == null) {
624 StringBundler msg = new StringBundler(8);
625
626 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
627
628 msg.append("userId=");
629 msg.append(userId);
630
631 msg.append(", classNameId=");
632 msg.append(classNameId);
633
634 msg.append(", classPK=");
635 msg.append(classPK);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 if (_log.isWarnEnabled()) {
640 _log.warn(msg.toString());
641 }
642
643 throw new NoSuchEntryException(msg.toString());
644 }
645
646 return ratingsEntry;
647 }
648
649 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
650 throws SystemException {
651 return fetchByU_C_C(userId, classNameId, classPK, true);
652 }
653
654 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
655 long classPK, boolean retrieveFromCache) throws SystemException {
656 Object[] finderArgs = new Object[] {
657 new Long(userId), new Long(classNameId), new Long(classPK)
658 };
659
660 Object result = null;
661
662 if (retrieveFromCache) {
663 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
664 finderArgs, this);
665 }
666
667 if (result == null) {
668 Session session = null;
669
670 try {
671 session = openSession();
672
673 StringBundler query = new StringBundler(4);
674
675 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
676
677 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
678
679 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
680
681 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
682
683 String sql = query.toString();
684
685 Query q = session.createQuery(sql);
686
687 QueryPos qPos = QueryPos.getInstance(q);
688
689 qPos.add(userId);
690
691 qPos.add(classNameId);
692
693 qPos.add(classPK);
694
695 List<RatingsEntry> list = q.list();
696
697 result = list;
698
699 RatingsEntry ratingsEntry = null;
700
701 if (list.isEmpty()) {
702 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
703 finderArgs, list);
704 }
705 else {
706 ratingsEntry = list.get(0);
707
708 cacheResult(ratingsEntry);
709
710 if ((ratingsEntry.getUserId() != userId) ||
711 (ratingsEntry.getClassNameId() != classNameId) ||
712 (ratingsEntry.getClassPK() != classPK)) {
713 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
714 finderArgs, ratingsEntry);
715 }
716 }
717
718 return ratingsEntry;
719 }
720 catch (Exception e) {
721 throw processException(e);
722 }
723 finally {
724 if (result == null) {
725 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
726 finderArgs, new ArrayList<RatingsEntry>());
727 }
728
729 closeSession(session);
730 }
731 }
732 else {
733 if (result instanceof List<?>) {
734 return null;
735 }
736 else {
737 return (RatingsEntry)result;
738 }
739 }
740 }
741
742 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
743 throws SystemException {
744 Session session = null;
745
746 try {
747 session = openSession();
748
749 dynamicQuery.compile(session);
750
751 return dynamicQuery.list();
752 }
753 catch (Exception e) {
754 throw processException(e);
755 }
756 finally {
757 closeSession(session);
758 }
759 }
760
761 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
762 int start, int end) throws SystemException {
763 Session session = null;
764
765 try {
766 session = openSession();
767
768 dynamicQuery.setLimit(start, end);
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<RatingsEntry> findAll() throws SystemException {
783 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
784 }
785
786 public List<RatingsEntry> findAll(int start, int end)
787 throws SystemException {
788 return findAll(start, end, null);
789 }
790
791 public List<RatingsEntry> findAll(int start, int end, OrderByComparator obc)
792 throws SystemException {
793 Object[] finderArgs = new Object[] {
794 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
795 };
796
797 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
798 finderArgs, this);
799
800 if (list == null) {
801 Session session = null;
802
803 try {
804 session = openSession();
805
806 StringBundler query = null;
807 String sql = null;
808
809 if (obc != null) {
810 query = new StringBundler(2 +
811 (obc.getOrderByFields().length * 3));
812
813 query.append(_SQL_SELECT_RATINGSENTRY);
814
815 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
816
817 sql = query.toString();
818 }
819
820 sql = _SQL_SELECT_RATINGSENTRY;
821
822 Query q = session.createQuery(sql);
823
824 if (obc == null) {
825 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
826 start, end, false);
827
828 Collections.sort(list);
829 }
830 else {
831 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
832 start, end);
833 }
834 }
835 catch (Exception e) {
836 throw processException(e);
837 }
838 finally {
839 if (list == null) {
840 list = new ArrayList<RatingsEntry>();
841 }
842
843 cacheResult(list);
844
845 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
846
847 closeSession(session);
848 }
849 }
850
851 return list;
852 }
853
854 public void removeByC_C(long classNameId, long classPK)
855 throws SystemException {
856 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
857 remove(ratingsEntry);
858 }
859 }
860
861 public void removeByU_C_C(long userId, long classNameId, long classPK)
862 throws NoSuchEntryException, SystemException {
863 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
864
865 remove(ratingsEntry);
866 }
867
868 public void removeAll() throws SystemException {
869 for (RatingsEntry ratingsEntry : findAll()) {
870 remove(ratingsEntry);
871 }
872 }
873
874 public int countByC_C(long classNameId, long classPK)
875 throws SystemException {
876 Object[] finderArgs = new Object[] {
877 new Long(classNameId), new Long(classPK)
878 };
879
880 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
881 finderArgs, this);
882
883 if (count == null) {
884 Session session = null;
885
886 try {
887 session = openSession();
888
889 StringBundler query = new StringBundler(3);
890
891 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
892
893 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
894
895 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
896
897 String sql = query.toString();
898
899 Query q = session.createQuery(sql);
900
901 QueryPos qPos = QueryPos.getInstance(q);
902
903 qPos.add(classNameId);
904
905 qPos.add(classPK);
906
907 count = (Long)q.uniqueResult();
908 }
909 catch (Exception e) {
910 throw processException(e);
911 }
912 finally {
913 if (count == null) {
914 count = Long.valueOf(0);
915 }
916
917 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
918 count);
919
920 closeSession(session);
921 }
922 }
923
924 return count.intValue();
925 }
926
927 public int countByU_C_C(long userId, long classNameId, long classPK)
928 throws SystemException {
929 Object[] finderArgs = new Object[] {
930 new Long(userId), new Long(classNameId), new Long(classPK)
931 };
932
933 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
934 finderArgs, this);
935
936 if (count == null) {
937 Session session = null;
938
939 try {
940 session = openSession();
941
942 StringBundler query = new StringBundler(4);
943
944 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
945
946 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
947
948 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
949
950 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
951
952 String sql = query.toString();
953
954 Query q = session.createQuery(sql);
955
956 QueryPos qPos = QueryPos.getInstance(q);
957
958 qPos.add(userId);
959
960 qPos.add(classNameId);
961
962 qPos.add(classPK);
963
964 count = (Long)q.uniqueResult();
965 }
966 catch (Exception e) {
967 throw processException(e);
968 }
969 finally {
970 if (count == null) {
971 count = Long.valueOf(0);
972 }
973
974 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
975 finderArgs, count);
976
977 closeSession(session);
978 }
979 }
980
981 return count.intValue();
982 }
983
984 public int countAll() throws SystemException {
985 Object[] finderArgs = new Object[0];
986
987 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
988 finderArgs, this);
989
990 if (count == null) {
991 Session session = null;
992
993 try {
994 session = openSession();
995
996 Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
997
998 count = (Long)q.uniqueResult();
999 }
1000 catch (Exception e) {
1001 throw processException(e);
1002 }
1003 finally {
1004 if (count == null) {
1005 count = Long.valueOf(0);
1006 }
1007
1008 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1009 count);
1010
1011 closeSession(session);
1012 }
1013 }
1014
1015 return count.intValue();
1016 }
1017
1018 public void afterPropertiesSet() {
1019 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1020 com.liferay.portal.util.PropsUtil.get(
1021 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1022
1023 if (listenerClassNames.length > 0) {
1024 try {
1025 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1026
1027 for (String listenerClassName : listenerClassNames) {
1028 listenersList.add((ModelListener<RatingsEntry>)Class.forName(
1029 listenerClassName).newInstance());
1030 }
1031
1032 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1033 }
1034 catch (Exception e) {
1035 _log.error(e);
1036 }
1037 }
1038 }
1039
1040 @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence")
1041 protected com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence ratingsEntryPersistence;
1042 @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence")
1043 protected com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence ratingsStatsPersistence;
1044 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1045 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1046 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1047 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1048 @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence")
1049 protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
1050 @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence")
1051 protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
1052 private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1053 private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1054 private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1055 private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1056 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1057 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1058 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1059 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1060 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1061 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1062 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1063 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1064 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1065}