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