1   /**
2    * Copyright (c) 2000-2009 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.annotation.BeanReference;
27  import com.liferay.portal.kernel.cache.CacheRegistry;
28  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderPath;
32  import com.liferay.portal.kernel.dao.orm.Query;
33  import com.liferay.portal.kernel.dao.orm.QueryPos;
34  import com.liferay.portal.kernel.dao.orm.QueryUtil;
35  import com.liferay.portal.kernel.dao.orm.Session;
36  import com.liferay.portal.kernel.log.Log;
37  import com.liferay.portal.kernel.log.LogFactoryUtil;
38  import com.liferay.portal.kernel.util.GetterUtil;
39  import com.liferay.portal.kernel.util.OrderByComparator;
40  import com.liferay.portal.kernel.util.StringPool;
41  import com.liferay.portal.kernel.util.StringUtil;
42  import com.liferay.portal.kernel.util.Validator;
43  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.service.persistence.BatchSessionUtil;
46  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
47  
48  import com.liferay.portlet.calendar.NoSuchEventException;
49  import com.liferay.portlet.calendar.model.CalEvent;
50  import com.liferay.portlet.calendar.model.impl.CalEventImpl;
51  import com.liferay.portlet.calendar.model.impl.CalEventModelImpl;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
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 BasePersistenceImpl
64      implements CalEventPersistence {
65      public static final String FINDER_CLASS_NAME_ENTITY = CalEventImpl.class.getName();
66      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67          ".List";
68      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
69              CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
70              "findByUuid", new String[] { String.class.getName() });
71      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
72              CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73              "findByUuid",
74              new String[] {
75                  String.class.getName(),
76                  
77              "java.lang.Integer", "java.lang.Integer",
78                  "com.liferay.portal.kernel.util.OrderByComparator"
79              });
80      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
81              CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
82              "countByUuid", new String[] { String.class.getName() });
83      public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
84              CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
85              "fetchByUUID_G",
86              new String[] { String.class.getName(), Long.class.getName() });
87      public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
88              CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
89              "countByUUID_G",
90              new String[] { String.class.getName(), Long.class.getName() });
91      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
92              CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93              "findByGroupId", new String[] { Long.class.getName() });
94      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
95              CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96              "findByGroupId",
97              new String[] {
98                  Long.class.getName(),
99                  
100             "java.lang.Integer", "java.lang.Integer",
101                 "com.liferay.portal.kernel.util.OrderByComparator"
102             });
103     public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
104             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105             "countByGroupId", new String[] { Long.class.getName() });
106     public static final FinderPath FINDER_PATH_FIND_BY_REMINDBY = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
107             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108             "findByRemindBy", new String[] { Integer.class.getName() });
109     public static final FinderPath FINDER_PATH_FIND_BY_OBC_REMINDBY = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
110             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111             "findByRemindBy",
112             new String[] {
113                 Integer.class.getName(),
114                 
115             "java.lang.Integer", "java.lang.Integer",
116                 "com.liferay.portal.kernel.util.OrderByComparator"
117             });
118     public static final FinderPath FINDER_PATH_COUNT_BY_REMINDBY = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
119             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
120             "countByRemindBy", new String[] { Integer.class.getName() });
121     public static final FinderPath FINDER_PATH_FIND_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
122             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123             "findByG_T",
124             new String[] { Long.class.getName(), String.class.getName() });
125     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
126             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
127             "findByG_T",
128             new String[] {
129                 Long.class.getName(), String.class.getName(),
130                 
131             "java.lang.Integer", "java.lang.Integer",
132                 "com.liferay.portal.kernel.util.OrderByComparator"
133             });
134     public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
135             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
136             "countByG_T",
137             new String[] { Long.class.getName(), String.class.getName() });
138     public static final FinderPath FINDER_PATH_FIND_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
139             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
140             "findByG_R",
141             new String[] { Long.class.getName(), Boolean.class.getName() });
142     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
143             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
144             "findByG_R",
145             new String[] {
146                 Long.class.getName(), Boolean.class.getName(),
147                 
148             "java.lang.Integer", "java.lang.Integer",
149                 "com.liferay.portal.kernel.util.OrderByComparator"
150             });
151     public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
152             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
153             "countByG_R",
154             new String[] { Long.class.getName(), Boolean.class.getName() });
155     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
156             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
157             "findAll", new String[0]);
158     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
159             CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
160             "countAll", new String[0]);
161 
162     public void cacheResult(CalEvent calEvent) {
163         EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
164             CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
165 
166         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
167             new Object[] { calEvent.getUuid(), new Long(calEvent.getGroupId()) },
168             calEvent);
169     }
170 
171     public void cacheResult(List<CalEvent> calEvents) {
172         for (CalEvent calEvent : calEvents) {
173             if (EntityCacheUtil.getResult(
174                         CalEventModelImpl.ENTITY_CACHE_ENABLED,
175                         CalEventImpl.class, calEvent.getPrimaryKey(), this) == null) {
176                 cacheResult(calEvent);
177             }
178         }
179     }
180 
181     public void clearCache() {
182         CacheRegistry.clear(CalEventImpl.class.getName());
183         EntityCacheUtil.clearCache(CalEventImpl.class.getName());
184         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
185         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
186     }
187 
188     public CalEvent create(long eventId) {
189         CalEvent calEvent = new CalEventImpl();
190 
191         calEvent.setNew(true);
192         calEvent.setPrimaryKey(eventId);
193 
194         String uuid = PortalUUIDUtil.generate();
195 
196         calEvent.setUuid(uuid);
197 
198         return calEvent;
199     }
200 
201     public CalEvent remove(long eventId)
202         throws NoSuchEventException, SystemException {
203         Session session = null;
204 
205         try {
206             session = openSession();
207 
208             CalEvent calEvent = (CalEvent)session.get(CalEventImpl.class,
209                     new Long(eventId));
210 
211             if (calEvent == null) {
212                 if (_log.isWarnEnabled()) {
213                     _log.warn("No CalEvent exists with the primary key " +
214                         eventId);
215                 }
216 
217                 throw new NoSuchEventException(
218                     "No CalEvent exists with the primary key " + eventId);
219             }
220 
221             return remove(calEvent);
222         }
223         catch (NoSuchEventException nsee) {
224             throw nsee;
225         }
226         catch (Exception e) {
227             throw processException(e);
228         }
229         finally {
230             closeSession(session);
231         }
232     }
233 
234     public CalEvent remove(CalEvent calEvent) throws SystemException {
235         for (ModelListener<CalEvent> listener : listeners) {
236             listener.onBeforeRemove(calEvent);
237         }
238 
239         calEvent = removeImpl(calEvent);
240 
241         for (ModelListener<CalEvent> listener : listeners) {
242             listener.onAfterRemove(calEvent);
243         }
244 
245         return calEvent;
246     }
247 
248     protected CalEvent removeImpl(CalEvent calEvent) throws SystemException {
249         Session session = null;
250 
251         try {
252             session = openSession();
253 
254             if (calEvent.isCachedModel() || BatchSessionUtil.isEnabled()) {
255                 Object staleObject = session.get(CalEventImpl.class,
256                         calEvent.getPrimaryKeyObj());
257 
258                 if (staleObject != null) {
259                     session.evict(staleObject);
260                 }
261             }
262 
263             session.delete(calEvent);
264 
265             session.flush();
266         }
267         catch (Exception e) {
268             throw processException(e);
269         }
270         finally {
271             closeSession(session);
272         }
273 
274         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
275 
276         CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
277 
278         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
279             new Object[] {
280                 calEventModelImpl.getOriginalUuid(),
281                 new Long(calEventModelImpl.getOriginalGroupId())
282             });
283 
284         EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
285             CalEventImpl.class, calEvent.getPrimaryKey());
286 
287         return calEvent;
288     }
289 
290     /**
291      * @deprecated Use <code>update(CalEvent calEvent, boolean merge)</code>.
292      */
293     public CalEvent update(CalEvent calEvent) throws SystemException {
294         if (_log.isWarnEnabled()) {
295             _log.warn(
296                 "Using the deprecated update(CalEvent calEvent) method. Use update(CalEvent calEvent, boolean merge) instead.");
297         }
298 
299         return update(calEvent, false);
300     }
301 
302     /**
303      * Add, update, or merge, the entity. This method also calls the model
304      * listeners to trigger the proper events associated with adding, deleting,
305      * or updating an entity.
306      *
307      * @param        calEvent the entity to add, update, or merge
308      * @param        merge boolean value for whether to merge the entity. The
309      *                default value is false. Setting merge to true is more
310      *                expensive and should only be true when calEvent is
311      *                transient. See LEP-5473 for a detailed discussion of this
312      *                method.
313      * @return        true if the portlet can be displayed via Ajax
314      */
315     public CalEvent update(CalEvent calEvent, boolean merge)
316         throws SystemException {
317         boolean isNew = calEvent.isNew();
318 
319         for (ModelListener<CalEvent> listener : listeners) {
320             if (isNew) {
321                 listener.onBeforeCreate(calEvent);
322             }
323             else {
324                 listener.onBeforeUpdate(calEvent);
325             }
326         }
327 
328         calEvent = updateImpl(calEvent, merge);
329 
330         for (ModelListener<CalEvent> listener : listeners) {
331             if (isNew) {
332                 listener.onAfterCreate(calEvent);
333             }
334             else {
335                 listener.onAfterUpdate(calEvent);
336             }
337         }
338 
339         return calEvent;
340     }
341 
342     public CalEvent updateImpl(
343         com.liferay.portlet.calendar.model.CalEvent calEvent, boolean merge)
344         throws SystemException {
345         boolean isNew = calEvent.isNew();
346 
347         CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
348 
349         if (Validator.isNull(calEvent.getUuid())) {
350             String uuid = PortalUUIDUtil.generate();
351 
352             calEvent.setUuid(uuid);
353         }
354 
355         Session session = null;
356 
357         try {
358             session = openSession();
359 
360             BatchSessionUtil.update(session, calEvent, merge);
361 
362             calEvent.setNew(false);
363         }
364         catch (Exception e) {
365             throw processException(e);
366         }
367         finally {
368             closeSession(session);
369         }
370 
371         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
372 
373         EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
374             CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
375 
376         if (!isNew &&
377                 (!Validator.equals(calEvent.getUuid(),
378                     calEventModelImpl.getOriginalUuid()) ||
379                 (calEvent.getGroupId() != calEventModelImpl.getOriginalGroupId()))) {
380             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
381                 new Object[] {
382                     calEventModelImpl.getOriginalUuid(),
383                     new Long(calEventModelImpl.getOriginalGroupId())
384                 });
385         }
386 
387         if (isNew ||
388                 (!Validator.equals(calEvent.getUuid(),
389                     calEventModelImpl.getOriginalUuid()) ||
390                 (calEvent.getGroupId() != calEventModelImpl.getOriginalGroupId()))) {
391             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
392                 new Object[] { calEvent.getUuid(), new Long(
393                         calEvent.getGroupId()) }, calEvent);
394         }
395 
396         return calEvent;
397     }
398 
399     public CalEvent findByPrimaryKey(long eventId)
400         throws NoSuchEventException, SystemException {
401         CalEvent calEvent = fetchByPrimaryKey(eventId);
402 
403         if (calEvent == null) {
404             if (_log.isWarnEnabled()) {
405                 _log.warn("No CalEvent exists with the primary key " + eventId);
406             }
407 
408             throw new NoSuchEventException(
409                 "No CalEvent exists with the primary key " + eventId);
410         }
411 
412         return calEvent;
413     }
414 
415     public CalEvent fetchByPrimaryKey(long eventId) throws SystemException {
416         CalEvent calEvent = (CalEvent)EntityCacheUtil.getResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
417                 CalEventImpl.class, eventId, this);
418 
419         if (calEvent == null) {
420             Session session = null;
421 
422             try {
423                 session = openSession();
424 
425                 calEvent = (CalEvent)session.get(CalEventImpl.class,
426                         new Long(eventId));
427             }
428             catch (Exception e) {
429                 throw processException(e);
430             }
431             finally {
432                 if (calEvent != null) {
433                     cacheResult(calEvent);
434                 }
435 
436                 closeSession(session);
437             }
438         }
439 
440         return calEvent;
441     }
442 
443     public List<CalEvent> findByUuid(String uuid) throws SystemException {
444         Object[] finderArgs = new Object[] { uuid };
445 
446         List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
447                 finderArgs, this);
448 
449         if (list == null) {
450             Session session = null;
451 
452             try {
453                 session = openSession();
454 
455                 StringBuilder query = new StringBuilder();
456 
457                 query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
458 
459                 if (uuid == null) {
460                     query.append("calEvent.uuid IS NULL");
461                 }
462                 else {
463                     query.append("calEvent.uuid = ?");
464                 }
465 
466                 query.append(" ");
467 
468                 query.append("ORDER BY ");
469 
470                 query.append("calEvent.startDate ASC, ");
471                 query.append("calEvent.title ASC");
472 
473                 Query q = session.createQuery(query.toString());
474 
475                 QueryPos qPos = QueryPos.getInstance(q);
476 
477                 if (uuid != null) {
478                     qPos.add(uuid);
479                 }
480 
481                 list = q.list();
482             }
483             catch (Exception e) {
484                 throw processException(e);
485             }
486             finally {
487                 if (list == null) {
488                     list = new ArrayList<CalEvent>();
489                 }
490 
491                 cacheResult(list);
492 
493                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
494                     list);
495 
496                 closeSession(session);
497             }
498         }
499 
500         return list;
501     }
502 
503     public List<CalEvent> findByUuid(String uuid, int start, int end)
504         throws SystemException {
505         return findByUuid(uuid, start, end, null);
506     }
507 
508     public List<CalEvent> findByUuid(String uuid, int start, int end,
509         OrderByComparator obc) throws SystemException {
510         Object[] finderArgs = new Object[] {
511                 uuid,
512                 
513                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
514             };
515 
516         List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
517                 finderArgs, this);
518 
519         if (list == null) {
520             Session session = null;
521 
522             try {
523                 session = openSession();
524 
525                 StringBuilder query = new StringBuilder();
526 
527                 query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
528 
529                 if (uuid == null) {
530                     query.append("calEvent.uuid IS NULL");
531                 }
532                 else {
533                     query.append("calEvent.uuid = ?");
534                 }
535 
536                 query.append(" ");
537 
538                 if (obc != null) {
539                     query.append("ORDER BY ");
540 
541                     String[] orderByFields = obc.getOrderByFields();
542 
543                     for (int i = 0; i < orderByFields.length; i++) {
544                         query.append("calEvent.");
545                         query.append(orderByFields[i]);
546 
547                         if (obc.isAscending()) {
548                             query.append(" ASC");
549                         }
550                         else {
551                             query.append(" DESC");
552                         }
553 
554                         if ((i + 1) < orderByFields.length) {
555                             query.append(", ");
556                         }
557                     }
558                 }
559 
560                 else {
561                     query.append("ORDER BY ");
562 
563                     query.append("calEvent.startDate ASC, ");
564                     query.append("calEvent.title ASC");
565                 }
566 
567                 Query q = session.createQuery(query.toString());
568 
569                 QueryPos qPos = QueryPos.getInstance(q);
570 
571                 if (uuid != null) {
572                     qPos.add(uuid);
573                 }
574 
575                 list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
576                         end);
577             }
578             catch (Exception e) {
579                 throw processException(e);
580             }
581             finally {
582                 if (list == null) {
583                     list = new ArrayList<CalEvent>();
584                 }
585 
586                 cacheResult(list);
587 
588                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
589                     finderArgs, list);
590 
591                 closeSession(session);
592             }
593         }
594 
595         return list;
596     }
597 
598     public CalEvent findByUuid_First(String uuid, OrderByComparator obc)
599         throws NoSuchEventException, SystemException {
600         List<CalEvent> list = findByUuid(uuid, 0, 1, obc);
601 
602         if (list.isEmpty()) {
603             StringBuilder msg = new StringBuilder();
604 
605             msg.append("No CalEvent exists with the key {");
606 
607             msg.append("uuid=" + uuid);
608 
609             msg.append(StringPool.CLOSE_CURLY_BRACE);
610 
611             throw new NoSuchEventException(msg.toString());
612         }
613         else {
614             return list.get(0);
615         }
616     }
617 
618     public CalEvent findByUuid_Last(String uuid, OrderByComparator obc)
619         throws NoSuchEventException, SystemException {
620         int count = countByUuid(uuid);
621 
622         List<CalEvent> list = findByUuid(uuid, count - 1, count, obc);
623 
624         if (list.isEmpty()) {
625             StringBuilder msg = new StringBuilder();
626 
627             msg.append("No CalEvent exists with the key {");
628 
629             msg.append("uuid=" + uuid);
630 
631             msg.append(StringPool.CLOSE_CURLY_BRACE);
632 
633             throw new NoSuchEventException(msg.toString());
634         }
635         else {
636             return list.get(0);
637         }
638     }
639 
640     public CalEvent[] findByUuid_PrevAndNext(long eventId, String uuid,
641         OrderByComparator obc) throws NoSuchEventException, SystemException {
642         CalEvent calEvent = findByPrimaryKey(eventId);
643 
644         int count = countByUuid(uuid);
645 
646         Session session = null;
647 
648         try {
649             session = openSession();
650 
651             StringBuilder query = new StringBuilder();
652 
653             query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
654 
655             if (uuid == null) {
656                 query.append("calEvent.uuid IS NULL");
657             }
658             else {
659                 query.append("calEvent.uuid = ?");
660             }
661 
662             query.append(" ");
663 
664             if (obc != null) {
665                 query.append("ORDER BY ");
666 
667                 String[] orderByFields = obc.getOrderByFields();
668 
669                 for (int i = 0; i < orderByFields.length; i++) {
670                     query.append("calEvent.");
671                     query.append(orderByFields[i]);
672 
673                     if (obc.isAscending()) {
674                         query.append(" ASC");
675                     }
676                     else {
677                         query.append(" DESC");
678                     }
679 
680                     if ((i + 1) < orderByFields.length) {
681                         query.append(", ");
682                     }
683                 }
684             }
685 
686             else {
687                 query.append("ORDER BY ");
688 
689                 query.append("calEvent.startDate ASC, ");
690                 query.append("calEvent.title ASC");
691             }
692 
693             Query q = session.createQuery(query.toString());
694 
695             QueryPos qPos = QueryPos.getInstance(q);
696 
697             if (uuid != null) {
698                 qPos.add(uuid);
699             }
700 
701             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
702 
703             CalEvent[] array = new CalEventImpl[3];
704 
705             array[0] = (CalEvent)objArray[0];
706             array[1] = (CalEvent)objArray[1];
707             array[2] = (CalEvent)objArray[2];
708 
709             return array;
710         }
711         catch (Exception e) {
712             throw processException(e);
713         }
714         finally {
715             closeSession(session);
716         }
717     }
718 
719     public CalEvent findByUUID_G(String uuid, long groupId)
720         throws NoSuchEventException, SystemException {
721         CalEvent calEvent = fetchByUUID_G(uuid, groupId);
722 
723         if (calEvent == null) {
724             StringBuilder msg = new StringBuilder();
725 
726             msg.append("No CalEvent exists with the key {");
727 
728             msg.append("uuid=" + uuid);
729 
730             msg.append(", ");
731             msg.append("groupId=" + groupId);
732 
733             msg.append(StringPool.CLOSE_CURLY_BRACE);
734 
735             if (_log.isWarnEnabled()) {
736                 _log.warn(msg.toString());
737             }
738 
739             throw new NoSuchEventException(msg.toString());
740         }
741 
742         return calEvent;
743     }
744 
745     public CalEvent fetchByUUID_G(String uuid, long groupId)
746         throws SystemException {
747         return fetchByUUID_G(uuid, groupId, true);
748     }
749 
750     public CalEvent fetchByUUID_G(String uuid, long groupId,
751         boolean retrieveFromCache) throws SystemException {
752         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
753 
754         Object result = null;
755 
756         if (retrieveFromCache) {
757             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
758                     finderArgs, this);
759         }
760 
761         if (result == null) {
762             Session session = null;
763 
764             try {
765                 session = openSession();
766 
767                 StringBuilder query = new StringBuilder();
768 
769                 query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
770 
771                 if (uuid == null) {
772                     query.append("calEvent.uuid IS NULL");
773                 }
774                 else {
775                     query.append("calEvent.uuid = ?");
776                 }
777 
778                 query.append(" AND ");
779 
780                 query.append("calEvent.groupId = ?");
781 
782                 query.append(" ");
783 
784                 query.append("ORDER BY ");
785 
786                 query.append("calEvent.startDate ASC, ");
787                 query.append("calEvent.title ASC");
788 
789                 Query q = session.createQuery(query.toString());
790 
791                 QueryPos qPos = QueryPos.getInstance(q);
792 
793                 if (uuid != null) {
794                     qPos.add(uuid);
795                 }
796 
797                 qPos.add(groupId);
798 
799                 List<CalEvent> list = q.list();
800 
801                 result = list;
802 
803                 CalEvent calEvent = null;
804 
805                 if (list.isEmpty()) {
806                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
807                         finderArgs, list);
808                 }
809                 else {
810                     calEvent = list.get(0);
811 
812                     cacheResult(calEvent);
813 
814                     if ((calEvent.getUuid() == null) ||
815                             !calEvent.getUuid().equals(uuid) ||
816                             (calEvent.getGroupId() != groupId)) {
817                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
818                             finderArgs, calEvent);
819                     }
820                 }
821 
822                 return calEvent;
823             }
824             catch (Exception e) {
825                 throw processException(e);
826             }
827             finally {
828                 if (result == null) {
829                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
830                         finderArgs, new ArrayList<CalEvent>());
831                 }
832 
833                 closeSession(session);
834             }
835         }
836         else {
837             if (result instanceof List) {
838                 return null;
839             }
840             else {
841                 return (CalEvent)result;
842             }
843         }
844     }
845 
846     public List<CalEvent> findByGroupId(long groupId) throws SystemException {
847         Object[] finderArgs = new Object[] { new Long(groupId) };
848 
849         List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
850                 finderArgs, this);
851 
852         if (list == null) {
853             Session session = null;
854 
855             try {
856                 session = openSession();
857 
858                 StringBuilder query = new StringBuilder();
859 
860                 query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
861 
862                 query.append("calEvent.groupId = ?");
863 
864                 query.append(" ");
865 
866                 query.append("ORDER BY ");
867 
868                 query.append("calEvent.startDate ASC, ");
869                 query.append("calEvent.title ASC");
870 
871                 Query q = session.createQuery(query.toString());
872 
873                 QueryPos qPos = QueryPos.getInstance(q);
874 
875                 qPos.add(groupId);
876 
877                 list = q.list();
878             }
879             catch (Exception e) {
880                 throw processException(e);
881             }
882             finally {
883                 if (list == null) {
884                     list = new ArrayList<CalEvent>();
885                 }
886 
887                 cacheResult(list);
888 
889                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
890                     finderArgs, list);
891 
892                 closeSession(session);
893             }
894         }
895 
896         return list;
897     }
898 
899     public List<CalEvent> findByGroupId(long groupId, int start, int end)
900         throws SystemException {
901         return findByGroupId(groupId, start, end, null);
902     }
903 
904     public List<CalEvent> findByGroupId(long groupId, int start, int end,
905         OrderByComparator obc) throws SystemException {
906         Object[] finderArgs = new Object[] {
907                 new Long(groupId),
908                 
909                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
910             };
911 
912         List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
913                 finderArgs, this);
914 
915         if (list == null) {
916             Session session = null;
917 
918             try {
919                 session = openSession();
920 
921                 StringBuilder query = new StringBuilder();
922 
923                 query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
924 
925                 query.append("calEvent.groupId = ?");
926 
927                 query.append(" ");
928 
929                 if (obc != null) {
930                     query.append("ORDER BY ");
931 
932                     String[] orderByFields = obc.getOrderByFields();
933 
934                     for (int i = 0; i < orderByFields.length; i++) {
935                         query.append("calEvent.");
936                         query.append(orderByFields[i]);
937 
938                         if (obc.isAscending()) {
939                             query.append(" ASC");
940                         }
941                         else {
942                             query.append(" DESC");
943                         }
944 
945                         if ((i + 1) < orderByFields.length) {
946                             query.append(", ");
947                         }
948                     }
949                 }
950 
951                 else {
952                     query.append("ORDER BY ");
953 
954                     query.append("calEvent.startDate ASC, ");
955                     query.append("calEvent.title ASC");
956                 }
957 
958                 Query q = session.createQuery(query.toString());
959 
960                 QueryPos qPos = QueryPos.getInstance(q);
961 
962                 qPos.add(groupId);
963 
964                 list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
965                         end);
966             }
967             catch (Exception e) {
968                 throw processException(e);
969             }
970             finally {
971                 if (list == null) {
972                     list = new ArrayList<CalEvent>();
973                 }
974 
975                 cacheResult(list);
976 
977                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
978                     finderArgs, list);
979 
980                 closeSession(session);
981             }
982         }
983 
984         return list;
985     }
986 
987     public CalEvent findByGroupId_First(long groupId, OrderByComparator obc)
988         throws NoSuchEventException, SystemException {
989         List<CalEvent> list = findByGroupId(groupId, 0, 1, obc);
990 
991         if (list.isEmpty()) {
992             StringBuilder msg = new StringBuilder();
993 
994             msg.append("No CalEvent exists with the key {");
995 
996             msg.append("groupId=" + groupId);
997 
998             msg.append(StringPool.CLOSE_CURLY_BRACE);
999 
1000            throw new NoSuchEventException(msg.toString());
1001        }
1002        else {
1003            return list.get(0);
1004        }
1005    }
1006
1007    public CalEvent findByGroupId_Last(long groupId, OrderByComparator obc)
1008        throws NoSuchEventException, SystemException {
1009        int count = countByGroupId(groupId);
1010
1011        List<CalEvent> list = findByGroupId(groupId, count - 1, count, obc);
1012
1013        if (list.isEmpty()) {
1014            StringBuilder msg = new StringBuilder();
1015
1016            msg.append("No CalEvent exists with the key {");
1017
1018            msg.append("groupId=" + groupId);
1019
1020            msg.append(StringPool.CLOSE_CURLY_BRACE);
1021
1022            throw new NoSuchEventException(msg.toString());
1023        }
1024        else {
1025            return list.get(0);
1026        }
1027    }
1028
1029    public CalEvent[] findByGroupId_PrevAndNext(long eventId, long groupId,
1030        OrderByComparator obc) throws NoSuchEventException, SystemException {
1031        CalEvent calEvent = findByPrimaryKey(eventId);
1032
1033        int count = countByGroupId(groupId);
1034
1035        Session session = null;
1036
1037        try {
1038            session = openSession();
1039
1040            StringBuilder query = new StringBuilder();
1041
1042            query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1043
1044            query.append("calEvent.groupId = ?");
1045
1046            query.append(" ");
1047
1048            if (obc != null) {
1049                query.append("ORDER BY ");
1050
1051                String[] orderByFields = obc.getOrderByFields();
1052
1053                for (int i = 0; i < orderByFields.length; i++) {
1054                    query.append("calEvent.");
1055                    query.append(orderByFields[i]);
1056
1057                    if (obc.isAscending()) {
1058                        query.append(" ASC");
1059                    }
1060                    else {
1061                        query.append(" DESC");
1062                    }
1063
1064                    if ((i + 1) < orderByFields.length) {
1065                        query.append(", ");
1066                    }
1067                }
1068            }
1069
1070            else {
1071                query.append("ORDER BY ");
1072
1073                query.append("calEvent.startDate ASC, ");
1074                query.append("calEvent.title ASC");
1075            }
1076
1077            Query q = session.createQuery(query.toString());
1078
1079            QueryPos qPos = QueryPos.getInstance(q);
1080
1081            qPos.add(groupId);
1082
1083            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
1084
1085            CalEvent[] array = new CalEventImpl[3];
1086
1087            array[0] = (CalEvent)objArray[0];
1088            array[1] = (CalEvent)objArray[1];
1089            array[2] = (CalEvent)objArray[2];
1090
1091            return array;
1092        }
1093        catch (Exception e) {
1094            throw processException(e);
1095        }
1096        finally {
1097            closeSession(session);
1098        }
1099    }
1100
1101    public List<CalEvent> findByRemindBy(int remindBy)
1102        throws SystemException {
1103        Object[] finderArgs = new Object[] { new Integer(remindBy) };
1104
1105        List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_REMINDBY,
1106                finderArgs, this);
1107
1108        if (list == null) {
1109            Session session = null;
1110
1111            try {
1112                session = openSession();
1113
1114                StringBuilder query = new StringBuilder();
1115
1116                query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1117
1118                query.append("calEvent.remindBy != ?");
1119
1120                query.append(" ");
1121
1122                query.append("ORDER BY ");
1123
1124                query.append("calEvent.startDate ASC, ");
1125                query.append("calEvent.title ASC");
1126
1127                Query q = session.createQuery(query.toString());
1128
1129                QueryPos qPos = QueryPos.getInstance(q);
1130
1131                qPos.add(remindBy);
1132
1133                list = q.list();
1134            }
1135            catch (Exception e) {
1136                throw processException(e);
1137            }
1138            finally {
1139                if (list == null) {
1140                    list = new ArrayList<CalEvent>();
1141                }
1142
1143                cacheResult(list);
1144
1145                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_REMINDBY,
1146                    finderArgs, list);
1147
1148                closeSession(session);
1149            }
1150        }
1151
1152        return list;
1153    }
1154
1155    public List<CalEvent> findByRemindBy(int remindBy, int start, int end)
1156        throws SystemException {
1157        return findByRemindBy(remindBy, start, end, null);
1158    }
1159
1160    public List<CalEvent> findByRemindBy(int remindBy, int start, int end,
1161        OrderByComparator obc) throws SystemException {
1162        Object[] finderArgs = new Object[] {
1163                new Integer(remindBy),
1164                
1165                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1166            };
1167
1168        List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_REMINDBY,
1169                finderArgs, this);
1170
1171        if (list == null) {
1172            Session session = null;
1173
1174            try {
1175                session = openSession();
1176
1177                StringBuilder query = new StringBuilder();
1178
1179                query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1180
1181                query.append("calEvent.remindBy != ?");
1182
1183                query.append(" ");
1184
1185                if (obc != null) {
1186                    query.append("ORDER BY ");
1187
1188                    String[] orderByFields = obc.getOrderByFields();
1189
1190                    for (int i = 0; i < orderByFields.length; i++) {
1191                        query.append("calEvent.");
1192                        query.append(orderByFields[i]);
1193
1194                        if (obc.isAscending()) {
1195                            query.append(" ASC");
1196                        }
1197                        else {
1198                            query.append(" DESC");
1199                        }
1200
1201                        if ((i + 1) < orderByFields.length) {
1202                            query.append(", ");
1203                        }
1204                    }
1205                }
1206
1207                else {
1208                    query.append("ORDER BY ");
1209
1210                    query.append("calEvent.startDate ASC, ");
1211                    query.append("calEvent.title ASC");
1212                }
1213
1214                Query q = session.createQuery(query.toString());
1215
1216                QueryPos qPos = QueryPos.getInstance(q);
1217
1218                qPos.add(remindBy);
1219
1220                list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1221                        end);
1222            }
1223            catch (Exception e) {
1224                throw processException(e);
1225            }
1226            finally {
1227                if (list == null) {
1228                    list = new ArrayList<CalEvent>();
1229                }
1230
1231                cacheResult(list);
1232
1233                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_REMINDBY,
1234                    finderArgs, list);
1235
1236                closeSession(session);
1237            }
1238        }
1239
1240        return list;
1241    }
1242
1243    public CalEvent findByRemindBy_First(int remindBy, OrderByComparator obc)
1244        throws NoSuchEventException, SystemException {
1245        List<CalEvent> list = findByRemindBy(remindBy, 0, 1, obc);
1246
1247        if (list.isEmpty()) {
1248            StringBuilder msg = new StringBuilder();
1249
1250            msg.append("No CalEvent exists with the key {");
1251
1252            msg.append("remindBy=" + remindBy);
1253
1254            msg.append(StringPool.CLOSE_CURLY_BRACE);
1255
1256            throw new NoSuchEventException(msg.toString());
1257        }
1258        else {
1259            return list.get(0);
1260        }
1261    }
1262
1263    public CalEvent findByRemindBy_Last(int remindBy, OrderByComparator obc)
1264        throws NoSuchEventException, SystemException {
1265        int count = countByRemindBy(remindBy);
1266
1267        List<CalEvent> list = findByRemindBy(remindBy, count - 1, count, obc);
1268
1269        if (list.isEmpty()) {
1270            StringBuilder msg = new StringBuilder();
1271
1272            msg.append("No CalEvent exists with the key {");
1273
1274            msg.append("remindBy=" + remindBy);
1275
1276            msg.append(StringPool.CLOSE_CURLY_BRACE);
1277
1278            throw new NoSuchEventException(msg.toString());
1279        }
1280        else {
1281            return list.get(0);
1282        }
1283    }
1284
1285    public CalEvent[] findByRemindBy_PrevAndNext(long eventId, int remindBy,
1286        OrderByComparator obc) throws NoSuchEventException, SystemException {
1287        CalEvent calEvent = findByPrimaryKey(eventId);
1288
1289        int count = countByRemindBy(remindBy);
1290
1291        Session session = null;
1292
1293        try {
1294            session = openSession();
1295
1296            StringBuilder query = new StringBuilder();
1297
1298            query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1299
1300            query.append("calEvent.remindBy != ?");
1301
1302            query.append(" ");
1303
1304            if (obc != null) {
1305                query.append("ORDER BY ");
1306
1307                String[] orderByFields = obc.getOrderByFields();
1308
1309                for (int i = 0; i < orderByFields.length; i++) {
1310                    query.append("calEvent.");
1311                    query.append(orderByFields[i]);
1312
1313                    if (obc.isAscending()) {
1314                        query.append(" ASC");
1315                    }
1316                    else {
1317                        query.append(" DESC");
1318                    }
1319
1320                    if ((i + 1) < orderByFields.length) {
1321                        query.append(", ");
1322                    }
1323                }
1324            }
1325
1326            else {
1327                query.append("ORDER BY ");
1328
1329                query.append("calEvent.startDate ASC, ");
1330                query.append("calEvent.title ASC");
1331            }
1332
1333            Query q = session.createQuery(query.toString());
1334
1335            QueryPos qPos = QueryPos.getInstance(q);
1336
1337            qPos.add(remindBy);
1338
1339            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
1340
1341            CalEvent[] array = new CalEventImpl[3];
1342
1343            array[0] = (CalEvent)objArray[0];
1344            array[1] = (CalEvent)objArray[1];
1345            array[2] = (CalEvent)objArray[2];
1346
1347            return array;
1348        }
1349        catch (Exception e) {
1350            throw processException(e);
1351        }
1352        finally {
1353            closeSession(session);
1354        }
1355    }
1356
1357    public List<CalEvent> findByG_T(long groupId, String type)
1358        throws SystemException {
1359        Object[] finderArgs = new Object[] { new Long(groupId), type };
1360
1361        List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_T,
1362                finderArgs, this);
1363
1364        if (list == null) {
1365            Session session = null;
1366
1367            try {
1368                session = openSession();
1369
1370                StringBuilder query = new StringBuilder();
1371
1372                query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1373
1374                query.append("calEvent.groupId = ?");
1375
1376                query.append(" AND ");
1377
1378                if (type == null) {
1379                    query.append("calEvent.type IS NULL");
1380                }
1381                else {
1382                    query.append("calEvent.type = ?");
1383                }
1384
1385                query.append(" ");
1386
1387                query.append("ORDER BY ");
1388
1389                query.append("calEvent.startDate ASC, ");
1390                query.append("calEvent.title ASC");
1391
1392                Query q = session.createQuery(query.toString());
1393
1394                QueryPos qPos = QueryPos.getInstance(q);
1395
1396                qPos.add(groupId);
1397
1398                if (type != null) {
1399                    qPos.add(type);
1400                }
1401
1402                list = q.list();
1403            }
1404            catch (Exception e) {
1405                throw processException(e);
1406            }
1407            finally {
1408                if (list == null) {
1409                    list = new ArrayList<CalEvent>();
1410                }
1411
1412                cacheResult(list);
1413
1414                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_T, finderArgs,
1415                    list);
1416
1417                closeSession(session);
1418            }
1419        }
1420
1421        return list;
1422    }
1423
1424    public List<CalEvent> findByG_T(long groupId, String type, int start,
1425        int end) throws SystemException {
1426        return findByG_T(groupId, type, start, end, null);
1427    }
1428
1429    public List<CalEvent> findByG_T(long groupId, String type, int start,
1430        int end, OrderByComparator obc) throws SystemException {
1431        Object[] finderArgs = new Object[] {
1432                new Long(groupId),
1433                
1434                type,
1435                
1436                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1437            };
1438
1439        List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_T,
1440                finderArgs, this);
1441
1442        if (list == null) {
1443            Session session = null;
1444
1445            try {
1446                session = openSession();
1447
1448                StringBuilder query = new StringBuilder();
1449
1450                query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1451
1452                query.append("calEvent.groupId = ?");
1453
1454                query.append(" AND ");
1455
1456                if (type == null) {
1457                    query.append("calEvent.type IS NULL");
1458                }
1459                else {
1460                    query.append("calEvent.type = ?");
1461                }
1462
1463                query.append(" ");
1464
1465                if (obc != null) {
1466                    query.append("ORDER BY ");
1467
1468                    String[] orderByFields = obc.getOrderByFields();
1469
1470                    for (int i = 0; i < orderByFields.length; i++) {
1471                        query.append("calEvent.");
1472                        query.append(orderByFields[i]);
1473
1474                        if (obc.isAscending()) {
1475                            query.append(" ASC");
1476                        }
1477                        else {
1478                            query.append(" DESC");
1479                        }
1480
1481                        if ((i + 1) < orderByFields.length) {
1482                            query.append(", ");
1483                        }
1484                    }
1485                }
1486
1487                else {
1488                    query.append("ORDER BY ");
1489
1490                    query.append("calEvent.startDate ASC, ");
1491                    query.append("calEvent.title ASC");
1492                }
1493
1494                Query q = session.createQuery(query.toString());
1495
1496                QueryPos qPos = QueryPos.getInstance(q);
1497
1498                qPos.add(groupId);
1499
1500                if (type != null) {
1501                    qPos.add(type);
1502                }
1503
1504                list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1505                        end);
1506            }
1507            catch (Exception e) {
1508                throw processException(e);
1509            }
1510            finally {
1511                if (list == null) {
1512                    list = new ArrayList<CalEvent>();
1513                }
1514
1515                cacheResult(list);
1516
1517                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_T,
1518                    finderArgs, list);
1519
1520                closeSession(session);
1521            }
1522        }
1523
1524        return list;
1525    }
1526
1527    public CalEvent findByG_T_First(long groupId, String type,
1528        OrderByComparator obc) throws NoSuchEventException, SystemException {
1529        List<CalEvent> list = findByG_T(groupId, type, 0, 1, obc);
1530
1531        if (list.isEmpty()) {
1532            StringBuilder msg = new StringBuilder();
1533
1534            msg.append("No CalEvent exists with the key {");
1535
1536            msg.append("groupId=" + groupId);
1537
1538            msg.append(", ");
1539            msg.append("type=" + type);
1540
1541            msg.append(StringPool.CLOSE_CURLY_BRACE);
1542
1543            throw new NoSuchEventException(msg.toString());
1544        }
1545        else {
1546            return list.get(0);
1547        }
1548    }
1549
1550    public CalEvent findByG_T_Last(long groupId, String type,
1551        OrderByComparator obc) throws NoSuchEventException, SystemException {
1552        int count = countByG_T(groupId, type);
1553
1554        List<CalEvent> list = findByG_T(groupId, type, count - 1, count, obc);
1555
1556        if (list.isEmpty()) {
1557            StringBuilder msg = new StringBuilder();
1558
1559            msg.append("No CalEvent exists with the key {");
1560
1561            msg.append("groupId=" + groupId);
1562
1563            msg.append(", ");
1564            msg.append("type=" + type);
1565
1566            msg.append(StringPool.CLOSE_CURLY_BRACE);
1567
1568            throw new NoSuchEventException(msg.toString());
1569        }
1570        else {
1571            return list.get(0);
1572        }
1573    }
1574
1575    public CalEvent[] findByG_T_PrevAndNext(long eventId, long groupId,
1576        String type, OrderByComparator obc)
1577        throws NoSuchEventException, SystemException {
1578        CalEvent calEvent = findByPrimaryKey(eventId);
1579
1580        int count = countByG_T(groupId, type);
1581
1582        Session session = null;
1583
1584        try {
1585            session = openSession();
1586
1587            StringBuilder query = new StringBuilder();
1588
1589            query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1590
1591            query.append("calEvent.groupId = ?");
1592
1593            query.append(" AND ");
1594
1595            if (type == null) {
1596                query.append("calEvent.type IS NULL");
1597            }
1598            else {
1599                query.append("calEvent.type = ?");
1600            }
1601
1602            query.append(" ");
1603
1604            if (obc != null) {
1605                query.append("ORDER BY ");
1606
1607                String[] orderByFields = obc.getOrderByFields();
1608
1609                for (int i = 0; i < orderByFields.length; i++) {
1610                    query.append("calEvent.");
1611                    query.append(orderByFields[i]);
1612
1613                    if (obc.isAscending()) {
1614                        query.append(" ASC");
1615                    }
1616                    else {
1617                        query.append(" DESC");
1618                    }
1619
1620                    if ((i + 1) < orderByFields.length) {
1621                        query.append(", ");
1622                    }
1623                }
1624            }
1625
1626            else {
1627                query.append("ORDER BY ");
1628
1629                query.append("calEvent.startDate ASC, ");
1630                query.append("calEvent.title ASC");
1631            }
1632
1633            Query q = session.createQuery(query.toString());
1634
1635            QueryPos qPos = QueryPos.getInstance(q);
1636
1637            qPos.add(groupId);
1638
1639            if (type != null) {
1640                qPos.add(type);
1641            }
1642
1643            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
1644
1645            CalEvent[] array = new CalEventImpl[3];
1646
1647            array[0] = (CalEvent)objArray[0];
1648            array[1] = (CalEvent)objArray[1];
1649            array[2] = (CalEvent)objArray[2];
1650
1651            return array;
1652        }
1653        catch (Exception e) {
1654            throw processException(e);
1655        }
1656        finally {
1657            closeSession(session);
1658        }
1659    }
1660
1661    public List<CalEvent> findByG_R(long groupId, boolean repeating)
1662        throws SystemException {
1663        Object[] finderArgs = new Object[] {
1664                new Long(groupId), Boolean.valueOf(repeating)
1665            };
1666
1667        List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_R,
1668                finderArgs, this);
1669
1670        if (list == null) {
1671            Session session = null;
1672
1673            try {
1674                session = openSession();
1675
1676                StringBuilder query = new StringBuilder();
1677
1678                query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1679
1680                query.append("calEvent.groupId = ?");
1681
1682                query.append(" AND ");
1683
1684                query.append("calEvent.repeating = ?");
1685
1686                query.append(" ");
1687
1688                query.append("ORDER BY ");
1689
1690                query.append("calEvent.startDate ASC, ");
1691                query.append("calEvent.title ASC");
1692
1693                Query q = session.createQuery(query.toString());
1694
1695                QueryPos qPos = QueryPos.getInstance(q);
1696
1697                qPos.add(groupId);
1698
1699                qPos.add(repeating);
1700
1701                list = q.list();
1702            }
1703            catch (Exception e) {
1704                throw processException(e);
1705            }
1706            finally {
1707                if (list == null) {
1708                    list = new ArrayList<CalEvent>();
1709                }
1710
1711                cacheResult(list);
1712
1713                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_R, finderArgs,
1714                    list);
1715
1716                closeSession(session);
1717            }
1718        }
1719
1720        return list;
1721    }
1722
1723    public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
1724        int end) throws SystemException {
1725        return findByG_R(groupId, repeating, start, end, null);
1726    }
1727
1728    public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
1729        int end, OrderByComparator obc) throws SystemException {
1730        Object[] finderArgs = new Object[] {
1731                new Long(groupId), Boolean.valueOf(repeating),
1732                
1733                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1734            };
1735
1736        List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_R,
1737                finderArgs, this);
1738
1739        if (list == null) {
1740            Session session = null;
1741
1742            try {
1743                session = openSession();
1744
1745                StringBuilder query = new StringBuilder();
1746
1747                query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1748
1749                query.append("calEvent.groupId = ?");
1750
1751                query.append(" AND ");
1752
1753                query.append("calEvent.repeating = ?");
1754
1755                query.append(" ");
1756
1757                if (obc != null) {
1758                    query.append("ORDER BY ");
1759
1760                    String[] orderByFields = obc.getOrderByFields();
1761
1762                    for (int i = 0; i < orderByFields.length; i++) {
1763                        query.append("calEvent.");
1764                        query.append(orderByFields[i]);
1765
1766                        if (obc.isAscending()) {
1767                            query.append(" ASC");
1768                        }
1769                        else {
1770                            query.append(" DESC");
1771                        }
1772
1773                        if ((i + 1) < orderByFields.length) {
1774                            query.append(", ");
1775                        }
1776                    }
1777                }
1778
1779                else {
1780                    query.append("ORDER BY ");
1781
1782                    query.append("calEvent.startDate ASC, ");
1783                    query.append("calEvent.title ASC");
1784                }
1785
1786                Query q = session.createQuery(query.toString());
1787
1788                QueryPos qPos = QueryPos.getInstance(q);
1789
1790                qPos.add(groupId);
1791
1792                qPos.add(repeating);
1793
1794                list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1795                        end);
1796            }
1797            catch (Exception e) {
1798                throw processException(e);
1799            }
1800            finally {
1801                if (list == null) {
1802                    list = new ArrayList<CalEvent>();
1803                }
1804
1805                cacheResult(list);
1806
1807                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_R,
1808                    finderArgs, list);
1809
1810                closeSession(session);
1811            }
1812        }
1813
1814        return list;
1815    }
1816
1817    public CalEvent findByG_R_First(long groupId, boolean repeating,
1818        OrderByComparator obc) throws NoSuchEventException, SystemException {
1819        List<CalEvent> list = findByG_R(groupId, repeating, 0, 1, obc);
1820
1821        if (list.isEmpty()) {
1822            StringBuilder msg = new StringBuilder();
1823
1824            msg.append("No CalEvent exists with the key {");
1825
1826            msg.append("groupId=" + groupId);
1827
1828            msg.append(", ");
1829            msg.append("repeating=" + repeating);
1830
1831            msg.append(StringPool.CLOSE_CURLY_BRACE);
1832
1833            throw new NoSuchEventException(msg.toString());
1834        }
1835        else {
1836            return list.get(0);
1837        }
1838    }
1839
1840    public CalEvent findByG_R_Last(long groupId, boolean repeating,
1841        OrderByComparator obc) throws NoSuchEventException, SystemException {
1842        int count = countByG_R(groupId, repeating);
1843
1844        List<CalEvent> list = findByG_R(groupId, repeating, count - 1, count,
1845                obc);
1846
1847        if (list.isEmpty()) {
1848            StringBuilder msg = new StringBuilder();
1849
1850            msg.append("No CalEvent exists with the key {");
1851
1852            msg.append("groupId=" + groupId);
1853
1854            msg.append(", ");
1855            msg.append("repeating=" + repeating);
1856
1857            msg.append(StringPool.CLOSE_CURLY_BRACE);
1858
1859            throw new NoSuchEventException(msg.toString());
1860        }
1861        else {
1862            return list.get(0);
1863        }
1864    }
1865
1866    public CalEvent[] findByG_R_PrevAndNext(long eventId, long groupId,
1867        boolean repeating, OrderByComparator obc)
1868        throws NoSuchEventException, SystemException {
1869        CalEvent calEvent = findByPrimaryKey(eventId);
1870
1871        int count = countByG_R(groupId, repeating);
1872
1873        Session session = null;
1874
1875        try {
1876            session = openSession();
1877
1878            StringBuilder query = new StringBuilder();
1879
1880            query.append("SELECT calEvent FROM CalEvent calEvent WHERE ");
1881
1882            query.append("calEvent.groupId = ?");
1883
1884            query.append(" AND ");
1885
1886            query.append("calEvent.repeating = ?");
1887
1888            query.append(" ");
1889
1890            if (obc != null) {
1891                query.append("ORDER BY ");
1892
1893                String[] orderByFields = obc.getOrderByFields();
1894
1895                for (int i = 0; i < orderByFields.length; i++) {
1896                    query.append("calEvent.");
1897                    query.append(orderByFields[i]);
1898
1899                    if (obc.isAscending()) {
1900                        query.append(" ASC");
1901                    }
1902                    else {
1903                        query.append(" DESC");
1904                    }
1905
1906                    if ((i + 1) < orderByFields.length) {
1907                        query.append(", ");
1908                    }
1909                }
1910            }
1911
1912            else {
1913                query.append("ORDER BY ");
1914
1915                query.append("calEvent.startDate ASC, ");
1916                query.append("calEvent.title ASC");
1917            }
1918
1919            Query q = session.createQuery(query.toString());
1920
1921            QueryPos qPos = QueryPos.getInstance(q);
1922
1923            qPos.add(groupId);
1924
1925            qPos.add(repeating);
1926
1927            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
1928
1929            CalEvent[] array = new CalEventImpl[3];
1930
1931            array[0] = (CalEvent)objArray[0];
1932            array[1] = (CalEvent)objArray[1];
1933            array[2] = (CalEvent)objArray[2];
1934
1935            return array;
1936        }
1937        catch (Exception e) {
1938            throw processException(e);
1939        }
1940        finally {
1941            closeSession(session);
1942        }
1943    }
1944
1945    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1946        throws SystemException {
1947        Session session = null;
1948
1949        try {
1950            session = openSession();
1951
1952            dynamicQuery.compile(session);
1953
1954            return dynamicQuery.list();
1955        }
1956        catch (Exception e) {
1957            throw processException(e);
1958        }
1959        finally {
1960            closeSession(session);
1961        }
1962    }
1963
1964    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1965        int start, int end) throws SystemException {
1966        Session session = null;
1967
1968        try {
1969            session = openSession();
1970
1971            dynamicQuery.setLimit(start, end);
1972
1973            dynamicQuery.compile(session);
1974
1975            return dynamicQuery.list();
1976        }
1977        catch (Exception e) {
1978            throw processException(e);
1979        }
1980        finally {
1981            closeSession(session);
1982        }
1983    }
1984
1985    public List<CalEvent> findAll() throws SystemException {
1986        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1987    }
1988
1989    public List<CalEvent> findAll(int start, int end) throws SystemException {
1990        return findAll(start, end, null);
1991    }
1992
1993    public List<CalEvent> findAll(int start, int end, OrderByComparator obc)
1994        throws SystemException {
1995        Object[] finderArgs = new Object[] {
1996                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1997            };
1998
1999        List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2000                finderArgs, this);
2001
2002        if (list == null) {
2003            Session session = null;
2004
2005            try {
2006                session = openSession();
2007
2008                StringBuilder query = new StringBuilder();
2009
2010                query.append("SELECT calEvent FROM CalEvent calEvent ");
2011
2012                if (obc != null) {
2013                    query.append("ORDER BY ");
2014
2015                    String[] orderByFields = obc.getOrderByFields();
2016
2017                    for (int i = 0; i < orderByFields.length; i++) {
2018                        query.append("calEvent.");
2019                        query.append(orderByFields[i]);
2020
2021                        if (obc.isAscending()) {
2022                            query.append(" ASC");
2023                        }
2024                        else {
2025                            query.append(" DESC");
2026                        }
2027
2028                        if ((i + 1) < orderByFields.length) {
2029                            query.append(", ");
2030                        }
2031                    }
2032                }
2033
2034                else {
2035                    query.append("ORDER BY ");
2036
2037                    query.append("calEvent.startDate ASC, ");
2038                    query.append("calEvent.title ASC");
2039                }
2040
2041                Query q = session.createQuery(query.toString());
2042
2043                if (obc == null) {
2044                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
2045                            start, end, false);
2046
2047                    Collections.sort(list);
2048                }
2049                else {
2050                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
2051                            start, end);
2052                }
2053            }
2054            catch (Exception e) {
2055                throw processException(e);
2056            }
2057            finally {
2058                if (list == null) {
2059                    list = new ArrayList<CalEvent>();
2060                }
2061
2062                cacheResult(list);
2063
2064                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2065
2066                closeSession(session);
2067            }
2068        }
2069
2070        return list;
2071    }
2072
2073    public void removeByUuid(String uuid) throws SystemException {
2074        for (CalEvent calEvent : findByUuid(uuid)) {
2075            remove(calEvent);
2076        }
2077    }
2078
2079    public void removeByUUID_G(String uuid, long groupId)
2080        throws NoSuchEventException, SystemException {
2081        CalEvent calEvent = findByUUID_G(uuid, groupId);
2082
2083        remove(calEvent);
2084    }
2085
2086    public void removeByGroupId(long groupId) throws SystemException {
2087        for (CalEvent calEvent : findByGroupId(groupId)) {
2088            remove(calEvent);
2089        }
2090    }
2091
2092    public void removeByRemindBy(int remindBy) throws SystemException {
2093        for (CalEvent calEvent : findByRemindBy(remindBy)) {
2094            remove(calEvent);
2095        }
2096    }
2097
2098    public void removeByG_T(long groupId, String type)
2099        throws SystemException {
2100        for (CalEvent calEvent : findByG_T(groupId, type)) {
2101            remove(calEvent);
2102        }
2103    }
2104
2105    public void removeByG_R(long groupId, boolean repeating)
2106        throws SystemException {
2107        for (CalEvent calEvent : findByG_R(groupId, repeating)) {
2108            remove(calEvent);
2109        }
2110    }
2111
2112    public void removeAll() throws SystemException {
2113        for (CalEvent calEvent : findAll()) {
2114            remove(calEvent);
2115        }
2116    }
2117
2118    public int countByUuid(String uuid) throws SystemException {
2119        Object[] finderArgs = new Object[] { uuid };
2120
2121        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2122                finderArgs, this);
2123
2124        if (count == null) {
2125            Session session = null;
2126
2127            try {
2128                session = openSession();
2129
2130                StringBuilder query = new StringBuilder();
2131
2132                query.append("SELECT COUNT(calEvent) ");
2133                query.append("FROM CalEvent calEvent WHERE ");
2134
2135                if (uuid == null) {
2136                    query.append("calEvent.uuid IS NULL");
2137                }
2138                else {
2139                    query.append("calEvent.uuid = ?");
2140                }
2141
2142                query.append(" ");
2143
2144                Query q = session.createQuery(query.toString());
2145
2146                QueryPos qPos = QueryPos.getInstance(q);
2147
2148                if (uuid != null) {
2149                    qPos.add(uuid);
2150                }
2151
2152                count = (Long)q.uniqueResult();
2153            }
2154            catch (Exception e) {
2155                throw processException(e);
2156            }
2157            finally {
2158                if (count == null) {
2159                    count = Long.valueOf(0);
2160                }
2161
2162                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2163                    finderArgs, count);
2164
2165                closeSession(session);
2166            }
2167        }
2168
2169        return count.intValue();
2170    }
2171
2172    public int countByUUID_G(String uuid, long groupId)
2173        throws SystemException {
2174        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
2175
2176        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2177                finderArgs, this);
2178
2179        if (count == null) {
2180            Session session = null;
2181
2182            try {
2183                session = openSession();
2184
2185                StringBuilder query = new StringBuilder();
2186
2187                query.append("SELECT COUNT(calEvent) ");
2188                query.append("FROM CalEvent calEvent WHERE ");
2189
2190                if (uuid == null) {
2191                    query.append("calEvent.uuid IS NULL");
2192                }
2193                else {
2194                    query.append("calEvent.uuid = ?");
2195                }
2196
2197                query.append(" AND ");
2198
2199                query.append("calEvent.groupId = ?");
2200
2201                query.append(" ");
2202
2203                Query q = session.createQuery(query.toString());
2204
2205                QueryPos qPos = QueryPos.getInstance(q);
2206
2207                if (uuid != null) {
2208                    qPos.add(uuid);
2209                }
2210
2211                qPos.add(groupId);
2212
2213                count = (Long)q.uniqueResult();
2214            }
2215            catch (Exception e) {
2216                throw processException(e);
2217            }
2218            finally {
2219                if (count == null) {
2220                    count = Long.valueOf(0);
2221                }
2222
2223                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2224                    finderArgs, count);
2225
2226                closeSession(session);
2227            }
2228        }
2229
2230        return count.intValue();
2231    }
2232
2233    public int countByGroupId(long groupId) throws SystemException {
2234        Object[] finderArgs = new Object[] { new Long(groupId) };
2235
2236        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2237                finderArgs, this);
2238
2239        if (count == null) {
2240            Session session = null;
2241
2242            try {
2243                session = openSession();
2244
2245                StringBuilder query = new StringBuilder();
2246
2247                query.append("SELECT COUNT(calEvent) ");
2248                query.append("FROM CalEvent calEvent WHERE ");
2249
2250                query.append("calEvent.groupId = ?");
2251
2252                query.append(" ");
2253
2254                Query q = session.createQuery(query.toString());
2255
2256                QueryPos qPos = QueryPos.getInstance(q);
2257
2258                qPos.add(groupId);
2259
2260                count = (Long)q.uniqueResult();
2261            }
2262            catch (Exception e) {
2263                throw processException(e);
2264            }
2265            finally {
2266                if (count == null) {
2267                    count = Long.valueOf(0);
2268                }
2269
2270                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2271                    finderArgs, count);
2272
2273                closeSession(session);
2274            }
2275        }
2276
2277        return count.intValue();
2278    }
2279
2280    public int countByRemindBy(int remindBy) throws SystemException {
2281        Object[] finderArgs = new Object[] { new Integer(remindBy) };
2282
2283        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_REMINDBY,
2284                finderArgs, this);
2285
2286        if (count == null) {
2287            Session session = null;
2288
2289            try {
2290                session = openSession();
2291
2292                StringBuilder query = new StringBuilder();
2293
2294                query.append("SELECT COUNT(calEvent) ");
2295                query.append("FROM CalEvent calEvent WHERE ");
2296
2297                query.append("calEvent.remindBy != ?");
2298
2299                query.append(" ");
2300
2301                Query q = session.createQuery(query.toString());
2302
2303                QueryPos qPos = QueryPos.getInstance(q);
2304
2305                qPos.add(remindBy);
2306
2307                count = (Long)q.uniqueResult();
2308            }
2309            catch (Exception e) {
2310                throw processException(e);
2311            }
2312            finally {
2313                if (count == null) {
2314                    count = Long.valueOf(0);
2315                }
2316
2317                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_REMINDBY,
2318                    finderArgs, count);
2319
2320                closeSession(session);
2321            }
2322        }
2323
2324        return count.intValue();
2325    }
2326
2327    public int countByG_T(long groupId, String type) throws SystemException {
2328        Object[] finderArgs = new Object[] { new Long(groupId), type };
2329
2330        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
2331                finderArgs, this);
2332
2333        if (count == null) {
2334            Session session = null;
2335
2336            try {
2337                session = openSession();
2338
2339                StringBuilder query = new StringBuilder();
2340
2341                query.append("SELECT COUNT(calEvent) ");
2342                query.append("FROM CalEvent calEvent WHERE ");
2343
2344                query.append("calEvent.groupId = ?");
2345
2346                query.append(" AND ");
2347
2348                if (type == null) {
2349                    query.append("calEvent.type IS NULL");
2350                }
2351                else {
2352                    query.append("calEvent.type = ?");
2353                }
2354
2355                query.append(" ");
2356
2357                Query q = session.createQuery(query.toString());
2358
2359                QueryPos qPos = QueryPos.getInstance(q);
2360
2361                qPos.add(groupId);
2362
2363                if (type != null) {
2364                    qPos.add(type);
2365                }
2366
2367                count = (Long)q.uniqueResult();
2368            }
2369            catch (Exception e) {
2370                throw processException(e);
2371            }
2372            finally {
2373                if (count == null) {
2374                    count = Long.valueOf(0);
2375                }
2376
2377                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
2378                    count);
2379
2380                closeSession(session);
2381            }
2382        }
2383
2384        return count.intValue();
2385    }
2386
2387    public int countByG_R(long groupId, boolean repeating)
2388        throws SystemException {
2389        Object[] finderArgs = new Object[] {
2390                new Long(groupId), Boolean.valueOf(repeating)
2391            };
2392
2393        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_R,
2394                finderArgs, this);
2395
2396        if (count == null) {
2397            Session session = null;
2398
2399            try {
2400                session = openSession();
2401
2402                StringBuilder query = new StringBuilder();
2403
2404                query.append("SELECT COUNT(calEvent) ");
2405                query.append("FROM CalEvent calEvent WHERE ");
2406
2407                query.append("calEvent.groupId = ?");
2408
2409                query.append(" AND ");
2410
2411                query.append("calEvent.repeating = ?");
2412
2413                query.append(" ");
2414
2415                Query q = session.createQuery(query.toString());
2416
2417                QueryPos qPos = QueryPos.getInstance(q);
2418
2419                qPos.add(groupId);
2420
2421                qPos.add(repeating);
2422
2423                count = (Long)q.uniqueResult();
2424            }
2425            catch (Exception e) {
2426                throw processException(e);
2427            }
2428            finally {
2429                if (count == null) {
2430                    count = Long.valueOf(0);
2431                }
2432
2433                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_R, finderArgs,
2434                    count);
2435
2436                closeSession(session);
2437            }
2438        }
2439
2440        return count.intValue();
2441    }
2442
2443    public int countAll() throws SystemException {
2444        Object[] finderArgs = new Object[0];
2445
2446        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2447                finderArgs, this);
2448
2449        if (count == null) {
2450            Session session = null;
2451
2452            try {
2453                session = openSession();
2454
2455                Query q = session.createQuery(
2456                        "SELECT COUNT(calEvent) FROM CalEvent calEvent");
2457
2458                count = (Long)q.uniqueResult();
2459            }
2460            catch (Exception e) {
2461                throw processException(e);
2462            }
2463            finally {
2464                if (count == null) {
2465                    count = Long.valueOf(0);
2466                }
2467
2468                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2469                    count);
2470
2471                closeSession(session);
2472            }
2473        }
2474
2475        return count.intValue();
2476    }
2477
2478    public void afterPropertiesSet() {
2479        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2480                    com.liferay.portal.util.PropsUtil.get(
2481                        "value.object.listener.com.liferay.portlet.calendar.model.CalEvent")));
2482
2483        if (listenerClassNames.length > 0) {
2484            try {
2485                List<ModelListener<CalEvent>> listenersList = new ArrayList<ModelListener<CalEvent>>();
2486
2487                for (String listenerClassName : listenerClassNames) {
2488                    listenersList.add((ModelListener<CalEvent>)Class.forName(
2489                            listenerClassName).newInstance());
2490                }
2491
2492                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2493            }
2494            catch (Exception e) {
2495                _log.error(e);
2496            }
2497        }
2498    }
2499
2500    @BeanReference(name = "com.liferay.portlet.calendar.service.persistence.CalEventPersistence.impl")
2501    protected com.liferay.portlet.calendar.service.persistence.CalEventPersistence calEventPersistence;
2502    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
2503    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
2504    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
2505    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
2506    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2507    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2508    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence.impl")
2509    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
2510    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2511    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2512    private static Log _log = LogFactoryUtil.getLog(CalEventPersistenceImpl.class);
2513}