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.BatchSessionUtil;
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 {
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 if (BatchSessionUtil.isEnabled()) {
135 Object staleObject = session.get(CalEventImpl.class,
136 calEvent.getPrimaryKeyObj());
137
138 if (staleObject != null) {
139 session.evict(staleObject);
140 }
141 }
142
143 session.delete(calEvent);
144
145 session.flush();
146
147 return calEvent;
148 }
149 catch (Exception e) {
150 throw processException(e);
151 }
152 finally {
153 closeSession(session);
154
155 FinderCacheUtil.clearCache(CalEvent.class.getName());
156 }
157 }
158
159
162 public CalEvent update(CalEvent calEvent) throws SystemException {
163 if (_log.isWarnEnabled()) {
164 _log.warn(
165 "Using the deprecated update(CalEvent calEvent) method. Use update(CalEvent calEvent, boolean merge) instead.");
166 }
167
168 return update(calEvent, false);
169 }
170
171
184 public CalEvent update(CalEvent calEvent, boolean merge)
185 throws SystemException {
186 boolean isNew = calEvent.isNew();
187
188 if (_listeners.length > 0) {
189 for (ModelListener listener : _listeners) {
190 if (isNew) {
191 listener.onBeforeCreate(calEvent);
192 }
193 else {
194 listener.onBeforeUpdate(calEvent);
195 }
196 }
197 }
198
199 calEvent = updateImpl(calEvent, merge);
200
201 if (_listeners.length > 0) {
202 for (ModelListener listener : _listeners) {
203 if (isNew) {
204 listener.onAfterCreate(calEvent);
205 }
206 else {
207 listener.onAfterUpdate(calEvent);
208 }
209 }
210 }
211
212 return calEvent;
213 }
214
215 public CalEvent updateImpl(
216 com.liferay.portlet.calendar.model.CalEvent calEvent, boolean merge)
217 throws SystemException {
218 if (Validator.isNull(calEvent.getUuid())) {
219 String uuid = PortalUUIDUtil.generate();
220
221 calEvent.setUuid(uuid);
222 }
223
224 Session session = null;
225
226 try {
227 session = openSession();
228
229 BatchSessionUtil.update(session, calEvent, merge);
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 = null;
1552
1553 if (obc == null) {
1554 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
1555 start, end, false);
1556
1557 Collections.sort(list);
1558 }
1559 else {
1560 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
1561 start, end);
1562 }
1563
1564 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1565 finderClassName, finderMethodName, finderParams,
1566 finderArgs, list);
1567
1568 return list;
1569 }
1570 catch (Exception e) {
1571 throw processException(e);
1572 }
1573 finally {
1574 closeSession(session);
1575 }
1576 }
1577 else {
1578 return (List<CalEvent>)result;
1579 }
1580 }
1581
1582 public void removeByUuid(String uuid) throws SystemException {
1583 for (CalEvent calEvent : findByUuid(uuid)) {
1584 remove(calEvent);
1585 }
1586 }
1587
1588 public void removeByUUID_G(String uuid, long groupId)
1589 throws NoSuchEventException, SystemException {
1590 CalEvent calEvent = findByUUID_G(uuid, groupId);
1591
1592 remove(calEvent);
1593 }
1594
1595 public void removeByGroupId(long groupId) throws SystemException {
1596 for (CalEvent calEvent : findByGroupId(groupId)) {
1597 remove(calEvent);
1598 }
1599 }
1600
1601 public void removeByG_T(long groupId, String type)
1602 throws SystemException {
1603 for (CalEvent calEvent : findByG_T(groupId, type)) {
1604 remove(calEvent);
1605 }
1606 }
1607
1608 public void removeByG_R(long groupId, boolean repeating)
1609 throws SystemException {
1610 for (CalEvent calEvent : findByG_R(groupId, repeating)) {
1611 remove(calEvent);
1612 }
1613 }
1614
1615 public void removeAll() throws SystemException {
1616 for (CalEvent calEvent : findAll()) {
1617 remove(calEvent);
1618 }
1619 }
1620
1621 public int countByUuid(String uuid) throws SystemException {
1622 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1623 String finderClassName = CalEvent.class.getName();
1624 String finderMethodName = "countByUuid";
1625 String[] finderParams = new String[] { String.class.getName() };
1626 Object[] finderArgs = new Object[] { uuid };
1627
1628 Object result = null;
1629
1630 if (finderClassNameCacheEnabled) {
1631 result = FinderCacheUtil.getResult(finderClassName,
1632 finderMethodName, finderParams, finderArgs, this);
1633 }
1634
1635 if (result == null) {
1636 Session session = null;
1637
1638 try {
1639 session = openSession();
1640
1641 StringBuilder query = new StringBuilder();
1642
1643 query.append("SELECT COUNT(*) ");
1644 query.append(
1645 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1646
1647 if (uuid == null) {
1648 query.append("uuid_ IS NULL");
1649 }
1650 else {
1651 query.append("uuid_ = ?");
1652 }
1653
1654 query.append(" ");
1655
1656 Query q = session.createQuery(query.toString());
1657
1658 QueryPos qPos = QueryPos.getInstance(q);
1659
1660 if (uuid != null) {
1661 qPos.add(uuid);
1662 }
1663
1664 Long count = null;
1665
1666 Iterator<Long> itr = q.list().iterator();
1667
1668 if (itr.hasNext()) {
1669 count = itr.next();
1670 }
1671
1672 if (count == null) {
1673 count = new Long(0);
1674 }
1675
1676 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1677 finderClassName, finderMethodName, finderParams,
1678 finderArgs, count);
1679
1680 return count.intValue();
1681 }
1682 catch (Exception e) {
1683 throw processException(e);
1684 }
1685 finally {
1686 closeSession(session);
1687 }
1688 }
1689 else {
1690 return ((Long)result).intValue();
1691 }
1692 }
1693
1694 public int countByUUID_G(String uuid, long groupId)
1695 throws SystemException {
1696 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1697 String finderClassName = CalEvent.class.getName();
1698 String finderMethodName = "countByUUID_G";
1699 String[] finderParams = new String[] {
1700 String.class.getName(), Long.class.getName()
1701 };
1702 Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1703
1704 Object result = null;
1705
1706 if (finderClassNameCacheEnabled) {
1707 result = FinderCacheUtil.getResult(finderClassName,
1708 finderMethodName, finderParams, finderArgs, this);
1709 }
1710
1711 if (result == null) {
1712 Session session = null;
1713
1714 try {
1715 session = openSession();
1716
1717 StringBuilder query = new StringBuilder();
1718
1719 query.append("SELECT COUNT(*) ");
1720 query.append(
1721 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1722
1723 if (uuid == null) {
1724 query.append("uuid_ IS NULL");
1725 }
1726 else {
1727 query.append("uuid_ = ?");
1728 }
1729
1730 query.append(" AND ");
1731
1732 query.append("groupId = ?");
1733
1734 query.append(" ");
1735
1736 Query q = session.createQuery(query.toString());
1737
1738 QueryPos qPos = QueryPos.getInstance(q);
1739
1740 if (uuid != null) {
1741 qPos.add(uuid);
1742 }
1743
1744 qPos.add(groupId);
1745
1746 Long count = null;
1747
1748 Iterator<Long> itr = q.list().iterator();
1749
1750 if (itr.hasNext()) {
1751 count = itr.next();
1752 }
1753
1754 if (count == null) {
1755 count = new Long(0);
1756 }
1757
1758 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1759 finderClassName, finderMethodName, finderParams,
1760 finderArgs, count);
1761
1762 return count.intValue();
1763 }
1764 catch (Exception e) {
1765 throw processException(e);
1766 }
1767 finally {
1768 closeSession(session);
1769 }
1770 }
1771 else {
1772 return ((Long)result).intValue();
1773 }
1774 }
1775
1776 public int countByGroupId(long groupId) throws SystemException {
1777 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1778 String finderClassName = CalEvent.class.getName();
1779 String finderMethodName = "countByGroupId";
1780 String[] finderParams = new String[] { Long.class.getName() };
1781 Object[] finderArgs = new Object[] { new Long(groupId) };
1782
1783 Object result = null;
1784
1785 if (finderClassNameCacheEnabled) {
1786 result = FinderCacheUtil.getResult(finderClassName,
1787 finderMethodName, finderParams, finderArgs, this);
1788 }
1789
1790 if (result == null) {
1791 Session session = null;
1792
1793 try {
1794 session = openSession();
1795
1796 StringBuilder query = new StringBuilder();
1797
1798 query.append("SELECT COUNT(*) ");
1799 query.append(
1800 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1801
1802 query.append("groupId = ?");
1803
1804 query.append(" ");
1805
1806 Query q = session.createQuery(query.toString());
1807
1808 QueryPos qPos = QueryPos.getInstance(q);
1809
1810 qPos.add(groupId);
1811
1812 Long count = null;
1813
1814 Iterator<Long> itr = q.list().iterator();
1815
1816 if (itr.hasNext()) {
1817 count = itr.next();
1818 }
1819
1820 if (count == null) {
1821 count = new Long(0);
1822 }
1823
1824 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1825 finderClassName, finderMethodName, finderParams,
1826 finderArgs, count);
1827
1828 return count.intValue();
1829 }
1830 catch (Exception e) {
1831 throw processException(e);
1832 }
1833 finally {
1834 closeSession(session);
1835 }
1836 }
1837 else {
1838 return ((Long)result).intValue();
1839 }
1840 }
1841
1842 public int countByG_T(long groupId, String type) throws SystemException {
1843 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1844 String finderClassName = CalEvent.class.getName();
1845 String finderMethodName = "countByG_T";
1846 String[] finderParams = new String[] {
1847 Long.class.getName(), String.class.getName()
1848 };
1849 Object[] finderArgs = new Object[] { new Long(groupId), type };
1850
1851 Object result = null;
1852
1853 if (finderClassNameCacheEnabled) {
1854 result = FinderCacheUtil.getResult(finderClassName,
1855 finderMethodName, finderParams, finderArgs, this);
1856 }
1857
1858 if (result == null) {
1859 Session session = null;
1860
1861 try {
1862 session = openSession();
1863
1864 StringBuilder query = new StringBuilder();
1865
1866 query.append("SELECT COUNT(*) ");
1867 query.append(
1868 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1869
1870 query.append("groupId = ?");
1871
1872 query.append(" AND ");
1873
1874 if (type == null) {
1875 query.append("type_ IS NULL");
1876 }
1877 else {
1878 query.append("type_ = ?");
1879 }
1880
1881 query.append(" ");
1882
1883 Query q = session.createQuery(query.toString());
1884
1885 QueryPos qPos = QueryPos.getInstance(q);
1886
1887 qPos.add(groupId);
1888
1889 if (type != null) {
1890 qPos.add(type);
1891 }
1892
1893 Long count = null;
1894
1895 Iterator<Long> itr = q.list().iterator();
1896
1897 if (itr.hasNext()) {
1898 count = itr.next();
1899 }
1900
1901 if (count == null) {
1902 count = new Long(0);
1903 }
1904
1905 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1906 finderClassName, finderMethodName, finderParams,
1907 finderArgs, count);
1908
1909 return count.intValue();
1910 }
1911 catch (Exception e) {
1912 throw processException(e);
1913 }
1914 finally {
1915 closeSession(session);
1916 }
1917 }
1918 else {
1919 return ((Long)result).intValue();
1920 }
1921 }
1922
1923 public int countByG_R(long groupId, boolean repeating)
1924 throws SystemException {
1925 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1926 String finderClassName = CalEvent.class.getName();
1927 String finderMethodName = "countByG_R";
1928 String[] finderParams = new String[] {
1929 Long.class.getName(), Boolean.class.getName()
1930 };
1931 Object[] finderArgs = new Object[] {
1932 new Long(groupId), Boolean.valueOf(repeating)
1933 };
1934
1935 Object result = null;
1936
1937 if (finderClassNameCacheEnabled) {
1938 result = FinderCacheUtil.getResult(finderClassName,
1939 finderMethodName, finderParams, finderArgs, this);
1940 }
1941
1942 if (result == null) {
1943 Session session = null;
1944
1945 try {
1946 session = openSession();
1947
1948 StringBuilder query = new StringBuilder();
1949
1950 query.append("SELECT COUNT(*) ");
1951 query.append(
1952 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1953
1954 query.append("groupId = ?");
1955
1956 query.append(" AND ");
1957
1958 query.append("repeating = ?");
1959
1960 query.append(" ");
1961
1962 Query q = session.createQuery(query.toString());
1963
1964 QueryPos qPos = QueryPos.getInstance(q);
1965
1966 qPos.add(groupId);
1967
1968 qPos.add(repeating);
1969
1970 Long count = null;
1971
1972 Iterator<Long> itr = q.list().iterator();
1973
1974 if (itr.hasNext()) {
1975 count = itr.next();
1976 }
1977
1978 if (count == null) {
1979 count = new Long(0);
1980 }
1981
1982 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1983 finderClassName, finderMethodName, finderParams,
1984 finderArgs, count);
1985
1986 return count.intValue();
1987 }
1988 catch (Exception e) {
1989 throw processException(e);
1990 }
1991 finally {
1992 closeSession(session);
1993 }
1994 }
1995 else {
1996 return ((Long)result).intValue();
1997 }
1998 }
1999
2000 public int countAll() throws SystemException {
2001 boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
2002 String finderClassName = CalEvent.class.getName();
2003 String finderMethodName = "countAll";
2004 String[] finderParams = new String[] { };
2005 Object[] finderArgs = new Object[] { };
2006
2007 Object result = null;
2008
2009 if (finderClassNameCacheEnabled) {
2010 result = FinderCacheUtil.getResult(finderClassName,
2011 finderMethodName, finderParams, finderArgs, this);
2012 }
2013
2014 if (result == null) {
2015 Session session = null;
2016
2017 try {
2018 session = openSession();
2019
2020 Query q = session.createQuery(
2021 "SELECT COUNT(*) FROM com.liferay.portlet.calendar.model.CalEvent");
2022
2023 Long count = null;
2024
2025 Iterator<Long> itr = q.list().iterator();
2026
2027 if (itr.hasNext()) {
2028 count = itr.next();
2029 }
2030
2031 if (count == null) {
2032 count = new Long(0);
2033 }
2034
2035 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2036 finderClassName, finderMethodName, finderParams,
2037 finderArgs, count);
2038
2039 return count.intValue();
2040 }
2041 catch (Exception e) {
2042 throw processException(e);
2043 }
2044 finally {
2045 closeSession(session);
2046 }
2047 }
2048 else {
2049 return ((Long)result).intValue();
2050 }
2051 }
2052
2053 public void registerListener(ModelListener listener) {
2054 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2055
2056 listeners.add(listener);
2057
2058 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2059 }
2060
2061 public void unregisterListener(ModelListener listener) {
2062 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2063
2064 listeners.remove(listener);
2065
2066 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2067 }
2068
2069 public void afterPropertiesSet() {
2070 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2071 com.liferay.portal.util.PropsUtil.get(
2072 "value.object.listener.com.liferay.portlet.calendar.model.CalEvent")));
2073
2074 if (listenerClassNames.length > 0) {
2075 try {
2076 List<ModelListener> listeners = new ArrayList<ModelListener>();
2077
2078 for (String listenerClassName : listenerClassNames) {
2079 listeners.add((ModelListener)Class.forName(
2080 listenerClassName).newInstance());
2081 }
2082
2083 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2084 }
2085 catch (Exception e) {
2086 _log.error(e);
2087 }
2088 }
2089 }
2090
2091 private static Log _log = LogFactory.getLog(CalEventPersistenceImpl.class);
2092 private ModelListener[] _listeners = new ModelListener[0];
2093}