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