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