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