001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.calendar.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.CompanyPersistence;
043    import com.liferay.portal.service.persistence.GroupPersistence;
044    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
045    import com.liferay.portal.service.persistence.ResourcePersistence;
046    import com.liferay.portal.service.persistence.UserPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
050    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
051    import com.liferay.portlet.calendar.NoSuchEventException;
052    import com.liferay.portlet.calendar.model.CalEvent;
053    import com.liferay.portlet.calendar.model.impl.CalEventImpl;
054    import com.liferay.portlet.calendar.model.impl.CalEventModelImpl;
055    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
056    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
057    
058    import java.io.Serializable;
059    
060    import java.util.ArrayList;
061    import java.util.Collections;
062    import java.util.List;
063    
064    /**
065     * The persistence implementation for the cal event service.
066     *
067     * <p>
068     * Never modify or reference this class directly. Always use {@link CalEventUtil} to access the cal event persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069     * </p>
070     *
071     * <p>
072     * Caching information and settings can be found in <code>portal.properties</code>
073     * </p>
074     *
075     * @author Brian Wing Shun Chan
076     * @see CalEventPersistence
077     * @see CalEventUtil
078     * @generated
079     */
080    public class CalEventPersistenceImpl extends BasePersistenceImpl<CalEvent>
081            implements CalEventPersistence {
082            public static final String FINDER_CLASS_NAME_ENTITY = CalEventImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
084                    ".List";
085            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
086                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087                            "findByUuid",
088                            new String[] {
089                                    String.class.getName(),
090                                    
091                            "java.lang.Integer", "java.lang.Integer",
092                                    "com.liferay.portal.kernel.util.OrderByComparator"
093                            });
094            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
095                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
096                            "countByUuid", new String[] { String.class.getName() });
097            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
098                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
099                            "fetchByUUID_G",
100                            new String[] { String.class.getName(), Long.class.getName() });
101            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
102                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103                            "countByUUID_G",
104                            new String[] { String.class.getName(), Long.class.getName() });
105            public static final FinderPath FINDER_PATH_FIND_BY_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",
120                            new String[] {
121                                    Long.class.getName(),
122                                    
123                            "java.lang.Integer", "java.lang.Integer",
124                                    "com.liferay.portal.kernel.util.OrderByComparator"
125                            });
126            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
127                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
128                            "countByGroupId", new String[] { Long.class.getName() });
129            public static final FinderPath FINDER_PATH_FIND_BY_NOTREMINDBY = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
130                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
131                            "findByNotRemindBy",
132                            new String[] {
133                                    Integer.class.getName(),
134                                    
135                            "java.lang.Integer", "java.lang.Integer",
136                                    "com.liferay.portal.kernel.util.OrderByComparator"
137                            });
138            public static final FinderPath FINDER_PATH_COUNT_BY_NOTREMINDBY = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
139                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
140                            "countByNotRemindBy", new String[] { Integer.class.getName() });
141            public static final FinderPath FINDER_PATH_FIND_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
142                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
143                            "findByG_T",
144                            new String[] {
145                                    Long.class.getName(), String.class.getName(),
146                                    
147                            "java.lang.Integer", "java.lang.Integer",
148                                    "com.liferay.portal.kernel.util.OrderByComparator"
149                            });
150            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
151                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
152                            "countByG_T",
153                            new String[] { Long.class.getName(), String.class.getName() });
154            public static final FinderPath FINDER_PATH_FIND_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
155                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
156                            "findByG_R",
157                            new String[] {
158                                    Long.class.getName(), Boolean.class.getName(),
159                                    
160                            "java.lang.Integer", "java.lang.Integer",
161                                    "com.liferay.portal.kernel.util.OrderByComparator"
162                            });
163            public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
164                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
165                            "countByG_R",
166                            new String[] { Long.class.getName(), Boolean.class.getName() });
167            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
168                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
169                            "findAll", new String[0]);
170            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
171                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
172                            "countAll", new String[0]);
173    
174            /**
175             * Caches the cal event in the entity cache if it is enabled.
176             *
177             * @param calEvent the cal event to cache
178             */
179            public void cacheResult(CalEvent calEvent) {
180                    EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
181                            CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
182    
183                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
184                            new Object[] { calEvent.getUuid(), new Long(calEvent.getGroupId()) },
185                            calEvent);
186            }
187    
188            /**
189             * Caches the cal events in the entity cache if it is enabled.
190             *
191             * @param calEvents the cal events to cache
192             */
193            public void cacheResult(List<CalEvent> calEvents) {
194                    for (CalEvent calEvent : calEvents) {
195                            if (EntityCacheUtil.getResult(
196                                                    CalEventModelImpl.ENTITY_CACHE_ENABLED,
197                                                    CalEventImpl.class, calEvent.getPrimaryKey(), this) == null) {
198                                    cacheResult(calEvent);
199                            }
200                    }
201            }
202    
203            /**
204             * Clears the cache for all cal events.
205             *
206             * <p>
207             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
208             * </p>
209             */
210            public void clearCache() {
211                    CacheRegistryUtil.clear(CalEventImpl.class.getName());
212                    EntityCacheUtil.clearCache(CalEventImpl.class.getName());
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
214                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
215            }
216    
217            /**
218             * Clears the cache for the cal event.
219             *
220             * <p>
221             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
222             * </p>
223             */
224            public void clearCache(CalEvent calEvent) {
225                    EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
226                            CalEventImpl.class, calEvent.getPrimaryKey());
227    
228                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
229                            new Object[] { calEvent.getUuid(), new Long(calEvent.getGroupId()) });
230            }
231    
232            /**
233             * Creates a new cal event with the primary key. Does not add the cal event to the database.
234             *
235             * @param eventId the primary key for the new cal event
236             * @return the new cal event
237             */
238            public CalEvent create(long eventId) {
239                    CalEvent calEvent = new CalEventImpl();
240    
241                    calEvent.setNew(true);
242                    calEvent.setPrimaryKey(eventId);
243    
244                    String uuid = PortalUUIDUtil.generate();
245    
246                    calEvent.setUuid(uuid);
247    
248                    return calEvent;
249            }
250    
251            /**
252             * Removes the cal event with the primary key from the database. Also notifies the appropriate model listeners.
253             *
254             * @param primaryKey the primary key of the cal event to remove
255             * @return the cal event that was removed
256             * @throws com.liferay.portal.NoSuchModelException if a cal event with the primary key could not be found
257             * @throws SystemException if a system exception occurred
258             */
259            public CalEvent remove(Serializable primaryKey)
260                    throws NoSuchModelException, SystemException {
261                    return remove(((Long)primaryKey).longValue());
262            }
263    
264            /**
265             * Removes the cal event with the primary key from the database. Also notifies the appropriate model listeners.
266             *
267             * @param eventId the primary key of the cal event to remove
268             * @return the cal event that was removed
269             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
270             * @throws SystemException if a system exception occurred
271             */
272            public CalEvent remove(long eventId)
273                    throws NoSuchEventException, SystemException {
274                    Session session = null;
275    
276                    try {
277                            session = openSession();
278    
279                            CalEvent calEvent = (CalEvent)session.get(CalEventImpl.class,
280                                            new Long(eventId));
281    
282                            if (calEvent == null) {
283                                    if (_log.isWarnEnabled()) {
284                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + eventId);
285                                    }
286    
287                                    throw new NoSuchEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
288                                            eventId);
289                            }
290    
291                            return remove(calEvent);
292                    }
293                    catch (NoSuchEventException nsee) {
294                            throw nsee;
295                    }
296                    catch (Exception e) {
297                            throw processException(e);
298                    }
299                    finally {
300                            closeSession(session);
301                    }
302            }
303    
304            protected CalEvent removeImpl(CalEvent calEvent) throws SystemException {
305                    calEvent = toUnwrappedModel(calEvent);
306    
307                    Session session = null;
308    
309                    try {
310                            session = openSession();
311    
312                            if (calEvent.isCachedModel() || BatchSessionUtil.isEnabled()) {
313                                    Object staleObject = session.get(CalEventImpl.class,
314                                                    calEvent.getPrimaryKeyObj());
315    
316                                    if (staleObject != null) {
317                                            session.evict(staleObject);
318                                    }
319                            }
320    
321                            session.delete(calEvent);
322    
323                            session.flush();
324                    }
325                    catch (Exception e) {
326                            throw processException(e);
327                    }
328                    finally {
329                            closeSession(session);
330                    }
331    
332                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
333    
334                    CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
335    
336                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
337                            new Object[] {
338                                    calEventModelImpl.getOriginalUuid(),
339                                    new Long(calEventModelImpl.getOriginalGroupId())
340                            });
341    
342                    EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
343                            CalEventImpl.class, calEvent.getPrimaryKey());
344    
345                    return calEvent;
346            }
347    
348            public CalEvent updateImpl(
349                    com.liferay.portlet.calendar.model.CalEvent calEvent, boolean merge)
350                    throws SystemException {
351                    calEvent = toUnwrappedModel(calEvent);
352    
353                    boolean isNew = calEvent.isNew();
354    
355                    CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
356    
357                    if (Validator.isNull(calEvent.getUuid())) {
358                            String uuid = PortalUUIDUtil.generate();
359    
360                            calEvent.setUuid(uuid);
361                    }
362    
363                    Session session = null;
364    
365                    try {
366                            session = openSession();
367    
368                            BatchSessionUtil.update(session, calEvent, merge);
369    
370                            calEvent.setNew(false);
371                    }
372                    catch (Exception e) {
373                            throw processException(e);
374                    }
375                    finally {
376                            closeSession(session);
377                    }
378    
379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
380    
381                    EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
382                            CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
383    
384                    if (!isNew &&
385                                    (!Validator.equals(calEvent.getUuid(),
386                                            calEventModelImpl.getOriginalUuid()) ||
387                                    (calEvent.getGroupId() != calEventModelImpl.getOriginalGroupId()))) {
388                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
389                                    new Object[] {
390                                            calEventModelImpl.getOriginalUuid(),
391                                            new Long(calEventModelImpl.getOriginalGroupId())
392                                    });
393                    }
394    
395                    if (isNew ||
396                                    (!Validator.equals(calEvent.getUuid(),
397                                            calEventModelImpl.getOriginalUuid()) ||
398                                    (calEvent.getGroupId() != calEventModelImpl.getOriginalGroupId()))) {
399                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
400                                    new Object[] { calEvent.getUuid(), new Long(
401                                                    calEvent.getGroupId()) }, calEvent);
402                    }
403    
404                    return calEvent;
405            }
406    
407            protected CalEvent toUnwrappedModel(CalEvent calEvent) {
408                    if (calEvent instanceof CalEventImpl) {
409                            return calEvent;
410                    }
411    
412                    CalEventImpl calEventImpl = new CalEventImpl();
413    
414                    calEventImpl.setNew(calEvent.isNew());
415                    calEventImpl.setPrimaryKey(calEvent.getPrimaryKey());
416    
417                    calEventImpl.setUuid(calEvent.getUuid());
418                    calEventImpl.setEventId(calEvent.getEventId());
419                    calEventImpl.setGroupId(calEvent.getGroupId());
420                    calEventImpl.setCompanyId(calEvent.getCompanyId());
421                    calEventImpl.setUserId(calEvent.getUserId());
422                    calEventImpl.setUserName(calEvent.getUserName());
423                    calEventImpl.setCreateDate(calEvent.getCreateDate());
424                    calEventImpl.setModifiedDate(calEvent.getModifiedDate());
425                    calEventImpl.setTitle(calEvent.getTitle());
426                    calEventImpl.setDescription(calEvent.getDescription());
427                    calEventImpl.setStartDate(calEvent.getStartDate());
428                    calEventImpl.setEndDate(calEvent.getEndDate());
429                    calEventImpl.setDurationHour(calEvent.getDurationHour());
430                    calEventImpl.setDurationMinute(calEvent.getDurationMinute());
431                    calEventImpl.setAllDay(calEvent.isAllDay());
432                    calEventImpl.setTimeZoneSensitive(calEvent.isTimeZoneSensitive());
433                    calEventImpl.setType(calEvent.getType());
434                    calEventImpl.setRepeating(calEvent.isRepeating());
435                    calEventImpl.setRecurrence(calEvent.getRecurrence());
436                    calEventImpl.setRemindBy(calEvent.getRemindBy());
437                    calEventImpl.setFirstReminder(calEvent.getFirstReminder());
438                    calEventImpl.setSecondReminder(calEvent.getSecondReminder());
439    
440                    return calEventImpl;
441            }
442    
443            /**
444             * Finds the cal event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
445             *
446             * @param primaryKey the primary key of the cal event to find
447             * @return the cal event
448             * @throws com.liferay.portal.NoSuchModelException if a cal event with the primary key could not be found
449             * @throws SystemException if a system exception occurred
450             */
451            public CalEvent findByPrimaryKey(Serializable primaryKey)
452                    throws NoSuchModelException, SystemException {
453                    return findByPrimaryKey(((Long)primaryKey).longValue());
454            }
455    
456            /**
457             * Finds the cal event with the primary key or throws a {@link com.liferay.portlet.calendar.NoSuchEventException} if it could not be found.
458             *
459             * @param eventId the primary key of the cal event to find
460             * @return the cal event
461             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
462             * @throws SystemException if a system exception occurred
463             */
464            public CalEvent findByPrimaryKey(long eventId)
465                    throws NoSuchEventException, SystemException {
466                    CalEvent calEvent = fetchByPrimaryKey(eventId);
467    
468                    if (calEvent == null) {
469                            if (_log.isWarnEnabled()) {
470                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + eventId);
471                            }
472    
473                            throw new NoSuchEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
474                                    eventId);
475                    }
476    
477                    return calEvent;
478            }
479    
480            /**
481             * Finds the cal event with the primary key or returns <code>null</code> if it could not be found.
482             *
483             * @param primaryKey the primary key of the cal event to find
484             * @return the cal event, or <code>null</code> if a cal event with the primary key could not be found
485             * @throws SystemException if a system exception occurred
486             */
487            public CalEvent fetchByPrimaryKey(Serializable primaryKey)
488                    throws SystemException {
489                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
490            }
491    
492            /**
493             * Finds the cal event with the primary key or returns <code>null</code> if it could not be found.
494             *
495             * @param eventId the primary key of the cal event to find
496             * @return the cal event, or <code>null</code> if a cal event with the primary key could not be found
497             * @throws SystemException if a system exception occurred
498             */
499            public CalEvent fetchByPrimaryKey(long eventId) throws SystemException {
500                    CalEvent calEvent = (CalEvent)EntityCacheUtil.getResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
501                                    CalEventImpl.class, eventId, this);
502    
503                    if (calEvent == null) {
504                            Session session = null;
505    
506                            try {
507                                    session = openSession();
508    
509                                    calEvent = (CalEvent)session.get(CalEventImpl.class,
510                                                    new Long(eventId));
511                            }
512                            catch (Exception e) {
513                                    throw processException(e);
514                            }
515                            finally {
516                                    if (calEvent != null) {
517                                            cacheResult(calEvent);
518                                    }
519    
520                                    closeSession(session);
521                            }
522                    }
523    
524                    return calEvent;
525            }
526    
527            /**
528             * Finds all the cal events where uuid = &#63;.
529             *
530             * @param uuid the uuid to search with
531             * @return the matching cal events
532             * @throws SystemException if a system exception occurred
533             */
534            public List<CalEvent> findByUuid(String uuid) throws SystemException {
535                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
536            }
537    
538            /**
539             * Finds a range of all the cal events where uuid = &#63;.
540             *
541             * <p>
542             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
543             * </p>
544             *
545             * @param uuid the uuid to search with
546             * @param start the lower bound of the range of cal events to return
547             * @param end the upper bound of the range of cal events to return (not inclusive)
548             * @return the range of matching cal events
549             * @throws SystemException if a system exception occurred
550             */
551            public List<CalEvent> findByUuid(String uuid, int start, int end)
552                    throws SystemException {
553                    return findByUuid(uuid, start, end, null);
554            }
555    
556            /**
557             * Finds an ordered range of all the cal events where uuid = &#63;.
558             *
559             * <p>
560             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
561             * </p>
562             *
563             * @param uuid the uuid to search with
564             * @param start the lower bound of the range of cal events to return
565             * @param end the upper bound of the range of cal events to return (not inclusive)
566             * @param orderByComparator the comparator to order the results by
567             * @return the ordered range of matching cal events
568             * @throws SystemException if a system exception occurred
569             */
570            public List<CalEvent> findByUuid(String uuid, int start, int end,
571                    OrderByComparator orderByComparator) throws SystemException {
572                    Object[] finderArgs = new Object[] {
573                                    uuid,
574                                    
575                                    String.valueOf(start), String.valueOf(end),
576                                    String.valueOf(orderByComparator)
577                            };
578    
579                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
580                                    finderArgs, this);
581    
582                    if (list == null) {
583                            Session session = null;
584    
585                            try {
586                                    session = openSession();
587    
588                                    StringBundler query = null;
589    
590                                    if (orderByComparator != null) {
591                                            query = new StringBundler(3 +
592                                                            (orderByComparator.getOrderByFields().length * 3));
593                                    }
594                                    else {
595                                            query = new StringBundler(3);
596                                    }
597    
598                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
599    
600                                    if (uuid == null) {
601                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
602                                    }
603                                    else {
604                                            if (uuid.equals(StringPool.BLANK)) {
605                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
606                                            }
607                                            else {
608                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
609                                            }
610                                    }
611    
612                                    if (orderByComparator != null) {
613                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
614                                                    orderByComparator);
615                                    }
616    
617                                    else {
618                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
619                                    }
620    
621                                    String sql = query.toString();
622    
623                                    Query q = session.createQuery(sql);
624    
625                                    QueryPos qPos = QueryPos.getInstance(q);
626    
627                                    if (uuid != null) {
628                                            qPos.add(uuid);
629                                    }
630    
631                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
632                                                    end);
633                            }
634                            catch (Exception e) {
635                                    throw processException(e);
636                            }
637                            finally {
638                                    if (list == null) {
639                                            list = new ArrayList<CalEvent>();
640                                    }
641    
642                                    cacheResult(list);
643    
644                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
645                                            list);
646    
647                                    closeSession(session);
648                            }
649                    }
650    
651                    return list;
652            }
653    
654            /**
655             * Finds the first cal event in the ordered set where uuid = &#63;.
656             *
657             * <p>
658             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
659             * </p>
660             *
661             * @param uuid the uuid to search with
662             * @param orderByComparator the comparator to order the set by
663             * @return the first matching cal event
664             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
665             * @throws SystemException if a system exception occurred
666             */
667            public CalEvent findByUuid_First(String uuid,
668                    OrderByComparator orderByComparator)
669                    throws NoSuchEventException, SystemException {
670                    List<CalEvent> list = findByUuid(uuid, 0, 1, orderByComparator);
671    
672                    if (list.isEmpty()) {
673                            StringBundler msg = new StringBundler(4);
674    
675                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
676    
677                            msg.append("uuid=");
678                            msg.append(uuid);
679    
680                            msg.append(StringPool.CLOSE_CURLY_BRACE);
681    
682                            throw new NoSuchEventException(msg.toString());
683                    }
684                    else {
685                            return list.get(0);
686                    }
687            }
688    
689            /**
690             * Finds the last cal event in the ordered set where uuid = &#63;.
691             *
692             * <p>
693             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
694             * </p>
695             *
696             * @param uuid the uuid to search with
697             * @param orderByComparator the comparator to order the set by
698             * @return the last matching cal event
699             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
700             * @throws SystemException if a system exception occurred
701             */
702            public CalEvent findByUuid_Last(String uuid,
703                    OrderByComparator orderByComparator)
704                    throws NoSuchEventException, SystemException {
705                    int count = countByUuid(uuid);
706    
707                    List<CalEvent> list = findByUuid(uuid, count - 1, count,
708                                    orderByComparator);
709    
710                    if (list.isEmpty()) {
711                            StringBundler msg = new StringBundler(4);
712    
713                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
714    
715                            msg.append("uuid=");
716                            msg.append(uuid);
717    
718                            msg.append(StringPool.CLOSE_CURLY_BRACE);
719    
720                            throw new NoSuchEventException(msg.toString());
721                    }
722                    else {
723                            return list.get(0);
724                    }
725            }
726    
727            /**
728             * Finds the cal events before and after the current cal event in the ordered set where uuid = &#63;.
729             *
730             * <p>
731             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
732             * </p>
733             *
734             * @param eventId the primary key of the current cal event
735             * @param uuid the uuid to search with
736             * @param orderByComparator the comparator to order the set by
737             * @return the previous, current, and next cal event
738             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
739             * @throws SystemException if a system exception occurred
740             */
741            public CalEvent[] findByUuid_PrevAndNext(long eventId, String uuid,
742                    OrderByComparator orderByComparator)
743                    throws NoSuchEventException, SystemException {
744                    CalEvent calEvent = findByPrimaryKey(eventId);
745    
746                    Session session = null;
747    
748                    try {
749                            session = openSession();
750    
751                            CalEvent[] array = new CalEventImpl[3];
752    
753                            array[0] = getByUuid_PrevAndNext(session, calEvent, uuid,
754                                            orderByComparator, true);
755    
756                            array[1] = calEvent;
757    
758                            array[2] = getByUuid_PrevAndNext(session, calEvent, uuid,
759                                            orderByComparator, false);
760    
761                            return array;
762                    }
763                    catch (Exception e) {
764                            throw processException(e);
765                    }
766                    finally {
767                            closeSession(session);
768                    }
769            }
770    
771            protected CalEvent getByUuid_PrevAndNext(Session session,
772                    CalEvent calEvent, String uuid, OrderByComparator orderByComparator,
773                    boolean previous) {
774                    StringBundler query = null;
775    
776                    if (orderByComparator != null) {
777                            query = new StringBundler(6 +
778                                            (orderByComparator.getOrderByFields().length * 6));
779                    }
780                    else {
781                            query = new StringBundler(3);
782                    }
783    
784                    query.append(_SQL_SELECT_CALEVENT_WHERE);
785    
786                    if (uuid == null) {
787                            query.append(_FINDER_COLUMN_UUID_UUID_1);
788                    }
789                    else {
790                            if (uuid.equals(StringPool.BLANK)) {
791                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
792                            }
793                            else {
794                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
795                            }
796                    }
797    
798                    if (orderByComparator != null) {
799                            String[] orderByFields = orderByComparator.getOrderByFields();
800    
801                            if (orderByFields.length > 0) {
802                                    query.append(WHERE_AND);
803                            }
804    
805                            for (int i = 0; i < orderByFields.length; i++) {
806                                    query.append(_ORDER_BY_ENTITY_ALIAS);
807                                    query.append(orderByFields[i]);
808    
809                                    if ((i + 1) < orderByFields.length) {
810                                            if (orderByComparator.isAscending() ^ previous) {
811                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
812                                            }
813                                            else {
814                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
815                                            }
816                                    }
817                                    else {
818                                            if (orderByComparator.isAscending() ^ previous) {
819                                                    query.append(WHERE_GREATER_THAN);
820                                            }
821                                            else {
822                                                    query.append(WHERE_LESSER_THAN);
823                                            }
824                                    }
825                            }
826    
827                            query.append(ORDER_BY_CLAUSE);
828    
829                            for (int i = 0; i < orderByFields.length; i++) {
830                                    query.append(_ORDER_BY_ENTITY_ALIAS);
831                                    query.append(orderByFields[i]);
832    
833                                    if ((i + 1) < orderByFields.length) {
834                                            if (orderByComparator.isAscending() ^ previous) {
835                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
836                                            }
837                                            else {
838                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
839                                            }
840                                    }
841                                    else {
842                                            if (orderByComparator.isAscending() ^ previous) {
843                                                    query.append(ORDER_BY_ASC);
844                                            }
845                                            else {
846                                                    query.append(ORDER_BY_DESC);
847                                            }
848                                    }
849                            }
850                    }
851    
852                    else {
853                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
854                    }
855    
856                    String sql = query.toString();
857    
858                    Query q = session.createQuery(sql);
859    
860                    q.setFirstResult(0);
861                    q.setMaxResults(2);
862    
863                    QueryPos qPos = QueryPos.getInstance(q);
864    
865                    if (uuid != null) {
866                            qPos.add(uuid);
867                    }
868    
869                    if (orderByComparator != null) {
870                            Object[] values = orderByComparator.getOrderByValues(calEvent);
871    
872                            for (Object value : values) {
873                                    qPos.add(value);
874                            }
875                    }
876    
877                    List<CalEvent> list = q.list();
878    
879                    if (list.size() == 2) {
880                            return list.get(1);
881                    }
882                    else {
883                            return null;
884                    }
885            }
886    
887            /**
888             * Finds the cal event where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.calendar.NoSuchEventException} if it could not be found.
889             *
890             * @param uuid the uuid to search with
891             * @param groupId the group id to search with
892             * @return the matching cal event
893             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
894             * @throws SystemException if a system exception occurred
895             */
896            public CalEvent findByUUID_G(String uuid, long groupId)
897                    throws NoSuchEventException, SystemException {
898                    CalEvent calEvent = fetchByUUID_G(uuid, groupId);
899    
900                    if (calEvent == null) {
901                            StringBundler msg = new StringBundler(6);
902    
903                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
904    
905                            msg.append("uuid=");
906                            msg.append(uuid);
907    
908                            msg.append(", groupId=");
909                            msg.append(groupId);
910    
911                            msg.append(StringPool.CLOSE_CURLY_BRACE);
912    
913                            if (_log.isWarnEnabled()) {
914                                    _log.warn(msg.toString());
915                            }
916    
917                            throw new NoSuchEventException(msg.toString());
918                    }
919    
920                    return calEvent;
921            }
922    
923            /**
924             * Finds the cal event where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
925             *
926             * @param uuid the uuid to search with
927             * @param groupId the group id to search with
928             * @return the matching cal event, or <code>null</code> if a matching cal event could not be found
929             * @throws SystemException if a system exception occurred
930             */
931            public CalEvent fetchByUUID_G(String uuid, long groupId)
932                    throws SystemException {
933                    return fetchByUUID_G(uuid, groupId, true);
934            }
935    
936            /**
937             * Finds the cal event where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
938             *
939             * @param uuid the uuid to search with
940             * @param groupId the group id to search with
941             * @return the matching cal event, or <code>null</code> if a matching cal event could not be found
942             * @throws SystemException if a system exception occurred
943             */
944            public CalEvent fetchByUUID_G(String uuid, long groupId,
945                    boolean retrieveFromCache) throws SystemException {
946                    Object[] finderArgs = new Object[] { uuid, groupId };
947    
948                    Object result = null;
949    
950                    if (retrieveFromCache) {
951                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
952                                            finderArgs, this);
953                    }
954    
955                    if (result == null) {
956                            Session session = null;
957    
958                            try {
959                                    session = openSession();
960    
961                                    StringBundler query = new StringBundler(4);
962    
963                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
964    
965                                    if (uuid == null) {
966                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
967                                    }
968                                    else {
969                                            if (uuid.equals(StringPool.BLANK)) {
970                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
971                                            }
972                                            else {
973                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
974                                            }
975                                    }
976    
977                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
978    
979                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
980    
981                                    String sql = query.toString();
982    
983                                    Query q = session.createQuery(sql);
984    
985                                    QueryPos qPos = QueryPos.getInstance(q);
986    
987                                    if (uuid != null) {
988                                            qPos.add(uuid);
989                                    }
990    
991                                    qPos.add(groupId);
992    
993                                    List<CalEvent> list = q.list();
994    
995                                    result = list;
996    
997                                    CalEvent calEvent = null;
998    
999                                    if (list.isEmpty()) {
1000                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1001                                                    finderArgs, list);
1002                                    }
1003                                    else {
1004                                            calEvent = list.get(0);
1005    
1006                                            cacheResult(calEvent);
1007    
1008                                            if ((calEvent.getUuid() == null) ||
1009                                                            !calEvent.getUuid().equals(uuid) ||
1010                                                            (calEvent.getGroupId() != groupId)) {
1011                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1012                                                            finderArgs, calEvent);
1013                                            }
1014                                    }
1015    
1016                                    return calEvent;
1017                            }
1018                            catch (Exception e) {
1019                                    throw processException(e);
1020                            }
1021                            finally {
1022                                    if (result == null) {
1023                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1024                                                    finderArgs, new ArrayList<CalEvent>());
1025                                    }
1026    
1027                                    closeSession(session);
1028                            }
1029                    }
1030                    else {
1031                            if (result instanceof List<?>) {
1032                                    return null;
1033                            }
1034                            else {
1035                                    return (CalEvent)result;
1036                            }
1037                    }
1038            }
1039    
1040            /**
1041             * Finds all the cal events where companyId = &#63;.
1042             *
1043             * @param companyId the company id to search with
1044             * @return the matching cal events
1045             * @throws SystemException if a system exception occurred
1046             */
1047            public List<CalEvent> findByCompanyId(long companyId)
1048                    throws SystemException {
1049                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1050                            null);
1051            }
1052    
1053            /**
1054             * Finds a range of all the cal events where companyId = &#63;.
1055             *
1056             * <p>
1057             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1058             * </p>
1059             *
1060             * @param companyId the company id to search with
1061             * @param start the lower bound of the range of cal events to return
1062             * @param end the upper bound of the range of cal events to return (not inclusive)
1063             * @return the range of matching cal events
1064             * @throws SystemException if a system exception occurred
1065             */
1066            public List<CalEvent> findByCompanyId(long companyId, int start, int end)
1067                    throws SystemException {
1068                    return findByCompanyId(companyId, start, end, null);
1069            }
1070    
1071            /**
1072             * Finds an ordered range of all the cal events where companyId = &#63;.
1073             *
1074             * <p>
1075             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1076             * </p>
1077             *
1078             * @param companyId the company id to search with
1079             * @param start the lower bound of the range of cal events to return
1080             * @param end the upper bound of the range of cal events to return (not inclusive)
1081             * @param orderByComparator the comparator to order the results by
1082             * @return the ordered range of matching cal events
1083             * @throws SystemException if a system exception occurred
1084             */
1085            public List<CalEvent> findByCompanyId(long companyId, int start, int end,
1086                    OrderByComparator orderByComparator) throws SystemException {
1087                    Object[] finderArgs = new Object[] {
1088                                    companyId,
1089                                    
1090                                    String.valueOf(start), String.valueOf(end),
1091                                    String.valueOf(orderByComparator)
1092                            };
1093    
1094                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1095                                    finderArgs, this);
1096    
1097                    if (list == null) {
1098                            Session session = null;
1099    
1100                            try {
1101                                    session = openSession();
1102    
1103                                    StringBundler query = null;
1104    
1105                                    if (orderByComparator != null) {
1106                                            query = new StringBundler(3 +
1107                                                            (orderByComparator.getOrderByFields().length * 3));
1108                                    }
1109                                    else {
1110                                            query = new StringBundler(3);
1111                                    }
1112    
1113                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1114    
1115                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1116    
1117                                    if (orderByComparator != null) {
1118                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1119                                                    orderByComparator);
1120                                    }
1121    
1122                                    else {
1123                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1124                                    }
1125    
1126                                    String sql = query.toString();
1127    
1128                                    Query q = session.createQuery(sql);
1129    
1130                                    QueryPos qPos = QueryPos.getInstance(q);
1131    
1132                                    qPos.add(companyId);
1133    
1134                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1135                                                    end);
1136                            }
1137                            catch (Exception e) {
1138                                    throw processException(e);
1139                            }
1140                            finally {
1141                                    if (list == null) {
1142                                            list = new ArrayList<CalEvent>();
1143                                    }
1144    
1145                                    cacheResult(list);
1146    
1147                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1148                                            finderArgs, list);
1149    
1150                                    closeSession(session);
1151                            }
1152                    }
1153    
1154                    return list;
1155            }
1156    
1157            /**
1158             * Finds the first cal event in the ordered set where companyId = &#63;.
1159             *
1160             * <p>
1161             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1162             * </p>
1163             *
1164             * @param companyId the company id to search with
1165             * @param orderByComparator the comparator to order the set by
1166             * @return the first matching cal event
1167             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1168             * @throws SystemException if a system exception occurred
1169             */
1170            public CalEvent findByCompanyId_First(long companyId,
1171                    OrderByComparator orderByComparator)
1172                    throws NoSuchEventException, SystemException {
1173                    List<CalEvent> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1174    
1175                    if (list.isEmpty()) {
1176                            StringBundler msg = new StringBundler(4);
1177    
1178                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1179    
1180                            msg.append("companyId=");
1181                            msg.append(companyId);
1182    
1183                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1184    
1185                            throw new NoSuchEventException(msg.toString());
1186                    }
1187                    else {
1188                            return list.get(0);
1189                    }
1190            }
1191    
1192            /**
1193             * Finds the last cal event in the ordered set where companyId = &#63;.
1194             *
1195             * <p>
1196             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1197             * </p>
1198             *
1199             * @param companyId the company id to search with
1200             * @param orderByComparator the comparator to order the set by
1201             * @return the last matching cal event
1202             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1203             * @throws SystemException if a system exception occurred
1204             */
1205            public CalEvent findByCompanyId_Last(long companyId,
1206                    OrderByComparator orderByComparator)
1207                    throws NoSuchEventException, SystemException {
1208                    int count = countByCompanyId(companyId);
1209    
1210                    List<CalEvent> list = findByCompanyId(companyId, count - 1, count,
1211                                    orderByComparator);
1212    
1213                    if (list.isEmpty()) {
1214                            StringBundler msg = new StringBundler(4);
1215    
1216                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1217    
1218                            msg.append("companyId=");
1219                            msg.append(companyId);
1220    
1221                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1222    
1223                            throw new NoSuchEventException(msg.toString());
1224                    }
1225                    else {
1226                            return list.get(0);
1227                    }
1228            }
1229    
1230            /**
1231             * Finds the cal events before and after the current cal event in the ordered set where companyId = &#63;.
1232             *
1233             * <p>
1234             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1235             * </p>
1236             *
1237             * @param eventId the primary key of the current cal event
1238             * @param companyId the company id to search with
1239             * @param orderByComparator the comparator to order the set by
1240             * @return the previous, current, and next cal event
1241             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
1242             * @throws SystemException if a system exception occurred
1243             */
1244            public CalEvent[] findByCompanyId_PrevAndNext(long eventId, long companyId,
1245                    OrderByComparator orderByComparator)
1246                    throws NoSuchEventException, SystemException {
1247                    CalEvent calEvent = findByPrimaryKey(eventId);
1248    
1249                    Session session = null;
1250    
1251                    try {
1252                            session = openSession();
1253    
1254                            CalEvent[] array = new CalEventImpl[3];
1255    
1256                            array[0] = getByCompanyId_PrevAndNext(session, calEvent, companyId,
1257                                            orderByComparator, true);
1258    
1259                            array[1] = calEvent;
1260    
1261                            array[2] = getByCompanyId_PrevAndNext(session, calEvent, companyId,
1262                                            orderByComparator, false);
1263    
1264                            return array;
1265                    }
1266                    catch (Exception e) {
1267                            throw processException(e);
1268                    }
1269                    finally {
1270                            closeSession(session);
1271                    }
1272            }
1273    
1274            protected CalEvent getByCompanyId_PrevAndNext(Session session,
1275                    CalEvent calEvent, long companyId, OrderByComparator orderByComparator,
1276                    boolean previous) {
1277                    StringBundler query = null;
1278    
1279                    if (orderByComparator != null) {
1280                            query = new StringBundler(6 +
1281                                            (orderByComparator.getOrderByFields().length * 6));
1282                    }
1283                    else {
1284                            query = new StringBundler(3);
1285                    }
1286    
1287                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1288    
1289                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1290    
1291                    if (orderByComparator != null) {
1292                            String[] orderByFields = orderByComparator.getOrderByFields();
1293    
1294                            if (orderByFields.length > 0) {
1295                                    query.append(WHERE_AND);
1296                            }
1297    
1298                            for (int i = 0; i < orderByFields.length; i++) {
1299                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1300                                    query.append(orderByFields[i]);
1301    
1302                                    if ((i + 1) < orderByFields.length) {
1303                                            if (orderByComparator.isAscending() ^ previous) {
1304                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1305                                            }
1306                                            else {
1307                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1308                                            }
1309                                    }
1310                                    else {
1311                                            if (orderByComparator.isAscending() ^ previous) {
1312                                                    query.append(WHERE_GREATER_THAN);
1313                                            }
1314                                            else {
1315                                                    query.append(WHERE_LESSER_THAN);
1316                                            }
1317                                    }
1318                            }
1319    
1320                            query.append(ORDER_BY_CLAUSE);
1321    
1322                            for (int i = 0; i < orderByFields.length; i++) {
1323                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1324                                    query.append(orderByFields[i]);
1325    
1326                                    if ((i + 1) < orderByFields.length) {
1327                                            if (orderByComparator.isAscending() ^ previous) {
1328                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1329                                            }
1330                                            else {
1331                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1332                                            }
1333                                    }
1334                                    else {
1335                                            if (orderByComparator.isAscending() ^ previous) {
1336                                                    query.append(ORDER_BY_ASC);
1337                                            }
1338                                            else {
1339                                                    query.append(ORDER_BY_DESC);
1340                                            }
1341                                    }
1342                            }
1343                    }
1344    
1345                    else {
1346                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1347                    }
1348    
1349                    String sql = query.toString();
1350    
1351                    Query q = session.createQuery(sql);
1352    
1353                    q.setFirstResult(0);
1354                    q.setMaxResults(2);
1355    
1356                    QueryPos qPos = QueryPos.getInstance(q);
1357    
1358                    qPos.add(companyId);
1359    
1360                    if (orderByComparator != null) {
1361                            Object[] values = orderByComparator.getOrderByValues(calEvent);
1362    
1363                            for (Object value : values) {
1364                                    qPos.add(value);
1365                            }
1366                    }
1367    
1368                    List<CalEvent> list = q.list();
1369    
1370                    if (list.size() == 2) {
1371                            return list.get(1);
1372                    }
1373                    else {
1374                            return null;
1375                    }
1376            }
1377    
1378            /**
1379             * Finds all the cal events where groupId = &#63;.
1380             *
1381             * @param groupId the group id to search with
1382             * @return the matching cal events
1383             * @throws SystemException if a system exception occurred
1384             */
1385            public List<CalEvent> findByGroupId(long groupId) throws SystemException {
1386                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1387            }
1388    
1389            /**
1390             * Finds a range of all the cal events where groupId = &#63;.
1391             *
1392             * <p>
1393             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1394             * </p>
1395             *
1396             * @param groupId the group id to search with
1397             * @param start the lower bound of the range of cal events to return
1398             * @param end the upper bound of the range of cal events to return (not inclusive)
1399             * @return the range of matching cal events
1400             * @throws SystemException if a system exception occurred
1401             */
1402            public List<CalEvent> findByGroupId(long groupId, int start, int end)
1403                    throws SystemException {
1404                    return findByGroupId(groupId, start, end, null);
1405            }
1406    
1407            /**
1408             * Finds an ordered range of all the cal events where groupId = &#63;.
1409             *
1410             * <p>
1411             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1412             * </p>
1413             *
1414             * @param groupId the group id to search with
1415             * @param start the lower bound of the range of cal events to return
1416             * @param end the upper bound of the range of cal events to return (not inclusive)
1417             * @param orderByComparator the comparator to order the results by
1418             * @return the ordered range of matching cal events
1419             * @throws SystemException if a system exception occurred
1420             */
1421            public List<CalEvent> findByGroupId(long groupId, int start, int end,
1422                    OrderByComparator orderByComparator) throws SystemException {
1423                    Object[] finderArgs = new Object[] {
1424                                    groupId,
1425                                    
1426                                    String.valueOf(start), String.valueOf(end),
1427                                    String.valueOf(orderByComparator)
1428                            };
1429    
1430                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1431                                    finderArgs, this);
1432    
1433                    if (list == null) {
1434                            Session session = null;
1435    
1436                            try {
1437                                    session = openSession();
1438    
1439                                    StringBundler query = null;
1440    
1441                                    if (orderByComparator != null) {
1442                                            query = new StringBundler(3 +
1443                                                            (orderByComparator.getOrderByFields().length * 3));
1444                                    }
1445                                    else {
1446                                            query = new StringBundler(3);
1447                                    }
1448    
1449                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1450    
1451                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1452    
1453                                    if (orderByComparator != null) {
1454                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1455                                                    orderByComparator);
1456                                    }
1457    
1458                                    else {
1459                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1460                                    }
1461    
1462                                    String sql = query.toString();
1463    
1464                                    Query q = session.createQuery(sql);
1465    
1466                                    QueryPos qPos = QueryPos.getInstance(q);
1467    
1468                                    qPos.add(groupId);
1469    
1470                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1471                                                    end);
1472                            }
1473                            catch (Exception e) {
1474                                    throw processException(e);
1475                            }
1476                            finally {
1477                                    if (list == null) {
1478                                            list = new ArrayList<CalEvent>();
1479                                    }
1480    
1481                                    cacheResult(list);
1482    
1483                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1484                                            finderArgs, list);
1485    
1486                                    closeSession(session);
1487                            }
1488                    }
1489    
1490                    return list;
1491            }
1492    
1493            /**
1494             * Finds the first cal event in the ordered set where groupId = &#63;.
1495             *
1496             * <p>
1497             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1498             * </p>
1499             *
1500             * @param groupId the group id to search with
1501             * @param orderByComparator the comparator to order the set by
1502             * @return the first matching cal event
1503             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1504             * @throws SystemException if a system exception occurred
1505             */
1506            public CalEvent findByGroupId_First(long groupId,
1507                    OrderByComparator orderByComparator)
1508                    throws NoSuchEventException, SystemException {
1509                    List<CalEvent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1510    
1511                    if (list.isEmpty()) {
1512                            StringBundler msg = new StringBundler(4);
1513    
1514                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1515    
1516                            msg.append("groupId=");
1517                            msg.append(groupId);
1518    
1519                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1520    
1521                            throw new NoSuchEventException(msg.toString());
1522                    }
1523                    else {
1524                            return list.get(0);
1525                    }
1526            }
1527    
1528            /**
1529             * Finds the last cal event in the ordered set where groupId = &#63;.
1530             *
1531             * <p>
1532             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1533             * </p>
1534             *
1535             * @param groupId the group id to search with
1536             * @param orderByComparator the comparator to order the set by
1537             * @return the last matching cal event
1538             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1539             * @throws SystemException if a system exception occurred
1540             */
1541            public CalEvent findByGroupId_Last(long groupId,
1542                    OrderByComparator orderByComparator)
1543                    throws NoSuchEventException, SystemException {
1544                    int count = countByGroupId(groupId);
1545    
1546                    List<CalEvent> list = findByGroupId(groupId, count - 1, count,
1547                                    orderByComparator);
1548    
1549                    if (list.isEmpty()) {
1550                            StringBundler msg = new StringBundler(4);
1551    
1552                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1553    
1554                            msg.append("groupId=");
1555                            msg.append(groupId);
1556    
1557                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1558    
1559                            throw new NoSuchEventException(msg.toString());
1560                    }
1561                    else {
1562                            return list.get(0);
1563                    }
1564            }
1565    
1566            /**
1567             * Finds the cal events before and after the current cal event in the ordered set where groupId = &#63;.
1568             *
1569             * <p>
1570             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1571             * </p>
1572             *
1573             * @param eventId the primary key of the current cal event
1574             * @param groupId the group id to search with
1575             * @param orderByComparator the comparator to order the set by
1576             * @return the previous, current, and next cal event
1577             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
1578             * @throws SystemException if a system exception occurred
1579             */
1580            public CalEvent[] findByGroupId_PrevAndNext(long eventId, long groupId,
1581                    OrderByComparator orderByComparator)
1582                    throws NoSuchEventException, SystemException {
1583                    CalEvent calEvent = findByPrimaryKey(eventId);
1584    
1585                    Session session = null;
1586    
1587                    try {
1588                            session = openSession();
1589    
1590                            CalEvent[] array = new CalEventImpl[3];
1591    
1592                            array[0] = getByGroupId_PrevAndNext(session, calEvent, groupId,
1593                                            orderByComparator, true);
1594    
1595                            array[1] = calEvent;
1596    
1597                            array[2] = getByGroupId_PrevAndNext(session, calEvent, groupId,
1598                                            orderByComparator, false);
1599    
1600                            return array;
1601                    }
1602                    catch (Exception e) {
1603                            throw processException(e);
1604                    }
1605                    finally {
1606                            closeSession(session);
1607                    }
1608            }
1609    
1610            protected CalEvent getByGroupId_PrevAndNext(Session session,
1611                    CalEvent calEvent, long groupId, OrderByComparator orderByComparator,
1612                    boolean previous) {
1613                    StringBundler query = null;
1614    
1615                    if (orderByComparator != null) {
1616                            query = new StringBundler(6 +
1617                                            (orderByComparator.getOrderByFields().length * 6));
1618                    }
1619                    else {
1620                            query = new StringBundler(3);
1621                    }
1622    
1623                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1624    
1625                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1626    
1627                    if (orderByComparator != null) {
1628                            String[] orderByFields = orderByComparator.getOrderByFields();
1629    
1630                            if (orderByFields.length > 0) {
1631                                    query.append(WHERE_AND);
1632                            }
1633    
1634                            for (int i = 0; i < orderByFields.length; i++) {
1635                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1636                                    query.append(orderByFields[i]);
1637    
1638                                    if ((i + 1) < orderByFields.length) {
1639                                            if (orderByComparator.isAscending() ^ previous) {
1640                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1641                                            }
1642                                            else {
1643                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1644                                            }
1645                                    }
1646                                    else {
1647                                            if (orderByComparator.isAscending() ^ previous) {
1648                                                    query.append(WHERE_GREATER_THAN);
1649                                            }
1650                                            else {
1651                                                    query.append(WHERE_LESSER_THAN);
1652                                            }
1653                                    }
1654                            }
1655    
1656                            query.append(ORDER_BY_CLAUSE);
1657    
1658                            for (int i = 0; i < orderByFields.length; i++) {
1659                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1660                                    query.append(orderByFields[i]);
1661    
1662                                    if ((i + 1) < orderByFields.length) {
1663                                            if (orderByComparator.isAscending() ^ previous) {
1664                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1665                                            }
1666                                            else {
1667                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1668                                            }
1669                                    }
1670                                    else {
1671                                            if (orderByComparator.isAscending() ^ previous) {
1672                                                    query.append(ORDER_BY_ASC);
1673                                            }
1674                                            else {
1675                                                    query.append(ORDER_BY_DESC);
1676                                            }
1677                                    }
1678                            }
1679                    }
1680    
1681                    else {
1682                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1683                    }
1684    
1685                    String sql = query.toString();
1686    
1687                    Query q = session.createQuery(sql);
1688    
1689                    q.setFirstResult(0);
1690                    q.setMaxResults(2);
1691    
1692                    QueryPos qPos = QueryPos.getInstance(q);
1693    
1694                    qPos.add(groupId);
1695    
1696                    if (orderByComparator != null) {
1697                            Object[] values = orderByComparator.getOrderByValues(calEvent);
1698    
1699                            for (Object value : values) {
1700                                    qPos.add(value);
1701                            }
1702                    }
1703    
1704                    List<CalEvent> list = q.list();
1705    
1706                    if (list.size() == 2) {
1707                            return list.get(1);
1708                    }
1709                    else {
1710                            return null;
1711                    }
1712            }
1713    
1714            /**
1715             * Filters by the user's permissions and finds all the cal events where groupId = &#63;.
1716             *
1717             * @param groupId the group id to search with
1718             * @return the matching cal events that the user has permission to view
1719             * @throws SystemException if a system exception occurred
1720             */
1721            public List<CalEvent> filterFindByGroupId(long groupId)
1722                    throws SystemException {
1723                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1724                            QueryUtil.ALL_POS, null);
1725            }
1726    
1727            /**
1728             * Filters by the user's permissions and finds a range of all the cal events where groupId = &#63;.
1729             *
1730             * <p>
1731             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1732             * </p>
1733             *
1734             * @param groupId the group id to search with
1735             * @param start the lower bound of the range of cal events to return
1736             * @param end the upper bound of the range of cal events to return (not inclusive)
1737             * @return the range of matching cal events that the user has permission to view
1738             * @throws SystemException if a system exception occurred
1739             */
1740            public List<CalEvent> filterFindByGroupId(long groupId, int start, int end)
1741                    throws SystemException {
1742                    return filterFindByGroupId(groupId, start, end, null);
1743            }
1744    
1745            /**
1746             * Filters by the user's permissions and finds an ordered range of all the cal events where groupId = &#63;.
1747             *
1748             * <p>
1749             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1750             * </p>
1751             *
1752             * @param groupId the group id to search with
1753             * @param start the lower bound of the range of cal events to return
1754             * @param end the upper bound of the range of cal events to return (not inclusive)
1755             * @param orderByComparator the comparator to order the results by
1756             * @return the ordered range of matching cal events that the user has permission to view
1757             * @throws SystemException if a system exception occurred
1758             */
1759            public List<CalEvent> filterFindByGroupId(long groupId, int start, int end,
1760                    OrderByComparator orderByComparator) throws SystemException {
1761                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1762                            return findByGroupId(groupId, start, end, orderByComparator);
1763                    }
1764    
1765                    Session session = null;
1766    
1767                    try {
1768                            session = openSession();
1769    
1770                            StringBundler query = null;
1771    
1772                            if (orderByComparator != null) {
1773                                    query = new StringBundler(3 +
1774                                                    (orderByComparator.getOrderByFields().length * 3));
1775                            }
1776                            else {
1777                                    query = new StringBundler(3);
1778                            }
1779    
1780                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
1781    
1782                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1783    
1784                            if (orderByComparator != null) {
1785                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1786                                            orderByComparator);
1787                            }
1788    
1789                            else {
1790                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
1791                            }
1792    
1793                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1794                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
1795                                            _FILTER_COLUMN_USERID, groupId);
1796    
1797                            SQLQuery q = session.createSQLQuery(sql);
1798    
1799                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
1800    
1801                            QueryPos qPos = QueryPos.getInstance(q);
1802    
1803                            qPos.add(groupId);
1804    
1805                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
1806                    }
1807                    catch (Exception e) {
1808                            throw processException(e);
1809                    }
1810                    finally {
1811                            closeSession(session);
1812                    }
1813            }
1814    
1815            /**
1816             * Finds all the cal events where remindBy &ne; &#63;.
1817             *
1818             * @param remindBy the remind by to search with
1819             * @return the matching cal events
1820             * @throws SystemException if a system exception occurred
1821             */
1822            public List<CalEvent> findByNotRemindBy(int remindBy)
1823                    throws SystemException {
1824                    return findByNotRemindBy(remindBy, QueryUtil.ALL_POS,
1825                            QueryUtil.ALL_POS, null);
1826            }
1827    
1828            /**
1829             * Finds a range of all the cal events where remindBy &ne; &#63;.
1830             *
1831             * <p>
1832             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1833             * </p>
1834             *
1835             * @param remindBy the remind by to search with
1836             * @param start the lower bound of the range of cal events to return
1837             * @param end the upper bound of the range of cal events to return (not inclusive)
1838             * @return the range of matching cal events
1839             * @throws SystemException if a system exception occurred
1840             */
1841            public List<CalEvent> findByNotRemindBy(int remindBy, int start, int end)
1842                    throws SystemException {
1843                    return findByNotRemindBy(remindBy, start, end, null);
1844            }
1845    
1846            /**
1847             * Finds an ordered range of all the cal events where remindBy &ne; &#63;.
1848             *
1849             * <p>
1850             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1851             * </p>
1852             *
1853             * @param remindBy the remind by to search with
1854             * @param start the lower bound of the range of cal events to return
1855             * @param end the upper bound of the range of cal events to return (not inclusive)
1856             * @param orderByComparator the comparator to order the results by
1857             * @return the ordered range of matching cal events
1858             * @throws SystemException if a system exception occurred
1859             */
1860            public List<CalEvent> findByNotRemindBy(int remindBy, int start, int end,
1861                    OrderByComparator orderByComparator) throws SystemException {
1862                    Object[] finderArgs = new Object[] {
1863                                    remindBy,
1864                                    
1865                                    String.valueOf(start), String.valueOf(end),
1866                                    String.valueOf(orderByComparator)
1867                            };
1868    
1869                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NOTREMINDBY,
1870                                    finderArgs, this);
1871    
1872                    if (list == null) {
1873                            Session session = null;
1874    
1875                            try {
1876                                    session = openSession();
1877    
1878                                    StringBundler query = null;
1879    
1880                                    if (orderByComparator != null) {
1881                                            query = new StringBundler(3 +
1882                                                            (orderByComparator.getOrderByFields().length * 3));
1883                                    }
1884                                    else {
1885                                            query = new StringBundler(3);
1886                                    }
1887    
1888                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1889    
1890                                    query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
1891    
1892                                    if (orderByComparator != null) {
1893                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1894                                                    orderByComparator);
1895                                    }
1896    
1897                                    else {
1898                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1899                                    }
1900    
1901                                    String sql = query.toString();
1902    
1903                                    Query q = session.createQuery(sql);
1904    
1905                                    QueryPos qPos = QueryPos.getInstance(q);
1906    
1907                                    qPos.add(remindBy);
1908    
1909                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1910                                                    end);
1911                            }
1912                            catch (Exception e) {
1913                                    throw processException(e);
1914                            }
1915                            finally {
1916                                    if (list == null) {
1917                                            list = new ArrayList<CalEvent>();
1918                                    }
1919    
1920                                    cacheResult(list);
1921    
1922                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NOTREMINDBY,
1923                                            finderArgs, list);
1924    
1925                                    closeSession(session);
1926                            }
1927                    }
1928    
1929                    return list;
1930            }
1931    
1932            /**
1933             * Finds the first cal event in the ordered set where remindBy &ne; &#63;.
1934             *
1935             * <p>
1936             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1937             * </p>
1938             *
1939             * @param remindBy the remind by to search with
1940             * @param orderByComparator the comparator to order the set by
1941             * @return the first matching cal event
1942             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1943             * @throws SystemException if a system exception occurred
1944             */
1945            public CalEvent findByNotRemindBy_First(int remindBy,
1946                    OrderByComparator orderByComparator)
1947                    throws NoSuchEventException, SystemException {
1948                    List<CalEvent> list = findByNotRemindBy(remindBy, 0, 1,
1949                                    orderByComparator);
1950    
1951                    if (list.isEmpty()) {
1952                            StringBundler msg = new StringBundler(4);
1953    
1954                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1955    
1956                            msg.append("remindBy=");
1957                            msg.append(remindBy);
1958    
1959                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1960    
1961                            throw new NoSuchEventException(msg.toString());
1962                    }
1963                    else {
1964                            return list.get(0);
1965                    }
1966            }
1967    
1968            /**
1969             * Finds the last cal event in the ordered set where remindBy &ne; &#63;.
1970             *
1971             * <p>
1972             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1973             * </p>
1974             *
1975             * @param remindBy the remind by to search with
1976             * @param orderByComparator the comparator to order the set by
1977             * @return the last matching cal event
1978             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1979             * @throws SystemException if a system exception occurred
1980             */
1981            public CalEvent findByNotRemindBy_Last(int remindBy,
1982                    OrderByComparator orderByComparator)
1983                    throws NoSuchEventException, SystemException {
1984                    int count = countByNotRemindBy(remindBy);
1985    
1986                    List<CalEvent> list = findByNotRemindBy(remindBy, count - 1, count,
1987                                    orderByComparator);
1988    
1989                    if (list.isEmpty()) {
1990                            StringBundler msg = new StringBundler(4);
1991    
1992                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1993    
1994                            msg.append("remindBy=");
1995                            msg.append(remindBy);
1996    
1997                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1998    
1999                            throw new NoSuchEventException(msg.toString());
2000                    }
2001                    else {
2002                            return list.get(0);
2003                    }
2004            }
2005    
2006            /**
2007             * Finds the cal events before and after the current cal event in the ordered set where remindBy &ne; &#63;.
2008             *
2009             * <p>
2010             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2011             * </p>
2012             *
2013             * @param eventId the primary key of the current cal event
2014             * @param remindBy the remind by to search with
2015             * @param orderByComparator the comparator to order the set by
2016             * @return the previous, current, and next cal event
2017             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
2018             * @throws SystemException if a system exception occurred
2019             */
2020            public CalEvent[] findByNotRemindBy_PrevAndNext(long eventId, int remindBy,
2021                    OrderByComparator orderByComparator)
2022                    throws NoSuchEventException, SystemException {
2023                    CalEvent calEvent = findByPrimaryKey(eventId);
2024    
2025                    Session session = null;
2026    
2027                    try {
2028                            session = openSession();
2029    
2030                            CalEvent[] array = new CalEventImpl[3];
2031    
2032                            array[0] = getByNotRemindBy_PrevAndNext(session, calEvent,
2033                                            remindBy, orderByComparator, true);
2034    
2035                            array[1] = calEvent;
2036    
2037                            array[2] = getByNotRemindBy_PrevAndNext(session, calEvent,
2038                                            remindBy, orderByComparator, false);
2039    
2040                            return array;
2041                    }
2042                    catch (Exception e) {
2043                            throw processException(e);
2044                    }
2045                    finally {
2046                            closeSession(session);
2047                    }
2048            }
2049    
2050            protected CalEvent getByNotRemindBy_PrevAndNext(Session session,
2051                    CalEvent calEvent, int remindBy, OrderByComparator orderByComparator,
2052                    boolean previous) {
2053                    StringBundler query = null;
2054    
2055                    if (orderByComparator != null) {
2056                            query = new StringBundler(6 +
2057                                            (orderByComparator.getOrderByFields().length * 6));
2058                    }
2059                    else {
2060                            query = new StringBundler(3);
2061                    }
2062    
2063                    query.append(_SQL_SELECT_CALEVENT_WHERE);
2064    
2065                    query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
2066    
2067                    if (orderByComparator != null) {
2068                            String[] orderByFields = orderByComparator.getOrderByFields();
2069    
2070                            if (orderByFields.length > 0) {
2071                                    query.append(WHERE_AND);
2072                            }
2073    
2074                            for (int i = 0; i < orderByFields.length; i++) {
2075                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2076                                    query.append(orderByFields[i]);
2077    
2078                                    if ((i + 1) < orderByFields.length) {
2079                                            if (orderByComparator.isAscending() ^ previous) {
2080                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2081                                            }
2082                                            else {
2083                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2084                                            }
2085                                    }
2086                                    else {
2087                                            if (orderByComparator.isAscending() ^ previous) {
2088                                                    query.append(WHERE_GREATER_THAN);
2089                                            }
2090                                            else {
2091                                                    query.append(WHERE_LESSER_THAN);
2092                                            }
2093                                    }
2094                            }
2095    
2096                            query.append(ORDER_BY_CLAUSE);
2097    
2098                            for (int i = 0; i < orderByFields.length; i++) {
2099                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2100                                    query.append(orderByFields[i]);
2101    
2102                                    if ((i + 1) < orderByFields.length) {
2103                                            if (orderByComparator.isAscending() ^ previous) {
2104                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2105                                            }
2106                                            else {
2107                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2108                                            }
2109                                    }
2110                                    else {
2111                                            if (orderByComparator.isAscending() ^ previous) {
2112                                                    query.append(ORDER_BY_ASC);
2113                                            }
2114                                            else {
2115                                                    query.append(ORDER_BY_DESC);
2116                                            }
2117                                    }
2118                            }
2119                    }
2120    
2121                    else {
2122                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2123                    }
2124    
2125                    String sql = query.toString();
2126    
2127                    Query q = session.createQuery(sql);
2128    
2129                    q.setFirstResult(0);
2130                    q.setMaxResults(2);
2131    
2132                    QueryPos qPos = QueryPos.getInstance(q);
2133    
2134                    qPos.add(remindBy);
2135    
2136                    if (orderByComparator != null) {
2137                            Object[] values = orderByComparator.getOrderByValues(calEvent);
2138    
2139                            for (Object value : values) {
2140                                    qPos.add(value);
2141                            }
2142                    }
2143    
2144                    List<CalEvent> list = q.list();
2145    
2146                    if (list.size() == 2) {
2147                            return list.get(1);
2148                    }
2149                    else {
2150                            return null;
2151                    }
2152            }
2153    
2154            /**
2155             * Finds all the cal events where groupId = &#63; and type = &#63;.
2156             *
2157             * @param groupId the group id to search with
2158             * @param type the type to search with
2159             * @return the matching cal events
2160             * @throws SystemException if a system exception occurred
2161             */
2162            public List<CalEvent> findByG_T(long groupId, String type)
2163                    throws SystemException {
2164                    return findByG_T(groupId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2165                            null);
2166            }
2167    
2168            /**
2169             * Finds a range of all the cal events where groupId = &#63; and type = &#63;.
2170             *
2171             * <p>
2172             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2173             * </p>
2174             *
2175             * @param groupId the group id to search with
2176             * @param type the type to search with
2177             * @param start the lower bound of the range of cal events to return
2178             * @param end the upper bound of the range of cal events to return (not inclusive)
2179             * @return the range of matching cal events
2180             * @throws SystemException if a system exception occurred
2181             */
2182            public List<CalEvent> findByG_T(long groupId, String type, int start,
2183                    int end) throws SystemException {
2184                    return findByG_T(groupId, type, start, end, null);
2185            }
2186    
2187            /**
2188             * Finds an ordered range of all the cal events where groupId = &#63; and type = &#63;.
2189             *
2190             * <p>
2191             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2192             * </p>
2193             *
2194             * @param groupId the group id to search with
2195             * @param type the type to search with
2196             * @param start the lower bound of the range of cal events to return
2197             * @param end the upper bound of the range of cal events to return (not inclusive)
2198             * @param orderByComparator the comparator to order the results by
2199             * @return the ordered range of matching cal events
2200             * @throws SystemException if a system exception occurred
2201             */
2202            public List<CalEvent> findByG_T(long groupId, String type, int start,
2203                    int end, OrderByComparator orderByComparator) throws SystemException {
2204                    Object[] finderArgs = new Object[] {
2205                                    groupId, type,
2206                                    
2207                                    String.valueOf(start), String.valueOf(end),
2208                                    String.valueOf(orderByComparator)
2209                            };
2210    
2211                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_T,
2212                                    finderArgs, this);
2213    
2214                    if (list == null) {
2215                            Session session = null;
2216    
2217                            try {
2218                                    session = openSession();
2219    
2220                                    StringBundler query = null;
2221    
2222                                    if (orderByComparator != null) {
2223                                            query = new StringBundler(4 +
2224                                                            (orderByComparator.getOrderByFields().length * 3));
2225                                    }
2226                                    else {
2227                                            query = new StringBundler(4);
2228                                    }
2229    
2230                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
2231    
2232                                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2233    
2234                                    if (type == null) {
2235                                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
2236                                    }
2237                                    else {
2238                                            if (type.equals(StringPool.BLANK)) {
2239                                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
2240                                            }
2241                                            else {
2242                                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
2243                                            }
2244                                    }
2245    
2246                                    if (orderByComparator != null) {
2247                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2248                                                    orderByComparator);
2249                                    }
2250    
2251                                    else {
2252                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2253                                    }
2254    
2255                                    String sql = query.toString();
2256    
2257                                    Query q = session.createQuery(sql);
2258    
2259                                    QueryPos qPos = QueryPos.getInstance(q);
2260    
2261                                    qPos.add(groupId);
2262    
2263                                    if (type != null) {
2264                                            qPos.add(type);
2265                                    }
2266    
2267                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
2268                                                    end);
2269                            }
2270                            catch (Exception e) {
2271                                    throw processException(e);
2272                            }
2273                            finally {
2274                                    if (list == null) {
2275                                            list = new ArrayList<CalEvent>();
2276                                    }
2277    
2278                                    cacheResult(list);
2279    
2280                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_T, finderArgs,
2281                                            list);
2282    
2283                                    closeSession(session);
2284                            }
2285                    }
2286    
2287                    return list;
2288            }
2289    
2290            /**
2291             * Finds the first cal event in the ordered set where groupId = &#63; and type = &#63;.
2292             *
2293             * <p>
2294             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2295             * </p>
2296             *
2297             * @param groupId the group id to search with
2298             * @param type the type to search with
2299             * @param orderByComparator the comparator to order the set by
2300             * @return the first matching cal event
2301             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
2302             * @throws SystemException if a system exception occurred
2303             */
2304            public CalEvent findByG_T_First(long groupId, String type,
2305                    OrderByComparator orderByComparator)
2306                    throws NoSuchEventException, SystemException {
2307                    List<CalEvent> list = findByG_T(groupId, type, 0, 1, orderByComparator);
2308    
2309                    if (list.isEmpty()) {
2310                            StringBundler msg = new StringBundler(6);
2311    
2312                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2313    
2314                            msg.append("groupId=");
2315                            msg.append(groupId);
2316    
2317                            msg.append(", type=");
2318                            msg.append(type);
2319    
2320                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2321    
2322                            throw new NoSuchEventException(msg.toString());
2323                    }
2324                    else {
2325                            return list.get(0);
2326                    }
2327            }
2328    
2329            /**
2330             * Finds the last cal event in the ordered set where groupId = &#63; and type = &#63;.
2331             *
2332             * <p>
2333             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2334             * </p>
2335             *
2336             * @param groupId the group id to search with
2337             * @param type the type to search with
2338             * @param orderByComparator the comparator to order the set by
2339             * @return the last matching cal event
2340             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
2341             * @throws SystemException if a system exception occurred
2342             */
2343            public CalEvent findByG_T_Last(long groupId, String type,
2344                    OrderByComparator orderByComparator)
2345                    throws NoSuchEventException, SystemException {
2346                    int count = countByG_T(groupId, type);
2347    
2348                    List<CalEvent> list = findByG_T(groupId, type, count - 1, count,
2349                                    orderByComparator);
2350    
2351                    if (list.isEmpty()) {
2352                            StringBundler msg = new StringBundler(6);
2353    
2354                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2355    
2356                            msg.append("groupId=");
2357                            msg.append(groupId);
2358    
2359                            msg.append(", type=");
2360                            msg.append(type);
2361    
2362                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2363    
2364                            throw new NoSuchEventException(msg.toString());
2365                    }
2366                    else {
2367                            return list.get(0);
2368                    }
2369            }
2370    
2371            /**
2372             * Finds the cal events before and after the current cal event in the ordered set where groupId = &#63; and type = &#63;.
2373             *
2374             * <p>
2375             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2376             * </p>
2377             *
2378             * @param eventId the primary key of the current cal event
2379             * @param groupId the group id to search with
2380             * @param type the type to search with
2381             * @param orderByComparator the comparator to order the set by
2382             * @return the previous, current, and next cal event
2383             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
2384             * @throws SystemException if a system exception occurred
2385             */
2386            public CalEvent[] findByG_T_PrevAndNext(long eventId, long groupId,
2387                    String type, OrderByComparator orderByComparator)
2388                    throws NoSuchEventException, SystemException {
2389                    CalEvent calEvent = findByPrimaryKey(eventId);
2390    
2391                    Session session = null;
2392    
2393                    try {
2394                            session = openSession();
2395    
2396                            CalEvent[] array = new CalEventImpl[3];
2397    
2398                            array[0] = getByG_T_PrevAndNext(session, calEvent, groupId, type,
2399                                            orderByComparator, true);
2400    
2401                            array[1] = calEvent;
2402    
2403                            array[2] = getByG_T_PrevAndNext(session, calEvent, groupId, type,
2404                                            orderByComparator, false);
2405    
2406                            return array;
2407                    }
2408                    catch (Exception e) {
2409                            throw processException(e);
2410                    }
2411                    finally {
2412                            closeSession(session);
2413                    }
2414            }
2415    
2416            protected CalEvent getByG_T_PrevAndNext(Session session, CalEvent calEvent,
2417                    long groupId, String type, OrderByComparator orderByComparator,
2418                    boolean previous) {
2419                    StringBundler query = null;
2420    
2421                    if (orderByComparator != null) {
2422                            query = new StringBundler(6 +
2423                                            (orderByComparator.getOrderByFields().length * 6));
2424                    }
2425                    else {
2426                            query = new StringBundler(3);
2427                    }
2428    
2429                    query.append(_SQL_SELECT_CALEVENT_WHERE);
2430    
2431                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2432    
2433                    if (type == null) {
2434                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
2435                    }
2436                    else {
2437                            if (type.equals(StringPool.BLANK)) {
2438                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
2439                            }
2440                            else {
2441                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
2442                            }
2443                    }
2444    
2445                    if (orderByComparator != null) {
2446                            String[] orderByFields = orderByComparator.getOrderByFields();
2447    
2448                            if (orderByFields.length > 0) {
2449                                    query.append(WHERE_AND);
2450                            }
2451    
2452                            for (int i = 0; i < orderByFields.length; i++) {
2453                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2454                                    query.append(orderByFields[i]);
2455    
2456                                    if ((i + 1) < orderByFields.length) {
2457                                            if (orderByComparator.isAscending() ^ previous) {
2458                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2459                                            }
2460                                            else {
2461                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2462                                            }
2463                                    }
2464                                    else {
2465                                            if (orderByComparator.isAscending() ^ previous) {
2466                                                    query.append(WHERE_GREATER_THAN);
2467                                            }
2468                                            else {
2469                                                    query.append(WHERE_LESSER_THAN);
2470                                            }
2471                                    }
2472                            }
2473    
2474                            query.append(ORDER_BY_CLAUSE);
2475    
2476                            for (int i = 0; i < orderByFields.length; i++) {
2477                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2478                                    query.append(orderByFields[i]);
2479    
2480                                    if ((i + 1) < orderByFields.length) {
2481                                            if (orderByComparator.isAscending() ^ previous) {
2482                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2483                                            }
2484                                            else {
2485                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2486                                            }
2487                                    }
2488                                    else {
2489                                            if (orderByComparator.isAscending() ^ previous) {
2490                                                    query.append(ORDER_BY_ASC);
2491                                            }
2492                                            else {
2493                                                    query.append(ORDER_BY_DESC);
2494                                            }
2495                                    }
2496                            }
2497                    }
2498    
2499                    else {
2500                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2501                    }
2502    
2503                    String sql = query.toString();
2504    
2505                    Query q = session.createQuery(sql);
2506    
2507                    q.setFirstResult(0);
2508                    q.setMaxResults(2);
2509    
2510                    QueryPos qPos = QueryPos.getInstance(q);
2511    
2512                    qPos.add(groupId);
2513    
2514                    if (type != null) {
2515                            qPos.add(type);
2516                    }
2517    
2518                    if (orderByComparator != null) {
2519                            Object[] values = orderByComparator.getOrderByValues(calEvent);
2520    
2521                            for (Object value : values) {
2522                                    qPos.add(value);
2523                            }
2524                    }
2525    
2526                    List<CalEvent> list = q.list();
2527    
2528                    if (list.size() == 2) {
2529                            return list.get(1);
2530                    }
2531                    else {
2532                            return null;
2533                    }
2534            }
2535    
2536            /**
2537             * Filters by the user's permissions and finds all the cal events where groupId = &#63; and type = &#63;.
2538             *
2539             * @param groupId the group id to search with
2540             * @param type the type to search with
2541             * @return the matching cal events that the user has permission to view
2542             * @throws SystemException if a system exception occurred
2543             */
2544            public List<CalEvent> filterFindByG_T(long groupId, String type)
2545                    throws SystemException {
2546                    return filterFindByG_T(groupId, type, QueryUtil.ALL_POS,
2547                            QueryUtil.ALL_POS, null);
2548            }
2549    
2550            /**
2551             * Filters by the user's permissions and finds a range of all the cal events where groupId = &#63; and type = &#63;.
2552             *
2553             * <p>
2554             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2555             * </p>
2556             *
2557             * @param groupId the group id to search with
2558             * @param type the type to search with
2559             * @param start the lower bound of the range of cal events to return
2560             * @param end the upper bound of the range of cal events to return (not inclusive)
2561             * @return the range of matching cal events that the user has permission to view
2562             * @throws SystemException if a system exception occurred
2563             */
2564            public List<CalEvent> filterFindByG_T(long groupId, String type, int start,
2565                    int end) throws SystemException {
2566                    return filterFindByG_T(groupId, type, start, end, null);
2567            }
2568    
2569            /**
2570             * Filters by the user's permissions and finds an ordered range of all the cal events where groupId = &#63; and type = &#63;.
2571             *
2572             * <p>
2573             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2574             * </p>
2575             *
2576             * @param groupId the group id to search with
2577             * @param type the type to search with
2578             * @param start the lower bound of the range of cal events to return
2579             * @param end the upper bound of the range of cal events to return (not inclusive)
2580             * @param orderByComparator the comparator to order the results by
2581             * @return the ordered range of matching cal events that the user has permission to view
2582             * @throws SystemException if a system exception occurred
2583             */
2584            public List<CalEvent> filterFindByG_T(long groupId, String type, int start,
2585                    int end, OrderByComparator orderByComparator) throws SystemException {
2586                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2587                            return findByG_T(groupId, type, start, end, orderByComparator);
2588                    }
2589    
2590                    Session session = null;
2591    
2592                    try {
2593                            session = openSession();
2594    
2595                            StringBundler query = null;
2596    
2597                            if (orderByComparator != null) {
2598                                    query = new StringBundler(4 +
2599                                                    (orderByComparator.getOrderByFields().length * 3));
2600                            }
2601                            else {
2602                                    query = new StringBundler(4);
2603                            }
2604    
2605                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
2606    
2607                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2608    
2609                            if (type == null) {
2610                                    query.append(_FINDER_COLUMN_G_T_TYPE_1);
2611                            }
2612                            else {
2613                                    if (type.equals(StringPool.BLANK)) {
2614                                            query.append(_FINDER_COLUMN_G_T_TYPE_3);
2615                                    }
2616                                    else {
2617                                            query.append(_FINDER_COLUMN_G_T_TYPE_2);
2618                                    }
2619                            }
2620    
2621                            if (orderByComparator != null) {
2622                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2623                                            orderByComparator);
2624                            }
2625    
2626                            else {
2627                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
2628                            }
2629    
2630                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2631                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
2632                                            _FILTER_COLUMN_USERID, groupId);
2633    
2634                            SQLQuery q = session.createSQLQuery(sql);
2635    
2636                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
2637    
2638                            QueryPos qPos = QueryPos.getInstance(q);
2639    
2640                            qPos.add(groupId);
2641    
2642                            if (type != null) {
2643                                    qPos.add(type);
2644                            }
2645    
2646                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
2647                    }
2648                    catch (Exception e) {
2649                            throw processException(e);
2650                    }
2651                    finally {
2652                            closeSession(session);
2653                    }
2654            }
2655    
2656            /**
2657             * Finds all the cal events where groupId = &#63; and repeating = &#63;.
2658             *
2659             * @param groupId the group id to search with
2660             * @param repeating the repeating to search with
2661             * @return the matching cal events
2662             * @throws SystemException if a system exception occurred
2663             */
2664            public List<CalEvent> findByG_R(long groupId, boolean repeating)
2665                    throws SystemException {
2666                    return findByG_R(groupId, repeating, QueryUtil.ALL_POS,
2667                            QueryUtil.ALL_POS, null);
2668            }
2669    
2670            /**
2671             * Finds a range of all the cal events where groupId = &#63; and repeating = &#63;.
2672             *
2673             * <p>
2674             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2675             * </p>
2676             *
2677             * @param groupId the group id to search with
2678             * @param repeating the repeating to search with
2679             * @param start the lower bound of the range of cal events to return
2680             * @param end the upper bound of the range of cal events to return (not inclusive)
2681             * @return the range of matching cal events
2682             * @throws SystemException if a system exception occurred
2683             */
2684            public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
2685                    int end) throws SystemException {
2686                    return findByG_R(groupId, repeating, start, end, null);
2687            }
2688    
2689            /**
2690             * Finds an ordered range of all the cal events where groupId = &#63; and repeating = &#63;.
2691             *
2692             * <p>
2693             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2694             * </p>
2695             *
2696             * @param groupId the group id to search with
2697             * @param repeating the repeating to search with
2698             * @param start the lower bound of the range of cal events to return
2699             * @param end the upper bound of the range of cal events to return (not inclusive)
2700             * @param orderByComparator the comparator to order the results by
2701             * @return the ordered range of matching cal events
2702             * @throws SystemException if a system exception occurred
2703             */
2704            public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
2705                    int end, OrderByComparator orderByComparator) throws SystemException {
2706                    Object[] finderArgs = new Object[] {
2707                                    groupId, repeating,
2708                                    
2709                                    String.valueOf(start), String.valueOf(end),
2710                                    String.valueOf(orderByComparator)
2711                            };
2712    
2713                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_R,
2714                                    finderArgs, this);
2715    
2716                    if (list == null) {
2717                            Session session = null;
2718    
2719                            try {
2720                                    session = openSession();
2721    
2722                                    StringBundler query = null;
2723    
2724                                    if (orderByComparator != null) {
2725                                            query = new StringBundler(4 +
2726                                                            (orderByComparator.getOrderByFields().length * 3));
2727                                    }
2728                                    else {
2729                                            query = new StringBundler(4);
2730                                    }
2731    
2732                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
2733    
2734                                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2735    
2736                                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
2737    
2738                                    if (orderByComparator != null) {
2739                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2740                                                    orderByComparator);
2741                                    }
2742    
2743                                    else {
2744                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2745                                    }
2746    
2747                                    String sql = query.toString();
2748    
2749                                    Query q = session.createQuery(sql);
2750    
2751                                    QueryPos qPos = QueryPos.getInstance(q);
2752    
2753                                    qPos.add(groupId);
2754    
2755                                    qPos.add(repeating);
2756    
2757                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
2758                                                    end);
2759                            }
2760                            catch (Exception e) {
2761                                    throw processException(e);
2762                            }
2763                            finally {
2764                                    if (list == null) {
2765                                            list = new ArrayList<CalEvent>();
2766                                    }
2767    
2768                                    cacheResult(list);
2769    
2770                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_R, finderArgs,
2771                                            list);
2772    
2773                                    closeSession(session);
2774                            }
2775                    }
2776    
2777                    return list;
2778            }
2779    
2780            /**
2781             * Finds the first cal event in the ordered set where groupId = &#63; and repeating = &#63;.
2782             *
2783             * <p>
2784             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2785             * </p>
2786             *
2787             * @param groupId the group id to search with
2788             * @param repeating the repeating to search with
2789             * @param orderByComparator the comparator to order the set by
2790             * @return the first matching cal event
2791             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
2792             * @throws SystemException if a system exception occurred
2793             */
2794            public CalEvent findByG_R_First(long groupId, boolean repeating,
2795                    OrderByComparator orderByComparator)
2796                    throws NoSuchEventException, SystemException {
2797                    List<CalEvent> list = findByG_R(groupId, repeating, 0, 1,
2798                                    orderByComparator);
2799    
2800                    if (list.isEmpty()) {
2801                            StringBundler msg = new StringBundler(6);
2802    
2803                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2804    
2805                            msg.append("groupId=");
2806                            msg.append(groupId);
2807    
2808                            msg.append(", repeating=");
2809                            msg.append(repeating);
2810    
2811                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2812    
2813                            throw new NoSuchEventException(msg.toString());
2814                    }
2815                    else {
2816                            return list.get(0);
2817                    }
2818            }
2819    
2820            /**
2821             * Finds the last cal event in the ordered set where groupId = &#63; and repeating = &#63;.
2822             *
2823             * <p>
2824             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2825             * </p>
2826             *
2827             * @param groupId the group id to search with
2828             * @param repeating the repeating to search with
2829             * @param orderByComparator the comparator to order the set by
2830             * @return the last matching cal event
2831             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
2832             * @throws SystemException if a system exception occurred
2833             */
2834            public CalEvent findByG_R_Last(long groupId, boolean repeating,
2835                    OrderByComparator orderByComparator)
2836                    throws NoSuchEventException, SystemException {
2837                    int count = countByG_R(groupId, repeating);
2838    
2839                    List<CalEvent> list = findByG_R(groupId, repeating, count - 1, count,
2840                                    orderByComparator);
2841    
2842                    if (list.isEmpty()) {
2843                            StringBundler msg = new StringBundler(6);
2844    
2845                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2846    
2847                            msg.append("groupId=");
2848                            msg.append(groupId);
2849    
2850                            msg.append(", repeating=");
2851                            msg.append(repeating);
2852    
2853                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2854    
2855                            throw new NoSuchEventException(msg.toString());
2856                    }
2857                    else {
2858                            return list.get(0);
2859                    }
2860            }
2861    
2862            /**
2863             * Finds the cal events before and after the current cal event in the ordered set where groupId = &#63; and repeating = &#63;.
2864             *
2865             * <p>
2866             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2867             * </p>
2868             *
2869             * @param eventId the primary key of the current cal event
2870             * @param groupId the group id to search with
2871             * @param repeating the repeating to search with
2872             * @param orderByComparator the comparator to order the set by
2873             * @return the previous, current, and next cal event
2874             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
2875             * @throws SystemException if a system exception occurred
2876             */
2877            public CalEvent[] findByG_R_PrevAndNext(long eventId, long groupId,
2878                    boolean repeating, OrderByComparator orderByComparator)
2879                    throws NoSuchEventException, SystemException {
2880                    CalEvent calEvent = findByPrimaryKey(eventId);
2881    
2882                    Session session = null;
2883    
2884                    try {
2885                            session = openSession();
2886    
2887                            CalEvent[] array = new CalEventImpl[3];
2888    
2889                            array[0] = getByG_R_PrevAndNext(session, calEvent, groupId,
2890                                            repeating, orderByComparator, true);
2891    
2892                            array[1] = calEvent;
2893    
2894                            array[2] = getByG_R_PrevAndNext(session, calEvent, groupId,
2895                                            repeating, orderByComparator, false);
2896    
2897                            return array;
2898                    }
2899                    catch (Exception e) {
2900                            throw processException(e);
2901                    }
2902                    finally {
2903                            closeSession(session);
2904                    }
2905            }
2906    
2907            protected CalEvent getByG_R_PrevAndNext(Session session, CalEvent calEvent,
2908                    long groupId, boolean repeating, OrderByComparator orderByComparator,
2909                    boolean previous) {
2910                    StringBundler query = null;
2911    
2912                    if (orderByComparator != null) {
2913                            query = new StringBundler(6 +
2914                                            (orderByComparator.getOrderByFields().length * 6));
2915                    }
2916                    else {
2917                            query = new StringBundler(3);
2918                    }
2919    
2920                    query.append(_SQL_SELECT_CALEVENT_WHERE);
2921    
2922                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2923    
2924                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
2925    
2926                    if (orderByComparator != null) {
2927                            String[] orderByFields = orderByComparator.getOrderByFields();
2928    
2929                            if (orderByFields.length > 0) {
2930                                    query.append(WHERE_AND);
2931                            }
2932    
2933                            for (int i = 0; i < orderByFields.length; i++) {
2934                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2935                                    query.append(orderByFields[i]);
2936    
2937                                    if ((i + 1) < orderByFields.length) {
2938                                            if (orderByComparator.isAscending() ^ previous) {
2939                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2940                                            }
2941                                            else {
2942                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2943                                            }
2944                                    }
2945                                    else {
2946                                            if (orderByComparator.isAscending() ^ previous) {
2947                                                    query.append(WHERE_GREATER_THAN);
2948                                            }
2949                                            else {
2950                                                    query.append(WHERE_LESSER_THAN);
2951                                            }
2952                                    }
2953                            }
2954    
2955                            query.append(ORDER_BY_CLAUSE);
2956    
2957                            for (int i = 0; i < orderByFields.length; i++) {
2958                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2959                                    query.append(orderByFields[i]);
2960    
2961                                    if ((i + 1) < orderByFields.length) {
2962                                            if (orderByComparator.isAscending() ^ previous) {
2963                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2964                                            }
2965                                            else {
2966                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2967                                            }
2968                                    }
2969                                    else {
2970                                            if (orderByComparator.isAscending() ^ previous) {
2971                                                    query.append(ORDER_BY_ASC);
2972                                            }
2973                                            else {
2974                                                    query.append(ORDER_BY_DESC);
2975                                            }
2976                                    }
2977                            }
2978                    }
2979    
2980                    else {
2981                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2982                    }
2983    
2984                    String sql = query.toString();
2985    
2986                    Query q = session.createQuery(sql);
2987    
2988                    q.setFirstResult(0);
2989                    q.setMaxResults(2);
2990    
2991                    QueryPos qPos = QueryPos.getInstance(q);
2992    
2993                    qPos.add(groupId);
2994    
2995                    qPos.add(repeating);
2996    
2997                    if (orderByComparator != null) {
2998                            Object[] values = orderByComparator.getOrderByValues(calEvent);
2999    
3000                            for (Object value : values) {
3001                                    qPos.add(value);
3002                            }
3003                    }
3004    
3005                    List<CalEvent> list = q.list();
3006    
3007                    if (list.size() == 2) {
3008                            return list.get(1);
3009                    }
3010                    else {
3011                            return null;
3012                    }
3013            }
3014    
3015            /**
3016             * Filters by the user's permissions and finds all the cal events where groupId = &#63; and repeating = &#63;.
3017             *
3018             * @param groupId the group id to search with
3019             * @param repeating the repeating to search with
3020             * @return the matching cal events that the user has permission to view
3021             * @throws SystemException if a system exception occurred
3022             */
3023            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating)
3024                    throws SystemException {
3025                    return filterFindByG_R(groupId, repeating, QueryUtil.ALL_POS,
3026                            QueryUtil.ALL_POS, null);
3027            }
3028    
3029            /**
3030             * Filters by the user's permissions and finds a range of all the cal events where groupId = &#63; and repeating = &#63;.
3031             *
3032             * <p>
3033             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3034             * </p>
3035             *
3036             * @param groupId the group id to search with
3037             * @param repeating the repeating to search with
3038             * @param start the lower bound of the range of cal events to return
3039             * @param end the upper bound of the range of cal events to return (not inclusive)
3040             * @return the range of matching cal events that the user has permission to view
3041             * @throws SystemException if a system exception occurred
3042             */
3043            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating,
3044                    int start, int end) throws SystemException {
3045                    return filterFindByG_R(groupId, repeating, start, end, null);
3046            }
3047    
3048            /**
3049             * Filters by the user's permissions and finds an ordered range of all the cal events where groupId = &#63; and repeating = &#63;.
3050             *
3051             * <p>
3052             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3053             * </p>
3054             *
3055             * @param groupId the group id to search with
3056             * @param repeating the repeating to search with
3057             * @param start the lower bound of the range of cal events to return
3058             * @param end the upper bound of the range of cal events to return (not inclusive)
3059             * @param orderByComparator the comparator to order the results by
3060             * @return the ordered range of matching cal events that the user has permission to view
3061             * @throws SystemException if a system exception occurred
3062             */
3063            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating,
3064                    int start, int end, OrderByComparator orderByComparator)
3065                    throws SystemException {
3066                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3067                            return findByG_R(groupId, repeating, start, end, orderByComparator);
3068                    }
3069    
3070                    Session session = null;
3071    
3072                    try {
3073                            session = openSession();
3074    
3075                            StringBundler query = null;
3076    
3077                            if (orderByComparator != null) {
3078                                    query = new StringBundler(4 +
3079                                                    (orderByComparator.getOrderByFields().length * 3));
3080                            }
3081                            else {
3082                                    query = new StringBundler(4);
3083                            }
3084    
3085                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
3086    
3087                            query.append(_FINDER_COLUMN_G_R_GROUPID_2);
3088    
3089                            query.append(_FINDER_COLUMN_G_R_REPEATING_2);
3090    
3091                            if (orderByComparator != null) {
3092                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3093                                            orderByComparator);
3094                            }
3095    
3096                            else {
3097                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
3098                            }
3099    
3100                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3101                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
3102                                            _FILTER_COLUMN_USERID, groupId);
3103    
3104                            SQLQuery q = session.createSQLQuery(sql);
3105    
3106                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
3107    
3108                            QueryPos qPos = QueryPos.getInstance(q);
3109    
3110                            qPos.add(groupId);
3111    
3112                            qPos.add(repeating);
3113    
3114                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
3115                    }
3116                    catch (Exception e) {
3117                            throw processException(e);
3118                    }
3119                    finally {
3120                            closeSession(session);
3121                    }
3122            }
3123    
3124            /**
3125             * Finds all the cal events.
3126             *
3127             * @return the cal events
3128             * @throws SystemException if a system exception occurred
3129             */
3130            public List<CalEvent> findAll() throws SystemException {
3131                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3132            }
3133    
3134            /**
3135             * Finds a range of all the cal events.
3136             *
3137             * <p>
3138             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3139             * </p>
3140             *
3141             * @param start the lower bound of the range of cal events to return
3142             * @param end the upper bound of the range of cal events to return (not inclusive)
3143             * @return the range of cal events
3144             * @throws SystemException if a system exception occurred
3145             */
3146            public List<CalEvent> findAll(int start, int end) throws SystemException {
3147                    return findAll(start, end, null);
3148            }
3149    
3150            /**
3151             * Finds an ordered range of all the cal events.
3152             *
3153             * <p>
3154             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3155             * </p>
3156             *
3157             * @param start the lower bound of the range of cal events to return
3158             * @param end the upper bound of the range of cal events to return (not inclusive)
3159             * @param orderByComparator the comparator to order the results by
3160             * @return the ordered range of cal events
3161             * @throws SystemException if a system exception occurred
3162             */
3163            public List<CalEvent> findAll(int start, int end,
3164                    OrderByComparator orderByComparator) throws SystemException {
3165                    Object[] finderArgs = new Object[] {
3166                                    String.valueOf(start), String.valueOf(end),
3167                                    String.valueOf(orderByComparator)
3168                            };
3169    
3170                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3171                                    finderArgs, this);
3172    
3173                    if (list == null) {
3174                            Session session = null;
3175    
3176                            try {
3177                                    session = openSession();
3178    
3179                                    StringBundler query = null;
3180                                    String sql = null;
3181    
3182                                    if (orderByComparator != null) {
3183                                            query = new StringBundler(2 +
3184                                                            (orderByComparator.getOrderByFields().length * 3));
3185    
3186                                            query.append(_SQL_SELECT_CALEVENT);
3187    
3188                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3189                                                    orderByComparator);
3190    
3191                                            sql = query.toString();
3192                                    }
3193                                    else {
3194                                            sql = _SQL_SELECT_CALEVENT.concat(CalEventModelImpl.ORDER_BY_JPQL);
3195                                    }
3196    
3197                                    Query q = session.createQuery(sql);
3198    
3199                                    if (orderByComparator == null) {
3200                                            list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
3201                                                            start, end, false);
3202    
3203                                            Collections.sort(list);
3204                                    }
3205                                    else {
3206                                            list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
3207                                                            start, end);
3208                                    }
3209                            }
3210                            catch (Exception e) {
3211                                    throw processException(e);
3212                            }
3213                            finally {
3214                                    if (list == null) {
3215                                            list = new ArrayList<CalEvent>();
3216                                    }
3217    
3218                                    cacheResult(list);
3219    
3220                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3221    
3222                                    closeSession(session);
3223                            }
3224                    }
3225    
3226                    return list;
3227            }
3228    
3229            /**
3230             * Removes all the cal events where uuid = &#63; from the database.
3231             *
3232             * @param uuid the uuid to search with
3233             * @throws SystemException if a system exception occurred
3234             */
3235            public void removeByUuid(String uuid) throws SystemException {
3236                    for (CalEvent calEvent : findByUuid(uuid)) {
3237                            remove(calEvent);
3238                    }
3239            }
3240    
3241            /**
3242             * Removes the cal event where uuid = &#63; and groupId = &#63; from the database.
3243             *
3244             * @param uuid the uuid to search with
3245             * @param groupId the group id to search with
3246             * @throws SystemException if a system exception occurred
3247             */
3248            public void removeByUUID_G(String uuid, long groupId)
3249                    throws NoSuchEventException, SystemException {
3250                    CalEvent calEvent = findByUUID_G(uuid, groupId);
3251    
3252                    remove(calEvent);
3253            }
3254    
3255            /**
3256             * Removes all the cal events where companyId = &#63; from the database.
3257             *
3258             * @param companyId the company id to search with
3259             * @throws SystemException if a system exception occurred
3260             */
3261            public void removeByCompanyId(long companyId) throws SystemException {
3262                    for (CalEvent calEvent : findByCompanyId(companyId)) {
3263                            remove(calEvent);
3264                    }
3265            }
3266    
3267            /**
3268             * Removes all the cal events where groupId = &#63; from the database.
3269             *
3270             * @param groupId the group id to search with
3271             * @throws SystemException if a system exception occurred
3272             */
3273            public void removeByGroupId(long groupId) throws SystemException {
3274                    for (CalEvent calEvent : findByGroupId(groupId)) {
3275                            remove(calEvent);
3276                    }
3277            }
3278    
3279            /**
3280             * Removes all the cal events where remindBy &ne; &#63; from the database.
3281             *
3282             * @param remindBy the remind by to search with
3283             * @throws SystemException if a system exception occurred
3284             */
3285            public void removeByNotRemindBy(int remindBy) throws SystemException {
3286                    for (CalEvent calEvent : findByNotRemindBy(remindBy)) {
3287                            remove(calEvent);
3288                    }
3289            }
3290    
3291            /**
3292             * Removes all the cal events where groupId = &#63; and type = &#63; from the database.
3293             *
3294             * @param groupId the group id to search with
3295             * @param type the type to search with
3296             * @throws SystemException if a system exception occurred
3297             */
3298            public void removeByG_T(long groupId, String type)
3299                    throws SystemException {
3300                    for (CalEvent calEvent : findByG_T(groupId, type)) {
3301                            remove(calEvent);
3302                    }
3303            }
3304    
3305            /**
3306             * Removes all the cal events where groupId = &#63; and repeating = &#63; from the database.
3307             *
3308             * @param groupId the group id to search with
3309             * @param repeating the repeating to search with
3310             * @throws SystemException if a system exception occurred
3311             */
3312            public void removeByG_R(long groupId, boolean repeating)
3313                    throws SystemException {
3314                    for (CalEvent calEvent : findByG_R(groupId, repeating)) {
3315                            remove(calEvent);
3316                    }
3317            }
3318    
3319            /**
3320             * Removes all the cal events from the database.
3321             *
3322             * @throws SystemException if a system exception occurred
3323             */
3324            public void removeAll() throws SystemException {
3325                    for (CalEvent calEvent : findAll()) {
3326                            remove(calEvent);
3327                    }
3328            }
3329    
3330            /**
3331             * Counts all the cal events where uuid = &#63;.
3332             *
3333             * @param uuid the uuid to search with
3334             * @return the number of matching cal events
3335             * @throws SystemException if a system exception occurred
3336             */
3337            public int countByUuid(String uuid) throws SystemException {
3338                    Object[] finderArgs = new Object[] { uuid };
3339    
3340                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3341                                    finderArgs, this);
3342    
3343                    if (count == null) {
3344                            Session session = null;
3345    
3346                            try {
3347                                    session = openSession();
3348    
3349                                    StringBundler query = new StringBundler(2);
3350    
3351                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
3352    
3353                                    if (uuid == null) {
3354                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
3355                                    }
3356                                    else {
3357                                            if (uuid.equals(StringPool.BLANK)) {
3358                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
3359                                            }
3360                                            else {
3361                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
3362                                            }
3363                                    }
3364    
3365                                    String sql = query.toString();
3366    
3367                                    Query q = session.createQuery(sql);
3368    
3369                                    QueryPos qPos = QueryPos.getInstance(q);
3370    
3371                                    if (uuid != null) {
3372                                            qPos.add(uuid);
3373                                    }
3374    
3375                                    count = (Long)q.uniqueResult();
3376                            }
3377                            catch (Exception e) {
3378                                    throw processException(e);
3379                            }
3380                            finally {
3381                                    if (count == null) {
3382                                            count = Long.valueOf(0);
3383                                    }
3384    
3385                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3386                                            finderArgs, count);
3387    
3388                                    closeSession(session);
3389                            }
3390                    }
3391    
3392                    return count.intValue();
3393            }
3394    
3395            /**
3396             * Counts all the cal events where uuid = &#63; and groupId = &#63;.
3397             *
3398             * @param uuid the uuid to search with
3399             * @param groupId the group id to search with
3400             * @return the number of matching cal events
3401             * @throws SystemException if a system exception occurred
3402             */
3403            public int countByUUID_G(String uuid, long groupId)
3404                    throws SystemException {
3405                    Object[] finderArgs = new Object[] { uuid, groupId };
3406    
3407                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3408                                    finderArgs, this);
3409    
3410                    if (count == null) {
3411                            Session session = null;
3412    
3413                            try {
3414                                    session = openSession();
3415    
3416                                    StringBundler query = new StringBundler(3);
3417    
3418                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
3419    
3420                                    if (uuid == null) {
3421                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3422                                    }
3423                                    else {
3424                                            if (uuid.equals(StringPool.BLANK)) {
3425                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3426                                            }
3427                                            else {
3428                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3429                                            }
3430                                    }
3431    
3432                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3433    
3434                                    String sql = query.toString();
3435    
3436                                    Query q = session.createQuery(sql);
3437    
3438                                    QueryPos qPos = QueryPos.getInstance(q);
3439    
3440                                    if (uuid != null) {
3441                                            qPos.add(uuid);
3442                                    }
3443    
3444                                    qPos.add(groupId);
3445    
3446                                    count = (Long)q.uniqueResult();
3447                            }
3448                            catch (Exception e) {
3449                                    throw processException(e);
3450                            }
3451                            finally {
3452                                    if (count == null) {
3453                                            count = Long.valueOf(0);
3454                                    }
3455    
3456                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3457                                            finderArgs, count);
3458    
3459                                    closeSession(session);
3460                            }
3461                    }
3462    
3463                    return count.intValue();
3464            }
3465    
3466            /**
3467             * Counts all the cal events where companyId = &#63;.
3468             *
3469             * @param companyId the company id to search with
3470             * @return the number of matching cal events
3471             * @throws SystemException if a system exception occurred
3472             */
3473            public int countByCompanyId(long companyId) throws SystemException {
3474                    Object[] finderArgs = new Object[] { companyId };
3475    
3476                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3477                                    finderArgs, this);
3478    
3479                    if (count == null) {
3480                            Session session = null;
3481    
3482                            try {
3483                                    session = openSession();
3484    
3485                                    StringBundler query = new StringBundler(2);
3486    
3487                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
3488    
3489                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3490    
3491                                    String sql = query.toString();
3492    
3493                                    Query q = session.createQuery(sql);
3494    
3495                                    QueryPos qPos = QueryPos.getInstance(q);
3496    
3497                                    qPos.add(companyId);
3498    
3499                                    count = (Long)q.uniqueResult();
3500                            }
3501                            catch (Exception e) {
3502                                    throw processException(e);
3503                            }
3504                            finally {
3505                                    if (count == null) {
3506                                            count = Long.valueOf(0);
3507                                    }
3508    
3509                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3510                                            finderArgs, count);
3511    
3512                                    closeSession(session);
3513                            }
3514                    }
3515    
3516                    return count.intValue();
3517            }
3518    
3519            /**
3520             * Counts all the cal events where groupId = &#63;.
3521             *
3522             * @param groupId the group id to search with
3523             * @return the number of matching cal events
3524             * @throws SystemException if a system exception occurred
3525             */
3526            public int countByGroupId(long groupId) throws SystemException {
3527                    Object[] finderArgs = new Object[] { groupId };
3528    
3529                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3530                                    finderArgs, this);
3531    
3532                    if (count == null) {
3533                            Session session = null;
3534    
3535                            try {
3536                                    session = openSession();
3537    
3538                                    StringBundler query = new StringBundler(2);
3539    
3540                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
3541    
3542                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3543    
3544                                    String sql = query.toString();
3545    
3546                                    Query q = session.createQuery(sql);
3547    
3548                                    QueryPos qPos = QueryPos.getInstance(q);
3549    
3550                                    qPos.add(groupId);
3551    
3552                                    count = (Long)q.uniqueResult();
3553                            }
3554                            catch (Exception e) {
3555                                    throw processException(e);
3556                            }
3557                            finally {
3558                                    if (count == null) {
3559                                            count = Long.valueOf(0);
3560                                    }
3561    
3562                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3563                                            finderArgs, count);
3564    
3565                                    closeSession(session);
3566                            }
3567                    }
3568    
3569                    return count.intValue();
3570            }
3571    
3572            /**
3573             * Filters by the user's permissions and counts all the cal events where groupId = &#63;.
3574             *
3575             * @param groupId the group id to search with
3576             * @return the number of matching cal events that the user has permission to view
3577             * @throws SystemException if a system exception occurred
3578             */
3579            public int filterCountByGroupId(long groupId) throws SystemException {
3580                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3581                            return countByGroupId(groupId);
3582                    }
3583    
3584                    Session session = null;
3585    
3586                    try {
3587                            session = openSession();
3588    
3589                            StringBundler query = new StringBundler(2);
3590    
3591                            query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
3592    
3593                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3594    
3595                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3596                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
3597                                            _FILTER_COLUMN_USERID, groupId);
3598    
3599                            SQLQuery q = session.createSQLQuery(sql);
3600    
3601                            q.addScalar(COUNT_COLUMN_NAME,
3602                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3603    
3604                            QueryPos qPos = QueryPos.getInstance(q);
3605    
3606                            qPos.add(groupId);
3607    
3608                            Long count = (Long)q.uniqueResult();
3609    
3610                            return count.intValue();
3611                    }
3612                    catch (Exception e) {
3613                            throw processException(e);
3614                    }
3615                    finally {
3616                            closeSession(session);
3617                    }
3618            }
3619    
3620            /**
3621             * Counts all the cal events where remindBy &ne; &#63;.
3622             *
3623             * @param remindBy the remind by to search with
3624             * @return the number of matching cal events
3625             * @throws SystemException if a system exception occurred
3626             */
3627            public int countByNotRemindBy(int remindBy) throws SystemException {
3628                    Object[] finderArgs = new Object[] { remindBy };
3629    
3630                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NOTREMINDBY,
3631                                    finderArgs, this);
3632    
3633                    if (count == null) {
3634                            Session session = null;
3635    
3636                            try {
3637                                    session = openSession();
3638    
3639                                    StringBundler query = new StringBundler(2);
3640    
3641                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
3642    
3643                                    query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
3644    
3645                                    String sql = query.toString();
3646    
3647                                    Query q = session.createQuery(sql);
3648    
3649                                    QueryPos qPos = QueryPos.getInstance(q);
3650    
3651                                    qPos.add(remindBy);
3652    
3653                                    count = (Long)q.uniqueResult();
3654                            }
3655                            catch (Exception e) {
3656                                    throw processException(e);
3657                            }
3658                            finally {
3659                                    if (count == null) {
3660                                            count = Long.valueOf(0);
3661                                    }
3662    
3663                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NOTREMINDBY,
3664                                            finderArgs, count);
3665    
3666                                    closeSession(session);
3667                            }
3668                    }
3669    
3670                    return count.intValue();
3671            }
3672    
3673            /**
3674             * Counts all the cal events where groupId = &#63; and type = &#63;.
3675             *
3676             * @param groupId the group id to search with
3677             * @param type the type to search with
3678             * @return the number of matching cal events
3679             * @throws SystemException if a system exception occurred
3680             */
3681            public int countByG_T(long groupId, String type) throws SystemException {
3682                    Object[] finderArgs = new Object[] { groupId, type };
3683    
3684                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
3685                                    finderArgs, this);
3686    
3687                    if (count == null) {
3688                            Session session = null;
3689    
3690                            try {
3691                                    session = openSession();
3692    
3693                                    StringBundler query = new StringBundler(3);
3694    
3695                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
3696    
3697                                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3698    
3699                                    if (type == null) {
3700                                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
3701                                    }
3702                                    else {
3703                                            if (type.equals(StringPool.BLANK)) {
3704                                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
3705                                            }
3706                                            else {
3707                                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
3708                                            }
3709                                    }
3710    
3711                                    String sql = query.toString();
3712    
3713                                    Query q = session.createQuery(sql);
3714    
3715                                    QueryPos qPos = QueryPos.getInstance(q);
3716    
3717                                    qPos.add(groupId);
3718    
3719                                    if (type != null) {
3720                                            qPos.add(type);
3721                                    }
3722    
3723                                    count = (Long)q.uniqueResult();
3724                            }
3725                            catch (Exception e) {
3726                                    throw processException(e);
3727                            }
3728                            finally {
3729                                    if (count == null) {
3730                                            count = Long.valueOf(0);
3731                                    }
3732    
3733                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
3734                                            count);
3735    
3736                                    closeSession(session);
3737                            }
3738                    }
3739    
3740                    return count.intValue();
3741            }
3742    
3743            /**
3744             * Filters by the user's permissions and counts all the cal events where groupId = &#63; and type = &#63;.
3745             *
3746             * @param groupId the group id to search with
3747             * @param type the type to search with
3748             * @return the number of matching cal events that the user has permission to view
3749             * @throws SystemException if a system exception occurred
3750             */
3751            public int filterCountByG_T(long groupId, String type)
3752                    throws SystemException {
3753                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3754                            return countByG_T(groupId, type);
3755                    }
3756    
3757                    Session session = null;
3758    
3759                    try {
3760                            session = openSession();
3761    
3762                            StringBundler query = new StringBundler(3);
3763    
3764                            query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
3765    
3766                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3767    
3768                            if (type == null) {
3769                                    query.append(_FINDER_COLUMN_G_T_TYPE_1);
3770                            }
3771                            else {
3772                                    if (type.equals(StringPool.BLANK)) {
3773                                            query.append(_FINDER_COLUMN_G_T_TYPE_3);
3774                                    }
3775                                    else {
3776                                            query.append(_FINDER_COLUMN_G_T_TYPE_2);
3777                                    }
3778                            }
3779    
3780                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3781                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
3782                                            _FILTER_COLUMN_USERID, groupId);
3783    
3784                            SQLQuery q = session.createSQLQuery(sql);
3785    
3786                            q.addScalar(COUNT_COLUMN_NAME,
3787                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3788    
3789                            QueryPos qPos = QueryPos.getInstance(q);
3790    
3791                            qPos.add(groupId);
3792    
3793                            if (type != null) {
3794                                    qPos.add(type);
3795                            }
3796    
3797                            Long count = (Long)q.uniqueResult();
3798    
3799                            return count.intValue();
3800                    }
3801                    catch (Exception e) {
3802                            throw processException(e);
3803                    }
3804                    finally {
3805                            closeSession(session);
3806                    }
3807            }
3808    
3809            /**
3810             * Counts all the cal events where groupId = &#63; and repeating = &#63;.
3811             *
3812             * @param groupId the group id to search with
3813             * @param repeating the repeating to search with
3814             * @return the number of matching cal events
3815             * @throws SystemException if a system exception occurred
3816             */
3817            public int countByG_R(long groupId, boolean repeating)
3818                    throws SystemException {
3819                    Object[] finderArgs = new Object[] { groupId, repeating };
3820    
3821                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_R,
3822                                    finderArgs, this);
3823    
3824                    if (count == null) {
3825                            Session session = null;
3826    
3827                            try {
3828                                    session = openSession();
3829    
3830                                    StringBundler query = new StringBundler(3);
3831    
3832                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
3833    
3834                                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
3835    
3836                                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
3837    
3838                                    String sql = query.toString();
3839    
3840                                    Query q = session.createQuery(sql);
3841    
3842                                    QueryPos qPos = QueryPos.getInstance(q);
3843    
3844                                    qPos.add(groupId);
3845    
3846                                    qPos.add(repeating);
3847    
3848                                    count = (Long)q.uniqueResult();
3849                            }
3850                            catch (Exception e) {
3851                                    throw processException(e);
3852                            }
3853                            finally {
3854                                    if (count == null) {
3855                                            count = Long.valueOf(0);
3856                                    }
3857    
3858                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_R, finderArgs,
3859                                            count);
3860    
3861                                    closeSession(session);
3862                            }
3863                    }
3864    
3865                    return count.intValue();
3866            }
3867    
3868            /**
3869             * Filters by the user's permissions and counts all the cal events where groupId = &#63; and repeating = &#63;.
3870             *
3871             * @param groupId the group id to search with
3872             * @param repeating the repeating to search with
3873             * @return the number of matching cal events that the user has permission to view
3874             * @throws SystemException if a system exception occurred
3875             */
3876            public int filterCountByG_R(long groupId, boolean repeating)
3877                    throws SystemException {
3878                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3879                            return countByG_R(groupId, repeating);
3880                    }
3881    
3882                    Session session = null;
3883    
3884                    try {
3885                            session = openSession();
3886    
3887                            StringBundler query = new StringBundler(3);
3888    
3889                            query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
3890    
3891                            query.append(_FINDER_COLUMN_G_R_GROUPID_2);
3892    
3893                            query.append(_FINDER_COLUMN_G_R_REPEATING_2);
3894    
3895                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3896                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
3897                                            _FILTER_COLUMN_USERID, groupId);
3898    
3899                            SQLQuery q = session.createSQLQuery(sql);
3900    
3901                            q.addScalar(COUNT_COLUMN_NAME,
3902                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3903    
3904                            QueryPos qPos = QueryPos.getInstance(q);
3905    
3906                            qPos.add(groupId);
3907    
3908                            qPos.add(repeating);
3909    
3910                            Long count = (Long)q.uniqueResult();
3911    
3912                            return count.intValue();
3913                    }
3914                    catch (Exception e) {
3915                            throw processException(e);
3916                    }
3917                    finally {
3918                            closeSession(session);
3919                    }
3920            }
3921    
3922            /**
3923             * Counts all the cal events.
3924             *
3925             * @return the number of cal events
3926             * @throws SystemException if a system exception occurred
3927             */
3928            public int countAll() throws SystemException {
3929                    Object[] finderArgs = new Object[0];
3930    
3931                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3932                                    finderArgs, this);
3933    
3934                    if (count == null) {
3935                            Session session = null;
3936    
3937                            try {
3938                                    session = openSession();
3939    
3940                                    Query q = session.createQuery(_SQL_COUNT_CALEVENT);
3941    
3942                                    count = (Long)q.uniqueResult();
3943                            }
3944                            catch (Exception e) {
3945                                    throw processException(e);
3946                            }
3947                            finally {
3948                                    if (count == null) {
3949                                            count = Long.valueOf(0);
3950                                    }
3951    
3952                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3953                                            count);
3954    
3955                                    closeSession(session);
3956                            }
3957                    }
3958    
3959                    return count.intValue();
3960            }
3961    
3962            /**
3963             * Initializes the cal event persistence.
3964             */
3965            public void afterPropertiesSet() {
3966                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3967                                            com.liferay.portal.util.PropsUtil.get(
3968                                                    "value.object.listener.com.liferay.portlet.calendar.model.CalEvent")));
3969    
3970                    if (listenerClassNames.length > 0) {
3971                            try {
3972                                    List<ModelListener<CalEvent>> listenersList = new ArrayList<ModelListener<CalEvent>>();
3973    
3974                                    for (String listenerClassName : listenerClassNames) {
3975                                            listenersList.add((ModelListener<CalEvent>)InstanceFactory.newInstance(
3976                                                            listenerClassName));
3977                                    }
3978    
3979                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3980                            }
3981                            catch (Exception e) {
3982                                    _log.error(e);
3983                            }
3984                    }
3985            }
3986    
3987            @BeanReference(type = CalEventPersistence.class)
3988            protected CalEventPersistence calEventPersistence;
3989            @BeanReference(type = CompanyPersistence.class)
3990            protected CompanyPersistence companyPersistence;
3991            @BeanReference(type = GroupPersistence.class)
3992            protected GroupPersistence groupPersistence;
3993            @BeanReference(type = PortletPreferencesPersistence.class)
3994            protected PortletPreferencesPersistence portletPreferencesPersistence;
3995            @BeanReference(type = ResourcePersistence.class)
3996            protected ResourcePersistence resourcePersistence;
3997            @BeanReference(type = UserPersistence.class)
3998            protected UserPersistence userPersistence;
3999            @BeanReference(type = AssetEntryPersistence.class)
4000            protected AssetEntryPersistence assetEntryPersistence;
4001            @BeanReference(type = AssetTagPersistence.class)
4002            protected AssetTagPersistence assetTagPersistence;
4003            @BeanReference(type = ExpandoValuePersistence.class)
4004            protected ExpandoValuePersistence expandoValuePersistence;
4005            @BeanReference(type = SocialActivityPersistence.class)
4006            protected SocialActivityPersistence socialActivityPersistence;
4007            private static final String _SQL_SELECT_CALEVENT = "SELECT calEvent FROM CalEvent calEvent";
4008            private static final String _SQL_SELECT_CALEVENT_WHERE = "SELECT calEvent FROM CalEvent calEvent WHERE ";
4009            private static final String _SQL_COUNT_CALEVENT = "SELECT COUNT(calEvent) FROM CalEvent calEvent";
4010            private static final String _SQL_COUNT_CALEVENT_WHERE = "SELECT COUNT(calEvent) FROM CalEvent calEvent WHERE ";
4011            private static final String _FINDER_COLUMN_UUID_UUID_1 = "calEvent.uuid IS NULL";
4012            private static final String _FINDER_COLUMN_UUID_UUID_2 = "calEvent.uuid = ?";
4013            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?)";
4014            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "calEvent.uuid IS NULL AND ";
4015            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "calEvent.uuid = ? AND ";
4016            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?) AND ";
4017            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "calEvent.groupId = ?";
4018            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "calEvent.companyId = ?";
4019            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "calEvent.groupId = ?";
4020            private static final String _FINDER_COLUMN_NOTREMINDBY_REMINDBY_2 = "calEvent.remindBy != ?";
4021            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "calEvent.groupId = ? AND ";
4022            private static final String _FINDER_COLUMN_G_T_TYPE_1 = "calEvent.type IS NULL";
4023            private static final String _FINDER_COLUMN_G_T_TYPE_2 = "calEvent.type = ?";
4024            private static final String _FINDER_COLUMN_G_T_TYPE_3 = "(calEvent.type IS NULL OR calEvent.type = ?)";
4025            private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "calEvent.groupId = ? AND ";
4026            private static final String _FINDER_COLUMN_G_R_REPEATING_2 = "calEvent.repeating = ?";
4027            private static final String _FILTER_SQL_SELECT_CALEVENT_WHERE = "SELECT DISTINCT {calEvent.*} FROM CalEvent calEvent WHERE ";
4028            private static final String _FILTER_SQL_COUNT_CALEVENT_WHERE = "SELECT COUNT(DISTINCT calEvent.eventId) AS COUNT_VALUE FROM CalEvent calEvent WHERE ";
4029            private static final String _FILTER_COLUMN_PK = "calEvent.eventId";
4030            private static final String _FILTER_COLUMN_USERID = "calEvent.userId";
4031            private static final String _FILTER_ENTITY_ALIAS = "calEvent";
4032            private static final String _ORDER_BY_ENTITY_ALIAS = "calEvent.";
4033            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No CalEvent exists with the primary key ";
4034            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No CalEvent exists with the key {";
4035            private static Log _log = LogFactoryUtil.getLog(CalEventPersistenceImpl.class);
4036    }