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