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