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