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