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