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