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