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