1
19
20 package com.liferay.portal.service.persistence;
21
22 import com.liferay.portal.NoSuchSubscriptionException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
25 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
26 import com.liferay.portal.kernel.dao.orm.Query;
27 import com.liferay.portal.kernel.dao.orm.QueryPos;
28 import com.liferay.portal.kernel.dao.orm.QueryUtil;
29 import com.liferay.portal.kernel.dao.orm.Session;
30 import com.liferay.portal.kernel.log.Log;
31 import com.liferay.portal.kernel.log.LogFactoryUtil;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.OrderByComparator;
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.model.Subscription;
38 import com.liferay.portal.model.impl.SubscriptionImpl;
39 import com.liferay.portal.model.impl.SubscriptionModelImpl;
40 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.Iterator;
45 import java.util.List;
46
47
53 public class SubscriptionPersistenceImpl extends BasePersistenceImpl
54 implements SubscriptionPersistence {
55 public Subscription create(long subscriptionId) {
56 Subscription subscription = new SubscriptionImpl();
57
58 subscription.setNew(true);
59 subscription.setPrimaryKey(subscriptionId);
60
61 return subscription;
62 }
63
64 public Subscription remove(long subscriptionId)
65 throws NoSuchSubscriptionException, SystemException {
66 Session session = null;
67
68 try {
69 session = openSession();
70
71 Subscription subscription = (Subscription)session.get(SubscriptionImpl.class,
72 new Long(subscriptionId));
73
74 if (subscription == null) {
75 if (_log.isWarnEnabled()) {
76 _log.warn("No Subscription exists with the primary key " +
77 subscriptionId);
78 }
79
80 throw new NoSuchSubscriptionException(
81 "No Subscription exists with the primary key " +
82 subscriptionId);
83 }
84
85 return remove(subscription);
86 }
87 catch (NoSuchSubscriptionException nsee) {
88 throw nsee;
89 }
90 catch (Exception e) {
91 throw processException(e);
92 }
93 finally {
94 closeSession(session);
95 }
96 }
97
98 public Subscription remove(Subscription subscription)
99 throws SystemException {
100 for (ModelListener listener : listeners) {
101 listener.onBeforeRemove(subscription);
102 }
103
104 subscription = removeImpl(subscription);
105
106 for (ModelListener listener : listeners) {
107 listener.onAfterRemove(subscription);
108 }
109
110 return subscription;
111 }
112
113 protected Subscription removeImpl(Subscription subscription)
114 throws SystemException {
115 Session session = null;
116
117 try {
118 session = openSession();
119
120 if (BatchSessionUtil.isEnabled()) {
121 Object staleObject = session.get(SubscriptionImpl.class,
122 subscription.getPrimaryKeyObj());
123
124 if (staleObject != null) {
125 session.evict(staleObject);
126 }
127 }
128
129 session.delete(subscription);
130
131 session.flush();
132
133 return subscription;
134 }
135 catch (Exception e) {
136 throw processException(e);
137 }
138 finally {
139 closeSession(session);
140
141 FinderCacheUtil.clearCache(Subscription.class.getName());
142 }
143 }
144
145
148 public Subscription update(Subscription subscription)
149 throws SystemException {
150 if (_log.isWarnEnabled()) {
151 _log.warn(
152 "Using the deprecated update(Subscription subscription) method. Use update(Subscription subscription, boolean merge) instead.");
153 }
154
155 return update(subscription, false);
156 }
157
158
171 public Subscription update(Subscription subscription, boolean merge)
172 throws SystemException {
173 boolean isNew = subscription.isNew();
174
175 for (ModelListener listener : listeners) {
176 if (isNew) {
177 listener.onBeforeCreate(subscription);
178 }
179 else {
180 listener.onBeforeUpdate(subscription);
181 }
182 }
183
184 subscription = updateImpl(subscription, merge);
185
186 for (ModelListener listener : listeners) {
187 if (isNew) {
188 listener.onAfterCreate(subscription);
189 }
190 else {
191 listener.onAfterUpdate(subscription);
192 }
193 }
194
195 return subscription;
196 }
197
198 public Subscription updateImpl(
199 com.liferay.portal.model.Subscription subscription, boolean merge)
200 throws SystemException {
201 Session session = null;
202
203 try {
204 session = openSession();
205
206 BatchSessionUtil.update(session, subscription, merge);
207
208 subscription.setNew(false);
209
210 return subscription;
211 }
212 catch (Exception e) {
213 throw processException(e);
214 }
215 finally {
216 closeSession(session);
217
218 FinderCacheUtil.clearCache(Subscription.class.getName());
219 }
220 }
221
222 public Subscription findByPrimaryKey(long subscriptionId)
223 throws NoSuchSubscriptionException, SystemException {
224 Subscription subscription = fetchByPrimaryKey(subscriptionId);
225
226 if (subscription == null) {
227 if (_log.isWarnEnabled()) {
228 _log.warn("No Subscription exists with the primary key " +
229 subscriptionId);
230 }
231
232 throw new NoSuchSubscriptionException(
233 "No Subscription exists with the primary key " +
234 subscriptionId);
235 }
236
237 return subscription;
238 }
239
240 public Subscription fetchByPrimaryKey(long subscriptionId)
241 throws SystemException {
242 Session session = null;
243
244 try {
245 session = openSession();
246
247 return (Subscription)session.get(SubscriptionImpl.class,
248 new Long(subscriptionId));
249 }
250 catch (Exception e) {
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 public List<Subscription> findByUserId(long userId)
259 throws SystemException {
260 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
261 String finderClassName = Subscription.class.getName();
262 String finderMethodName = "findByUserId";
263 String[] finderParams = new String[] { Long.class.getName() };
264 Object[] finderArgs = new Object[] { new Long(userId) };
265
266 Object result = null;
267
268 if (finderClassNameCacheEnabled) {
269 result = FinderCacheUtil.getResult(finderClassName,
270 finderMethodName, finderParams, finderArgs, this);
271 }
272
273 if (result == null) {
274 Session session = null;
275
276 try {
277 session = openSession();
278
279 StringBuilder query = new StringBuilder();
280
281 query.append(
282 "FROM com.liferay.portal.model.Subscription WHERE ");
283
284 query.append("userId = ?");
285
286 query.append(" ");
287
288 Query q = session.createQuery(query.toString());
289
290 QueryPos qPos = QueryPos.getInstance(q);
291
292 qPos.add(userId);
293
294 List<Subscription> list = q.list();
295
296 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
297 finderClassName, finderMethodName, finderParams,
298 finderArgs, list);
299
300 return list;
301 }
302 catch (Exception e) {
303 throw processException(e);
304 }
305 finally {
306 closeSession(session);
307 }
308 }
309 else {
310 return (List<Subscription>)result;
311 }
312 }
313
314 public List<Subscription> findByUserId(long userId, int start, int end)
315 throws SystemException {
316 return findByUserId(userId, start, end, null);
317 }
318
319 public List<Subscription> findByUserId(long userId, int start, int end,
320 OrderByComparator obc) throws SystemException {
321 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
322 String finderClassName = Subscription.class.getName();
323 String finderMethodName = "findByUserId";
324 String[] finderParams = new String[] {
325 Long.class.getName(),
326
327 "java.lang.Integer", "java.lang.Integer",
328 "com.liferay.portal.kernel.util.OrderByComparator"
329 };
330 Object[] finderArgs = new Object[] {
331 new Long(userId),
332
333 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
334 };
335
336 Object result = null;
337
338 if (finderClassNameCacheEnabled) {
339 result = FinderCacheUtil.getResult(finderClassName,
340 finderMethodName, finderParams, finderArgs, this);
341 }
342
343 if (result == null) {
344 Session session = null;
345
346 try {
347 session = openSession();
348
349 StringBuilder query = new StringBuilder();
350
351 query.append(
352 "FROM com.liferay.portal.model.Subscription WHERE ");
353
354 query.append("userId = ?");
355
356 query.append(" ");
357
358 if (obc != null) {
359 query.append("ORDER BY ");
360 query.append(obc.getOrderBy());
361 }
362
363 Query q = session.createQuery(query.toString());
364
365 QueryPos qPos = QueryPos.getInstance(q);
366
367 qPos.add(userId);
368
369 List<Subscription> list = (List<Subscription>)QueryUtil.list(q,
370 getDialect(), start, end);
371
372 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
373 finderClassName, finderMethodName, finderParams,
374 finderArgs, list);
375
376 return list;
377 }
378 catch (Exception e) {
379 throw processException(e);
380 }
381 finally {
382 closeSession(session);
383 }
384 }
385 else {
386 return (List<Subscription>)result;
387 }
388 }
389
390 public Subscription findByUserId_First(long userId, OrderByComparator obc)
391 throws NoSuchSubscriptionException, SystemException {
392 List<Subscription> list = findByUserId(userId, 0, 1, obc);
393
394 if (list.size() == 0) {
395 StringBuilder msg = new StringBuilder();
396
397 msg.append("No Subscription exists with the key {");
398
399 msg.append("userId=" + userId);
400
401 msg.append(StringPool.CLOSE_CURLY_BRACE);
402
403 throw new NoSuchSubscriptionException(msg.toString());
404 }
405 else {
406 return list.get(0);
407 }
408 }
409
410 public Subscription findByUserId_Last(long userId, OrderByComparator obc)
411 throws NoSuchSubscriptionException, SystemException {
412 int count = countByUserId(userId);
413
414 List<Subscription> list = findByUserId(userId, count - 1, count, obc);
415
416 if (list.size() == 0) {
417 StringBuilder msg = new StringBuilder();
418
419 msg.append("No Subscription exists with the key {");
420
421 msg.append("userId=" + userId);
422
423 msg.append(StringPool.CLOSE_CURLY_BRACE);
424
425 throw new NoSuchSubscriptionException(msg.toString());
426 }
427 else {
428 return list.get(0);
429 }
430 }
431
432 public Subscription[] findByUserId_PrevAndNext(long subscriptionId,
433 long userId, OrderByComparator obc)
434 throws NoSuchSubscriptionException, SystemException {
435 Subscription subscription = findByPrimaryKey(subscriptionId);
436
437 int count = countByUserId(userId);
438
439 Session session = null;
440
441 try {
442 session = openSession();
443
444 StringBuilder query = new StringBuilder();
445
446 query.append("FROM com.liferay.portal.model.Subscription WHERE ");
447
448 query.append("userId = ?");
449
450 query.append(" ");
451
452 if (obc != null) {
453 query.append("ORDER BY ");
454 query.append(obc.getOrderBy());
455 }
456
457 Query q = session.createQuery(query.toString());
458
459 QueryPos qPos = QueryPos.getInstance(q);
460
461 qPos.add(userId);
462
463 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
464 subscription);
465
466 Subscription[] array = new SubscriptionImpl[3];
467
468 array[0] = (Subscription)objArray[0];
469 array[1] = (Subscription)objArray[1];
470 array[2] = (Subscription)objArray[2];
471
472 return array;
473 }
474 catch (Exception e) {
475 throw processException(e);
476 }
477 finally {
478 closeSession(session);
479 }
480 }
481
482 public List<Subscription> findByC_C_C(long companyId, long classNameId,
483 long classPK) throws SystemException {
484 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
485 String finderClassName = Subscription.class.getName();
486 String finderMethodName = "findByC_C_C";
487 String[] finderParams = new String[] {
488 Long.class.getName(), Long.class.getName(), Long.class.getName()
489 };
490 Object[] finderArgs = new Object[] {
491 new Long(companyId), new Long(classNameId), new Long(classPK)
492 };
493
494 Object result = null;
495
496 if (finderClassNameCacheEnabled) {
497 result = FinderCacheUtil.getResult(finderClassName,
498 finderMethodName, finderParams, finderArgs, this);
499 }
500
501 if (result == null) {
502 Session session = null;
503
504 try {
505 session = openSession();
506
507 StringBuilder query = new StringBuilder();
508
509 query.append(
510 "FROM com.liferay.portal.model.Subscription WHERE ");
511
512 query.append("companyId = ?");
513
514 query.append(" AND ");
515
516 query.append("classNameId = ?");
517
518 query.append(" AND ");
519
520 query.append("classPK = ?");
521
522 query.append(" ");
523
524 Query q = session.createQuery(query.toString());
525
526 QueryPos qPos = QueryPos.getInstance(q);
527
528 qPos.add(companyId);
529
530 qPos.add(classNameId);
531
532 qPos.add(classPK);
533
534 List<Subscription> list = q.list();
535
536 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
537 finderClassName, finderMethodName, finderParams,
538 finderArgs, list);
539
540 return list;
541 }
542 catch (Exception e) {
543 throw processException(e);
544 }
545 finally {
546 closeSession(session);
547 }
548 }
549 else {
550 return (List<Subscription>)result;
551 }
552 }
553
554 public List<Subscription> findByC_C_C(long companyId, long classNameId,
555 long classPK, int start, int end) throws SystemException {
556 return findByC_C_C(companyId, classNameId, classPK, start, end, null);
557 }
558
559 public List<Subscription> findByC_C_C(long companyId, long classNameId,
560 long classPK, int start, int end, OrderByComparator obc)
561 throws SystemException {
562 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
563 String finderClassName = Subscription.class.getName();
564 String finderMethodName = "findByC_C_C";
565 String[] finderParams = new String[] {
566 Long.class.getName(), Long.class.getName(), Long.class.getName(),
567
568 "java.lang.Integer", "java.lang.Integer",
569 "com.liferay.portal.kernel.util.OrderByComparator"
570 };
571 Object[] finderArgs = new Object[] {
572 new Long(companyId), new Long(classNameId), new Long(classPK),
573
574 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
575 };
576
577 Object result = null;
578
579 if (finderClassNameCacheEnabled) {
580 result = FinderCacheUtil.getResult(finderClassName,
581 finderMethodName, finderParams, finderArgs, this);
582 }
583
584 if (result == null) {
585 Session session = null;
586
587 try {
588 session = openSession();
589
590 StringBuilder query = new StringBuilder();
591
592 query.append(
593 "FROM com.liferay.portal.model.Subscription WHERE ");
594
595 query.append("companyId = ?");
596
597 query.append(" AND ");
598
599 query.append("classNameId = ?");
600
601 query.append(" AND ");
602
603 query.append("classPK = ?");
604
605 query.append(" ");
606
607 if (obc != null) {
608 query.append("ORDER BY ");
609 query.append(obc.getOrderBy());
610 }
611
612 Query q = session.createQuery(query.toString());
613
614 QueryPos qPos = QueryPos.getInstance(q);
615
616 qPos.add(companyId);
617
618 qPos.add(classNameId);
619
620 qPos.add(classPK);
621
622 List<Subscription> list = (List<Subscription>)QueryUtil.list(q,
623 getDialect(), start, end);
624
625 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
626 finderClassName, finderMethodName, finderParams,
627 finderArgs, list);
628
629 return list;
630 }
631 catch (Exception e) {
632 throw processException(e);
633 }
634 finally {
635 closeSession(session);
636 }
637 }
638 else {
639 return (List<Subscription>)result;
640 }
641 }
642
643 public Subscription findByC_C_C_First(long companyId, long classNameId,
644 long classPK, OrderByComparator obc)
645 throws NoSuchSubscriptionException, SystemException {
646 List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
647 0, 1, obc);
648
649 if (list.size() == 0) {
650 StringBuilder msg = new StringBuilder();
651
652 msg.append("No Subscription exists with the key {");
653
654 msg.append("companyId=" + companyId);
655
656 msg.append(", ");
657 msg.append("classNameId=" + classNameId);
658
659 msg.append(", ");
660 msg.append("classPK=" + classPK);
661
662 msg.append(StringPool.CLOSE_CURLY_BRACE);
663
664 throw new NoSuchSubscriptionException(msg.toString());
665 }
666 else {
667 return list.get(0);
668 }
669 }
670
671 public Subscription findByC_C_C_Last(long companyId, long classNameId,
672 long classPK, OrderByComparator obc)
673 throws NoSuchSubscriptionException, SystemException {
674 int count = countByC_C_C(companyId, classNameId, classPK);
675
676 List<Subscription> list = findByC_C_C(companyId, classNameId, classPK,
677 count - 1, count, obc);
678
679 if (list.size() == 0) {
680 StringBuilder msg = new StringBuilder();
681
682 msg.append("No Subscription exists with the key {");
683
684 msg.append("companyId=" + companyId);
685
686 msg.append(", ");
687 msg.append("classNameId=" + classNameId);
688
689 msg.append(", ");
690 msg.append("classPK=" + classPK);
691
692 msg.append(StringPool.CLOSE_CURLY_BRACE);
693
694 throw new NoSuchSubscriptionException(msg.toString());
695 }
696 else {
697 return list.get(0);
698 }
699 }
700
701 public Subscription[] findByC_C_C_PrevAndNext(long subscriptionId,
702 long companyId, long classNameId, long classPK, OrderByComparator obc)
703 throws NoSuchSubscriptionException, SystemException {
704 Subscription subscription = findByPrimaryKey(subscriptionId);
705
706 int count = countByC_C_C(companyId, classNameId, classPK);
707
708 Session session = null;
709
710 try {
711 session = openSession();
712
713 StringBuilder query = new StringBuilder();
714
715 query.append("FROM com.liferay.portal.model.Subscription WHERE ");
716
717 query.append("companyId = ?");
718
719 query.append(" AND ");
720
721 query.append("classNameId = ?");
722
723 query.append(" AND ");
724
725 query.append("classPK = ?");
726
727 query.append(" ");
728
729 if (obc != null) {
730 query.append("ORDER BY ");
731 query.append(obc.getOrderBy());
732 }
733
734 Query q = session.createQuery(query.toString());
735
736 QueryPos qPos = QueryPos.getInstance(q);
737
738 qPos.add(companyId);
739
740 qPos.add(classNameId);
741
742 qPos.add(classPK);
743
744 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
745 subscription);
746
747 Subscription[] array = new SubscriptionImpl[3];
748
749 array[0] = (Subscription)objArray[0];
750 array[1] = (Subscription)objArray[1];
751 array[2] = (Subscription)objArray[2];
752
753 return array;
754 }
755 catch (Exception e) {
756 throw processException(e);
757 }
758 finally {
759 closeSession(session);
760 }
761 }
762
763 public Subscription findByC_U_C_C(long companyId, long userId,
764 long classNameId, long classPK)
765 throws NoSuchSubscriptionException, SystemException {
766 Subscription subscription = fetchByC_U_C_C(companyId, userId,
767 classNameId, classPK);
768
769 if (subscription == null) {
770 StringBuilder msg = new StringBuilder();
771
772 msg.append("No Subscription exists with the key {");
773
774 msg.append("companyId=" + companyId);
775
776 msg.append(", ");
777 msg.append("userId=" + userId);
778
779 msg.append(", ");
780 msg.append("classNameId=" + classNameId);
781
782 msg.append(", ");
783 msg.append("classPK=" + classPK);
784
785 msg.append(StringPool.CLOSE_CURLY_BRACE);
786
787 if (_log.isWarnEnabled()) {
788 _log.warn(msg.toString());
789 }
790
791 throw new NoSuchSubscriptionException(msg.toString());
792 }
793
794 return subscription;
795 }
796
797 public Subscription fetchByC_U_C_C(long companyId, long userId,
798 long classNameId, long classPK) throws SystemException {
799 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
800 String finderClassName = Subscription.class.getName();
801 String finderMethodName = "fetchByC_U_C_C";
802 String[] finderParams = new String[] {
803 Long.class.getName(), Long.class.getName(), Long.class.getName(),
804 Long.class.getName()
805 };
806 Object[] finderArgs = new Object[] {
807 new Long(companyId), new Long(userId), new Long(classNameId),
808 new Long(classPK)
809 };
810
811 Object result = null;
812
813 if (finderClassNameCacheEnabled) {
814 result = FinderCacheUtil.getResult(finderClassName,
815 finderMethodName, finderParams, finderArgs, this);
816 }
817
818 if (result == null) {
819 Session session = null;
820
821 try {
822 session = openSession();
823
824 StringBuilder query = new StringBuilder();
825
826 query.append(
827 "FROM com.liferay.portal.model.Subscription WHERE ");
828
829 query.append("companyId = ?");
830
831 query.append(" AND ");
832
833 query.append("userId = ?");
834
835 query.append(" AND ");
836
837 query.append("classNameId = ?");
838
839 query.append(" AND ");
840
841 query.append("classPK = ?");
842
843 query.append(" ");
844
845 Query q = session.createQuery(query.toString());
846
847 QueryPos qPos = QueryPos.getInstance(q);
848
849 qPos.add(companyId);
850
851 qPos.add(userId);
852
853 qPos.add(classNameId);
854
855 qPos.add(classPK);
856
857 List<Subscription> list = q.list();
858
859 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
860 finderClassName, finderMethodName, finderParams,
861 finderArgs, list);
862
863 if (list.size() == 0) {
864 return null;
865 }
866 else {
867 return list.get(0);
868 }
869 }
870 catch (Exception e) {
871 throw processException(e);
872 }
873 finally {
874 closeSession(session);
875 }
876 }
877 else {
878 List<Subscription> list = (List<Subscription>)result;
879
880 if (list.size() == 0) {
881 return null;
882 }
883 else {
884 return list.get(0);
885 }
886 }
887 }
888
889 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
890 throws SystemException {
891 Session session = null;
892
893 try {
894 session = openSession();
895
896 dynamicQuery.compile(session);
897
898 return dynamicQuery.list();
899 }
900 catch (Exception e) {
901 throw processException(e);
902 }
903 finally {
904 closeSession(session);
905 }
906 }
907
908 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
909 int start, int end) throws SystemException {
910 Session session = null;
911
912 try {
913 session = openSession();
914
915 dynamicQuery.setLimit(start, end);
916
917 dynamicQuery.compile(session);
918
919 return dynamicQuery.list();
920 }
921 catch (Exception e) {
922 throw processException(e);
923 }
924 finally {
925 closeSession(session);
926 }
927 }
928
929 public List<Subscription> findAll() throws SystemException {
930 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
931 }
932
933 public List<Subscription> findAll(int start, int end)
934 throws SystemException {
935 return findAll(start, end, null);
936 }
937
938 public List<Subscription> findAll(int start, int end, OrderByComparator obc)
939 throws SystemException {
940 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
941 String finderClassName = Subscription.class.getName();
942 String finderMethodName = "findAll";
943 String[] finderParams = new String[] {
944 "java.lang.Integer", "java.lang.Integer",
945 "com.liferay.portal.kernel.util.OrderByComparator"
946 };
947 Object[] finderArgs = new Object[] {
948 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
949 };
950
951 Object result = null;
952
953 if (finderClassNameCacheEnabled) {
954 result = FinderCacheUtil.getResult(finderClassName,
955 finderMethodName, finderParams, finderArgs, this);
956 }
957
958 if (result == null) {
959 Session session = null;
960
961 try {
962 session = openSession();
963
964 StringBuilder query = new StringBuilder();
965
966 query.append("FROM com.liferay.portal.model.Subscription ");
967
968 if (obc != null) {
969 query.append("ORDER BY ");
970 query.append(obc.getOrderBy());
971 }
972
973 Query q = session.createQuery(query.toString());
974
975 List<Subscription> list = null;
976
977 if (obc == null) {
978 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
979 start, end, false);
980
981 Collections.sort(list);
982 }
983 else {
984 list = (List<Subscription>)QueryUtil.list(q, getDialect(),
985 start, end);
986 }
987
988 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
989 finderClassName, finderMethodName, finderParams,
990 finderArgs, list);
991
992 return list;
993 }
994 catch (Exception e) {
995 throw processException(e);
996 }
997 finally {
998 closeSession(session);
999 }
1000 }
1001 else {
1002 return (List<Subscription>)result;
1003 }
1004 }
1005
1006 public void removeByUserId(long userId) throws SystemException {
1007 for (Subscription subscription : findByUserId(userId)) {
1008 remove(subscription);
1009 }
1010 }
1011
1012 public void removeByC_C_C(long companyId, long classNameId, long classPK)
1013 throws SystemException {
1014 for (Subscription subscription : findByC_C_C(companyId, classNameId,
1015 classPK)) {
1016 remove(subscription);
1017 }
1018 }
1019
1020 public void removeByC_U_C_C(long companyId, long userId, long classNameId,
1021 long classPK) throws NoSuchSubscriptionException, SystemException {
1022 Subscription subscription = findByC_U_C_C(companyId, userId,
1023 classNameId, classPK);
1024
1025 remove(subscription);
1026 }
1027
1028 public void removeAll() throws SystemException {
1029 for (Subscription subscription : findAll()) {
1030 remove(subscription);
1031 }
1032 }
1033
1034 public int countByUserId(long userId) throws SystemException {
1035 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
1036 String finderClassName = Subscription.class.getName();
1037 String finderMethodName = "countByUserId";
1038 String[] finderParams = new String[] { Long.class.getName() };
1039 Object[] finderArgs = new Object[] { new Long(userId) };
1040
1041 Object result = null;
1042
1043 if (finderClassNameCacheEnabled) {
1044 result = FinderCacheUtil.getResult(finderClassName,
1045 finderMethodName, finderParams, finderArgs, this);
1046 }
1047
1048 if (result == null) {
1049 Session session = null;
1050
1051 try {
1052 session = openSession();
1053
1054 StringBuilder query = new StringBuilder();
1055
1056 query.append("SELECT COUNT(*) ");
1057 query.append(
1058 "FROM com.liferay.portal.model.Subscription WHERE ");
1059
1060 query.append("userId = ?");
1061
1062 query.append(" ");
1063
1064 Query q = session.createQuery(query.toString());
1065
1066 QueryPos qPos = QueryPos.getInstance(q);
1067
1068 qPos.add(userId);
1069
1070 Long count = null;
1071
1072 Iterator<Long> itr = q.list().iterator();
1073
1074 if (itr.hasNext()) {
1075 count = itr.next();
1076 }
1077
1078 if (count == null) {
1079 count = new Long(0);
1080 }
1081
1082 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1083 finderClassName, finderMethodName, finderParams,
1084 finderArgs, count);
1085
1086 return count.intValue();
1087 }
1088 catch (Exception e) {
1089 throw processException(e);
1090 }
1091 finally {
1092 closeSession(session);
1093 }
1094 }
1095 else {
1096 return ((Long)result).intValue();
1097 }
1098 }
1099
1100 public int countByC_C_C(long companyId, long classNameId, long classPK)
1101 throws SystemException {
1102 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
1103 String finderClassName = Subscription.class.getName();
1104 String finderMethodName = "countByC_C_C";
1105 String[] finderParams = new String[] {
1106 Long.class.getName(), Long.class.getName(), Long.class.getName()
1107 };
1108 Object[] finderArgs = new Object[] {
1109 new Long(companyId), new Long(classNameId), new Long(classPK)
1110 };
1111
1112 Object result = null;
1113
1114 if (finderClassNameCacheEnabled) {
1115 result = FinderCacheUtil.getResult(finderClassName,
1116 finderMethodName, finderParams, finderArgs, this);
1117 }
1118
1119 if (result == null) {
1120 Session session = null;
1121
1122 try {
1123 session = openSession();
1124
1125 StringBuilder query = new StringBuilder();
1126
1127 query.append("SELECT COUNT(*) ");
1128 query.append(
1129 "FROM com.liferay.portal.model.Subscription WHERE ");
1130
1131 query.append("companyId = ?");
1132
1133 query.append(" AND ");
1134
1135 query.append("classNameId = ?");
1136
1137 query.append(" AND ");
1138
1139 query.append("classPK = ?");
1140
1141 query.append(" ");
1142
1143 Query q = session.createQuery(query.toString());
1144
1145 QueryPos qPos = QueryPos.getInstance(q);
1146
1147 qPos.add(companyId);
1148
1149 qPos.add(classNameId);
1150
1151 qPos.add(classPK);
1152
1153 Long count = null;
1154
1155 Iterator<Long> itr = q.list().iterator();
1156
1157 if (itr.hasNext()) {
1158 count = itr.next();
1159 }
1160
1161 if (count == null) {
1162 count = new Long(0);
1163 }
1164
1165 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1166 finderClassName, finderMethodName, finderParams,
1167 finderArgs, count);
1168
1169 return count.intValue();
1170 }
1171 catch (Exception e) {
1172 throw processException(e);
1173 }
1174 finally {
1175 closeSession(session);
1176 }
1177 }
1178 else {
1179 return ((Long)result).intValue();
1180 }
1181 }
1182
1183 public int countByC_U_C_C(long companyId, long userId, long classNameId,
1184 long classPK) throws SystemException {
1185 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
1186 String finderClassName = Subscription.class.getName();
1187 String finderMethodName = "countByC_U_C_C";
1188 String[] finderParams = new String[] {
1189 Long.class.getName(), Long.class.getName(), Long.class.getName(),
1190 Long.class.getName()
1191 };
1192 Object[] finderArgs = new Object[] {
1193 new Long(companyId), new Long(userId), new Long(classNameId),
1194 new Long(classPK)
1195 };
1196
1197 Object result = null;
1198
1199 if (finderClassNameCacheEnabled) {
1200 result = FinderCacheUtil.getResult(finderClassName,
1201 finderMethodName, finderParams, finderArgs, this);
1202 }
1203
1204 if (result == null) {
1205 Session session = null;
1206
1207 try {
1208 session = openSession();
1209
1210 StringBuilder query = new StringBuilder();
1211
1212 query.append("SELECT COUNT(*) ");
1213 query.append(
1214 "FROM com.liferay.portal.model.Subscription WHERE ");
1215
1216 query.append("companyId = ?");
1217
1218 query.append(" AND ");
1219
1220 query.append("userId = ?");
1221
1222 query.append(" AND ");
1223
1224 query.append("classNameId = ?");
1225
1226 query.append(" AND ");
1227
1228 query.append("classPK = ?");
1229
1230 query.append(" ");
1231
1232 Query q = session.createQuery(query.toString());
1233
1234 QueryPos qPos = QueryPos.getInstance(q);
1235
1236 qPos.add(companyId);
1237
1238 qPos.add(userId);
1239
1240 qPos.add(classNameId);
1241
1242 qPos.add(classPK);
1243
1244 Long count = null;
1245
1246 Iterator<Long> itr = q.list().iterator();
1247
1248 if (itr.hasNext()) {
1249 count = itr.next();
1250 }
1251
1252 if (count == null) {
1253 count = new Long(0);
1254 }
1255
1256 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1257 finderClassName, finderMethodName, finderParams,
1258 finderArgs, count);
1259
1260 return count.intValue();
1261 }
1262 catch (Exception e) {
1263 throw processException(e);
1264 }
1265 finally {
1266 closeSession(session);
1267 }
1268 }
1269 else {
1270 return ((Long)result).intValue();
1271 }
1272 }
1273
1274 public int countAll() throws SystemException {
1275 boolean finderClassNameCacheEnabled = SubscriptionModelImpl.CACHE_ENABLED;
1276 String finderClassName = Subscription.class.getName();
1277 String finderMethodName = "countAll";
1278 String[] finderParams = new String[] { };
1279 Object[] finderArgs = new Object[] { };
1280
1281 Object result = null;
1282
1283 if (finderClassNameCacheEnabled) {
1284 result = FinderCacheUtil.getResult(finderClassName,
1285 finderMethodName, finderParams, finderArgs, this);
1286 }
1287
1288 if (result == null) {
1289 Session session = null;
1290
1291 try {
1292 session = openSession();
1293
1294 Query q = session.createQuery(
1295 "SELECT COUNT(*) FROM com.liferay.portal.model.Subscription");
1296
1297 Long count = null;
1298
1299 Iterator<Long> itr = q.list().iterator();
1300
1301 if (itr.hasNext()) {
1302 count = itr.next();
1303 }
1304
1305 if (count == null) {
1306 count = new Long(0);
1307 }
1308
1309 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1310 finderClassName, finderMethodName, finderParams,
1311 finderArgs, count);
1312
1313 return count.intValue();
1314 }
1315 catch (Exception e) {
1316 throw processException(e);
1317 }
1318 finally {
1319 closeSession(session);
1320 }
1321 }
1322 else {
1323 return ((Long)result).intValue();
1324 }
1325 }
1326
1327 public void afterPropertiesSet() {
1328 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1329 com.liferay.portal.util.PropsUtil.get(
1330 "value.object.listener.com.liferay.portal.model.Subscription")));
1331
1332 if (listenerClassNames.length > 0) {
1333 try {
1334 List<ModelListener> listenersList = new ArrayList<ModelListener>();
1335
1336 for (String listenerClassName : listenerClassNames) {
1337 listenersList.add((ModelListener)Class.forName(
1338 listenerClassName).newInstance());
1339 }
1340
1341 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1342 }
1343 catch (Exception e) {
1344 _log.error(e);
1345 }
1346 }
1347 }
1348
1349 private static Log _log = LogFactoryUtil.getLog(SubscriptionPersistenceImpl.class);
1350}