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