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