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