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