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