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