1
22
23 package com.liferay.portlet.calendar.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
27 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28 import com.liferay.portal.kernel.dao.orm.Query;
29 import com.liferay.portal.kernel.dao.orm.QueryPos;
30 import com.liferay.portal.kernel.dao.orm.QueryUtil;
31 import com.liferay.portal.kernel.dao.orm.Session;
32 import com.liferay.portal.kernel.util.GetterUtil;
33 import com.liferay.portal.kernel.util.ListUtil;
34 import com.liferay.portal.kernel.util.OrderByComparator;
35 import com.liferay.portal.kernel.util.StringPool;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.kernel.util.Validator;
38 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
39 import com.liferay.portal.model.ModelListener;
40 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41
42 import com.liferay.portlet.calendar.NoSuchEventException;
43 import com.liferay.portlet.calendar.model.CalEvent;
44 import com.liferay.portlet.calendar.model.impl.CalEventImpl;
45 import com.liferay.portlet.calendar.model.impl.CalEventModelImpl;
46
47 import org.apache.commons.logging.Log;
48 import org.apache.commons.logging.LogFactory;
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 CalEventPersistenceImpl extends BasePersistenceImpl
62 implements CalEventPersistence {
63 public CalEvent create(long eventId) {
64 CalEvent calEvent = new CalEventImpl();
65
66 calEvent.setNew(true);
67 calEvent.setPrimaryKey(eventId);
68
69 String uuid = PortalUUIDUtil.generate();
70
71 calEvent.setUuid(uuid);
72
73 return calEvent;
74 }
75
76 public CalEvent remove(long eventId)
77 throws NoSuchEventException, SystemException {
78 Session session = null;
79
80 try {
81 session = openSession();
82
83 CalEvent calEvent = (CalEvent)session.get(CalEventImpl.class,
84 new Long(eventId));
85
86 if (calEvent == null) {
87 if (_log.isWarnEnabled()) {
88 _log.warn("No CalEvent exists with the primary key " +
89 eventId);
90 }
91
92 throw new NoSuchEventException(
93 "No CalEvent exists with the primary key " + eventId);
94 }
95
96 return remove(calEvent);
97 }
98 catch (NoSuchEventException nsee) {
99 throw nsee;
100 }
101 catch (Exception e) {
102 throw processException(e);
103 }
104 finally {
105 closeSession(session);
106 }
107 }
108
109 public CalEvent remove(CalEvent calEvent) throws SystemException {
110 if (_listeners.length > 0) {
111 for (ModelListener listener : _listeners) {
112 listener.onBeforeRemove(calEvent);
113 }
114 }
115
116 calEvent = removeImpl(calEvent);
117
118 if (_listeners.length > 0) {
119 for (ModelListener listener : _listeners) {
120 listener.onAfterRemove(calEvent);
121 }
122 }
123
124 return calEvent;
125 }
126
127 protected CalEvent removeImpl(CalEvent calEvent) throws SystemException {
128 Session session = null;
129
130 try {
131 session = openSession();
132
133 session.delete(calEvent);
134
135 session.flush();
136
137 return calEvent;
138 }
139 catch (Exception e) {
140 throw processException(e);
141 }
142 finally {
143 closeSession(session);
144
145 FinderCacheUtil.clearCache(CalEvent.class.getName());
146 }
147 }
148
149
152 public CalEvent update(CalEvent calEvent) throws SystemException {
153 if (_log.isWarnEnabled()) {
154 _log.warn(
155 "Using the deprecated update(CalEvent calEvent) method. Use update(CalEvent calEvent, boolean merge) instead.");
156 }
157
158 return update(calEvent, false);
159 }
160
161
174 public CalEvent update(CalEvent calEvent, boolean merge)
175 throws SystemException {
176 boolean isNew = calEvent.isNew();
177
178 if (_listeners.length > 0) {
179 for (ModelListener listener : _listeners) {
180 if (isNew) {
181 listener.onBeforeCreate(calEvent);
182 }
183 else {
184 listener.onBeforeUpdate(calEvent);
185 }
186 }
187 }
188
189 calEvent = updateImpl(calEvent, merge);
190
191 if (_listeners.length > 0) {
192 for (ModelListener listener : _listeners) {
193 if (isNew) {
194 listener.onAfterCreate(calEvent);
195 }
196 else {
197 listener.onAfterUpdate(calEvent);
198 }
199 }
200 }
201
202 return calEvent;
203 }
204
205 public CalEvent updateImpl(
206 com.liferay.portlet.calendar.model.CalEvent calEvent, boolean merge)
207 throws SystemException {
208 if (Validator.isNull(calEvent.getUuid())) {
209 String uuid = PortalUUIDUtil.generate();
210
211 calEvent.setUuid(uuid);
212 }
213
214 Session session = null;
215
216 try {
217 session = openSession();
218
219 if (merge) {
220 session.merge(calEvent);
221 }
222 else {
223 if (calEvent.isNew()) {
224 session.save(calEvent);
225 }
226 }
227
228 session.flush();
229
230 calEvent.setNew(false);
231
232 return calEvent;
233 }
234 catch (Exception e) {
235 throw processException(e);
236 }
237 finally {
238 closeSession(session);
239
240 FinderCacheUtil.clearCache(CalEvent.class.getName());
241 }
242 }
243
244 public CalEvent findByPrimaryKey(long eventId)
245 throws NoSuchEventException, SystemException {
246 CalEvent calEvent = fetchByPrimaryKey(eventId);
247
248 if (calEvent == null) {
249 if (_log.isWarnEnabled()) {
250 _log.warn("No CalEvent exists with the primary key " + eventId);
251 }
252
253 throw new NoSuchEventException(
254 "No CalEvent exists with the primary key " + eventId);
255 }
256
257 return calEvent;
258 }
259
260 public CalEvent fetchByPrimaryKey(long eventId) throws SystemException {
261 Session session = null;
262
263 try {
264 session = openSession();
265
266 return (CalEvent)session.get(CalEventImpl.class, new Long(eventId));
267 }
268 catch (Exception e) {
269 throw processException(e);
270 }
271 finally {
272 closeSession(session);
273 }
274 }
275
276 public List<CalEvent> findByUuid(String uuid) throws SystemException {
277 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
278 String finderClassName = CalEvent.class.getName();
279 String finderMethodName = "findByUuid";
280 String[] finderParams = new String[] { String.class.getName() };
281 Object[] finderArgs = new Object[] { uuid };
282
283 Object result = null;
284
285 if (finderClassNameCacheEnabled) {
286 result = FinderCacheUtil.getResult(finderClassName,
287 finderMethodName, finderParams, finderArgs, this);
288 }
289
290 if (result == null) {
291 Session session = null;
292
293 try {
294 session = openSession();
295
296 StringBuilder query = new StringBuilder();
297
298 query.append(
299 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
300
301 if (uuid == null) {
302 query.append("uuid_ IS NULL");
303 }
304 else {
305 query.append("uuid_ = ?");
306 }
307
308 query.append(" ");
309
310 query.append("ORDER BY ");
311
312 query.append("startDate ASC, ");
313 query.append("title ASC");
314
315 Query q = session.createQuery(query.toString());
316
317 QueryPos qPos = QueryPos.getInstance(q);
318
319 if (uuid != null) {
320 qPos.add(uuid);
321 }
322
323 List<CalEvent> list = q.list();
324
325 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
326 finderClassName, finderMethodName, finderParams,
327 finderArgs, list);
328
329 return list;
330 }
331 catch (Exception e) {
332 throw processException(e);
333 }
334 finally {
335 closeSession(session);
336 }
337 }
338 else {
339 return (List<CalEvent>)result;
340 }
341 }
342
343 public List<CalEvent> findByUuid(String uuid, int start, int end)
344 throws SystemException {
345 return findByUuid(uuid, start, end, null);
346 }
347
348 public List<CalEvent> findByUuid(String uuid, int start, int end,
349 OrderByComparator obc) throws SystemException {
350 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
351 String finderClassName = CalEvent.class.getName();
352 String finderMethodName = "findByUuid";
353 String[] finderParams = new String[] {
354 String.class.getName(),
355
356 "java.lang.Integer", "java.lang.Integer",
357 "com.liferay.portal.kernel.util.OrderByComparator"
358 };
359 Object[] finderArgs = new Object[] {
360 uuid,
361
362 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
363 };
364
365 Object result = null;
366
367 if (finderClassNameCacheEnabled) {
368 result = FinderCacheUtil.getResult(finderClassName,
369 finderMethodName, finderParams, finderArgs, this);
370 }
371
372 if (result == null) {
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 StringBuilder query = new StringBuilder();
379
380 query.append(
381 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
382
383 if (uuid == null) {
384 query.append("uuid_ IS NULL");
385 }
386 else {
387 query.append("uuid_ = ?");
388 }
389
390 query.append(" ");
391
392 if (obc != null) {
393 query.append("ORDER BY ");
394 query.append(obc.getOrderBy());
395 }
396
397 else {
398 query.append("ORDER BY ");
399
400 query.append("startDate ASC, ");
401 query.append("title ASC");
402 }
403
404 Query q = session.createQuery(query.toString());
405
406 QueryPos qPos = QueryPos.getInstance(q);
407
408 if (uuid != null) {
409 qPos.add(uuid);
410 }
411
412 List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
413 getDialect(), start, end);
414
415 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
416 finderClassName, finderMethodName, finderParams,
417 finderArgs, list);
418
419 return list;
420 }
421 catch (Exception e) {
422 throw processException(e);
423 }
424 finally {
425 closeSession(session);
426 }
427 }
428 else {
429 return (List<CalEvent>)result;
430 }
431 }
432
433 public CalEvent findByUuid_First(String uuid, OrderByComparator obc)
434 throws NoSuchEventException, SystemException {
435 List<CalEvent> list = findByUuid(uuid, 0, 1, obc);
436
437 if (list.size() == 0) {
438 StringBuilder msg = new StringBuilder();
439
440 msg.append("No CalEvent exists with the key {");
441
442 msg.append("uuid=" + uuid);
443
444 msg.append(StringPool.CLOSE_CURLY_BRACE);
445
446 throw new NoSuchEventException(msg.toString());
447 }
448 else {
449 return list.get(0);
450 }
451 }
452
453 public CalEvent findByUuid_Last(String uuid, OrderByComparator obc)
454 throws NoSuchEventException, SystemException {
455 int count = countByUuid(uuid);
456
457 List<CalEvent> list = findByUuid(uuid, count - 1, count, obc);
458
459 if (list.size() == 0) {
460 StringBuilder msg = new StringBuilder();
461
462 msg.append("No CalEvent exists with the key {");
463
464 msg.append("uuid=" + uuid);
465
466 msg.append(StringPool.CLOSE_CURLY_BRACE);
467
468 throw new NoSuchEventException(msg.toString());
469 }
470 else {
471 return list.get(0);
472 }
473 }
474
475 public CalEvent[] findByUuid_PrevAndNext(long eventId, String uuid,
476 OrderByComparator obc) throws NoSuchEventException, SystemException {
477 CalEvent calEvent = findByPrimaryKey(eventId);
478
479 int count = countByUuid(uuid);
480
481 Session session = null;
482
483 try {
484 session = openSession();
485
486 StringBuilder query = new StringBuilder();
487
488 query.append(
489 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
490
491 if (uuid == null) {
492 query.append("uuid_ IS NULL");
493 }
494 else {
495 query.append("uuid_ = ?");
496 }
497
498 query.append(" ");
499
500 if (obc != null) {
501 query.append("ORDER BY ");
502 query.append(obc.getOrderBy());
503 }
504
505 else {
506 query.append("ORDER BY ");
507
508 query.append("startDate ASC, ");
509 query.append("title ASC");
510 }
511
512 Query q = session.createQuery(query.toString());
513
514 QueryPos qPos = QueryPos.getInstance(q);
515
516 if (uuid != null) {
517 qPos.add(uuid);
518 }
519
520 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
521
522 CalEvent[] array = new CalEventImpl[3];
523
524 array[0] = (CalEvent)objArray[0];
525 array[1] = (CalEvent)objArray[1];
526 array[2] = (CalEvent)objArray[2];
527
528 return array;
529 }
530 catch (Exception e) {
531 throw processException(e);
532 }
533 finally {
534 closeSession(session);
535 }
536 }
537
538 public CalEvent findByUUID_G(String uuid, long groupId)
539 throws NoSuchEventException, SystemException {
540 CalEvent calEvent = fetchByUUID_G(uuid, groupId);
541
542 if (calEvent == null) {
543 StringBuilder msg = new StringBuilder();
544
545 msg.append("No CalEvent exists with the key {");
546
547 msg.append("uuid=" + uuid);
548
549 msg.append(", ");
550 msg.append("groupId=" + groupId);
551
552 msg.append(StringPool.CLOSE_CURLY_BRACE);
553
554 if (_log.isWarnEnabled()) {
555 _log.warn(msg.toString());
556 }
557
558 throw new NoSuchEventException(msg.toString());
559 }
560
561 return calEvent;
562 }
563
564 public CalEvent fetchByUUID_G(String uuid, long groupId)
565 throws SystemException {
566 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
567 String finderClassName = CalEvent.class.getName();
568 String finderMethodName = "fetchByUUID_G";
569 String[] finderParams = new String[] {
570 String.class.getName(), Long.class.getName()
571 };
572 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
573
574 Object result = null;
575
576 if (finderClassNameCacheEnabled) {
577 result = FinderCacheUtil.getResult(finderClassName,
578 finderMethodName, finderParams, finderArgs, this);
579 }
580
581 if (result == null) {
582 Session session = null;
583
584 try {
585 session = openSession();
586
587 StringBuilder query = new StringBuilder();
588
589 query.append(
590 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
591
592 if (uuid == null) {
593 query.append("uuid_ IS NULL");
594 }
595 else {
596 query.append("uuid_ = ?");
597 }
598
599 query.append(" AND ");
600
601 query.append("groupId = ?");
602
603 query.append(" ");
604
605 query.append("ORDER BY ");
606
607 query.append("startDate ASC, ");
608 query.append("title ASC");
609
610 Query q = session.createQuery(query.toString());
611
612 QueryPos qPos = QueryPos.getInstance(q);
613
614 if (uuid != null) {
615 qPos.add(uuid);
616 }
617
618 qPos.add(groupId);
619
620 List<CalEvent> list = q.list();
621
622 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
623 finderClassName, finderMethodName, finderParams,
624 finderArgs, list);
625
626 if (list.size() == 0) {
627 return null;
628 }
629 else {
630 return list.get(0);
631 }
632 }
633 catch (Exception e) {
634 throw processException(e);
635 }
636 finally {
637 closeSession(session);
638 }
639 }
640 else {
641 List<CalEvent> list = (List<CalEvent>)result;
642
643 if (list.size() == 0) {
644 return null;
645 }
646 else {
647 return list.get(0);
648 }
649 }
650 }
651
652 public List<CalEvent> findByGroupId(long groupId) throws SystemException {
653 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
654 String finderClassName = CalEvent.class.getName();
655 String finderMethodName = "findByGroupId";
656 String[] finderParams = new String[] { Long.class.getName() };
657 Object[] finderArgs = new Object[] { new Long(groupId) };
658
659 Object result = null;
660
661 if (finderClassNameCacheEnabled) {
662 result = FinderCacheUtil.getResult(finderClassName,
663 finderMethodName, finderParams, finderArgs, this);
664 }
665
666 if (result == null) {
667 Session session = null;
668
669 try {
670 session = openSession();
671
672 StringBuilder query = new StringBuilder();
673
674 query.append(
675 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
676
677 query.append("groupId = ?");
678
679 query.append(" ");
680
681 query.append("ORDER BY ");
682
683 query.append("startDate ASC, ");
684 query.append("title ASC");
685
686 Query q = session.createQuery(query.toString());
687
688 QueryPos qPos = QueryPos.getInstance(q);
689
690 qPos.add(groupId);
691
692 List<CalEvent> list = q.list();
693
694 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
695 finderClassName, finderMethodName, finderParams,
696 finderArgs, list);
697
698 return list;
699 }
700 catch (Exception e) {
701 throw processException(e);
702 }
703 finally {
704 closeSession(session);
705 }
706 }
707 else {
708 return (List<CalEvent>)result;
709 }
710 }
711
712 public List<CalEvent> findByGroupId(long groupId, int start, int end)
713 throws SystemException {
714 return findByGroupId(groupId, start, end, null);
715 }
716
717 public List<CalEvent> findByGroupId(long groupId, int start, int end,
718 OrderByComparator obc) throws SystemException {
719 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
720 String finderClassName = CalEvent.class.getName();
721 String finderMethodName = "findByGroupId";
722 String[] finderParams = new String[] {
723 Long.class.getName(),
724
725 "java.lang.Integer", "java.lang.Integer",
726 "com.liferay.portal.kernel.util.OrderByComparator"
727 };
728 Object[] finderArgs = new Object[] {
729 new Long(groupId),
730
731 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
732 };
733
734 Object result = null;
735
736 if (finderClassNameCacheEnabled) {
737 result = FinderCacheUtil.getResult(finderClassName,
738 finderMethodName, finderParams, finderArgs, this);
739 }
740
741 if (result == null) {
742 Session session = null;
743
744 try {
745 session = openSession();
746
747 StringBuilder query = new StringBuilder();
748
749 query.append(
750 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
751
752 query.append("groupId = ?");
753
754 query.append(" ");
755
756 if (obc != null) {
757 query.append("ORDER BY ");
758 query.append(obc.getOrderBy());
759 }
760
761 else {
762 query.append("ORDER BY ");
763
764 query.append("startDate ASC, ");
765 query.append("title ASC");
766 }
767
768 Query q = session.createQuery(query.toString());
769
770 QueryPos qPos = QueryPos.getInstance(q);
771
772 qPos.add(groupId);
773
774 List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
775 getDialect(), start, end);
776
777 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
778 finderClassName, finderMethodName, finderParams,
779 finderArgs, list);
780
781 return list;
782 }
783 catch (Exception e) {
784 throw processException(e);
785 }
786 finally {
787 closeSession(session);
788 }
789 }
790 else {
791 return (List<CalEvent>)result;
792 }
793 }
794
795 public CalEvent findByGroupId_First(long groupId, OrderByComparator obc)
796 throws NoSuchEventException, SystemException {
797 List<CalEvent> list = findByGroupId(groupId, 0, 1, obc);
798
799 if (list.size() == 0) {
800 StringBuilder msg = new StringBuilder();
801
802 msg.append("No CalEvent exists with the key {");
803
804 msg.append("groupId=" + groupId);
805
806 msg.append(StringPool.CLOSE_CURLY_BRACE);
807
808 throw new NoSuchEventException(msg.toString());
809 }
810 else {
811 return list.get(0);
812 }
813 }
814
815 public CalEvent findByGroupId_Last(long groupId, OrderByComparator obc)
816 throws NoSuchEventException, SystemException {
817 int count = countByGroupId(groupId);
818
819 List<CalEvent> list = findByGroupId(groupId, count - 1, count, obc);
820
821 if (list.size() == 0) {
822 StringBuilder msg = new StringBuilder();
823
824 msg.append("No CalEvent exists with the key {");
825
826 msg.append("groupId=" + groupId);
827
828 msg.append(StringPool.CLOSE_CURLY_BRACE);
829
830 throw new NoSuchEventException(msg.toString());
831 }
832 else {
833 return list.get(0);
834 }
835 }
836
837 public CalEvent[] findByGroupId_PrevAndNext(long eventId, long groupId,
838 OrderByComparator obc) throws NoSuchEventException, SystemException {
839 CalEvent calEvent = findByPrimaryKey(eventId);
840
841 int count = countByGroupId(groupId);
842
843 Session session = null;
844
845 try {
846 session = openSession();
847
848 StringBuilder query = new StringBuilder();
849
850 query.append(
851 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
852
853 query.append("groupId = ?");
854
855 query.append(" ");
856
857 if (obc != null) {
858 query.append("ORDER BY ");
859 query.append(obc.getOrderBy());
860 }
861
862 else {
863 query.append("ORDER BY ");
864
865 query.append("startDate ASC, ");
866 query.append("title ASC");
867 }
868
869 Query q = session.createQuery(query.toString());
870
871 QueryPos qPos = QueryPos.getInstance(q);
872
873 qPos.add(groupId);
874
875 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
876
877 CalEvent[] array = new CalEventImpl[3];
878
879 array[0] = (CalEvent)objArray[0];
880 array[1] = (CalEvent)objArray[1];
881 array[2] = (CalEvent)objArray[2];
882
883 return array;
884 }
885 catch (Exception e) {
886 throw processException(e);
887 }
888 finally {
889 closeSession(session);
890 }
891 }
892
893 public List<CalEvent> findByG_T(long groupId, String type)
894 throws SystemException {
895 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
896 String finderClassName = CalEvent.class.getName();
897 String finderMethodName = "findByG_T";
898 String[] finderParams = new String[] {
899 Long.class.getName(), String.class.getName()
900 };
901 Object[] finderArgs = new Object[] { new Long(groupId), type };
902
903 Object result = null;
904
905 if (finderClassNameCacheEnabled) {
906 result = FinderCacheUtil.getResult(finderClassName,
907 finderMethodName, finderParams, finderArgs, this);
908 }
909
910 if (result == null) {
911 Session session = null;
912
913 try {
914 session = openSession();
915
916 StringBuilder query = new StringBuilder();
917
918 query.append(
919 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
920
921 query.append("groupId = ?");
922
923 query.append(" AND ");
924
925 if (type == null) {
926 query.append("type_ IS NULL");
927 }
928 else {
929 query.append("type_ = ?");
930 }
931
932 query.append(" ");
933
934 query.append("ORDER BY ");
935
936 query.append("startDate ASC, ");
937 query.append("title ASC");
938
939 Query q = session.createQuery(query.toString());
940
941 QueryPos qPos = QueryPos.getInstance(q);
942
943 qPos.add(groupId);
944
945 if (type != null) {
946 qPos.add(type);
947 }
948
949 List<CalEvent> list = q.list();
950
951 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
952 finderClassName, finderMethodName, finderParams,
953 finderArgs, list);
954
955 return list;
956 }
957 catch (Exception e) {
958 throw processException(e);
959 }
960 finally {
961 closeSession(session);
962 }
963 }
964 else {
965 return (List<CalEvent>)result;
966 }
967 }
968
969 public List<CalEvent> findByG_T(long groupId, String type, int start,
970 int end) throws SystemException {
971 return findByG_T(groupId, type, start, end, null);
972 }
973
974 public List<CalEvent> findByG_T(long groupId, String type, int start,
975 int end, OrderByComparator obc) throws SystemException {
976 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
977 String finderClassName = CalEvent.class.getName();
978 String finderMethodName = "findByG_T";
979 String[] finderParams = new String[] {
980 Long.class.getName(), String.class.getName(),
981
982 "java.lang.Integer", "java.lang.Integer",
983 "com.liferay.portal.kernel.util.OrderByComparator"
984 };
985 Object[] finderArgs = new Object[] {
986 new Long(groupId),
987
988 type,
989
990 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
991 };
992
993 Object result = null;
994
995 if (finderClassNameCacheEnabled) {
996 result = FinderCacheUtil.getResult(finderClassName,
997 finderMethodName, finderParams, finderArgs, this);
998 }
999
1000 if (result == null) {
1001 Session session = null;
1002
1003 try {
1004 session = openSession();
1005
1006 StringBuilder query = new StringBuilder();
1007
1008 query.append(
1009 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1010
1011 query.append("groupId = ?");
1012
1013 query.append(" AND ");
1014
1015 if (type == null) {
1016 query.append("type_ IS NULL");
1017 }
1018 else {
1019 query.append("type_ = ?");
1020 }
1021
1022 query.append(" ");
1023
1024 if (obc != null) {
1025 query.append("ORDER BY ");
1026 query.append(obc.getOrderBy());
1027 }
1028
1029 else {
1030 query.append("ORDER BY ");
1031
1032 query.append("startDate ASC, ");
1033 query.append("title ASC");
1034 }
1035
1036 Query q = session.createQuery(query.toString());
1037
1038 QueryPos qPos = QueryPos.getInstance(q);
1039
1040 qPos.add(groupId);
1041
1042 if (type != null) {
1043 qPos.add(type);
1044 }
1045
1046 List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
1047 getDialect(), start, end);
1048
1049 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1050 finderClassName, finderMethodName, finderParams,
1051 finderArgs, list);
1052
1053 return list;
1054 }
1055 catch (Exception e) {
1056 throw processException(e);
1057 }
1058 finally {
1059 closeSession(session);
1060 }
1061 }
1062 else {
1063 return (List<CalEvent>)result;
1064 }
1065 }
1066
1067 public CalEvent findByG_T_First(long groupId, String type,
1068 OrderByComparator obc) throws NoSuchEventException, SystemException {
1069 List<CalEvent> list = findByG_T(groupId, type, 0, 1, obc);
1070
1071 if (list.size() == 0) {
1072 StringBuilder msg = new StringBuilder();
1073
1074 msg.append("No CalEvent exists with the key {");
1075
1076 msg.append("groupId=" + groupId);
1077
1078 msg.append(", ");
1079 msg.append("type=" + type);
1080
1081 msg.append(StringPool.CLOSE_CURLY_BRACE);
1082
1083 throw new NoSuchEventException(msg.toString());
1084 }
1085 else {
1086 return list.get(0);
1087 }
1088 }
1089
1090 public CalEvent findByG_T_Last(long groupId, String type,
1091 OrderByComparator obc) throws NoSuchEventException, SystemException {
1092 int count = countByG_T(groupId, type);
1093
1094 List<CalEvent> list = findByG_T(groupId, type, count - 1, count, obc);
1095
1096 if (list.size() == 0) {
1097 StringBuilder msg = new StringBuilder();
1098
1099 msg.append("No CalEvent exists with the key {");
1100
1101 msg.append("groupId=" + groupId);
1102
1103 msg.append(", ");
1104 msg.append("type=" + type);
1105
1106 msg.append(StringPool.CLOSE_CURLY_BRACE);
1107
1108 throw new NoSuchEventException(msg.toString());
1109 }
1110 else {
1111 return list.get(0);
1112 }
1113 }
1114
1115 public CalEvent[] findByG_T_PrevAndNext(long eventId, long groupId,
1116 String type, OrderByComparator obc)
1117 throws NoSuchEventException, SystemException {
1118 CalEvent calEvent = findByPrimaryKey(eventId);
1119
1120 int count = countByG_T(groupId, type);
1121
1122 Session session = null;
1123
1124 try {
1125 session = openSession();
1126
1127 StringBuilder query = new StringBuilder();
1128
1129 query.append(
1130 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1131
1132 query.append("groupId = ?");
1133
1134 query.append(" AND ");
1135
1136 if (type == null) {
1137 query.append("type_ IS NULL");
1138 }
1139 else {
1140 query.append("type_ = ?");
1141 }
1142
1143 query.append(" ");
1144
1145 if (obc != null) {
1146 query.append("ORDER BY ");
1147 query.append(obc.getOrderBy());
1148 }
1149
1150 else {
1151 query.append("ORDER BY ");
1152
1153 query.append("startDate ASC, ");
1154 query.append("title ASC");
1155 }
1156
1157 Query q = session.createQuery(query.toString());
1158
1159 QueryPos qPos = QueryPos.getInstance(q);
1160
1161 qPos.add(groupId);
1162
1163 if (type != null) {
1164 qPos.add(type);
1165 }
1166
1167 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
1168
1169 CalEvent[] array = new CalEventImpl[3];
1170
1171 array[0] = (CalEvent)objArray[0];
1172 array[1] = (CalEvent)objArray[1];
1173 array[2] = (CalEvent)objArray[2];
1174
1175 return array;
1176 }
1177 catch (Exception e) {
1178 throw processException(e);
1179 }
1180 finally {
1181 closeSession(session);
1182 }
1183 }
1184
1185 public List<CalEvent> findByG_R(long groupId, boolean repeating)
1186 throws SystemException {
1187 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1188 String finderClassName = CalEvent.class.getName();
1189 String finderMethodName = "findByG_R";
1190 String[] finderParams = new String[] {
1191 Long.class.getName(), Boolean.class.getName()
1192 };
1193 Object[] finderArgs = new Object[] {
1194 new Long(groupId), Boolean.valueOf(repeating)
1195 };
1196
1197 Object result = null;
1198
1199 if (finderClassNameCacheEnabled) {
1200 result = FinderCacheUtil.getResult(finderClassName,
1201 finderMethodName, finderParams, finderArgs, this);
1202 }
1203
1204 if (result == null) {
1205 Session session = null;
1206
1207 try {
1208 session = openSession();
1209
1210 StringBuilder query = new StringBuilder();
1211
1212 query.append(
1213 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1214
1215 query.append("groupId = ?");
1216
1217 query.append(" AND ");
1218
1219 query.append("repeating = ?");
1220
1221 query.append(" ");
1222
1223 query.append("ORDER BY ");
1224
1225 query.append("startDate ASC, ");
1226 query.append("title ASC");
1227
1228 Query q = session.createQuery(query.toString());
1229
1230 QueryPos qPos = QueryPos.getInstance(q);
1231
1232 qPos.add(groupId);
1233
1234 qPos.add(repeating);
1235
1236 List<CalEvent> list = q.list();
1237
1238 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1239 finderClassName, finderMethodName, finderParams,
1240 finderArgs, list);
1241
1242 return list;
1243 }
1244 catch (Exception e) {
1245 throw processException(e);
1246 }
1247 finally {
1248 closeSession(session);
1249 }
1250 }
1251 else {
1252 return (List<CalEvent>)result;
1253 }
1254 }
1255
1256 public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
1257 int end) throws SystemException {
1258 return findByG_R(groupId, repeating, start, end, null);
1259 }
1260
1261 public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
1262 int end, OrderByComparator obc) throws SystemException {
1263 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1264 String finderClassName = CalEvent.class.getName();
1265 String finderMethodName = "findByG_R";
1266 String[] finderParams = new String[] {
1267 Long.class.getName(), Boolean.class.getName(),
1268
1269 "java.lang.Integer", "java.lang.Integer",
1270 "com.liferay.portal.kernel.util.OrderByComparator"
1271 };
1272 Object[] finderArgs = new Object[] {
1273 new Long(groupId), Boolean.valueOf(repeating),
1274
1275 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1276 };
1277
1278 Object result = null;
1279
1280 if (finderClassNameCacheEnabled) {
1281 result = FinderCacheUtil.getResult(finderClassName,
1282 finderMethodName, finderParams, finderArgs, this);
1283 }
1284
1285 if (result == null) {
1286 Session session = null;
1287
1288 try {
1289 session = openSession();
1290
1291 StringBuilder query = new StringBuilder();
1292
1293 query.append(
1294 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1295
1296 query.append("groupId = ?");
1297
1298 query.append(" AND ");
1299
1300 query.append("repeating = ?");
1301
1302 query.append(" ");
1303
1304 if (obc != null) {
1305 query.append("ORDER BY ");
1306 query.append(obc.getOrderBy());
1307 }
1308
1309 else {
1310 query.append("ORDER BY ");
1311
1312 query.append("startDate ASC, ");
1313 query.append("title ASC");
1314 }
1315
1316 Query q = session.createQuery(query.toString());
1317
1318 QueryPos qPos = QueryPos.getInstance(q);
1319
1320 qPos.add(groupId);
1321
1322 qPos.add(repeating);
1323
1324 List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
1325 getDialect(), start, end);
1326
1327 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1328 finderClassName, finderMethodName, finderParams,
1329 finderArgs, list);
1330
1331 return list;
1332 }
1333 catch (Exception e) {
1334 throw processException(e);
1335 }
1336 finally {
1337 closeSession(session);
1338 }
1339 }
1340 else {
1341 return (List<CalEvent>)result;
1342 }
1343 }
1344
1345 public CalEvent findByG_R_First(long groupId, boolean repeating,
1346 OrderByComparator obc) throws NoSuchEventException, SystemException {
1347 List<CalEvent> list = findByG_R(groupId, repeating, 0, 1, obc);
1348
1349 if (list.size() == 0) {
1350 StringBuilder msg = new StringBuilder();
1351
1352 msg.append("No CalEvent exists with the key {");
1353
1354 msg.append("groupId=" + groupId);
1355
1356 msg.append(", ");
1357 msg.append("repeating=" + repeating);
1358
1359 msg.append(StringPool.CLOSE_CURLY_BRACE);
1360
1361 throw new NoSuchEventException(msg.toString());
1362 }
1363 else {
1364 return list.get(0);
1365 }
1366 }
1367
1368 public CalEvent findByG_R_Last(long groupId, boolean repeating,
1369 OrderByComparator obc) throws NoSuchEventException, SystemException {
1370 int count = countByG_R(groupId, repeating);
1371
1372 List<CalEvent> list = findByG_R(groupId, repeating, count - 1, count,
1373 obc);
1374
1375 if (list.size() == 0) {
1376 StringBuilder msg = new StringBuilder();
1377
1378 msg.append("No CalEvent exists with the key {");
1379
1380 msg.append("groupId=" + groupId);
1381
1382 msg.append(", ");
1383 msg.append("repeating=" + repeating);
1384
1385 msg.append(StringPool.CLOSE_CURLY_BRACE);
1386
1387 throw new NoSuchEventException(msg.toString());
1388 }
1389 else {
1390 return list.get(0);
1391 }
1392 }
1393
1394 public CalEvent[] findByG_R_PrevAndNext(long eventId, long groupId,
1395 boolean repeating, OrderByComparator obc)
1396 throws NoSuchEventException, SystemException {
1397 CalEvent calEvent = findByPrimaryKey(eventId);
1398
1399 int count = countByG_R(groupId, repeating);
1400
1401 Session session = null;
1402
1403 try {
1404 session = openSession();
1405
1406 StringBuilder query = new StringBuilder();
1407
1408 query.append(
1409 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1410
1411 query.append("groupId = ?");
1412
1413 query.append(" AND ");
1414
1415 query.append("repeating = ?");
1416
1417 query.append(" ");
1418
1419 if (obc != null) {
1420 query.append("ORDER BY ");
1421 query.append(obc.getOrderBy());
1422 }
1423
1424 else {
1425 query.append("ORDER BY ");
1426
1427 query.append("startDate ASC, ");
1428 query.append("title ASC");
1429 }
1430
1431 Query q = session.createQuery(query.toString());
1432
1433 QueryPos qPos = QueryPos.getInstance(q);
1434
1435 qPos.add(groupId);
1436
1437 qPos.add(repeating);
1438
1439 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
1440
1441 CalEvent[] array = new CalEventImpl[3];
1442
1443 array[0] = (CalEvent)objArray[0];
1444 array[1] = (CalEvent)objArray[1];
1445 array[2] = (CalEvent)objArray[2];
1446
1447 return array;
1448 }
1449 catch (Exception e) {
1450 throw processException(e);
1451 }
1452 finally {
1453 closeSession(session);
1454 }
1455 }
1456
1457 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1458 throws SystemException {
1459 Session session = null;
1460
1461 try {
1462 session = openSession();
1463
1464 dynamicQuery.compile(session);
1465
1466 return dynamicQuery.list();
1467 }
1468 catch (Exception e) {
1469 throw processException(e);
1470 }
1471 finally {
1472 closeSession(session);
1473 }
1474 }
1475
1476 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1477 int start, int end) throws SystemException {
1478 Session session = null;
1479
1480 try {
1481 session = openSession();
1482
1483 dynamicQuery.setLimit(start, end);
1484
1485 dynamicQuery.compile(session);
1486
1487 return dynamicQuery.list();
1488 }
1489 catch (Exception e) {
1490 throw processException(e);
1491 }
1492 finally {
1493 closeSession(session);
1494 }
1495 }
1496
1497 public List<CalEvent> findAll() throws SystemException {
1498 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1499 }
1500
1501 public List<CalEvent> findAll(int start, int end) throws SystemException {
1502 return findAll(start, end, null);
1503 }
1504
1505 public List<CalEvent> findAll(int start, int end, OrderByComparator obc)
1506 throws SystemException {
1507 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1508 String finderClassName = CalEvent.class.getName();
1509 String finderMethodName = "findAll";
1510 String[] finderParams = new String[] {
1511 "java.lang.Integer", "java.lang.Integer",
1512 "com.liferay.portal.kernel.util.OrderByComparator"
1513 };
1514 Object[] finderArgs = new Object[] {
1515 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1516 };
1517
1518 Object result = null;
1519
1520 if (finderClassNameCacheEnabled) {
1521 result = FinderCacheUtil.getResult(finderClassName,
1522 finderMethodName, finderParams, finderArgs, this);
1523 }
1524
1525 if (result == null) {
1526 Session session = null;
1527
1528 try {
1529 session = openSession();
1530
1531 StringBuilder query = new StringBuilder();
1532
1533 query.append(
1534 "FROM com.liferay.portlet.calendar.model.CalEvent ");
1535
1536 if (obc != null) {
1537 query.append("ORDER BY ");
1538 query.append(obc.getOrderBy());
1539 }
1540
1541 else {
1542 query.append("ORDER BY ");
1543
1544 query.append("startDate ASC, ");
1545 query.append("title ASC");
1546 }
1547
1548 Query q = session.createQuery(query.toString());
1549
1550 List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
1551 getDialect(), start, end);
1552
1553 if (obc == null) {
1554 Collections.sort(list);
1555 }
1556
1557 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1558 finderClassName, finderMethodName, finderParams,
1559 finderArgs, list);
1560
1561 return list;
1562 }
1563 catch (Exception e) {
1564 throw processException(e);
1565 }
1566 finally {
1567 closeSession(session);
1568 }
1569 }
1570 else {
1571 return (List<CalEvent>)result;
1572 }
1573 }
1574
1575 public void removeByUuid(String uuid) throws SystemException {
1576 for (CalEvent calEvent : findByUuid(uuid)) {
1577 remove(calEvent);
1578 }
1579 }
1580
1581 public void removeByUUID_G(String uuid, long groupId)
1582 throws NoSuchEventException, SystemException {
1583 CalEvent calEvent = findByUUID_G(uuid, groupId);
1584
1585 remove(calEvent);
1586 }
1587
1588 public void removeByGroupId(long groupId) throws SystemException {
1589 for (CalEvent calEvent : findByGroupId(groupId)) {
1590 remove(calEvent);
1591 }
1592 }
1593
1594 public void removeByG_T(long groupId, String type)
1595 throws SystemException {
1596 for (CalEvent calEvent : findByG_T(groupId, type)) {
1597 remove(calEvent);
1598 }
1599 }
1600
1601 public void removeByG_R(long groupId, boolean repeating)
1602 throws SystemException {
1603 for (CalEvent calEvent : findByG_R(groupId, repeating)) {
1604 remove(calEvent);
1605 }
1606 }
1607
1608 public void removeAll() throws SystemException {
1609 for (CalEvent calEvent : findAll()) {
1610 remove(calEvent);
1611 }
1612 }
1613
1614 public int countByUuid(String uuid) throws SystemException {
1615 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1616 String finderClassName = CalEvent.class.getName();
1617 String finderMethodName = "countByUuid";
1618 String[] finderParams = new String[] { String.class.getName() };
1619 Object[] finderArgs = new Object[] { uuid };
1620
1621 Object result = null;
1622
1623 if (finderClassNameCacheEnabled) {
1624 result = FinderCacheUtil.getResult(finderClassName,
1625 finderMethodName, finderParams, finderArgs, this);
1626 }
1627
1628 if (result == null) {
1629 Session session = null;
1630
1631 try {
1632 session = openSession();
1633
1634 StringBuilder query = new StringBuilder();
1635
1636 query.append("SELECT COUNT(*) ");
1637 query.append(
1638 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1639
1640 if (uuid == null) {
1641 query.append("uuid_ IS NULL");
1642 }
1643 else {
1644 query.append("uuid_ = ?");
1645 }
1646
1647 query.append(" ");
1648
1649 Query q = session.createQuery(query.toString());
1650
1651 QueryPos qPos = QueryPos.getInstance(q);
1652
1653 if (uuid != null) {
1654 qPos.add(uuid);
1655 }
1656
1657 Long count = null;
1658
1659 Iterator<Long> itr = q.list().iterator();
1660
1661 if (itr.hasNext()) {
1662 count = itr.next();
1663 }
1664
1665 if (count == null) {
1666 count = new Long(0);
1667 }
1668
1669 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1670 finderClassName, finderMethodName, finderParams,
1671 finderArgs, count);
1672
1673 return count.intValue();
1674 }
1675 catch (Exception e) {
1676 throw processException(e);
1677 }
1678 finally {
1679 closeSession(session);
1680 }
1681 }
1682 else {
1683 return ((Long)result).intValue();
1684 }
1685 }
1686
1687 public int countByUUID_G(String uuid, long groupId)
1688 throws SystemException {
1689 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1690 String finderClassName = CalEvent.class.getName();
1691 String finderMethodName = "countByUUID_G";
1692 String[] finderParams = new String[] {
1693 String.class.getName(), Long.class.getName()
1694 };
1695 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1696
1697 Object result = null;
1698
1699 if (finderClassNameCacheEnabled) {
1700 result = FinderCacheUtil.getResult(finderClassName,
1701 finderMethodName, finderParams, finderArgs, this);
1702 }
1703
1704 if (result == null) {
1705 Session session = null;
1706
1707 try {
1708 session = openSession();
1709
1710 StringBuilder query = new StringBuilder();
1711
1712 query.append("SELECT COUNT(*) ");
1713 query.append(
1714 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1715
1716 if (uuid == null) {
1717 query.append("uuid_ IS NULL");
1718 }
1719 else {
1720 query.append("uuid_ = ?");
1721 }
1722
1723 query.append(" AND ");
1724
1725 query.append("groupId = ?");
1726
1727 query.append(" ");
1728
1729 Query q = session.createQuery(query.toString());
1730
1731 QueryPos qPos = QueryPos.getInstance(q);
1732
1733 if (uuid != null) {
1734 qPos.add(uuid);
1735 }
1736
1737 qPos.add(groupId);
1738
1739 Long count = null;
1740
1741 Iterator<Long> itr = q.list().iterator();
1742
1743 if (itr.hasNext()) {
1744 count = itr.next();
1745 }
1746
1747 if (count == null) {
1748 count = new Long(0);
1749 }
1750
1751 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1752 finderClassName, finderMethodName, finderParams,
1753 finderArgs, count);
1754
1755 return count.intValue();
1756 }
1757 catch (Exception e) {
1758 throw processException(e);
1759 }
1760 finally {
1761 closeSession(session);
1762 }
1763 }
1764 else {
1765 return ((Long)result).intValue();
1766 }
1767 }
1768
1769 public int countByGroupId(long groupId) throws SystemException {
1770 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1771 String finderClassName = CalEvent.class.getName();
1772 String finderMethodName = "countByGroupId";
1773 String[] finderParams = new String[] { Long.class.getName() };
1774 Object[] finderArgs = new Object[] { new Long(groupId) };
1775
1776 Object result = null;
1777
1778 if (finderClassNameCacheEnabled) {
1779 result = FinderCacheUtil.getResult(finderClassName,
1780 finderMethodName, finderParams, finderArgs, this);
1781 }
1782
1783 if (result == null) {
1784 Session session = null;
1785
1786 try {
1787 session = openSession();
1788
1789 StringBuilder query = new StringBuilder();
1790
1791 query.append("SELECT COUNT(*) ");
1792 query.append(
1793 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1794
1795 query.append("groupId = ?");
1796
1797 query.append(" ");
1798
1799 Query q = session.createQuery(query.toString());
1800
1801 QueryPos qPos = QueryPos.getInstance(q);
1802
1803 qPos.add(groupId);
1804
1805 Long count = null;
1806
1807 Iterator<Long> itr = q.list().iterator();
1808
1809 if (itr.hasNext()) {
1810 count = itr.next();
1811 }
1812
1813 if (count == null) {
1814 count = new Long(0);
1815 }
1816
1817 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1818 finderClassName, finderMethodName, finderParams,
1819 finderArgs, count);
1820
1821 return count.intValue();
1822 }
1823 catch (Exception e) {
1824 throw processException(e);
1825 }
1826 finally {
1827 closeSession(session);
1828 }
1829 }
1830 else {
1831 return ((Long)result).intValue();
1832 }
1833 }
1834
1835 public int countByG_T(long groupId, String type) throws SystemException {
1836 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1837 String finderClassName = CalEvent.class.getName();
1838 String finderMethodName = "countByG_T";
1839 String[] finderParams = new String[] {
1840 Long.class.getName(), String.class.getName()
1841 };
1842 Object[] finderArgs = new Object[] { new Long(groupId), type };
1843
1844 Object result = null;
1845
1846 if (finderClassNameCacheEnabled) {
1847 result = FinderCacheUtil.getResult(finderClassName,
1848 finderMethodName, finderParams, finderArgs, this);
1849 }
1850
1851 if (result == null) {
1852 Session session = null;
1853
1854 try {
1855 session = openSession();
1856
1857 StringBuilder query = new StringBuilder();
1858
1859 query.append("SELECT COUNT(*) ");
1860 query.append(
1861 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1862
1863 query.append("groupId = ?");
1864
1865 query.append(" AND ");
1866
1867 if (type == null) {
1868 query.append("type_ IS NULL");
1869 }
1870 else {
1871 query.append("type_ = ?");
1872 }
1873
1874 query.append(" ");
1875
1876 Query q = session.createQuery(query.toString());
1877
1878 QueryPos qPos = QueryPos.getInstance(q);
1879
1880 qPos.add(groupId);
1881
1882 if (type != null) {
1883 qPos.add(type);
1884 }
1885
1886 Long count = null;
1887
1888 Iterator<Long> itr = q.list().iterator();
1889
1890 if (itr.hasNext()) {
1891 count = itr.next();
1892 }
1893
1894 if (count == null) {
1895 count = new Long(0);
1896 }
1897
1898 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1899 finderClassName, finderMethodName, finderParams,
1900 finderArgs, count);
1901
1902 return count.intValue();
1903 }
1904 catch (Exception e) {
1905 throw processException(e);
1906 }
1907 finally {
1908 closeSession(session);
1909 }
1910 }
1911 else {
1912 return ((Long)result).intValue();
1913 }
1914 }
1915
1916 public int countByG_R(long groupId, boolean repeating)
1917 throws SystemException {
1918 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1919 String finderClassName = CalEvent.class.getName();
1920 String finderMethodName = "countByG_R";
1921 String[] finderParams = new String[] {
1922 Long.class.getName(), Boolean.class.getName()
1923 };
1924 Object[] finderArgs = new Object[] {
1925 new Long(groupId), Boolean.valueOf(repeating)
1926 };
1927
1928 Object result = null;
1929
1930 if (finderClassNameCacheEnabled) {
1931 result = FinderCacheUtil.getResult(finderClassName,
1932 finderMethodName, finderParams, finderArgs, this);
1933 }
1934
1935 if (result == null) {
1936 Session session = null;
1937
1938 try {
1939 session = openSession();
1940
1941 StringBuilder query = new StringBuilder();
1942
1943 query.append("SELECT COUNT(*) ");
1944 query.append(
1945 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1946
1947 query.append("groupId = ?");
1948
1949 query.append(" AND ");
1950
1951 query.append("repeating = ?");
1952
1953 query.append(" ");
1954
1955 Query q = session.createQuery(query.toString());
1956
1957 QueryPos qPos = QueryPos.getInstance(q);
1958
1959 qPos.add(groupId);
1960
1961 qPos.add(repeating);
1962
1963 Long count = null;
1964
1965 Iterator<Long> itr = q.list().iterator();
1966
1967 if (itr.hasNext()) {
1968 count = itr.next();
1969 }
1970
1971 if (count == null) {
1972 count = new Long(0);
1973 }
1974
1975 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1976 finderClassName, finderMethodName, finderParams,
1977 finderArgs, count);
1978
1979 return count.intValue();
1980 }
1981 catch (Exception e) {
1982 throw processException(e);
1983 }
1984 finally {
1985 closeSession(session);
1986 }
1987 }
1988 else {
1989 return ((Long)result).intValue();
1990 }
1991 }
1992
1993 public int countAll() throws SystemException {
1994 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1995 String finderClassName = CalEvent.class.getName();
1996 String finderMethodName = "countAll";
1997 String[] finderParams = new String[] { };
1998 Object[] finderArgs = new Object[] { };
1999
2000 Object result = null;
2001
2002 if (finderClassNameCacheEnabled) {
2003 result = FinderCacheUtil.getResult(finderClassName,
2004 finderMethodName, finderParams, finderArgs, this);
2005 }
2006
2007 if (result == null) {
2008 Session session = null;
2009
2010 try {
2011 session = openSession();
2012
2013 Query q = session.createQuery(
2014 "SELECT COUNT(*) FROM com.liferay.portlet.calendar.model.CalEvent");
2015
2016 Long count = null;
2017
2018 Iterator<Long> itr = q.list().iterator();
2019
2020 if (itr.hasNext()) {
2021 count = itr.next();
2022 }
2023
2024 if (count == null) {
2025 count = new Long(0);
2026 }
2027
2028 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2029 finderClassName, finderMethodName, finderParams,
2030 finderArgs, count);
2031
2032 return count.intValue();
2033 }
2034 catch (Exception e) {
2035 throw processException(e);
2036 }
2037 finally {
2038 closeSession(session);
2039 }
2040 }
2041 else {
2042 return ((Long)result).intValue();
2043 }
2044 }
2045
2046 public void registerListener(ModelListener listener) {
2047 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2048
2049 listeners.add(listener);
2050
2051 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2052 }
2053
2054 public void unregisterListener(ModelListener listener) {
2055 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2056
2057 listeners.remove(listener);
2058
2059 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2060 }
2061
2062 public void afterPropertiesSet() {
2063 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2064 com.liferay.portal.util.PropsUtil.get(
2065 "value.object.listener.com.liferay.portlet.calendar.model.CalEvent")));
2066
2067 if (listenerClassNames.length > 0) {
2068 try {
2069 List<ModelListener> listeners = new ArrayList<ModelListener>();
2070
2071 for (String listenerClassName : listenerClassNames) {
2072 listeners.add((ModelListener)Class.forName(
2073 listenerClassName).newInstance());
2074 }
2075
2076 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2077 }
2078 catch (Exception e) {
2079 _log.error(e);
2080 }
2081 }
2082 }
2083
2084 private static Log _log = LogFactory.getLog(CalEventPersistenceImpl.class);
2085 private ModelListener[] _listeners = new ModelListener[0];
2086}