001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.calendar.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.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.sanitizer.Sanitizer;
032    import com.liferay.portal.kernel.sanitizer.SanitizerException;
033    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
034    import com.liferay.portal.kernel.util.ArrayUtil;
035    import com.liferay.portal.kernel.util.ContentTypes;
036    import com.liferay.portal.kernel.util.GetterUtil;
037    import com.liferay.portal.kernel.util.InstanceFactory;
038    import com.liferay.portal.kernel.util.OrderByComparator;
039    import com.liferay.portal.kernel.util.StringBundler;
040    import com.liferay.portal.kernel.util.StringPool;
041    import com.liferay.portal.kernel.util.StringUtil;
042    import com.liferay.portal.kernel.util.Validator;
043    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044    import com.liferay.portal.model.CacheModel;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.security.auth.PrincipalThreadLocal;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.BatchSessionUtil;
049    import com.liferay.portal.service.persistence.CompanyPersistence;
050    import com.liferay.portal.service.persistence.GroupPersistence;
051    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
052    import com.liferay.portal.service.persistence.ResourcePersistence;
053    import com.liferay.portal.service.persistence.UserPersistence;
054    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
055    
056    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
057    import com.liferay.portlet.asset.service.persistence.AssetLinkPersistence;
058    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
059    import com.liferay.portlet.calendar.NoSuchEventException;
060    import com.liferay.portlet.calendar.model.CalEvent;
061    import com.liferay.portlet.calendar.model.impl.CalEventImpl;
062    import com.liferay.portlet.calendar.model.impl.CalEventModelImpl;
063    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
064    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
065    
066    import java.io.Serializable;
067    
068    import java.util.ArrayList;
069    import java.util.Collections;
070    import java.util.List;
071    
072    /**
073     * The persistence implementation for the cal event service.
074     *
075     * <p>
076     * Caching information and settings can be found in <code>portal.properties</code>
077     * </p>
078     *
079     * @author Brian Wing Shun Chan
080     * @see CalEventPersistence
081     * @see CalEventUtil
082     * @generated
083     */
084    public class CalEventPersistenceImpl extends BasePersistenceImpl<CalEvent>
085            implements CalEventPersistence {
086            /*
087             * NOTE FOR DEVELOPERS:
088             *
089             * 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.
090             */
091            public static final String FINDER_CLASS_NAME_ENTITY = CalEventImpl.class.getName();
092            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
093                    ".List1";
094            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
095                    ".List2";
096            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
097                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
099                            new String[] {
100                                    String.class.getName(),
101                                    
102                            "java.lang.Integer", "java.lang.Integer",
103                                    "com.liferay.portal.kernel.util.OrderByComparator"
104                            });
105            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
106                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
108                            new String[] { String.class.getName() },
109                            CalEventModelImpl.UUID_COLUMN_BITMASK);
110            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
111                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
113                            new String[] { String.class.getName() });
114            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
115                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
116                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
117                            new String[] { String.class.getName(), Long.class.getName() },
118                            CalEventModelImpl.UUID_COLUMN_BITMASK |
119                            CalEventModelImpl.GROUPID_COLUMN_BITMASK);
120            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
121                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
122                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
123                            new String[] { String.class.getName(), Long.class.getName() });
124            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
125                    new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
126                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
127                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
128                            new String[] {
129                                    Long.class.getName(),
130                                    
131                            "java.lang.Integer", "java.lang.Integer",
132                                    "com.liferay.portal.kernel.util.OrderByComparator"
133                            });
134            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
135                    new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
136                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
137                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
138                            new String[] { Long.class.getName() },
139                            CalEventModelImpl.COMPANYID_COLUMN_BITMASK);
140            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
141                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
142                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
143                            new String[] { Long.class.getName() });
144            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
145                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
146                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
147                            new String[] {
148                                    Long.class.getName(),
149                                    
150                            "java.lang.Integer", "java.lang.Integer",
151                                    "com.liferay.portal.kernel.util.OrderByComparator"
152                            });
153            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
154                    new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
155                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
156                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
157                            new String[] { Long.class.getName() },
158                            CalEventModelImpl.GROUPID_COLUMN_BITMASK);
159            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
160                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
161                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
162                            new String[] { Long.class.getName() });
163            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTREMINDBY =
164                    new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
165                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
166                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNotRemindBy",
167                            new String[] {
168                                    Integer.class.getName(),
169                                    
170                            "java.lang.Integer", "java.lang.Integer",
171                                    "com.liferay.portal.kernel.util.OrderByComparator"
172                            });
173            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOTREMINDBY =
174                    new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
175                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
176                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByNotRemindBy",
177                            new String[] { Integer.class.getName() },
178                            CalEventModelImpl.REMINDBY_COLUMN_BITMASK);
179            public static final FinderPath FINDER_PATH_COUNT_BY_NOTREMINDBY = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
180                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
181                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByNotRemindBy",
182                            new String[] { Integer.class.getName() });
183            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
184                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
185                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_T",
186                            new String[] {
187                                    Long.class.getName(), String.class.getName(),
188                                    
189                            "java.lang.Integer", "java.lang.Integer",
190                                    "com.liferay.portal.kernel.util.OrderByComparator"
191                            });
192            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
193                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
194                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_T",
195                            new String[] { Long.class.getName(), String.class.getName() },
196                            CalEventModelImpl.GROUPID_COLUMN_BITMASK |
197                            CalEventModelImpl.TYPE_COLUMN_BITMASK);
198            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
199                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T",
201                            new String[] { Long.class.getName(), String.class.getName() });
202            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
203                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
204                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_T",
205                            new String[] { Long.class.getName(), String.class.getName() });
206            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
207                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
208                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_R",
209                            new String[] {
210                                    Long.class.getName(), Boolean.class.getName(),
211                                    
212                            "java.lang.Integer", "java.lang.Integer",
213                                    "com.liferay.portal.kernel.util.OrderByComparator"
214                            });
215            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
216                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
217                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_R",
218                            new String[] { Long.class.getName(), Boolean.class.getName() },
219                            CalEventModelImpl.GROUPID_COLUMN_BITMASK |
220                            CalEventModelImpl.REPEATING_COLUMN_BITMASK);
221            public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
222                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
223                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_R",
224                            new String[] { Long.class.getName(), Boolean.class.getName() });
225            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
226                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
227                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_T_R",
228                            new String[] {
229                                    Long.class.getName(), String.class.getName(),
230                                    Boolean.class.getName(),
231                                    
232                            "java.lang.Integer", "java.lang.Integer",
233                                    "com.liferay.portal.kernel.util.OrderByComparator"
234                            });
235            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
236                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
237                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_T_R",
238                            new String[] {
239                                    Long.class.getName(), String.class.getName(),
240                                    Boolean.class.getName()
241                            },
242                            CalEventModelImpl.GROUPID_COLUMN_BITMASK |
243                            CalEventModelImpl.TYPE_COLUMN_BITMASK |
244                            CalEventModelImpl.REPEATING_COLUMN_BITMASK);
245            public static final FinderPath FINDER_PATH_COUNT_BY_G_T_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
246                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
247                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T_R",
248                            new String[] {
249                                    Long.class.getName(), String.class.getName(),
250                                    Boolean.class.getName()
251                            });
252            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
253                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
254                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_T_R",
255                            new String[] {
256                                    Long.class.getName(), String.class.getName(),
257                                    Boolean.class.getName()
258                            });
259            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
260                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
261                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
262            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
263                            CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
264                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
265            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
266                            CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
267                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
268    
269            /**
270             * Caches the cal event in the entity cache if it is enabled.
271             *
272             * @param calEvent the cal event
273             */
274            public void cacheResult(CalEvent calEvent) {
275                    EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
276                            CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
277    
278                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
279                            new Object[] { calEvent.getUuid(), Long.valueOf(
280                                            calEvent.getGroupId()) }, calEvent);
281    
282                    calEvent.resetOriginalValues();
283            }
284    
285            /**
286             * Caches the cal events in the entity cache if it is enabled.
287             *
288             * @param calEvents the cal events
289             */
290            public void cacheResult(List<CalEvent> calEvents) {
291                    for (CalEvent calEvent : calEvents) {
292                            if (EntityCacheUtil.getResult(
293                                                    CalEventModelImpl.ENTITY_CACHE_ENABLED,
294                                                    CalEventImpl.class, calEvent.getPrimaryKey()) == null) {
295                                    cacheResult(calEvent);
296                            }
297                            else {
298                                    calEvent.resetOriginalValues();
299                            }
300                    }
301            }
302    
303            /**
304             * Clears the cache for all cal events.
305             *
306             * <p>
307             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
308             * </p>
309             */
310            @Override
311            public void clearCache() {
312                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
313                            CacheRegistryUtil.clear(CalEventImpl.class.getName());
314                    }
315    
316                    EntityCacheUtil.clearCache(CalEventImpl.class.getName());
317    
318                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
319                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
320                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
321            }
322    
323            /**
324             * Clears the cache for the cal event.
325             *
326             * <p>
327             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
328             * </p>
329             */
330            @Override
331            public void clearCache(CalEvent calEvent) {
332                    EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
333                            CalEventImpl.class, calEvent.getPrimaryKey());
334    
335                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
336                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
337    
338                    clearUniqueFindersCache(calEvent);
339            }
340    
341            @Override
342            public void clearCache(List<CalEvent> calEvents) {
343                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
344                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
345    
346                    for (CalEvent calEvent : calEvents) {
347                            EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
348                                    CalEventImpl.class, calEvent.getPrimaryKey());
349    
350                            clearUniqueFindersCache(calEvent);
351                    }
352            }
353    
354            protected void clearUniqueFindersCache(CalEvent calEvent) {
355                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
356                            new Object[] { calEvent.getUuid(), Long.valueOf(
357                                            calEvent.getGroupId()) });
358            }
359    
360            /**
361             * Creates a new cal event with the primary key. Does not add the cal event to the database.
362             *
363             * @param eventId the primary key for the new cal event
364             * @return the new cal event
365             */
366            public CalEvent create(long eventId) {
367                    CalEvent calEvent = new CalEventImpl();
368    
369                    calEvent.setNew(true);
370                    calEvent.setPrimaryKey(eventId);
371    
372                    String uuid = PortalUUIDUtil.generate();
373    
374                    calEvent.setUuid(uuid);
375    
376                    return calEvent;
377            }
378    
379            /**
380             * Removes the cal event with the primary key from the database. Also notifies the appropriate model listeners.
381             *
382             * @param eventId the primary key of the cal event
383             * @return the cal event that was removed
384             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
385             * @throws SystemException if a system exception occurred
386             */
387            public CalEvent remove(long eventId)
388                    throws NoSuchEventException, SystemException {
389                    return remove(Long.valueOf(eventId));
390            }
391    
392            /**
393             * Removes the cal event with the primary key from the database. Also notifies the appropriate model listeners.
394             *
395             * @param primaryKey the primary key of the cal event
396             * @return the cal event that was removed
397             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
398             * @throws SystemException if a system exception occurred
399             */
400            @Override
401            public CalEvent remove(Serializable primaryKey)
402                    throws NoSuchEventException, SystemException {
403                    Session session = null;
404    
405                    try {
406                            session = openSession();
407    
408                            CalEvent calEvent = (CalEvent)session.get(CalEventImpl.class,
409                                            primaryKey);
410    
411                            if (calEvent == null) {
412                                    if (_log.isWarnEnabled()) {
413                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
414                                    }
415    
416                                    throw new NoSuchEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
417                                            primaryKey);
418                            }
419    
420                            return remove(calEvent);
421                    }
422                    catch (NoSuchEventException nsee) {
423                            throw nsee;
424                    }
425                    catch (Exception e) {
426                            throw processException(e);
427                    }
428                    finally {
429                            closeSession(session);
430                    }
431            }
432    
433            @Override
434            protected CalEvent removeImpl(CalEvent calEvent) throws SystemException {
435                    calEvent = toUnwrappedModel(calEvent);
436    
437                    Session session = null;
438    
439                    try {
440                            session = openSession();
441    
442                            BatchSessionUtil.delete(session, calEvent);
443                    }
444                    catch (Exception e) {
445                            throw processException(e);
446                    }
447                    finally {
448                            closeSession(session);
449                    }
450    
451                    clearCache(calEvent);
452    
453                    return calEvent;
454            }
455    
456            @Override
457            public CalEvent updateImpl(
458                    com.liferay.portlet.calendar.model.CalEvent calEvent, boolean merge)
459                    throws SystemException {
460                    calEvent = toUnwrappedModel(calEvent);
461    
462                    boolean isNew = calEvent.isNew();
463    
464                    CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
465    
466                    if (Validator.isNull(calEvent.getUuid())) {
467                            String uuid = PortalUUIDUtil.generate();
468    
469                            calEvent.setUuid(uuid);
470                    }
471    
472                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
473    
474                    if (userId > 0) {
475                            long companyId = calEvent.getCompanyId();
476    
477                            long groupId = calEvent.getGroupId();
478    
479                            long eventId = 0;
480    
481                            if (!isNew) {
482                                    eventId = calEvent.getPrimaryKey();
483                            }
484    
485                            try {
486                                    calEvent.setTitle(SanitizerUtil.sanitize(companyId, groupId,
487                                                    userId,
488                                                    com.liferay.portlet.calendar.model.CalEvent.class.getName(),
489                                                    eventId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
490                                                    calEvent.getTitle(), null));
491    
492                                    calEvent.setDescription(SanitizerUtil.sanitize(companyId,
493                                                    groupId, userId,
494                                                    com.liferay.portlet.calendar.model.CalEvent.class.getName(),
495                                                    eventId, ContentTypes.TEXT_HTML, Sanitizer.MODE_ALL,
496                                                    calEvent.getDescription(), null));
497                            }
498                            catch (SanitizerException se) {
499                                    throw new SystemException(se);
500                            }
501                    }
502    
503                    Session session = null;
504    
505                    try {
506                            session = openSession();
507    
508                            BatchSessionUtil.update(session, calEvent, merge);
509    
510                            calEvent.setNew(false);
511                    }
512                    catch (Exception e) {
513                            throw processException(e);
514                    }
515                    finally {
516                            closeSession(session);
517                    }
518    
519                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
520    
521                    if (isNew || !CalEventModelImpl.COLUMN_BITMASK_ENABLED) {
522                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
523                    }
524                    else {
525                            if ((calEventModelImpl.getColumnBitmask() &
526                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
527                                    Object[] args = new Object[] { calEventModelImpl.getOriginalUuid() };
528    
529                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
530                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
531                                            args);
532    
533                                    args = new Object[] { calEventModelImpl.getUuid() };
534    
535                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
536                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
537                                            args);
538                            }
539    
540                            if ((calEventModelImpl.getColumnBitmask() &
541                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
542                                    Object[] args = new Object[] {
543                                                    Long.valueOf(calEventModelImpl.getOriginalCompanyId())
544                                            };
545    
546                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
547                                            args);
548                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
549                                            args);
550    
551                                    args = new Object[] {
552                                                    Long.valueOf(calEventModelImpl.getCompanyId())
553                                            };
554    
555                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
556                                            args);
557                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
558                                            args);
559                            }
560    
561                            if ((calEventModelImpl.getColumnBitmask() &
562                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
563                                    Object[] args = new Object[] {
564                                                    Long.valueOf(calEventModelImpl.getOriginalGroupId())
565                                            };
566    
567                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
568                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
569                                            args);
570    
571                                    args = new Object[] { Long.valueOf(calEventModelImpl.getGroupId()) };
572    
573                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
574                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
575                                            args);
576                            }
577    
578                            if ((calEventModelImpl.getColumnBitmask() &
579                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOTREMINDBY.getColumnBitmask()) != 0) {
580                                    Object[] args = new Object[] {
581                                                    Integer.valueOf(calEventModelImpl.getOriginalRemindBy())
582                                            };
583    
584                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NOTREMINDBY,
585                                            args);
586                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOTREMINDBY,
587                                            args);
588    
589                                    args = new Object[] {
590                                                    Integer.valueOf(calEventModelImpl.getRemindBy())
591                                            };
592    
593                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NOTREMINDBY,
594                                            args);
595                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOTREMINDBY,
596                                            args);
597                            }
598    
599                            if ((calEventModelImpl.getColumnBitmask() &
600                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T.getColumnBitmask()) != 0) {
601                                    Object[] args = new Object[] {
602                                                    Long.valueOf(calEventModelImpl.getOriginalGroupId()),
603                                                    
604                                                    calEventModelImpl.getOriginalType()
605                                            };
606    
607                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
608                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T,
609                                            args);
610    
611                                    args = new Object[] {
612                                                    Long.valueOf(calEventModelImpl.getGroupId()),
613                                                    
614                                                    calEventModelImpl.getType()
615                                            };
616    
617                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
618                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T,
619                                            args);
620                            }
621    
622                            if ((calEventModelImpl.getColumnBitmask() &
623                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R.getColumnBitmask()) != 0) {
624                                    Object[] args = new Object[] {
625                                                    Long.valueOf(calEventModelImpl.getOriginalGroupId()),
626                                                    Boolean.valueOf(calEventModelImpl.getOriginalRepeating())
627                                            };
628    
629                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
630                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
631                                            args);
632    
633                                    args = new Object[] {
634                                                    Long.valueOf(calEventModelImpl.getGroupId()),
635                                                    Boolean.valueOf(calEventModelImpl.getRepeating())
636                                            };
637    
638                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
639                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
640                                            args);
641                            }
642    
643                            if ((calEventModelImpl.getColumnBitmask() &
644                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R.getColumnBitmask()) != 0) {
645                                    Object[] args = new Object[] {
646                                                    Long.valueOf(calEventModelImpl.getOriginalGroupId()),
647                                                    
648                                                    calEventModelImpl.getOriginalType(),
649                                                    Boolean.valueOf(calEventModelImpl.getOriginalRepeating())
650                                            };
651    
652                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T_R, args);
653                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R,
654                                            args);
655    
656                                    args = new Object[] {
657                                                    Long.valueOf(calEventModelImpl.getGroupId()),
658                                                    
659                                                    calEventModelImpl.getType(),
660                                                    Boolean.valueOf(calEventModelImpl.getRepeating())
661                                            };
662    
663                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T_R, args);
664                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R,
665                                            args);
666                            }
667                    }
668    
669                    EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
670                            CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
671    
672                    if (isNew) {
673                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
674                                    new Object[] {
675                                            calEvent.getUuid(), Long.valueOf(calEvent.getGroupId())
676                                    }, calEvent);
677                    }
678                    else {
679                            if ((calEventModelImpl.getColumnBitmask() &
680                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
681                                    Object[] args = new Object[] {
682                                                    calEventModelImpl.getOriginalUuid(),
683                                                    Long.valueOf(calEventModelImpl.getOriginalGroupId())
684                                            };
685    
686                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
687                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
688    
689                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
690                                            new Object[] {
691                                                    calEvent.getUuid(), Long.valueOf(calEvent.getGroupId())
692                                            }, calEvent);
693                            }
694                    }
695    
696                    return calEvent;
697            }
698    
699            protected CalEvent toUnwrappedModel(CalEvent calEvent) {
700                    if (calEvent instanceof CalEventImpl) {
701                            return calEvent;
702                    }
703    
704                    CalEventImpl calEventImpl = new CalEventImpl();
705    
706                    calEventImpl.setNew(calEvent.isNew());
707                    calEventImpl.setPrimaryKey(calEvent.getPrimaryKey());
708    
709                    calEventImpl.setUuid(calEvent.getUuid());
710                    calEventImpl.setEventId(calEvent.getEventId());
711                    calEventImpl.setGroupId(calEvent.getGroupId());
712                    calEventImpl.setCompanyId(calEvent.getCompanyId());
713                    calEventImpl.setUserId(calEvent.getUserId());
714                    calEventImpl.setUserName(calEvent.getUserName());
715                    calEventImpl.setCreateDate(calEvent.getCreateDate());
716                    calEventImpl.setModifiedDate(calEvent.getModifiedDate());
717                    calEventImpl.setTitle(calEvent.getTitle());
718                    calEventImpl.setDescription(calEvent.getDescription());
719                    calEventImpl.setLocation(calEvent.getLocation());
720                    calEventImpl.setStartDate(calEvent.getStartDate());
721                    calEventImpl.setEndDate(calEvent.getEndDate());
722                    calEventImpl.setDurationHour(calEvent.getDurationHour());
723                    calEventImpl.setDurationMinute(calEvent.getDurationMinute());
724                    calEventImpl.setAllDay(calEvent.isAllDay());
725                    calEventImpl.setTimeZoneSensitive(calEvent.isTimeZoneSensitive());
726                    calEventImpl.setType(calEvent.getType());
727                    calEventImpl.setRepeating(calEvent.isRepeating());
728                    calEventImpl.setRecurrence(calEvent.getRecurrence());
729                    calEventImpl.setRemindBy(calEvent.getRemindBy());
730                    calEventImpl.setFirstReminder(calEvent.getFirstReminder());
731                    calEventImpl.setSecondReminder(calEvent.getSecondReminder());
732    
733                    return calEventImpl;
734            }
735    
736            /**
737             * Returns the cal event with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
738             *
739             * @param primaryKey the primary key of the cal event
740             * @return the cal event
741             * @throws com.liferay.portal.NoSuchModelException if a cal event with the primary key could not be found
742             * @throws SystemException if a system exception occurred
743             */
744            @Override
745            public CalEvent findByPrimaryKey(Serializable primaryKey)
746                    throws NoSuchModelException, SystemException {
747                    return findByPrimaryKey(((Long)primaryKey).longValue());
748            }
749    
750            /**
751             * Returns the cal event with the primary key or throws a {@link com.liferay.portlet.calendar.NoSuchEventException} if it could not be found.
752             *
753             * @param eventId the primary key of the cal event
754             * @return the cal event
755             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
756             * @throws SystemException if a system exception occurred
757             */
758            public CalEvent findByPrimaryKey(long eventId)
759                    throws NoSuchEventException, SystemException {
760                    CalEvent calEvent = fetchByPrimaryKey(eventId);
761    
762                    if (calEvent == null) {
763                            if (_log.isWarnEnabled()) {
764                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + eventId);
765                            }
766    
767                            throw new NoSuchEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
768                                    eventId);
769                    }
770    
771                    return calEvent;
772            }
773    
774            /**
775             * Returns the cal event with the primary key or returns <code>null</code> if it could not be found.
776             *
777             * @param primaryKey the primary key of the cal event
778             * @return the cal event, or <code>null</code> if a cal event with the primary key could not be found
779             * @throws SystemException if a system exception occurred
780             */
781            @Override
782            public CalEvent fetchByPrimaryKey(Serializable primaryKey)
783                    throws SystemException {
784                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
785            }
786    
787            /**
788             * Returns the cal event with the primary key or returns <code>null</code> if it could not be found.
789             *
790             * @param eventId the primary key of the cal event
791             * @return the cal event, or <code>null</code> if a cal event with the primary key could not be found
792             * @throws SystemException if a system exception occurred
793             */
794            public CalEvent fetchByPrimaryKey(long eventId) throws SystemException {
795                    CalEvent calEvent = (CalEvent)EntityCacheUtil.getResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
796                                    CalEventImpl.class, eventId);
797    
798                    if (calEvent == _nullCalEvent) {
799                            return null;
800                    }
801    
802                    if (calEvent == null) {
803                            Session session = null;
804    
805                            boolean hasException = false;
806    
807                            try {
808                                    session = openSession();
809    
810                                    calEvent = (CalEvent)session.get(CalEventImpl.class,
811                                                    Long.valueOf(eventId));
812                            }
813                            catch (Exception e) {
814                                    hasException = true;
815    
816                                    throw processException(e);
817                            }
818                            finally {
819                                    if (calEvent != null) {
820                                            cacheResult(calEvent);
821                                    }
822                                    else if (!hasException) {
823                                            EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
824                                                    CalEventImpl.class, eventId, _nullCalEvent);
825                                    }
826    
827                                    closeSession(session);
828                            }
829                    }
830    
831                    return calEvent;
832            }
833    
834            /**
835             * Returns all the cal events where uuid = &#63;.
836             *
837             * @param uuid the uuid
838             * @return the matching cal events
839             * @throws SystemException if a system exception occurred
840             */
841            public List<CalEvent> findByUuid(String uuid) throws SystemException {
842                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
843            }
844    
845            /**
846             * Returns a range of all the cal events where uuid = &#63;.
847             *
848             * <p>
849             * 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.
850             * </p>
851             *
852             * @param uuid the uuid
853             * @param start the lower bound of the range of cal events
854             * @param end the upper bound of the range of cal events (not inclusive)
855             * @return the range of matching cal events
856             * @throws SystemException if a system exception occurred
857             */
858            public List<CalEvent> findByUuid(String uuid, int start, int end)
859                    throws SystemException {
860                    return findByUuid(uuid, start, end, null);
861            }
862    
863            /**
864             * Returns an ordered range of all the cal events where uuid = &#63;.
865             *
866             * <p>
867             * 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.
868             * </p>
869             *
870             * @param uuid the uuid
871             * @param start the lower bound of the range of cal events
872             * @param end the upper bound of the range of cal events (not inclusive)
873             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
874             * @return the ordered range of matching cal events
875             * @throws SystemException if a system exception occurred
876             */
877            public List<CalEvent> findByUuid(String uuid, int start, int end,
878                    OrderByComparator orderByComparator) throws SystemException {
879                    FinderPath finderPath = null;
880                    Object[] finderArgs = null;
881    
882                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
883                                    (orderByComparator == null)) {
884                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
885                            finderArgs = new Object[] { uuid };
886                    }
887                    else {
888                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
889                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
890                    }
891    
892                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
893                                    finderArgs, this);
894    
895                    if ((list != null) && !list.isEmpty()) {
896                            for (CalEvent calEvent : list) {
897                                    if (!Validator.equals(uuid, calEvent.getUuid())) {
898                                            list = null;
899    
900                                            break;
901                                    }
902                            }
903                    }
904    
905                    if (list == null) {
906                            StringBundler query = null;
907    
908                            if (orderByComparator != null) {
909                                    query = new StringBundler(3 +
910                                                    (orderByComparator.getOrderByFields().length * 3));
911                            }
912                            else {
913                                    query = new StringBundler(3);
914                            }
915    
916                            query.append(_SQL_SELECT_CALEVENT_WHERE);
917    
918                            if (uuid == null) {
919                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
920                            }
921                            else {
922                                    if (uuid.equals(StringPool.BLANK)) {
923                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
924                                    }
925                                    else {
926                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
927                                    }
928                            }
929    
930                            if (orderByComparator != null) {
931                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
932                                            orderByComparator);
933                            }
934    
935                            else {
936                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
937                            }
938    
939                            String sql = query.toString();
940    
941                            Session session = null;
942    
943                            try {
944                                    session = openSession();
945    
946                                    Query q = session.createQuery(sql);
947    
948                                    QueryPos qPos = QueryPos.getInstance(q);
949    
950                                    if (uuid != null) {
951                                            qPos.add(uuid);
952                                    }
953    
954                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
955                                                    end);
956                            }
957                            catch (Exception e) {
958                                    throw processException(e);
959                            }
960                            finally {
961                                    if (list == null) {
962                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
963                                    }
964                                    else {
965                                            cacheResult(list);
966    
967                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
968                                    }
969    
970                                    closeSession(session);
971                            }
972                    }
973    
974                    return list;
975            }
976    
977            /**
978             * Returns the first cal event in the ordered set where uuid = &#63;.
979             *
980             * <p>
981             * 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.
982             * </p>
983             *
984             * @param uuid the uuid
985             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
986             * @return the first matching cal event
987             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
988             * @throws SystemException if a system exception occurred
989             */
990            public CalEvent findByUuid_First(String uuid,
991                    OrderByComparator orderByComparator)
992                    throws NoSuchEventException, SystemException {
993                    List<CalEvent> list = findByUuid(uuid, 0, 1, orderByComparator);
994    
995                    if (list.isEmpty()) {
996                            StringBundler msg = new StringBundler(4);
997    
998                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
999    
1000                            msg.append("uuid=");
1001                            msg.append(uuid);
1002    
1003                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1004    
1005                            throw new NoSuchEventException(msg.toString());
1006                    }
1007                    else {
1008                            return list.get(0);
1009                    }
1010            }
1011    
1012            /**
1013             * Returns the last cal event in the ordered set where uuid = &#63;.
1014             *
1015             * <p>
1016             * 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.
1017             * </p>
1018             *
1019             * @param uuid the uuid
1020             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1021             * @return the last matching cal event
1022             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1023             * @throws SystemException if a system exception occurred
1024             */
1025            public CalEvent findByUuid_Last(String uuid,
1026                    OrderByComparator orderByComparator)
1027                    throws NoSuchEventException, SystemException {
1028                    int count = countByUuid(uuid);
1029    
1030                    List<CalEvent> list = findByUuid(uuid, count - 1, count,
1031                                    orderByComparator);
1032    
1033                    if (list.isEmpty()) {
1034                            StringBundler msg = new StringBundler(4);
1035    
1036                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1037    
1038                            msg.append("uuid=");
1039                            msg.append(uuid);
1040    
1041                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1042    
1043                            throw new NoSuchEventException(msg.toString());
1044                    }
1045                    else {
1046                            return list.get(0);
1047                    }
1048            }
1049    
1050            /**
1051             * Returns the cal events before and after the current cal event in the ordered set where uuid = &#63;.
1052             *
1053             * <p>
1054             * 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.
1055             * </p>
1056             *
1057             * @param eventId the primary key of the current cal event
1058             * @param uuid the uuid
1059             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1060             * @return the previous, current, and next cal event
1061             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
1062             * @throws SystemException if a system exception occurred
1063             */
1064            public CalEvent[] findByUuid_PrevAndNext(long eventId, String uuid,
1065                    OrderByComparator orderByComparator)
1066                    throws NoSuchEventException, SystemException {
1067                    CalEvent calEvent = findByPrimaryKey(eventId);
1068    
1069                    Session session = null;
1070    
1071                    try {
1072                            session = openSession();
1073    
1074                            CalEvent[] array = new CalEventImpl[3];
1075    
1076                            array[0] = getByUuid_PrevAndNext(session, calEvent, uuid,
1077                                            orderByComparator, true);
1078    
1079                            array[1] = calEvent;
1080    
1081                            array[2] = getByUuid_PrevAndNext(session, calEvent, uuid,
1082                                            orderByComparator, false);
1083    
1084                            return array;
1085                    }
1086                    catch (Exception e) {
1087                            throw processException(e);
1088                    }
1089                    finally {
1090                            closeSession(session);
1091                    }
1092            }
1093    
1094            protected CalEvent getByUuid_PrevAndNext(Session session,
1095                    CalEvent calEvent, String uuid, OrderByComparator orderByComparator,
1096                    boolean previous) {
1097                    StringBundler query = null;
1098    
1099                    if (orderByComparator != null) {
1100                            query = new StringBundler(6 +
1101                                            (orderByComparator.getOrderByFields().length * 6));
1102                    }
1103                    else {
1104                            query = new StringBundler(3);
1105                    }
1106    
1107                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1108    
1109                    if (uuid == null) {
1110                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1111                    }
1112                    else {
1113                            if (uuid.equals(StringPool.BLANK)) {
1114                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1115                            }
1116                            else {
1117                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1118                            }
1119                    }
1120    
1121                    if (orderByComparator != null) {
1122                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1123    
1124                            if (orderByConditionFields.length > 0) {
1125                                    query.append(WHERE_AND);
1126                            }
1127    
1128                            for (int i = 0; i < orderByConditionFields.length; i++) {
1129                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1130                                    query.append(orderByConditionFields[i]);
1131    
1132                                    if ((i + 1) < orderByConditionFields.length) {
1133                                            if (orderByComparator.isAscending() ^ previous) {
1134                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1135                                            }
1136                                            else {
1137                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1138                                            }
1139                                    }
1140                                    else {
1141                                            if (orderByComparator.isAscending() ^ previous) {
1142                                                    query.append(WHERE_GREATER_THAN);
1143                                            }
1144                                            else {
1145                                                    query.append(WHERE_LESSER_THAN);
1146                                            }
1147                                    }
1148                            }
1149    
1150                            query.append(ORDER_BY_CLAUSE);
1151    
1152                            String[] orderByFields = orderByComparator.getOrderByFields();
1153    
1154                            for (int i = 0; i < orderByFields.length; i++) {
1155                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1156                                    query.append(orderByFields[i]);
1157    
1158                                    if ((i + 1) < orderByFields.length) {
1159                                            if (orderByComparator.isAscending() ^ previous) {
1160                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1161                                            }
1162                                            else {
1163                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1164                                            }
1165                                    }
1166                                    else {
1167                                            if (orderByComparator.isAscending() ^ previous) {
1168                                                    query.append(ORDER_BY_ASC);
1169                                            }
1170                                            else {
1171                                                    query.append(ORDER_BY_DESC);
1172                                            }
1173                                    }
1174                            }
1175                    }
1176    
1177                    else {
1178                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1179                    }
1180    
1181                    String sql = query.toString();
1182    
1183                    Query q = session.createQuery(sql);
1184    
1185                    q.setFirstResult(0);
1186                    q.setMaxResults(2);
1187    
1188                    QueryPos qPos = QueryPos.getInstance(q);
1189    
1190                    if (uuid != null) {
1191                            qPos.add(uuid);
1192                    }
1193    
1194                    if (orderByComparator != null) {
1195                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
1196    
1197                            for (Object value : values) {
1198                                    qPos.add(value);
1199                            }
1200                    }
1201    
1202                    List<CalEvent> list = q.list();
1203    
1204                    if (list.size() == 2) {
1205                            return list.get(1);
1206                    }
1207                    else {
1208                            return null;
1209                    }
1210            }
1211    
1212            /**
1213             * Returns the cal event where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.calendar.NoSuchEventException} if it could not be found.
1214             *
1215             * @param uuid the uuid
1216             * @param groupId the group ID
1217             * @return the matching cal event
1218             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1219             * @throws SystemException if a system exception occurred
1220             */
1221            public CalEvent findByUUID_G(String uuid, long groupId)
1222                    throws NoSuchEventException, SystemException {
1223                    CalEvent calEvent = fetchByUUID_G(uuid, groupId);
1224    
1225                    if (calEvent == null) {
1226                            StringBundler msg = new StringBundler(6);
1227    
1228                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1229    
1230                            msg.append("uuid=");
1231                            msg.append(uuid);
1232    
1233                            msg.append(", groupId=");
1234                            msg.append(groupId);
1235    
1236                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1237    
1238                            if (_log.isWarnEnabled()) {
1239                                    _log.warn(msg.toString());
1240                            }
1241    
1242                            throw new NoSuchEventException(msg.toString());
1243                    }
1244    
1245                    return calEvent;
1246            }
1247    
1248            /**
1249             * Returns the cal event where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1250             *
1251             * @param uuid the uuid
1252             * @param groupId the group ID
1253             * @return the matching cal event, or <code>null</code> if a matching cal event could not be found
1254             * @throws SystemException if a system exception occurred
1255             */
1256            public CalEvent fetchByUUID_G(String uuid, long groupId)
1257                    throws SystemException {
1258                    return fetchByUUID_G(uuid, groupId, true);
1259            }
1260    
1261            /**
1262             * Returns 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.
1263             *
1264             * @param uuid the uuid
1265             * @param groupId the group ID
1266             * @param retrieveFromCache whether to use the finder cache
1267             * @return the matching cal event, or <code>null</code> if a matching cal event could not be found
1268             * @throws SystemException if a system exception occurred
1269             */
1270            public CalEvent fetchByUUID_G(String uuid, long groupId,
1271                    boolean retrieveFromCache) throws SystemException {
1272                    Object[] finderArgs = new Object[] { uuid, groupId };
1273    
1274                    Object result = null;
1275    
1276                    if (retrieveFromCache) {
1277                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1278                                            finderArgs, this);
1279                    }
1280    
1281                    if (result instanceof CalEvent) {
1282                            CalEvent calEvent = (CalEvent)result;
1283    
1284                            if (!Validator.equals(uuid, calEvent.getUuid()) ||
1285                                            (groupId != calEvent.getGroupId())) {
1286                                    result = null;
1287                            }
1288                    }
1289    
1290                    if (result == null) {
1291                            StringBundler query = new StringBundler(4);
1292    
1293                            query.append(_SQL_SELECT_CALEVENT_WHERE);
1294    
1295                            if (uuid == null) {
1296                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1297                            }
1298                            else {
1299                                    if (uuid.equals(StringPool.BLANK)) {
1300                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1301                                    }
1302                                    else {
1303                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1304                                    }
1305                            }
1306    
1307                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1308    
1309                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1310    
1311                            String sql = query.toString();
1312    
1313                            Session session = null;
1314    
1315                            try {
1316                                    session = openSession();
1317    
1318                                    Query q = session.createQuery(sql);
1319    
1320                                    QueryPos qPos = QueryPos.getInstance(q);
1321    
1322                                    if (uuid != null) {
1323                                            qPos.add(uuid);
1324                                    }
1325    
1326                                    qPos.add(groupId);
1327    
1328                                    List<CalEvent> list = q.list();
1329    
1330                                    result = list;
1331    
1332                                    CalEvent calEvent = null;
1333    
1334                                    if (list.isEmpty()) {
1335                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1336                                                    finderArgs, list);
1337                                    }
1338                                    else {
1339                                            calEvent = list.get(0);
1340    
1341                                            cacheResult(calEvent);
1342    
1343                                            if ((calEvent.getUuid() == null) ||
1344                                                            !calEvent.getUuid().equals(uuid) ||
1345                                                            (calEvent.getGroupId() != groupId)) {
1346                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1347                                                            finderArgs, calEvent);
1348                                            }
1349                                    }
1350    
1351                                    return calEvent;
1352                            }
1353                            catch (Exception e) {
1354                                    throw processException(e);
1355                            }
1356                            finally {
1357                                    if (result == null) {
1358                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1359                                                    finderArgs);
1360                                    }
1361    
1362                                    closeSession(session);
1363                            }
1364                    }
1365                    else {
1366                            if (result instanceof List<?>) {
1367                                    return null;
1368                            }
1369                            else {
1370                                    return (CalEvent)result;
1371                            }
1372                    }
1373            }
1374    
1375            /**
1376             * Returns all the cal events where companyId = &#63;.
1377             *
1378             * @param companyId the company ID
1379             * @return the matching cal events
1380             * @throws SystemException if a system exception occurred
1381             */
1382            public List<CalEvent> findByCompanyId(long companyId)
1383                    throws SystemException {
1384                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1385                            null);
1386            }
1387    
1388            /**
1389             * Returns a range of all the cal events where companyId = &#63;.
1390             *
1391             * <p>
1392             * 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.
1393             * </p>
1394             *
1395             * @param companyId the company ID
1396             * @param start the lower bound of the range of cal events
1397             * @param end the upper bound of the range of cal events (not inclusive)
1398             * @return the range of matching cal events
1399             * @throws SystemException if a system exception occurred
1400             */
1401            public List<CalEvent> findByCompanyId(long companyId, int start, int end)
1402                    throws SystemException {
1403                    return findByCompanyId(companyId, start, end, null);
1404            }
1405    
1406            /**
1407             * Returns an ordered range of all the cal events where companyId = &#63;.
1408             *
1409             * <p>
1410             * 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.
1411             * </p>
1412             *
1413             * @param companyId the company ID
1414             * @param start the lower bound of the range of cal events
1415             * @param end the upper bound of the range of cal events (not inclusive)
1416             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1417             * @return the ordered range of matching cal events
1418             * @throws SystemException if a system exception occurred
1419             */
1420            public List<CalEvent> findByCompanyId(long companyId, int start, int end,
1421                    OrderByComparator orderByComparator) throws SystemException {
1422                    FinderPath finderPath = null;
1423                    Object[] finderArgs = null;
1424    
1425                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1426                                    (orderByComparator == null)) {
1427                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1428                            finderArgs = new Object[] { companyId };
1429                    }
1430                    else {
1431                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1432                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1433                    }
1434    
1435                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
1436                                    finderArgs, this);
1437    
1438                    if ((list != null) && !list.isEmpty()) {
1439                            for (CalEvent calEvent : list) {
1440                                    if ((companyId != calEvent.getCompanyId())) {
1441                                            list = null;
1442    
1443                                            break;
1444                                    }
1445                            }
1446                    }
1447    
1448                    if (list == null) {
1449                            StringBundler query = null;
1450    
1451                            if (orderByComparator != null) {
1452                                    query = new StringBundler(3 +
1453                                                    (orderByComparator.getOrderByFields().length * 3));
1454                            }
1455                            else {
1456                                    query = new StringBundler(3);
1457                            }
1458    
1459                            query.append(_SQL_SELECT_CALEVENT_WHERE);
1460    
1461                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1462    
1463                            if (orderByComparator != null) {
1464                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1465                                            orderByComparator);
1466                            }
1467    
1468                            else {
1469                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
1470                            }
1471    
1472                            String sql = query.toString();
1473    
1474                            Session session = null;
1475    
1476                            try {
1477                                    session = openSession();
1478    
1479                                    Query q = session.createQuery(sql);
1480    
1481                                    QueryPos qPos = QueryPos.getInstance(q);
1482    
1483                                    qPos.add(companyId);
1484    
1485                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1486                                                    end);
1487                            }
1488                            catch (Exception e) {
1489                                    throw processException(e);
1490                            }
1491                            finally {
1492                                    if (list == null) {
1493                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1494                                    }
1495                                    else {
1496                                            cacheResult(list);
1497    
1498                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1499                                    }
1500    
1501                                    closeSession(session);
1502                            }
1503                    }
1504    
1505                    return list;
1506            }
1507    
1508            /**
1509             * Returns the first cal event in the ordered set where companyId = &#63;.
1510             *
1511             * <p>
1512             * 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.
1513             * </p>
1514             *
1515             * @param companyId the company ID
1516             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1517             * @return the first matching cal event
1518             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1519             * @throws SystemException if a system exception occurred
1520             */
1521            public CalEvent findByCompanyId_First(long companyId,
1522                    OrderByComparator orderByComparator)
1523                    throws NoSuchEventException, SystemException {
1524                    List<CalEvent> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1525    
1526                    if (list.isEmpty()) {
1527                            StringBundler msg = new StringBundler(4);
1528    
1529                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1530    
1531                            msg.append("companyId=");
1532                            msg.append(companyId);
1533    
1534                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1535    
1536                            throw new NoSuchEventException(msg.toString());
1537                    }
1538                    else {
1539                            return list.get(0);
1540                    }
1541            }
1542    
1543            /**
1544             * Returns the last cal event in the ordered set where companyId = &#63;.
1545             *
1546             * <p>
1547             * 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.
1548             * </p>
1549             *
1550             * @param companyId the company ID
1551             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1552             * @return the last matching cal event
1553             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1554             * @throws SystemException if a system exception occurred
1555             */
1556            public CalEvent findByCompanyId_Last(long companyId,
1557                    OrderByComparator orderByComparator)
1558                    throws NoSuchEventException, SystemException {
1559                    int count = countByCompanyId(companyId);
1560    
1561                    List<CalEvent> list = findByCompanyId(companyId, count - 1, count,
1562                                    orderByComparator);
1563    
1564                    if (list.isEmpty()) {
1565                            StringBundler msg = new StringBundler(4);
1566    
1567                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1568    
1569                            msg.append("companyId=");
1570                            msg.append(companyId);
1571    
1572                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1573    
1574                            throw new NoSuchEventException(msg.toString());
1575                    }
1576                    else {
1577                            return list.get(0);
1578                    }
1579            }
1580    
1581            /**
1582             * Returns the cal events before and after the current cal event in the ordered set where companyId = &#63;.
1583             *
1584             * <p>
1585             * 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.
1586             * </p>
1587             *
1588             * @param eventId the primary key of the current cal event
1589             * @param companyId the company ID
1590             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1591             * @return the previous, current, and next cal event
1592             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
1593             * @throws SystemException if a system exception occurred
1594             */
1595            public CalEvent[] findByCompanyId_PrevAndNext(long eventId, long companyId,
1596                    OrderByComparator orderByComparator)
1597                    throws NoSuchEventException, SystemException {
1598                    CalEvent calEvent = findByPrimaryKey(eventId);
1599    
1600                    Session session = null;
1601    
1602                    try {
1603                            session = openSession();
1604    
1605                            CalEvent[] array = new CalEventImpl[3];
1606    
1607                            array[0] = getByCompanyId_PrevAndNext(session, calEvent, companyId,
1608                                            orderByComparator, true);
1609    
1610                            array[1] = calEvent;
1611    
1612                            array[2] = getByCompanyId_PrevAndNext(session, calEvent, companyId,
1613                                            orderByComparator, false);
1614    
1615                            return array;
1616                    }
1617                    catch (Exception e) {
1618                            throw processException(e);
1619                    }
1620                    finally {
1621                            closeSession(session);
1622                    }
1623            }
1624    
1625            protected CalEvent getByCompanyId_PrevAndNext(Session session,
1626                    CalEvent calEvent, long companyId, OrderByComparator orderByComparator,
1627                    boolean previous) {
1628                    StringBundler query = null;
1629    
1630                    if (orderByComparator != null) {
1631                            query = new StringBundler(6 +
1632                                            (orderByComparator.getOrderByFields().length * 6));
1633                    }
1634                    else {
1635                            query = new StringBundler(3);
1636                    }
1637    
1638                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1639    
1640                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1641    
1642                    if (orderByComparator != null) {
1643                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1644    
1645                            if (orderByConditionFields.length > 0) {
1646                                    query.append(WHERE_AND);
1647                            }
1648    
1649                            for (int i = 0; i < orderByConditionFields.length; i++) {
1650                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1651                                    query.append(orderByConditionFields[i]);
1652    
1653                                    if ((i + 1) < orderByConditionFields.length) {
1654                                            if (orderByComparator.isAscending() ^ previous) {
1655                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1656                                            }
1657                                            else {
1658                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1659                                            }
1660                                    }
1661                                    else {
1662                                            if (orderByComparator.isAscending() ^ previous) {
1663                                                    query.append(WHERE_GREATER_THAN);
1664                                            }
1665                                            else {
1666                                                    query.append(WHERE_LESSER_THAN);
1667                                            }
1668                                    }
1669                            }
1670    
1671                            query.append(ORDER_BY_CLAUSE);
1672    
1673                            String[] orderByFields = orderByComparator.getOrderByFields();
1674    
1675                            for (int i = 0; i < orderByFields.length; i++) {
1676                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1677                                    query.append(orderByFields[i]);
1678    
1679                                    if ((i + 1) < orderByFields.length) {
1680                                            if (orderByComparator.isAscending() ^ previous) {
1681                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1682                                            }
1683                                            else {
1684                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1685                                            }
1686                                    }
1687                                    else {
1688                                            if (orderByComparator.isAscending() ^ previous) {
1689                                                    query.append(ORDER_BY_ASC);
1690                                            }
1691                                            else {
1692                                                    query.append(ORDER_BY_DESC);
1693                                            }
1694                                    }
1695                            }
1696                    }
1697    
1698                    else {
1699                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1700                    }
1701    
1702                    String sql = query.toString();
1703    
1704                    Query q = session.createQuery(sql);
1705    
1706                    q.setFirstResult(0);
1707                    q.setMaxResults(2);
1708    
1709                    QueryPos qPos = QueryPos.getInstance(q);
1710    
1711                    qPos.add(companyId);
1712    
1713                    if (orderByComparator != null) {
1714                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
1715    
1716                            for (Object value : values) {
1717                                    qPos.add(value);
1718                            }
1719                    }
1720    
1721                    List<CalEvent> list = q.list();
1722    
1723                    if (list.size() == 2) {
1724                            return list.get(1);
1725                    }
1726                    else {
1727                            return null;
1728                    }
1729            }
1730    
1731            /**
1732             * Returns all the cal events where groupId = &#63;.
1733             *
1734             * @param groupId the group ID
1735             * @return the matching cal events
1736             * @throws SystemException if a system exception occurred
1737             */
1738            public List<CalEvent> findByGroupId(long groupId) throws SystemException {
1739                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1740            }
1741    
1742            /**
1743             * Returns a range of all the cal events where groupId = &#63;.
1744             *
1745             * <p>
1746             * 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.
1747             * </p>
1748             *
1749             * @param groupId the group ID
1750             * @param start the lower bound of the range of cal events
1751             * @param end the upper bound of the range of cal events (not inclusive)
1752             * @return the range of matching cal events
1753             * @throws SystemException if a system exception occurred
1754             */
1755            public List<CalEvent> findByGroupId(long groupId, int start, int end)
1756                    throws SystemException {
1757                    return findByGroupId(groupId, start, end, null);
1758            }
1759    
1760            /**
1761             * Returns an ordered range of all the cal events where groupId = &#63;.
1762             *
1763             * <p>
1764             * 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.
1765             * </p>
1766             *
1767             * @param groupId the group ID
1768             * @param start the lower bound of the range of cal events
1769             * @param end the upper bound of the range of cal events (not inclusive)
1770             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1771             * @return the ordered range of matching cal events
1772             * @throws SystemException if a system exception occurred
1773             */
1774            public List<CalEvent> findByGroupId(long groupId, int start, int end,
1775                    OrderByComparator orderByComparator) throws SystemException {
1776                    FinderPath finderPath = null;
1777                    Object[] finderArgs = null;
1778    
1779                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1780                                    (orderByComparator == null)) {
1781                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1782                            finderArgs = new Object[] { groupId };
1783                    }
1784                    else {
1785                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1786                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1787                    }
1788    
1789                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
1790                                    finderArgs, this);
1791    
1792                    if ((list != null) && !list.isEmpty()) {
1793                            for (CalEvent calEvent : list) {
1794                                    if ((groupId != calEvent.getGroupId())) {
1795                                            list = null;
1796    
1797                                            break;
1798                                    }
1799                            }
1800                    }
1801    
1802                    if (list == null) {
1803                            StringBundler query = null;
1804    
1805                            if (orderByComparator != null) {
1806                                    query = new StringBundler(3 +
1807                                                    (orderByComparator.getOrderByFields().length * 3));
1808                            }
1809                            else {
1810                                    query = new StringBundler(3);
1811                            }
1812    
1813                            query.append(_SQL_SELECT_CALEVENT_WHERE);
1814    
1815                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1816    
1817                            if (orderByComparator != null) {
1818                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1819                                            orderByComparator);
1820                            }
1821    
1822                            else {
1823                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
1824                            }
1825    
1826                            String sql = query.toString();
1827    
1828                            Session session = null;
1829    
1830                            try {
1831                                    session = openSession();
1832    
1833                                    Query q = session.createQuery(sql);
1834    
1835                                    QueryPos qPos = QueryPos.getInstance(q);
1836    
1837                                    qPos.add(groupId);
1838    
1839                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1840                                                    end);
1841                            }
1842                            catch (Exception e) {
1843                                    throw processException(e);
1844                            }
1845                            finally {
1846                                    if (list == null) {
1847                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1848                                    }
1849                                    else {
1850                                            cacheResult(list);
1851    
1852                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1853                                    }
1854    
1855                                    closeSession(session);
1856                            }
1857                    }
1858    
1859                    return list;
1860            }
1861    
1862            /**
1863             * Returns the first cal event in the ordered set where groupId = &#63;.
1864             *
1865             * <p>
1866             * 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.
1867             * </p>
1868             *
1869             * @param groupId the group ID
1870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1871             * @return the first matching cal event
1872             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1873             * @throws SystemException if a system exception occurred
1874             */
1875            public CalEvent findByGroupId_First(long groupId,
1876                    OrderByComparator orderByComparator)
1877                    throws NoSuchEventException, SystemException {
1878                    List<CalEvent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1879    
1880                    if (list.isEmpty()) {
1881                            StringBundler msg = new StringBundler(4);
1882    
1883                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1884    
1885                            msg.append("groupId=");
1886                            msg.append(groupId);
1887    
1888                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1889    
1890                            throw new NoSuchEventException(msg.toString());
1891                    }
1892                    else {
1893                            return list.get(0);
1894                    }
1895            }
1896    
1897            /**
1898             * Returns the last cal event in the ordered set where groupId = &#63;.
1899             *
1900             * <p>
1901             * 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.
1902             * </p>
1903             *
1904             * @param groupId the group ID
1905             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1906             * @return the last matching cal event
1907             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
1908             * @throws SystemException if a system exception occurred
1909             */
1910            public CalEvent findByGroupId_Last(long groupId,
1911                    OrderByComparator orderByComparator)
1912                    throws NoSuchEventException, SystemException {
1913                    int count = countByGroupId(groupId);
1914    
1915                    List<CalEvent> list = findByGroupId(groupId, count - 1, count,
1916                                    orderByComparator);
1917    
1918                    if (list.isEmpty()) {
1919                            StringBundler msg = new StringBundler(4);
1920    
1921                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1922    
1923                            msg.append("groupId=");
1924                            msg.append(groupId);
1925    
1926                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1927    
1928                            throw new NoSuchEventException(msg.toString());
1929                    }
1930                    else {
1931                            return list.get(0);
1932                    }
1933            }
1934    
1935            /**
1936             * Returns the cal events before and after the current cal event in the ordered set where groupId = &#63;.
1937             *
1938             * <p>
1939             * 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.
1940             * </p>
1941             *
1942             * @param eventId the primary key of the current cal event
1943             * @param groupId the group ID
1944             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1945             * @return the previous, current, and next cal event
1946             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
1947             * @throws SystemException if a system exception occurred
1948             */
1949            public CalEvent[] findByGroupId_PrevAndNext(long eventId, long groupId,
1950                    OrderByComparator orderByComparator)
1951                    throws NoSuchEventException, SystemException {
1952                    CalEvent calEvent = findByPrimaryKey(eventId);
1953    
1954                    Session session = null;
1955    
1956                    try {
1957                            session = openSession();
1958    
1959                            CalEvent[] array = new CalEventImpl[3];
1960    
1961                            array[0] = getByGroupId_PrevAndNext(session, calEvent, groupId,
1962                                            orderByComparator, true);
1963    
1964                            array[1] = calEvent;
1965    
1966                            array[2] = getByGroupId_PrevAndNext(session, calEvent, groupId,
1967                                            orderByComparator, false);
1968    
1969                            return array;
1970                    }
1971                    catch (Exception e) {
1972                            throw processException(e);
1973                    }
1974                    finally {
1975                            closeSession(session);
1976                    }
1977            }
1978    
1979            protected CalEvent getByGroupId_PrevAndNext(Session session,
1980                    CalEvent calEvent, long groupId, OrderByComparator orderByComparator,
1981                    boolean previous) {
1982                    StringBundler query = null;
1983    
1984                    if (orderByComparator != null) {
1985                            query = new StringBundler(6 +
1986                                            (orderByComparator.getOrderByFields().length * 6));
1987                    }
1988                    else {
1989                            query = new StringBundler(3);
1990                    }
1991    
1992                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1993    
1994                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1995    
1996                    if (orderByComparator != null) {
1997                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1998    
1999                            if (orderByConditionFields.length > 0) {
2000                                    query.append(WHERE_AND);
2001                            }
2002    
2003                            for (int i = 0; i < orderByConditionFields.length; i++) {
2004                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2005                                    query.append(orderByConditionFields[i]);
2006    
2007                                    if ((i + 1) < orderByConditionFields.length) {
2008                                            if (orderByComparator.isAscending() ^ previous) {
2009                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2010                                            }
2011                                            else {
2012                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2013                                            }
2014                                    }
2015                                    else {
2016                                            if (orderByComparator.isAscending() ^ previous) {
2017                                                    query.append(WHERE_GREATER_THAN);
2018                                            }
2019                                            else {
2020                                                    query.append(WHERE_LESSER_THAN);
2021                                            }
2022                                    }
2023                            }
2024    
2025                            query.append(ORDER_BY_CLAUSE);
2026    
2027                            String[] orderByFields = orderByComparator.getOrderByFields();
2028    
2029                            for (int i = 0; i < orderByFields.length; i++) {
2030                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2031                                    query.append(orderByFields[i]);
2032    
2033                                    if ((i + 1) < orderByFields.length) {
2034                                            if (orderByComparator.isAscending() ^ previous) {
2035                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2036                                            }
2037                                            else {
2038                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2039                                            }
2040                                    }
2041                                    else {
2042                                            if (orderByComparator.isAscending() ^ previous) {
2043                                                    query.append(ORDER_BY_ASC);
2044                                            }
2045                                            else {
2046                                                    query.append(ORDER_BY_DESC);
2047                                            }
2048                                    }
2049                            }
2050                    }
2051    
2052                    else {
2053                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2054                    }
2055    
2056                    String sql = query.toString();
2057    
2058                    Query q = session.createQuery(sql);
2059    
2060                    q.setFirstResult(0);
2061                    q.setMaxResults(2);
2062    
2063                    QueryPos qPos = QueryPos.getInstance(q);
2064    
2065                    qPos.add(groupId);
2066    
2067                    if (orderByComparator != null) {
2068                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
2069    
2070                            for (Object value : values) {
2071                                    qPos.add(value);
2072                            }
2073                    }
2074    
2075                    List<CalEvent> list = q.list();
2076    
2077                    if (list.size() == 2) {
2078                            return list.get(1);
2079                    }
2080                    else {
2081                            return null;
2082                    }
2083            }
2084    
2085            /**
2086             * Returns all the cal events that the user has permission to view where groupId = &#63;.
2087             *
2088             * @param groupId the group ID
2089             * @return the matching cal events that the user has permission to view
2090             * @throws SystemException if a system exception occurred
2091             */
2092            public List<CalEvent> filterFindByGroupId(long groupId)
2093                    throws SystemException {
2094                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2095                            QueryUtil.ALL_POS, null);
2096            }
2097    
2098            /**
2099             * Returns a range of all the cal events that the user has permission to view where groupId = &#63;.
2100             *
2101             * <p>
2102             * 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.
2103             * </p>
2104             *
2105             * @param groupId the group ID
2106             * @param start the lower bound of the range of cal events
2107             * @param end the upper bound of the range of cal events (not inclusive)
2108             * @return the range of matching cal events that the user has permission to view
2109             * @throws SystemException if a system exception occurred
2110             */
2111            public List<CalEvent> filterFindByGroupId(long groupId, int start, int end)
2112                    throws SystemException {
2113                    return filterFindByGroupId(groupId, start, end, null);
2114            }
2115    
2116            /**
2117             * Returns an ordered range of all the cal events that the user has permissions to view where groupId = &#63;.
2118             *
2119             * <p>
2120             * 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.
2121             * </p>
2122             *
2123             * @param groupId the group ID
2124             * @param start the lower bound of the range of cal events
2125             * @param end the upper bound of the range of cal events (not inclusive)
2126             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2127             * @return the ordered range of matching cal events that the user has permission to view
2128             * @throws SystemException if a system exception occurred
2129             */
2130            public List<CalEvent> filterFindByGroupId(long groupId, int start, int end,
2131                    OrderByComparator orderByComparator) throws SystemException {
2132                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2133                            return findByGroupId(groupId, start, end, orderByComparator);
2134                    }
2135    
2136                    StringBundler query = null;
2137    
2138                    if (orderByComparator != null) {
2139                            query = new StringBundler(3 +
2140                                            (orderByComparator.getOrderByFields().length * 3));
2141                    }
2142                    else {
2143                            query = new StringBundler(3);
2144                    }
2145    
2146                    if (getDB().isSupportsInlineDistinct()) {
2147                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
2148                    }
2149                    else {
2150                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
2151                    }
2152    
2153                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2154    
2155                    if (!getDB().isSupportsInlineDistinct()) {
2156                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
2157                    }
2158    
2159                    if (orderByComparator != null) {
2160                            if (getDB().isSupportsInlineDistinct()) {
2161                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2162                                            orderByComparator);
2163                            }
2164                            else {
2165                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2166                                            orderByComparator);
2167                            }
2168                    }
2169    
2170                    else {
2171                            if (getDB().isSupportsInlineDistinct()) {
2172                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
2173                            }
2174                            else {
2175                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
2176                            }
2177                    }
2178    
2179                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2180                                    CalEvent.class.getName(),
2181                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2182    
2183                    Session session = null;
2184    
2185                    try {
2186                            session = openSession();
2187    
2188                            SQLQuery q = session.createSQLQuery(sql);
2189    
2190                            if (getDB().isSupportsInlineDistinct()) {
2191                                    q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
2192                            }
2193                            else {
2194                                    q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
2195                            }
2196    
2197                            QueryPos qPos = QueryPos.getInstance(q);
2198    
2199                            qPos.add(groupId);
2200    
2201                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
2202                    }
2203                    catch (Exception e) {
2204                            throw processException(e);
2205                    }
2206                    finally {
2207                            closeSession(session);
2208                    }
2209            }
2210    
2211            /**
2212             * Returns the cal events before and after the current cal event in the ordered set of cal events that the user has permission to view where groupId = &#63;.
2213             *
2214             * @param eventId the primary key of the current cal event
2215             * @param groupId the group ID
2216             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2217             * @return the previous, current, and next cal event
2218             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
2219             * @throws SystemException if a system exception occurred
2220             */
2221            public CalEvent[] filterFindByGroupId_PrevAndNext(long eventId,
2222                    long groupId, OrderByComparator orderByComparator)
2223                    throws NoSuchEventException, SystemException {
2224                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2225                            return findByGroupId_PrevAndNext(eventId, groupId, orderByComparator);
2226                    }
2227    
2228                    CalEvent calEvent = findByPrimaryKey(eventId);
2229    
2230                    Session session = null;
2231    
2232                    try {
2233                            session = openSession();
2234    
2235                            CalEvent[] array = new CalEventImpl[3];
2236    
2237                            array[0] = filterGetByGroupId_PrevAndNext(session, calEvent,
2238                                            groupId, orderByComparator, true);
2239    
2240                            array[1] = calEvent;
2241    
2242                            array[2] = filterGetByGroupId_PrevAndNext(session, calEvent,
2243                                            groupId, orderByComparator, false);
2244    
2245                            return array;
2246                    }
2247                    catch (Exception e) {
2248                            throw processException(e);
2249                    }
2250                    finally {
2251                            closeSession(session);
2252                    }
2253            }
2254    
2255            protected CalEvent filterGetByGroupId_PrevAndNext(Session session,
2256                    CalEvent calEvent, long groupId, OrderByComparator orderByComparator,
2257                    boolean previous) {
2258                    StringBundler query = null;
2259    
2260                    if (orderByComparator != null) {
2261                            query = new StringBundler(6 +
2262                                            (orderByComparator.getOrderByFields().length * 6));
2263                    }
2264                    else {
2265                            query = new StringBundler(3);
2266                    }
2267    
2268                    if (getDB().isSupportsInlineDistinct()) {
2269                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
2270                    }
2271                    else {
2272                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
2273                    }
2274    
2275                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2276    
2277                    if (!getDB().isSupportsInlineDistinct()) {
2278                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
2279                    }
2280    
2281                    if (orderByComparator != null) {
2282                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2283    
2284                            if (orderByConditionFields.length > 0) {
2285                                    query.append(WHERE_AND);
2286                            }
2287    
2288                            for (int i = 0; i < orderByConditionFields.length; i++) {
2289                                    if (getDB().isSupportsInlineDistinct()) {
2290                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2291                                    }
2292                                    else {
2293                                            query.append(_ORDER_BY_ENTITY_TABLE);
2294                                    }
2295    
2296                                    query.append(orderByConditionFields[i]);
2297    
2298                                    if ((i + 1) < orderByConditionFields.length) {
2299                                            if (orderByComparator.isAscending() ^ previous) {
2300                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2301                                            }
2302                                            else {
2303                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2304                                            }
2305                                    }
2306                                    else {
2307                                            if (orderByComparator.isAscending() ^ previous) {
2308                                                    query.append(WHERE_GREATER_THAN);
2309                                            }
2310                                            else {
2311                                                    query.append(WHERE_LESSER_THAN);
2312                                            }
2313                                    }
2314                            }
2315    
2316                            query.append(ORDER_BY_CLAUSE);
2317    
2318                            String[] orderByFields = orderByComparator.getOrderByFields();
2319    
2320                            for (int i = 0; i < orderByFields.length; i++) {
2321                                    if (getDB().isSupportsInlineDistinct()) {
2322                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2323                                    }
2324                                    else {
2325                                            query.append(_ORDER_BY_ENTITY_TABLE);
2326                                    }
2327    
2328                                    query.append(orderByFields[i]);
2329    
2330                                    if ((i + 1) < orderByFields.length) {
2331                                            if (orderByComparator.isAscending() ^ previous) {
2332                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2333                                            }
2334                                            else {
2335                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2336                                            }
2337                                    }
2338                                    else {
2339                                            if (orderByComparator.isAscending() ^ previous) {
2340                                                    query.append(ORDER_BY_ASC);
2341                                            }
2342                                            else {
2343                                                    query.append(ORDER_BY_DESC);
2344                                            }
2345                                    }
2346                            }
2347                    }
2348    
2349                    else {
2350                            if (getDB().isSupportsInlineDistinct()) {
2351                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
2352                            }
2353                            else {
2354                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
2355                            }
2356                    }
2357    
2358                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2359                                    CalEvent.class.getName(),
2360                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2361    
2362                    SQLQuery q = session.createSQLQuery(sql);
2363    
2364                    q.setFirstResult(0);
2365                    q.setMaxResults(2);
2366    
2367                    if (getDB().isSupportsInlineDistinct()) {
2368                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
2369                    }
2370                    else {
2371                            q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
2372                    }
2373    
2374                    QueryPos qPos = QueryPos.getInstance(q);
2375    
2376                    qPos.add(groupId);
2377    
2378                    if (orderByComparator != null) {
2379                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
2380    
2381                            for (Object value : values) {
2382                                    qPos.add(value);
2383                            }
2384                    }
2385    
2386                    List<CalEvent> list = q.list();
2387    
2388                    if (list.size() == 2) {
2389                            return list.get(1);
2390                    }
2391                    else {
2392                            return null;
2393                    }
2394            }
2395    
2396            /**
2397             * Returns all the cal events where remindBy &ne; &#63;.
2398             *
2399             * @param remindBy the remind by
2400             * @return the matching cal events
2401             * @throws SystemException if a system exception occurred
2402             */
2403            public List<CalEvent> findByNotRemindBy(int remindBy)
2404                    throws SystemException {
2405                    return findByNotRemindBy(remindBy, QueryUtil.ALL_POS,
2406                            QueryUtil.ALL_POS, null);
2407            }
2408    
2409            /**
2410             * Returns a range of all the cal events where remindBy &ne; &#63;.
2411             *
2412             * <p>
2413             * 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.
2414             * </p>
2415             *
2416             * @param remindBy the remind by
2417             * @param start the lower bound of the range of cal events
2418             * @param end the upper bound of the range of cal events (not inclusive)
2419             * @return the range of matching cal events
2420             * @throws SystemException if a system exception occurred
2421             */
2422            public List<CalEvent> findByNotRemindBy(int remindBy, int start, int end)
2423                    throws SystemException {
2424                    return findByNotRemindBy(remindBy, start, end, null);
2425            }
2426    
2427            /**
2428             * Returns an ordered range of all the cal events where remindBy &ne; &#63;.
2429             *
2430             * <p>
2431             * 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.
2432             * </p>
2433             *
2434             * @param remindBy the remind by
2435             * @param start the lower bound of the range of cal events
2436             * @param end the upper bound of the range of cal events (not inclusive)
2437             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2438             * @return the ordered range of matching cal events
2439             * @throws SystemException if a system exception occurred
2440             */
2441            public List<CalEvent> findByNotRemindBy(int remindBy, int start, int end,
2442                    OrderByComparator orderByComparator) throws SystemException {
2443                    FinderPath finderPath = null;
2444                    Object[] finderArgs = null;
2445    
2446                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2447                                    (orderByComparator == null)) {
2448                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NOTREMINDBY;
2449                            finderArgs = new Object[] { remindBy };
2450                    }
2451                    else {
2452                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTREMINDBY;
2453                            finderArgs = new Object[] { remindBy, start, end, orderByComparator };
2454                    }
2455    
2456                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
2457                                    finderArgs, this);
2458    
2459                    if ((list != null) && !list.isEmpty()) {
2460                            for (CalEvent calEvent : list) {
2461                                    if ((remindBy != calEvent.getRemindBy())) {
2462                                            list = null;
2463    
2464                                            break;
2465                                    }
2466                            }
2467                    }
2468    
2469                    if (list == null) {
2470                            StringBundler query = null;
2471    
2472                            if (orderByComparator != null) {
2473                                    query = new StringBundler(3 +
2474                                                    (orderByComparator.getOrderByFields().length * 3));
2475                            }
2476                            else {
2477                                    query = new StringBundler(3);
2478                            }
2479    
2480                            query.append(_SQL_SELECT_CALEVENT_WHERE);
2481    
2482                            query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
2483    
2484                            if (orderByComparator != null) {
2485                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2486                                            orderByComparator);
2487                            }
2488    
2489                            else {
2490                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
2491                            }
2492    
2493                            String sql = query.toString();
2494    
2495                            Session session = null;
2496    
2497                            try {
2498                                    session = openSession();
2499    
2500                                    Query q = session.createQuery(sql);
2501    
2502                                    QueryPos qPos = QueryPos.getInstance(q);
2503    
2504                                    qPos.add(remindBy);
2505    
2506                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
2507                                                    end);
2508                            }
2509                            catch (Exception e) {
2510                                    throw processException(e);
2511                            }
2512                            finally {
2513                                    if (list == null) {
2514                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2515                                    }
2516                                    else {
2517                                            cacheResult(list);
2518    
2519                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2520                                    }
2521    
2522                                    closeSession(session);
2523                            }
2524                    }
2525    
2526                    return list;
2527            }
2528    
2529            /**
2530             * Returns the first cal event in the ordered set where remindBy &ne; &#63;.
2531             *
2532             * <p>
2533             * 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.
2534             * </p>
2535             *
2536             * @param remindBy the remind by
2537             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2538             * @return the first matching cal event
2539             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
2540             * @throws SystemException if a system exception occurred
2541             */
2542            public CalEvent findByNotRemindBy_First(int remindBy,
2543                    OrderByComparator orderByComparator)
2544                    throws NoSuchEventException, SystemException {
2545                    List<CalEvent> list = findByNotRemindBy(remindBy, 0, 1,
2546                                    orderByComparator);
2547    
2548                    if (list.isEmpty()) {
2549                            StringBundler msg = new StringBundler(4);
2550    
2551                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2552    
2553                            msg.append("remindBy=");
2554                            msg.append(remindBy);
2555    
2556                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2557    
2558                            throw new NoSuchEventException(msg.toString());
2559                    }
2560                    else {
2561                            return list.get(0);
2562                    }
2563            }
2564    
2565            /**
2566             * Returns the last cal event in the ordered set where remindBy &ne; &#63;.
2567             *
2568             * <p>
2569             * 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.
2570             * </p>
2571             *
2572             * @param remindBy the remind by
2573             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2574             * @return the last matching cal event
2575             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
2576             * @throws SystemException if a system exception occurred
2577             */
2578            public CalEvent findByNotRemindBy_Last(int remindBy,
2579                    OrderByComparator orderByComparator)
2580                    throws NoSuchEventException, SystemException {
2581                    int count = countByNotRemindBy(remindBy);
2582    
2583                    List<CalEvent> list = findByNotRemindBy(remindBy, count - 1, count,
2584                                    orderByComparator);
2585    
2586                    if (list.isEmpty()) {
2587                            StringBundler msg = new StringBundler(4);
2588    
2589                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2590    
2591                            msg.append("remindBy=");
2592                            msg.append(remindBy);
2593    
2594                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2595    
2596                            throw new NoSuchEventException(msg.toString());
2597                    }
2598                    else {
2599                            return list.get(0);
2600                    }
2601            }
2602    
2603            /**
2604             * Returns the cal events before and after the current cal event in the ordered set where remindBy &ne; &#63;.
2605             *
2606             * <p>
2607             * 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.
2608             * </p>
2609             *
2610             * @param eventId the primary key of the current cal event
2611             * @param remindBy the remind by
2612             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2613             * @return the previous, current, and next cal event
2614             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
2615             * @throws SystemException if a system exception occurred
2616             */
2617            public CalEvent[] findByNotRemindBy_PrevAndNext(long eventId, int remindBy,
2618                    OrderByComparator orderByComparator)
2619                    throws NoSuchEventException, SystemException {
2620                    CalEvent calEvent = findByPrimaryKey(eventId);
2621    
2622                    Session session = null;
2623    
2624                    try {
2625                            session = openSession();
2626    
2627                            CalEvent[] array = new CalEventImpl[3];
2628    
2629                            array[0] = getByNotRemindBy_PrevAndNext(session, calEvent,
2630                                            remindBy, orderByComparator, true);
2631    
2632                            array[1] = calEvent;
2633    
2634                            array[2] = getByNotRemindBy_PrevAndNext(session, calEvent,
2635                                            remindBy, orderByComparator, false);
2636    
2637                            return array;
2638                    }
2639                    catch (Exception e) {
2640                            throw processException(e);
2641                    }
2642                    finally {
2643                            closeSession(session);
2644                    }
2645            }
2646    
2647            protected CalEvent getByNotRemindBy_PrevAndNext(Session session,
2648                    CalEvent calEvent, int remindBy, OrderByComparator orderByComparator,
2649                    boolean previous) {
2650                    StringBundler query = null;
2651    
2652                    if (orderByComparator != null) {
2653                            query = new StringBundler(6 +
2654                                            (orderByComparator.getOrderByFields().length * 6));
2655                    }
2656                    else {
2657                            query = new StringBundler(3);
2658                    }
2659    
2660                    query.append(_SQL_SELECT_CALEVENT_WHERE);
2661    
2662                    query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
2663    
2664                    if (orderByComparator != null) {
2665                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2666    
2667                            if (orderByConditionFields.length > 0) {
2668                                    query.append(WHERE_AND);
2669                            }
2670    
2671                            for (int i = 0; i < orderByConditionFields.length; i++) {
2672                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2673                                    query.append(orderByConditionFields[i]);
2674    
2675                                    if ((i + 1) < orderByConditionFields.length) {
2676                                            if (orderByComparator.isAscending() ^ previous) {
2677                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2678                                            }
2679                                            else {
2680                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2681                                            }
2682                                    }
2683                                    else {
2684                                            if (orderByComparator.isAscending() ^ previous) {
2685                                                    query.append(WHERE_GREATER_THAN);
2686                                            }
2687                                            else {
2688                                                    query.append(WHERE_LESSER_THAN);
2689                                            }
2690                                    }
2691                            }
2692    
2693                            query.append(ORDER_BY_CLAUSE);
2694    
2695                            String[] orderByFields = orderByComparator.getOrderByFields();
2696    
2697                            for (int i = 0; i < orderByFields.length; i++) {
2698                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2699                                    query.append(orderByFields[i]);
2700    
2701                                    if ((i + 1) < orderByFields.length) {
2702                                            if (orderByComparator.isAscending() ^ previous) {
2703                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2704                                            }
2705                                            else {
2706                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2707                                            }
2708                                    }
2709                                    else {
2710                                            if (orderByComparator.isAscending() ^ previous) {
2711                                                    query.append(ORDER_BY_ASC);
2712                                            }
2713                                            else {
2714                                                    query.append(ORDER_BY_DESC);
2715                                            }
2716                                    }
2717                            }
2718                    }
2719    
2720                    else {
2721                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2722                    }
2723    
2724                    String sql = query.toString();
2725    
2726                    Query q = session.createQuery(sql);
2727    
2728                    q.setFirstResult(0);
2729                    q.setMaxResults(2);
2730    
2731                    QueryPos qPos = QueryPos.getInstance(q);
2732    
2733                    qPos.add(remindBy);
2734    
2735                    if (orderByComparator != null) {
2736                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
2737    
2738                            for (Object value : values) {
2739                                    qPos.add(value);
2740                            }
2741                    }
2742    
2743                    List<CalEvent> list = q.list();
2744    
2745                    if (list.size() == 2) {
2746                            return list.get(1);
2747                    }
2748                    else {
2749                            return null;
2750                    }
2751            }
2752    
2753            /**
2754             * Returns all the cal events where groupId = &#63; and type = &#63;.
2755             *
2756             * @param groupId the group ID
2757             * @param type the type
2758             * @return the matching cal events
2759             * @throws SystemException if a system exception occurred
2760             */
2761            public List<CalEvent> findByG_T(long groupId, String type)
2762                    throws SystemException {
2763                    return findByG_T(groupId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2764                            null);
2765            }
2766    
2767            /**
2768             * Returns a range of all the cal events where groupId = &#63; and type = &#63;.
2769             *
2770             * <p>
2771             * 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.
2772             * </p>
2773             *
2774             * @param groupId the group ID
2775             * @param type the type
2776             * @param start the lower bound of the range of cal events
2777             * @param end the upper bound of the range of cal events (not inclusive)
2778             * @return the range of matching cal events
2779             * @throws SystemException if a system exception occurred
2780             */
2781            public List<CalEvent> findByG_T(long groupId, String type, int start,
2782                    int end) throws SystemException {
2783                    return findByG_T(groupId, type, start, end, null);
2784            }
2785    
2786            /**
2787             * Returns an ordered range of all the cal events where groupId = &#63; and type = &#63;.
2788             *
2789             * <p>
2790             * 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.
2791             * </p>
2792             *
2793             * @param groupId the group ID
2794             * @param type the type
2795             * @param start the lower bound of the range of cal events
2796             * @param end the upper bound of the range of cal events (not inclusive)
2797             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2798             * @return the ordered range of matching cal events
2799             * @throws SystemException if a system exception occurred
2800             */
2801            public List<CalEvent> findByG_T(long groupId, String type, int start,
2802                    int end, OrderByComparator orderByComparator) throws SystemException {
2803                    FinderPath finderPath = null;
2804                    Object[] finderArgs = null;
2805    
2806                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2807                                    (orderByComparator == null)) {
2808                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T;
2809                            finderArgs = new Object[] { groupId, type };
2810                    }
2811                    else {
2812                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T;
2813                            finderArgs = new Object[] {
2814                                            groupId, type,
2815                                            
2816                                            start, end, orderByComparator
2817                                    };
2818                    }
2819    
2820                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
2821                                    finderArgs, this);
2822    
2823                    if ((list != null) && !list.isEmpty()) {
2824                            for (CalEvent calEvent : list) {
2825                                    if ((groupId != calEvent.getGroupId()) ||
2826                                                    !Validator.equals(type, calEvent.getType())) {
2827                                            list = null;
2828    
2829                                            break;
2830                                    }
2831                            }
2832                    }
2833    
2834                    if (list == null) {
2835                            StringBundler query = null;
2836    
2837                            if (orderByComparator != null) {
2838                                    query = new StringBundler(4 +
2839                                                    (orderByComparator.getOrderByFields().length * 3));
2840                            }
2841                            else {
2842                                    query = new StringBundler(4);
2843                            }
2844    
2845                            query.append(_SQL_SELECT_CALEVENT_WHERE);
2846    
2847                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2848    
2849                            if (type == null) {
2850                                    query.append(_FINDER_COLUMN_G_T_TYPE_1);
2851                            }
2852                            else {
2853                                    if (type.equals(StringPool.BLANK)) {
2854                                            query.append(_FINDER_COLUMN_G_T_TYPE_3);
2855                                    }
2856                                    else {
2857                                            query.append(_FINDER_COLUMN_G_T_TYPE_2);
2858                                    }
2859                            }
2860    
2861                            if (orderByComparator != null) {
2862                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2863                                            orderByComparator);
2864                            }
2865    
2866                            else {
2867                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
2868                            }
2869    
2870                            String sql = query.toString();
2871    
2872                            Session session = null;
2873    
2874                            try {
2875                                    session = openSession();
2876    
2877                                    Query q = session.createQuery(sql);
2878    
2879                                    QueryPos qPos = QueryPos.getInstance(q);
2880    
2881                                    qPos.add(groupId);
2882    
2883                                    if (type != null) {
2884                                            qPos.add(type);
2885                                    }
2886    
2887                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
2888                                                    end);
2889                            }
2890                            catch (Exception e) {
2891                                    throw processException(e);
2892                            }
2893                            finally {
2894                                    if (list == null) {
2895                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2896                                    }
2897                                    else {
2898                                            cacheResult(list);
2899    
2900                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2901                                    }
2902    
2903                                    closeSession(session);
2904                            }
2905                    }
2906    
2907                    return list;
2908            }
2909    
2910            /**
2911             * Returns the first cal event in the ordered set where groupId = &#63; and type = &#63;.
2912             *
2913             * <p>
2914             * 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.
2915             * </p>
2916             *
2917             * @param groupId the group ID
2918             * @param type the type
2919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2920             * @return the first matching cal event
2921             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
2922             * @throws SystemException if a system exception occurred
2923             */
2924            public CalEvent findByG_T_First(long groupId, String type,
2925                    OrderByComparator orderByComparator)
2926                    throws NoSuchEventException, SystemException {
2927                    List<CalEvent> list = findByG_T(groupId, type, 0, 1, orderByComparator);
2928    
2929                    if (list.isEmpty()) {
2930                            StringBundler msg = new StringBundler(6);
2931    
2932                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2933    
2934                            msg.append("groupId=");
2935                            msg.append(groupId);
2936    
2937                            msg.append(", type=");
2938                            msg.append(type);
2939    
2940                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2941    
2942                            throw new NoSuchEventException(msg.toString());
2943                    }
2944                    else {
2945                            return list.get(0);
2946                    }
2947            }
2948    
2949            /**
2950             * Returns the last cal event in the ordered set where groupId = &#63; and type = &#63;.
2951             *
2952             * <p>
2953             * 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.
2954             * </p>
2955             *
2956             * @param groupId the group ID
2957             * @param type the type
2958             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2959             * @return the last matching cal event
2960             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
2961             * @throws SystemException if a system exception occurred
2962             */
2963            public CalEvent findByG_T_Last(long groupId, String type,
2964                    OrderByComparator orderByComparator)
2965                    throws NoSuchEventException, SystemException {
2966                    int count = countByG_T(groupId, type);
2967    
2968                    List<CalEvent> list = findByG_T(groupId, type, count - 1, count,
2969                                    orderByComparator);
2970    
2971                    if (list.isEmpty()) {
2972                            StringBundler msg = new StringBundler(6);
2973    
2974                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2975    
2976                            msg.append("groupId=");
2977                            msg.append(groupId);
2978    
2979                            msg.append(", type=");
2980                            msg.append(type);
2981    
2982                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2983    
2984                            throw new NoSuchEventException(msg.toString());
2985                    }
2986                    else {
2987                            return list.get(0);
2988                    }
2989            }
2990    
2991            /**
2992             * Returns the cal events before and after the current cal event in the ordered set where groupId = &#63; and type = &#63;.
2993             *
2994             * <p>
2995             * 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.
2996             * </p>
2997             *
2998             * @param eventId the primary key of the current cal event
2999             * @param groupId the group ID
3000             * @param type the type
3001             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3002             * @return the previous, current, and next cal event
3003             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
3004             * @throws SystemException if a system exception occurred
3005             */
3006            public CalEvent[] findByG_T_PrevAndNext(long eventId, long groupId,
3007                    String type, OrderByComparator orderByComparator)
3008                    throws NoSuchEventException, SystemException {
3009                    CalEvent calEvent = findByPrimaryKey(eventId);
3010    
3011                    Session session = null;
3012    
3013                    try {
3014                            session = openSession();
3015    
3016                            CalEvent[] array = new CalEventImpl[3];
3017    
3018                            array[0] = getByG_T_PrevAndNext(session, calEvent, groupId, type,
3019                                            orderByComparator, true);
3020    
3021                            array[1] = calEvent;
3022    
3023                            array[2] = getByG_T_PrevAndNext(session, calEvent, groupId, type,
3024                                            orderByComparator, false);
3025    
3026                            return array;
3027                    }
3028                    catch (Exception e) {
3029                            throw processException(e);
3030                    }
3031                    finally {
3032                            closeSession(session);
3033                    }
3034            }
3035    
3036            protected CalEvent getByG_T_PrevAndNext(Session session, CalEvent calEvent,
3037                    long groupId, String type, OrderByComparator orderByComparator,
3038                    boolean previous) {
3039                    StringBundler query = null;
3040    
3041                    if (orderByComparator != null) {
3042                            query = new StringBundler(6 +
3043                                            (orderByComparator.getOrderByFields().length * 6));
3044                    }
3045                    else {
3046                            query = new StringBundler(3);
3047                    }
3048    
3049                    query.append(_SQL_SELECT_CALEVENT_WHERE);
3050    
3051                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3052    
3053                    if (type == null) {
3054                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
3055                    }
3056                    else {
3057                            if (type.equals(StringPool.BLANK)) {
3058                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
3059                            }
3060                            else {
3061                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
3062                            }
3063                    }
3064    
3065                    if (orderByComparator != null) {
3066                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3067    
3068                            if (orderByConditionFields.length > 0) {
3069                                    query.append(WHERE_AND);
3070                            }
3071    
3072                            for (int i = 0; i < orderByConditionFields.length; i++) {
3073                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3074                                    query.append(orderByConditionFields[i]);
3075    
3076                                    if ((i + 1) < orderByConditionFields.length) {
3077                                            if (orderByComparator.isAscending() ^ previous) {
3078                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3079                                            }
3080                                            else {
3081                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3082                                            }
3083                                    }
3084                                    else {
3085                                            if (orderByComparator.isAscending() ^ previous) {
3086                                                    query.append(WHERE_GREATER_THAN);
3087                                            }
3088                                            else {
3089                                                    query.append(WHERE_LESSER_THAN);
3090                                            }
3091                                    }
3092                            }
3093    
3094                            query.append(ORDER_BY_CLAUSE);
3095    
3096                            String[] orderByFields = orderByComparator.getOrderByFields();
3097    
3098                            for (int i = 0; i < orderByFields.length; i++) {
3099                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3100                                    query.append(orderByFields[i]);
3101    
3102                                    if ((i + 1) < orderByFields.length) {
3103                                            if (orderByComparator.isAscending() ^ previous) {
3104                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3105                                            }
3106                                            else {
3107                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3108                                            }
3109                                    }
3110                                    else {
3111                                            if (orderByComparator.isAscending() ^ previous) {
3112                                                    query.append(ORDER_BY_ASC);
3113                                            }
3114                                            else {
3115                                                    query.append(ORDER_BY_DESC);
3116                                            }
3117                                    }
3118                            }
3119                    }
3120    
3121                    else {
3122                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
3123                    }
3124    
3125                    String sql = query.toString();
3126    
3127                    Query q = session.createQuery(sql);
3128    
3129                    q.setFirstResult(0);
3130                    q.setMaxResults(2);
3131    
3132                    QueryPos qPos = QueryPos.getInstance(q);
3133    
3134                    qPos.add(groupId);
3135    
3136                    if (type != null) {
3137                            qPos.add(type);
3138                    }
3139    
3140                    if (orderByComparator != null) {
3141                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
3142    
3143                            for (Object value : values) {
3144                                    qPos.add(value);
3145                            }
3146                    }
3147    
3148                    List<CalEvent> list = q.list();
3149    
3150                    if (list.size() == 2) {
3151                            return list.get(1);
3152                    }
3153                    else {
3154                            return null;
3155                    }
3156            }
3157    
3158            /**
3159             * Returns all the cal events where groupId = &#63; and type = any &#63;.
3160             *
3161             * <p>
3162             * 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.
3163             * </p>
3164             *
3165             * @param groupId the group ID
3166             * @param types the types
3167             * @return the matching cal events
3168             * @throws SystemException if a system exception occurred
3169             */
3170            public List<CalEvent> findByG_T(long groupId, String[] types)
3171                    throws SystemException {
3172                    return findByG_T(groupId, types, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3173                            null);
3174            }
3175    
3176            /**
3177             * Returns a range of all the cal events where groupId = &#63; and type = any &#63;.
3178             *
3179             * <p>
3180             * 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.
3181             * </p>
3182             *
3183             * @param groupId the group ID
3184             * @param types the types
3185             * @param start the lower bound of the range of cal events
3186             * @param end the upper bound of the range of cal events (not inclusive)
3187             * @return the range of matching cal events
3188             * @throws SystemException if a system exception occurred
3189             */
3190            public List<CalEvent> findByG_T(long groupId, String[] types, int start,
3191                    int end) throws SystemException {
3192                    return findByG_T(groupId, types, start, end, null);
3193            }
3194    
3195            /**
3196             * Returns an ordered range of all the cal events where groupId = &#63; and type = any &#63;.
3197             *
3198             * <p>
3199             * 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.
3200             * </p>
3201             *
3202             * @param groupId the group ID
3203             * @param types the types
3204             * @param start the lower bound of the range of cal events
3205             * @param end the upper bound of the range of cal events (not inclusive)
3206             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3207             * @return the ordered range of matching cal events
3208             * @throws SystemException if a system exception occurred
3209             */
3210            public List<CalEvent> findByG_T(long groupId, String[] types, int start,
3211                    int end, OrderByComparator orderByComparator) throws SystemException {
3212                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T;
3213                    Object[] finderArgs = null;
3214    
3215                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3216                                    (orderByComparator == null)) {
3217                            finderArgs = new Object[] { groupId, StringUtil.merge(types) };
3218                    }
3219                    else {
3220                            finderArgs = new Object[] {
3221                                            groupId, StringUtil.merge(types),
3222                                            
3223                                            start, end, orderByComparator
3224                                    };
3225                    }
3226    
3227                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
3228                                    finderArgs, this);
3229    
3230                    if ((list != null) && !list.isEmpty()) {
3231                            for (CalEvent calEvent : list) {
3232                                    if ((groupId != calEvent.getGroupId()) ||
3233                                                    !ArrayUtil.contains(types, calEvent.getType())) {
3234                                            list = null;
3235    
3236                                            break;
3237                                    }
3238                            }
3239                    }
3240    
3241                    if (list == null) {
3242                            StringBundler query = new StringBundler();
3243    
3244                            query.append(_SQL_SELECT_CALEVENT_WHERE);
3245    
3246                            boolean conjunctionable = false;
3247    
3248                            if (conjunctionable) {
3249                                    query.append(WHERE_AND);
3250                            }
3251    
3252                            query.append(_FINDER_COLUMN_G_T_GROUPID_5);
3253    
3254                            conjunctionable = true;
3255    
3256                            if ((types == null) || (types.length > 0)) {
3257                                    if (conjunctionable) {
3258                                            query.append(WHERE_AND);
3259                                    }
3260    
3261                                    query.append(StringPool.OPEN_PARENTHESIS);
3262    
3263                                    for (int i = 0; i < types.length; i++) {
3264                                            String type = types[i];
3265    
3266                                            if (type == null) {
3267                                                    query.append(_FINDER_COLUMN_G_T_TYPE_4);
3268                                            }
3269                                            else {
3270                                                    if (type.equals(StringPool.BLANK)) {
3271                                                            query.append(_FINDER_COLUMN_G_T_TYPE_6);
3272                                                    }
3273                                                    else {
3274                                                            query.append(_FINDER_COLUMN_G_T_TYPE_5);
3275                                                    }
3276                                            }
3277    
3278                                            if ((i + 1) < types.length) {
3279                                                    query.append(WHERE_OR);
3280                                            }
3281                                    }
3282    
3283                                    query.append(StringPool.CLOSE_PARENTHESIS);
3284    
3285                                    conjunctionable = true;
3286                            }
3287    
3288                            if (orderByComparator != null) {
3289                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3290                                            orderByComparator);
3291                            }
3292    
3293                            else {
3294                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
3295                            }
3296    
3297                            String sql = query.toString();
3298    
3299                            Session session = null;
3300    
3301                            try {
3302                                    session = openSession();
3303    
3304                                    Query q = session.createQuery(sql);
3305    
3306                                    QueryPos qPos = QueryPos.getInstance(q);
3307    
3308                                    qPos.add(groupId);
3309    
3310                                    if (types != null) {
3311                                            qPos.add(types);
3312                                    }
3313    
3314                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
3315                                                    end);
3316                            }
3317                            catch (Exception e) {
3318                                    throw processException(e);
3319                            }
3320                            finally {
3321                                    if (list == null) {
3322                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3323                                    }
3324                                    else {
3325                                            cacheResult(list);
3326    
3327                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3328                                    }
3329    
3330                                    closeSession(session);
3331                            }
3332                    }
3333    
3334                    return list;
3335            }
3336    
3337            /**
3338             * Returns all the cal events that the user has permission to view where groupId = &#63; and type = &#63;.
3339             *
3340             * @param groupId the group ID
3341             * @param type the type
3342             * @return the matching cal events that the user has permission to view
3343             * @throws SystemException if a system exception occurred
3344             */
3345            public List<CalEvent> filterFindByG_T(long groupId, String type)
3346                    throws SystemException {
3347                    return filterFindByG_T(groupId, type, QueryUtil.ALL_POS,
3348                            QueryUtil.ALL_POS, null);
3349            }
3350    
3351            /**
3352             * Returns a range of all the cal events that the user has permission to view where groupId = &#63; and type = &#63;.
3353             *
3354             * <p>
3355             * 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.
3356             * </p>
3357             *
3358             * @param groupId the group ID
3359             * @param type the type
3360             * @param start the lower bound of the range of cal events
3361             * @param end the upper bound of the range of cal events (not inclusive)
3362             * @return the range of matching cal events that the user has permission to view
3363             * @throws SystemException if a system exception occurred
3364             */
3365            public List<CalEvent> filterFindByG_T(long groupId, String type, int start,
3366                    int end) throws SystemException {
3367                    return filterFindByG_T(groupId, type, start, end, null);
3368            }
3369    
3370            /**
3371             * Returns an ordered range of all the cal events that the user has permissions to view where groupId = &#63; and type = &#63;.
3372             *
3373             * <p>
3374             * 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.
3375             * </p>
3376             *
3377             * @param groupId the group ID
3378             * @param type the type
3379             * @param start the lower bound of the range of cal events
3380             * @param end the upper bound of the range of cal events (not inclusive)
3381             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3382             * @return the ordered range of matching cal events that the user has permission to view
3383             * @throws SystemException if a system exception occurred
3384             */
3385            public List<CalEvent> filterFindByG_T(long groupId, String type, int start,
3386                    int end, OrderByComparator orderByComparator) throws SystemException {
3387                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3388                            return findByG_T(groupId, type, start, end, orderByComparator);
3389                    }
3390    
3391                    StringBundler query = null;
3392    
3393                    if (orderByComparator != null) {
3394                            query = new StringBundler(4 +
3395                                            (orderByComparator.getOrderByFields().length * 3));
3396                    }
3397                    else {
3398                            query = new StringBundler(4);
3399                    }
3400    
3401                    if (getDB().isSupportsInlineDistinct()) {
3402                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
3403                    }
3404                    else {
3405                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
3406                    }
3407    
3408                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3409    
3410                    if (type == null) {
3411                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
3412                    }
3413                    else {
3414                            if (type.equals(StringPool.BLANK)) {
3415                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
3416                            }
3417                            else {
3418                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
3419                            }
3420                    }
3421    
3422                    if (!getDB().isSupportsInlineDistinct()) {
3423                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
3424                    }
3425    
3426                    if (orderByComparator != null) {
3427                            if (getDB().isSupportsInlineDistinct()) {
3428                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3429                                            orderByComparator);
3430                            }
3431                            else {
3432                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3433                                            orderByComparator);
3434                            }
3435                    }
3436    
3437                    else {
3438                            if (getDB().isSupportsInlineDistinct()) {
3439                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
3440                            }
3441                            else {
3442                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
3443                            }
3444                    }
3445    
3446                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3447                                    CalEvent.class.getName(),
3448                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3449    
3450                    Session session = null;
3451    
3452                    try {
3453                            session = openSession();
3454    
3455                            SQLQuery q = session.createSQLQuery(sql);
3456    
3457                            if (getDB().isSupportsInlineDistinct()) {
3458                                    q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
3459                            }
3460                            else {
3461                                    q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
3462                            }
3463    
3464                            QueryPos qPos = QueryPos.getInstance(q);
3465    
3466                            qPos.add(groupId);
3467    
3468                            if (type != null) {
3469                                    qPos.add(type);
3470                            }
3471    
3472                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
3473                    }
3474                    catch (Exception e) {
3475                            throw processException(e);
3476                    }
3477                    finally {
3478                            closeSession(session);
3479                    }
3480            }
3481    
3482            /**
3483             * Returns the cal events before and after the current cal event in the ordered set of cal events that the user has permission to view where groupId = &#63; and type = &#63;.
3484             *
3485             * @param eventId the primary key of the current cal event
3486             * @param groupId the group ID
3487             * @param type the type
3488             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3489             * @return the previous, current, and next cal event
3490             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
3491             * @throws SystemException if a system exception occurred
3492             */
3493            public CalEvent[] filterFindByG_T_PrevAndNext(long eventId, long groupId,
3494                    String type, OrderByComparator orderByComparator)
3495                    throws NoSuchEventException, SystemException {
3496                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3497                            return findByG_T_PrevAndNext(eventId, groupId, type,
3498                                    orderByComparator);
3499                    }
3500    
3501                    CalEvent calEvent = findByPrimaryKey(eventId);
3502    
3503                    Session session = null;
3504    
3505                    try {
3506                            session = openSession();
3507    
3508                            CalEvent[] array = new CalEventImpl[3];
3509    
3510                            array[0] = filterGetByG_T_PrevAndNext(session, calEvent, groupId,
3511                                            type, orderByComparator, true);
3512    
3513                            array[1] = calEvent;
3514    
3515                            array[2] = filterGetByG_T_PrevAndNext(session, calEvent, groupId,
3516                                            type, orderByComparator, false);
3517    
3518                            return array;
3519                    }
3520                    catch (Exception e) {
3521                            throw processException(e);
3522                    }
3523                    finally {
3524                            closeSession(session);
3525                    }
3526            }
3527    
3528            protected CalEvent filterGetByG_T_PrevAndNext(Session session,
3529                    CalEvent calEvent, long groupId, String type,
3530                    OrderByComparator orderByComparator, boolean previous) {
3531                    StringBundler query = null;
3532    
3533                    if (orderByComparator != null) {
3534                            query = new StringBundler(6 +
3535                                            (orderByComparator.getOrderByFields().length * 6));
3536                    }
3537                    else {
3538                            query = new StringBundler(3);
3539                    }
3540    
3541                    if (getDB().isSupportsInlineDistinct()) {
3542                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
3543                    }
3544                    else {
3545                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
3546                    }
3547    
3548                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3549    
3550                    if (type == null) {
3551                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
3552                    }
3553                    else {
3554                            if (type.equals(StringPool.BLANK)) {
3555                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
3556                            }
3557                            else {
3558                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
3559                            }
3560                    }
3561    
3562                    if (!getDB().isSupportsInlineDistinct()) {
3563                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
3564                    }
3565    
3566                    if (orderByComparator != null) {
3567                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3568    
3569                            if (orderByConditionFields.length > 0) {
3570                                    query.append(WHERE_AND);
3571                            }
3572    
3573                            for (int i = 0; i < orderByConditionFields.length; i++) {
3574                                    if (getDB().isSupportsInlineDistinct()) {
3575                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3576                                    }
3577                                    else {
3578                                            query.append(_ORDER_BY_ENTITY_TABLE);
3579                                    }
3580    
3581                                    query.append(orderByConditionFields[i]);
3582    
3583                                    if ((i + 1) < orderByConditionFields.length) {
3584                                            if (orderByComparator.isAscending() ^ previous) {
3585                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3586                                            }
3587                                            else {
3588                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3589                                            }
3590                                    }
3591                                    else {
3592                                            if (orderByComparator.isAscending() ^ previous) {
3593                                                    query.append(WHERE_GREATER_THAN);
3594                                            }
3595                                            else {
3596                                                    query.append(WHERE_LESSER_THAN);
3597                                            }
3598                                    }
3599                            }
3600    
3601                            query.append(ORDER_BY_CLAUSE);
3602    
3603                            String[] orderByFields = orderByComparator.getOrderByFields();
3604    
3605                            for (int i = 0; i < orderByFields.length; i++) {
3606                                    if (getDB().isSupportsInlineDistinct()) {
3607                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3608                                    }
3609                                    else {
3610                                            query.append(_ORDER_BY_ENTITY_TABLE);
3611                                    }
3612    
3613                                    query.append(orderByFields[i]);
3614    
3615                                    if ((i + 1) < orderByFields.length) {
3616                                            if (orderByComparator.isAscending() ^ previous) {
3617                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3618                                            }
3619                                            else {
3620                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3621                                            }
3622                                    }
3623                                    else {
3624                                            if (orderByComparator.isAscending() ^ previous) {
3625                                                    query.append(ORDER_BY_ASC);
3626                                            }
3627                                            else {
3628                                                    query.append(ORDER_BY_DESC);
3629                                            }
3630                                    }
3631                            }
3632                    }
3633    
3634                    else {
3635                            if (getDB().isSupportsInlineDistinct()) {
3636                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
3637                            }
3638                            else {
3639                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
3640                            }
3641                    }
3642    
3643                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3644                                    CalEvent.class.getName(),
3645                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3646    
3647                    SQLQuery q = session.createSQLQuery(sql);
3648    
3649                    q.setFirstResult(0);
3650                    q.setMaxResults(2);
3651    
3652                    if (getDB().isSupportsInlineDistinct()) {
3653                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
3654                    }
3655                    else {
3656                            q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
3657                    }
3658    
3659                    QueryPos qPos = QueryPos.getInstance(q);
3660    
3661                    qPos.add(groupId);
3662    
3663                    if (type != null) {
3664                            qPos.add(type);
3665                    }
3666    
3667                    if (orderByComparator != null) {
3668                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
3669    
3670                            for (Object value : values) {
3671                                    qPos.add(value);
3672                            }
3673                    }
3674    
3675                    List<CalEvent> list = q.list();
3676    
3677                    if (list.size() == 2) {
3678                            return list.get(1);
3679                    }
3680                    else {
3681                            return null;
3682                    }
3683            }
3684    
3685            /**
3686             * Returns all the cal events that the user has permission to view where groupId = &#63; and type = any &#63;.
3687             *
3688             * @param groupId the group ID
3689             * @param types the types
3690             * @return the matching cal events that the user has permission to view
3691             * @throws SystemException if a system exception occurred
3692             */
3693            public List<CalEvent> filterFindByG_T(long groupId, String[] types)
3694                    throws SystemException {
3695                    return filterFindByG_T(groupId, types, QueryUtil.ALL_POS,
3696                            QueryUtil.ALL_POS, null);
3697            }
3698    
3699            /**
3700             * Returns a range of all the cal events that the user has permission to view where groupId = &#63; and type = any &#63;.
3701             *
3702             * <p>
3703             * 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.
3704             * </p>
3705             *
3706             * @param groupId the group ID
3707             * @param types the types
3708             * @param start the lower bound of the range of cal events
3709             * @param end the upper bound of the range of cal events (not inclusive)
3710             * @return the range of matching cal events that the user has permission to view
3711             * @throws SystemException if a system exception occurred
3712             */
3713            public List<CalEvent> filterFindByG_T(long groupId, String[] types,
3714                    int start, int end) throws SystemException {
3715                    return filterFindByG_T(groupId, types, start, end, null);
3716            }
3717    
3718            /**
3719             * Returns an ordered range of all the cal events that the user has permission to view where groupId = &#63; and type = any &#63;.
3720             *
3721             * <p>
3722             * 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.
3723             * </p>
3724             *
3725             * @param groupId the group ID
3726             * @param types the types
3727             * @param start the lower bound of the range of cal events
3728             * @param end the upper bound of the range of cal events (not inclusive)
3729             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3730             * @return the ordered range of matching cal events that the user has permission to view
3731             * @throws SystemException if a system exception occurred
3732             */
3733            public List<CalEvent> filterFindByG_T(long groupId, String[] types,
3734                    int start, int end, OrderByComparator orderByComparator)
3735                    throws SystemException {
3736                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3737                            return findByG_T(groupId, types, start, end, orderByComparator);
3738                    }
3739    
3740                    StringBundler query = new StringBundler();
3741    
3742                    if (getDB().isSupportsInlineDistinct()) {
3743                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
3744                    }
3745                    else {
3746                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
3747                    }
3748    
3749                    boolean conjunctionable = false;
3750    
3751                    if (conjunctionable) {
3752                            query.append(WHERE_AND);
3753                    }
3754    
3755                    query.append(_FINDER_COLUMN_G_T_GROUPID_5);
3756    
3757                    conjunctionable = true;
3758    
3759                    if ((types == null) || (types.length > 0)) {
3760                            if (conjunctionable) {
3761                                    query.append(WHERE_AND);
3762                            }
3763    
3764                            query.append(StringPool.OPEN_PARENTHESIS);
3765    
3766                            for (int i = 0; i < types.length; i++) {
3767                                    String type = types[i];
3768    
3769                                    if (type == null) {
3770                                            query.append(_FINDER_COLUMN_G_T_TYPE_4);
3771                                    }
3772                                    else {
3773                                            if (type.equals(StringPool.BLANK)) {
3774                                                    query.append(_FINDER_COLUMN_G_T_TYPE_6);
3775                                            }
3776                                            else {
3777                                                    query.append(_FINDER_COLUMN_G_T_TYPE_5);
3778                                            }
3779                                    }
3780    
3781                                    if ((i + 1) < types.length) {
3782                                            query.append(WHERE_OR);
3783                                    }
3784                            }
3785    
3786                            query.append(StringPool.CLOSE_PARENTHESIS);
3787    
3788                            conjunctionable = true;
3789                    }
3790    
3791                    if (!getDB().isSupportsInlineDistinct()) {
3792                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
3793                    }
3794    
3795                    if (orderByComparator != null) {
3796                            if (getDB().isSupportsInlineDistinct()) {
3797                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3798                                            orderByComparator);
3799                            }
3800                            else {
3801                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3802                                            orderByComparator);
3803                            }
3804                    }
3805    
3806                    else {
3807                            if (getDB().isSupportsInlineDistinct()) {
3808                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
3809                            }
3810                            else {
3811                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
3812                            }
3813                    }
3814    
3815                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3816                                    CalEvent.class.getName(),
3817                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3818    
3819                    Session session = null;
3820    
3821                    try {
3822                            session = openSession();
3823    
3824                            SQLQuery q = session.createSQLQuery(sql);
3825    
3826                            if (getDB().isSupportsInlineDistinct()) {
3827                                    q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
3828                            }
3829                            else {
3830                                    q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
3831                            }
3832    
3833                            QueryPos qPos = QueryPos.getInstance(q);
3834    
3835                            qPos.add(groupId);
3836    
3837                            if (types != null) {
3838                                    qPos.add(types);
3839                            }
3840    
3841                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
3842                    }
3843                    catch (Exception e) {
3844                            throw processException(e);
3845                    }
3846                    finally {
3847                            closeSession(session);
3848                    }
3849            }
3850    
3851            /**
3852             * Returns all the cal events where groupId = &#63; and repeating = &#63;.
3853             *
3854             * @param groupId the group ID
3855             * @param repeating the repeating
3856             * @return the matching cal events
3857             * @throws SystemException if a system exception occurred
3858             */
3859            public List<CalEvent> findByG_R(long groupId, boolean repeating)
3860                    throws SystemException {
3861                    return findByG_R(groupId, repeating, QueryUtil.ALL_POS,
3862                            QueryUtil.ALL_POS, null);
3863            }
3864    
3865            /**
3866             * Returns a range of all the cal events where groupId = &#63; and repeating = &#63;.
3867             *
3868             * <p>
3869             * 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.
3870             * </p>
3871             *
3872             * @param groupId the group ID
3873             * @param repeating the repeating
3874             * @param start the lower bound of the range of cal events
3875             * @param end the upper bound of the range of cal events (not inclusive)
3876             * @return the range of matching cal events
3877             * @throws SystemException if a system exception occurred
3878             */
3879            public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
3880                    int end) throws SystemException {
3881                    return findByG_R(groupId, repeating, start, end, null);
3882            }
3883    
3884            /**
3885             * Returns an ordered range of all the cal events where groupId = &#63; and repeating = &#63;.
3886             *
3887             * <p>
3888             * 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.
3889             * </p>
3890             *
3891             * @param groupId the group ID
3892             * @param repeating the repeating
3893             * @param start the lower bound of the range of cal events
3894             * @param end the upper bound of the range of cal events (not inclusive)
3895             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3896             * @return the ordered range of matching cal events
3897             * @throws SystemException if a system exception occurred
3898             */
3899            public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
3900                    int end, OrderByComparator orderByComparator) throws SystemException {
3901                    FinderPath finderPath = null;
3902                    Object[] finderArgs = null;
3903    
3904                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3905                                    (orderByComparator == null)) {
3906                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R;
3907                            finderArgs = new Object[] { groupId, repeating };
3908                    }
3909                    else {
3910                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R;
3911                            finderArgs = new Object[] {
3912                                            groupId, repeating,
3913                                            
3914                                            start, end, orderByComparator
3915                                    };
3916                    }
3917    
3918                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
3919                                    finderArgs, this);
3920    
3921                    if ((list != null) && !list.isEmpty()) {
3922                            for (CalEvent calEvent : list) {
3923                                    if ((groupId != calEvent.getGroupId()) ||
3924                                                    (repeating != calEvent.getRepeating())) {
3925                                            list = null;
3926    
3927                                            break;
3928                                    }
3929                            }
3930                    }
3931    
3932                    if (list == null) {
3933                            StringBundler query = null;
3934    
3935                            if (orderByComparator != null) {
3936                                    query = new StringBundler(4 +
3937                                                    (orderByComparator.getOrderByFields().length * 3));
3938                            }
3939                            else {
3940                                    query = new StringBundler(4);
3941                            }
3942    
3943                            query.append(_SQL_SELECT_CALEVENT_WHERE);
3944    
3945                            query.append(_FINDER_COLUMN_G_R_GROUPID_2);
3946    
3947                            query.append(_FINDER_COLUMN_G_R_REPEATING_2);
3948    
3949                            if (orderByComparator != null) {
3950                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3951                                            orderByComparator);
3952                            }
3953    
3954                            else {
3955                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
3956                            }
3957    
3958                            String sql = query.toString();
3959    
3960                            Session session = null;
3961    
3962                            try {
3963                                    session = openSession();
3964    
3965                                    Query q = session.createQuery(sql);
3966    
3967                                    QueryPos qPos = QueryPos.getInstance(q);
3968    
3969                                    qPos.add(groupId);
3970    
3971                                    qPos.add(repeating);
3972    
3973                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
3974                                                    end);
3975                            }
3976                            catch (Exception e) {
3977                                    throw processException(e);
3978                            }
3979                            finally {
3980                                    if (list == null) {
3981                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3982                                    }
3983                                    else {
3984                                            cacheResult(list);
3985    
3986                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3987                                    }
3988    
3989                                    closeSession(session);
3990                            }
3991                    }
3992    
3993                    return list;
3994            }
3995    
3996            /**
3997             * Returns the first cal event in the ordered set where groupId = &#63; and repeating = &#63;.
3998             *
3999             * <p>
4000             * 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.
4001             * </p>
4002             *
4003             * @param groupId the group ID
4004             * @param repeating the repeating
4005             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4006             * @return the first matching cal event
4007             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
4008             * @throws SystemException if a system exception occurred
4009             */
4010            public CalEvent findByG_R_First(long groupId, boolean repeating,
4011                    OrderByComparator orderByComparator)
4012                    throws NoSuchEventException, SystemException {
4013                    List<CalEvent> list = findByG_R(groupId, repeating, 0, 1,
4014                                    orderByComparator);
4015    
4016                    if (list.isEmpty()) {
4017                            StringBundler msg = new StringBundler(6);
4018    
4019                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4020    
4021                            msg.append("groupId=");
4022                            msg.append(groupId);
4023    
4024                            msg.append(", repeating=");
4025                            msg.append(repeating);
4026    
4027                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4028    
4029                            throw new NoSuchEventException(msg.toString());
4030                    }
4031                    else {
4032                            return list.get(0);
4033                    }
4034            }
4035    
4036            /**
4037             * Returns the last cal event in the ordered set where groupId = &#63; and repeating = &#63;.
4038             *
4039             * <p>
4040             * 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.
4041             * </p>
4042             *
4043             * @param groupId the group ID
4044             * @param repeating the repeating
4045             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4046             * @return the last matching cal event
4047             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
4048             * @throws SystemException if a system exception occurred
4049             */
4050            public CalEvent findByG_R_Last(long groupId, boolean repeating,
4051                    OrderByComparator orderByComparator)
4052                    throws NoSuchEventException, SystemException {
4053                    int count = countByG_R(groupId, repeating);
4054    
4055                    List<CalEvent> list = findByG_R(groupId, repeating, count - 1, count,
4056                                    orderByComparator);
4057    
4058                    if (list.isEmpty()) {
4059                            StringBundler msg = new StringBundler(6);
4060    
4061                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4062    
4063                            msg.append("groupId=");
4064                            msg.append(groupId);
4065    
4066                            msg.append(", repeating=");
4067                            msg.append(repeating);
4068    
4069                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4070    
4071                            throw new NoSuchEventException(msg.toString());
4072                    }
4073                    else {
4074                            return list.get(0);
4075                    }
4076            }
4077    
4078            /**
4079             * Returns the cal events before and after the current cal event in the ordered set where groupId = &#63; and repeating = &#63;.
4080             *
4081             * <p>
4082             * 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.
4083             * </p>
4084             *
4085             * @param eventId the primary key of the current cal event
4086             * @param groupId the group ID
4087             * @param repeating the repeating
4088             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4089             * @return the previous, current, and next cal event
4090             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
4091             * @throws SystemException if a system exception occurred
4092             */
4093            public CalEvent[] findByG_R_PrevAndNext(long eventId, long groupId,
4094                    boolean repeating, OrderByComparator orderByComparator)
4095                    throws NoSuchEventException, SystemException {
4096                    CalEvent calEvent = findByPrimaryKey(eventId);
4097    
4098                    Session session = null;
4099    
4100                    try {
4101                            session = openSession();
4102    
4103                            CalEvent[] array = new CalEventImpl[3];
4104    
4105                            array[0] = getByG_R_PrevAndNext(session, calEvent, groupId,
4106                                            repeating, orderByComparator, true);
4107    
4108                            array[1] = calEvent;
4109    
4110                            array[2] = getByG_R_PrevAndNext(session, calEvent, groupId,
4111                                            repeating, orderByComparator, false);
4112    
4113                            return array;
4114                    }
4115                    catch (Exception e) {
4116                            throw processException(e);
4117                    }
4118                    finally {
4119                            closeSession(session);
4120                    }
4121            }
4122    
4123            protected CalEvent getByG_R_PrevAndNext(Session session, CalEvent calEvent,
4124                    long groupId, boolean repeating, OrderByComparator orderByComparator,
4125                    boolean previous) {
4126                    StringBundler query = null;
4127    
4128                    if (orderByComparator != null) {
4129                            query = new StringBundler(6 +
4130                                            (orderByComparator.getOrderByFields().length * 6));
4131                    }
4132                    else {
4133                            query = new StringBundler(3);
4134                    }
4135    
4136                    query.append(_SQL_SELECT_CALEVENT_WHERE);
4137    
4138                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
4139    
4140                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
4141    
4142                    if (orderByComparator != null) {
4143                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4144    
4145                            if (orderByConditionFields.length > 0) {
4146                                    query.append(WHERE_AND);
4147                            }
4148    
4149                            for (int i = 0; i < orderByConditionFields.length; i++) {
4150                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4151                                    query.append(orderByConditionFields[i]);
4152    
4153                                    if ((i + 1) < orderByConditionFields.length) {
4154                                            if (orderByComparator.isAscending() ^ previous) {
4155                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4156                                            }
4157                                            else {
4158                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4159                                            }
4160                                    }
4161                                    else {
4162                                            if (orderByComparator.isAscending() ^ previous) {
4163                                                    query.append(WHERE_GREATER_THAN);
4164                                            }
4165                                            else {
4166                                                    query.append(WHERE_LESSER_THAN);
4167                                            }
4168                                    }
4169                            }
4170    
4171                            query.append(ORDER_BY_CLAUSE);
4172    
4173                            String[] orderByFields = orderByComparator.getOrderByFields();
4174    
4175                            for (int i = 0; i < orderByFields.length; i++) {
4176                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4177                                    query.append(orderByFields[i]);
4178    
4179                                    if ((i + 1) < orderByFields.length) {
4180                                            if (orderByComparator.isAscending() ^ previous) {
4181                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4182                                            }
4183                                            else {
4184                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4185                                            }
4186                                    }
4187                                    else {
4188                                            if (orderByComparator.isAscending() ^ previous) {
4189                                                    query.append(ORDER_BY_ASC);
4190                                            }
4191                                            else {
4192                                                    query.append(ORDER_BY_DESC);
4193                                            }
4194                                    }
4195                            }
4196                    }
4197    
4198                    else {
4199                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
4200                    }
4201    
4202                    String sql = query.toString();
4203    
4204                    Query q = session.createQuery(sql);
4205    
4206                    q.setFirstResult(0);
4207                    q.setMaxResults(2);
4208    
4209                    QueryPos qPos = QueryPos.getInstance(q);
4210    
4211                    qPos.add(groupId);
4212    
4213                    qPos.add(repeating);
4214    
4215                    if (orderByComparator != null) {
4216                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
4217    
4218                            for (Object value : values) {
4219                                    qPos.add(value);
4220                            }
4221                    }
4222    
4223                    List<CalEvent> list = q.list();
4224    
4225                    if (list.size() == 2) {
4226                            return list.get(1);
4227                    }
4228                    else {
4229                            return null;
4230                    }
4231            }
4232    
4233            /**
4234             * Returns all the cal events that the user has permission to view where groupId = &#63; and repeating = &#63;.
4235             *
4236             * @param groupId the group ID
4237             * @param repeating the repeating
4238             * @return the matching cal events that the user has permission to view
4239             * @throws SystemException if a system exception occurred
4240             */
4241            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating)
4242                    throws SystemException {
4243                    return filterFindByG_R(groupId, repeating, QueryUtil.ALL_POS,
4244                            QueryUtil.ALL_POS, null);
4245            }
4246    
4247            /**
4248             * Returns a range of all the cal events that the user has permission to view where groupId = &#63; and repeating = &#63;.
4249             *
4250             * <p>
4251             * 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.
4252             * </p>
4253             *
4254             * @param groupId the group ID
4255             * @param repeating the repeating
4256             * @param start the lower bound of the range of cal events
4257             * @param end the upper bound of the range of cal events (not inclusive)
4258             * @return the range of matching cal events that the user has permission to view
4259             * @throws SystemException if a system exception occurred
4260             */
4261            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating,
4262                    int start, int end) throws SystemException {
4263                    return filterFindByG_R(groupId, repeating, start, end, null);
4264            }
4265    
4266            /**
4267             * Returns an ordered range of all the cal events that the user has permissions to view where groupId = &#63; and repeating = &#63;.
4268             *
4269             * <p>
4270             * 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.
4271             * </p>
4272             *
4273             * @param groupId the group ID
4274             * @param repeating the repeating
4275             * @param start the lower bound of the range of cal events
4276             * @param end the upper bound of the range of cal events (not inclusive)
4277             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4278             * @return the ordered range of matching cal events that the user has permission to view
4279             * @throws SystemException if a system exception occurred
4280             */
4281            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating,
4282                    int start, int end, OrderByComparator orderByComparator)
4283                    throws SystemException {
4284                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4285                            return findByG_R(groupId, repeating, start, end, orderByComparator);
4286                    }
4287    
4288                    StringBundler query = null;
4289    
4290                    if (orderByComparator != null) {
4291                            query = new StringBundler(4 +
4292                                            (orderByComparator.getOrderByFields().length * 3));
4293                    }
4294                    else {
4295                            query = new StringBundler(4);
4296                    }
4297    
4298                    if (getDB().isSupportsInlineDistinct()) {
4299                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
4300                    }
4301                    else {
4302                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
4303                    }
4304    
4305                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
4306    
4307                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
4308    
4309                    if (!getDB().isSupportsInlineDistinct()) {
4310                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
4311                    }
4312    
4313                    if (orderByComparator != null) {
4314                            if (getDB().isSupportsInlineDistinct()) {
4315                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4316                                            orderByComparator);
4317                            }
4318                            else {
4319                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4320                                            orderByComparator);
4321                            }
4322                    }
4323    
4324                    else {
4325                            if (getDB().isSupportsInlineDistinct()) {
4326                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
4327                            }
4328                            else {
4329                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
4330                            }
4331                    }
4332    
4333                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4334                                    CalEvent.class.getName(),
4335                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4336    
4337                    Session session = null;
4338    
4339                    try {
4340                            session = openSession();
4341    
4342                            SQLQuery q = session.createSQLQuery(sql);
4343    
4344                            if (getDB().isSupportsInlineDistinct()) {
4345                                    q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
4346                            }
4347                            else {
4348                                    q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
4349                            }
4350    
4351                            QueryPos qPos = QueryPos.getInstance(q);
4352    
4353                            qPos.add(groupId);
4354    
4355                            qPos.add(repeating);
4356    
4357                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
4358                    }
4359                    catch (Exception e) {
4360                            throw processException(e);
4361                    }
4362                    finally {
4363                            closeSession(session);
4364                    }
4365            }
4366    
4367            /**
4368             * Returns the cal events before and after the current cal event in the ordered set of cal events that the user has permission to view where groupId = &#63; and repeating = &#63;.
4369             *
4370             * @param eventId the primary key of the current cal event
4371             * @param groupId the group ID
4372             * @param repeating the repeating
4373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4374             * @return the previous, current, and next cal event
4375             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
4376             * @throws SystemException if a system exception occurred
4377             */
4378            public CalEvent[] filterFindByG_R_PrevAndNext(long eventId, long groupId,
4379                    boolean repeating, OrderByComparator orderByComparator)
4380                    throws NoSuchEventException, SystemException {
4381                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4382                            return findByG_R_PrevAndNext(eventId, groupId, repeating,
4383                                    orderByComparator);
4384                    }
4385    
4386                    CalEvent calEvent = findByPrimaryKey(eventId);
4387    
4388                    Session session = null;
4389    
4390                    try {
4391                            session = openSession();
4392    
4393                            CalEvent[] array = new CalEventImpl[3];
4394    
4395                            array[0] = filterGetByG_R_PrevAndNext(session, calEvent, groupId,
4396                                            repeating, orderByComparator, true);
4397    
4398                            array[1] = calEvent;
4399    
4400                            array[2] = filterGetByG_R_PrevAndNext(session, calEvent, groupId,
4401                                            repeating, orderByComparator, false);
4402    
4403                            return array;
4404                    }
4405                    catch (Exception e) {
4406                            throw processException(e);
4407                    }
4408                    finally {
4409                            closeSession(session);
4410                    }
4411            }
4412    
4413            protected CalEvent filterGetByG_R_PrevAndNext(Session session,
4414                    CalEvent calEvent, long groupId, boolean repeating,
4415                    OrderByComparator orderByComparator, boolean previous) {
4416                    StringBundler query = null;
4417    
4418                    if (orderByComparator != null) {
4419                            query = new StringBundler(6 +
4420                                            (orderByComparator.getOrderByFields().length * 6));
4421                    }
4422                    else {
4423                            query = new StringBundler(3);
4424                    }
4425    
4426                    if (getDB().isSupportsInlineDistinct()) {
4427                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
4428                    }
4429                    else {
4430                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
4431                    }
4432    
4433                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
4434    
4435                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
4436    
4437                    if (!getDB().isSupportsInlineDistinct()) {
4438                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
4439                    }
4440    
4441                    if (orderByComparator != null) {
4442                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4443    
4444                            if (orderByConditionFields.length > 0) {
4445                                    query.append(WHERE_AND);
4446                            }
4447    
4448                            for (int i = 0; i < orderByConditionFields.length; i++) {
4449                                    if (getDB().isSupportsInlineDistinct()) {
4450                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4451                                    }
4452                                    else {
4453                                            query.append(_ORDER_BY_ENTITY_TABLE);
4454                                    }
4455    
4456                                    query.append(orderByConditionFields[i]);
4457    
4458                                    if ((i + 1) < orderByConditionFields.length) {
4459                                            if (orderByComparator.isAscending() ^ previous) {
4460                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4461                                            }
4462                                            else {
4463                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4464                                            }
4465                                    }
4466                                    else {
4467                                            if (orderByComparator.isAscending() ^ previous) {
4468                                                    query.append(WHERE_GREATER_THAN);
4469                                            }
4470                                            else {
4471                                                    query.append(WHERE_LESSER_THAN);
4472                                            }
4473                                    }
4474                            }
4475    
4476                            query.append(ORDER_BY_CLAUSE);
4477    
4478                            String[] orderByFields = orderByComparator.getOrderByFields();
4479    
4480                            for (int i = 0; i < orderByFields.length; i++) {
4481                                    if (getDB().isSupportsInlineDistinct()) {
4482                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4483                                    }
4484                                    else {
4485                                            query.append(_ORDER_BY_ENTITY_TABLE);
4486                                    }
4487    
4488                                    query.append(orderByFields[i]);
4489    
4490                                    if ((i + 1) < orderByFields.length) {
4491                                            if (orderByComparator.isAscending() ^ previous) {
4492                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4493                                            }
4494                                            else {
4495                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4496                                            }
4497                                    }
4498                                    else {
4499                                            if (orderByComparator.isAscending() ^ previous) {
4500                                                    query.append(ORDER_BY_ASC);
4501                                            }
4502                                            else {
4503                                                    query.append(ORDER_BY_DESC);
4504                                            }
4505                                    }
4506                            }
4507                    }
4508    
4509                    else {
4510                            if (getDB().isSupportsInlineDistinct()) {
4511                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
4512                            }
4513                            else {
4514                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
4515                            }
4516                    }
4517    
4518                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4519                                    CalEvent.class.getName(),
4520                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4521    
4522                    SQLQuery q = session.createSQLQuery(sql);
4523    
4524                    q.setFirstResult(0);
4525                    q.setMaxResults(2);
4526    
4527                    if (getDB().isSupportsInlineDistinct()) {
4528                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
4529                    }
4530                    else {
4531                            q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
4532                    }
4533    
4534                    QueryPos qPos = QueryPos.getInstance(q);
4535    
4536                    qPos.add(groupId);
4537    
4538                    qPos.add(repeating);
4539    
4540                    if (orderByComparator != null) {
4541                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
4542    
4543                            for (Object value : values) {
4544                                    qPos.add(value);
4545                            }
4546                    }
4547    
4548                    List<CalEvent> list = q.list();
4549    
4550                    if (list.size() == 2) {
4551                            return list.get(1);
4552                    }
4553                    else {
4554                            return null;
4555                    }
4556            }
4557    
4558            /**
4559             * Returns all the cal events where groupId = &#63; and type = &#63; and repeating = &#63;.
4560             *
4561             * @param groupId the group ID
4562             * @param type the type
4563             * @param repeating the repeating
4564             * @return the matching cal events
4565             * @throws SystemException if a system exception occurred
4566             */
4567            public List<CalEvent> findByG_T_R(long groupId, String type,
4568                    boolean repeating) throws SystemException {
4569                    return findByG_T_R(groupId, type, repeating, QueryUtil.ALL_POS,
4570                            QueryUtil.ALL_POS, null);
4571            }
4572    
4573            /**
4574             * Returns a range of all the cal events where groupId = &#63; and type = &#63; and repeating = &#63;.
4575             *
4576             * <p>
4577             * 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.
4578             * </p>
4579             *
4580             * @param groupId the group ID
4581             * @param type the type
4582             * @param repeating the repeating
4583             * @param start the lower bound of the range of cal events
4584             * @param end the upper bound of the range of cal events (not inclusive)
4585             * @return the range of matching cal events
4586             * @throws SystemException if a system exception occurred
4587             */
4588            public List<CalEvent> findByG_T_R(long groupId, String type,
4589                    boolean repeating, int start, int end) throws SystemException {
4590                    return findByG_T_R(groupId, type, repeating, start, end, null);
4591            }
4592    
4593            /**
4594             * Returns an ordered range of all the cal events where groupId = &#63; and type = &#63; and repeating = &#63;.
4595             *
4596             * <p>
4597             * 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.
4598             * </p>
4599             *
4600             * @param groupId the group ID
4601             * @param type the type
4602             * @param repeating the repeating
4603             * @param start the lower bound of the range of cal events
4604             * @param end the upper bound of the range of cal events (not inclusive)
4605             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4606             * @return the ordered range of matching cal events
4607             * @throws SystemException if a system exception occurred
4608             */
4609            public List<CalEvent> findByG_T_R(long groupId, String type,
4610                    boolean repeating, int start, int end,
4611                    OrderByComparator orderByComparator) throws SystemException {
4612                    FinderPath finderPath = null;
4613                    Object[] finderArgs = null;
4614    
4615                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4616                                    (orderByComparator == null)) {
4617                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R;
4618                            finderArgs = new Object[] { groupId, type, repeating };
4619                    }
4620                    else {
4621                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R;
4622                            finderArgs = new Object[] {
4623                                            groupId, type, repeating,
4624                                            
4625                                            start, end, orderByComparator
4626                                    };
4627                    }
4628    
4629                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
4630                                    finderArgs, this);
4631    
4632                    if ((list != null) && !list.isEmpty()) {
4633                            for (CalEvent calEvent : list) {
4634                                    if ((groupId != calEvent.getGroupId()) ||
4635                                                    !Validator.equals(type, calEvent.getType()) ||
4636                                                    (repeating != calEvent.getRepeating())) {
4637                                            list = null;
4638    
4639                                            break;
4640                                    }
4641                            }
4642                    }
4643    
4644                    if (list == null) {
4645                            StringBundler query = null;
4646    
4647                            if (orderByComparator != null) {
4648                                    query = new StringBundler(5 +
4649                                                    (orderByComparator.getOrderByFields().length * 3));
4650                            }
4651                            else {
4652                                    query = new StringBundler(5);
4653                            }
4654    
4655                            query.append(_SQL_SELECT_CALEVENT_WHERE);
4656    
4657                            query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
4658    
4659                            if (type == null) {
4660                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
4661                            }
4662                            else {
4663                                    if (type.equals(StringPool.BLANK)) {
4664                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
4665                                    }
4666                                    else {
4667                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
4668                                    }
4669                            }
4670    
4671                            query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
4672    
4673                            if (orderByComparator != null) {
4674                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4675                                            orderByComparator);
4676                            }
4677    
4678                            else {
4679                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
4680                            }
4681    
4682                            String sql = query.toString();
4683    
4684                            Session session = null;
4685    
4686                            try {
4687                                    session = openSession();
4688    
4689                                    Query q = session.createQuery(sql);
4690    
4691                                    QueryPos qPos = QueryPos.getInstance(q);
4692    
4693                                    qPos.add(groupId);
4694    
4695                                    if (type != null) {
4696                                            qPos.add(type);
4697                                    }
4698    
4699                                    qPos.add(repeating);
4700    
4701                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
4702                                                    end);
4703                            }
4704                            catch (Exception e) {
4705                                    throw processException(e);
4706                            }
4707                            finally {
4708                                    if (list == null) {
4709                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4710                                    }
4711                                    else {
4712                                            cacheResult(list);
4713    
4714                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4715                                    }
4716    
4717                                    closeSession(session);
4718                            }
4719                    }
4720    
4721                    return list;
4722            }
4723    
4724            /**
4725             * Returns the first cal event in the ordered set where groupId = &#63; and type = &#63; and repeating = &#63;.
4726             *
4727             * <p>
4728             * 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.
4729             * </p>
4730             *
4731             * @param groupId the group ID
4732             * @param type the type
4733             * @param repeating the repeating
4734             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4735             * @return the first matching cal event
4736             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
4737             * @throws SystemException if a system exception occurred
4738             */
4739            public CalEvent findByG_T_R_First(long groupId, String type,
4740                    boolean repeating, OrderByComparator orderByComparator)
4741                    throws NoSuchEventException, SystemException {
4742                    List<CalEvent> list = findByG_T_R(groupId, type, repeating, 0, 1,
4743                                    orderByComparator);
4744    
4745                    if (list.isEmpty()) {
4746                            StringBundler msg = new StringBundler(8);
4747    
4748                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4749    
4750                            msg.append("groupId=");
4751                            msg.append(groupId);
4752    
4753                            msg.append(", type=");
4754                            msg.append(type);
4755    
4756                            msg.append(", repeating=");
4757                            msg.append(repeating);
4758    
4759                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4760    
4761                            throw new NoSuchEventException(msg.toString());
4762                    }
4763                    else {
4764                            return list.get(0);
4765                    }
4766            }
4767    
4768            /**
4769             * Returns the last cal event in the ordered set where groupId = &#63; and type = &#63; and repeating = &#63;.
4770             *
4771             * <p>
4772             * 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.
4773             * </p>
4774             *
4775             * @param groupId the group ID
4776             * @param type the type
4777             * @param repeating the repeating
4778             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4779             * @return the last matching cal event
4780             * @throws com.liferay.portlet.calendar.NoSuchEventException if a matching cal event could not be found
4781             * @throws SystemException if a system exception occurred
4782             */
4783            public CalEvent findByG_T_R_Last(long groupId, String type,
4784                    boolean repeating, OrderByComparator orderByComparator)
4785                    throws NoSuchEventException, SystemException {
4786                    int count = countByG_T_R(groupId, type, repeating);
4787    
4788                    List<CalEvent> list = findByG_T_R(groupId, type, repeating, count - 1,
4789                                    count, orderByComparator);
4790    
4791                    if (list.isEmpty()) {
4792                            StringBundler msg = new StringBundler(8);
4793    
4794                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4795    
4796                            msg.append("groupId=");
4797                            msg.append(groupId);
4798    
4799                            msg.append(", type=");
4800                            msg.append(type);
4801    
4802                            msg.append(", repeating=");
4803                            msg.append(repeating);
4804    
4805                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4806    
4807                            throw new NoSuchEventException(msg.toString());
4808                    }
4809                    else {
4810                            return list.get(0);
4811                    }
4812            }
4813    
4814            /**
4815             * Returns the cal events before and after the current cal event in the ordered set where groupId = &#63; and type = &#63; and repeating = &#63;.
4816             *
4817             * <p>
4818             * 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.
4819             * </p>
4820             *
4821             * @param eventId the primary key of the current cal event
4822             * @param groupId the group ID
4823             * @param type the type
4824             * @param repeating the repeating
4825             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4826             * @return the previous, current, and next cal event
4827             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
4828             * @throws SystemException if a system exception occurred
4829             */
4830            public CalEvent[] findByG_T_R_PrevAndNext(long eventId, long groupId,
4831                    String type, boolean repeating, OrderByComparator orderByComparator)
4832                    throws NoSuchEventException, SystemException {
4833                    CalEvent calEvent = findByPrimaryKey(eventId);
4834    
4835                    Session session = null;
4836    
4837                    try {
4838                            session = openSession();
4839    
4840                            CalEvent[] array = new CalEventImpl[3];
4841    
4842                            array[0] = getByG_T_R_PrevAndNext(session, calEvent, groupId, type,
4843                                            repeating, orderByComparator, true);
4844    
4845                            array[1] = calEvent;
4846    
4847                            array[2] = getByG_T_R_PrevAndNext(session, calEvent, groupId, type,
4848                                            repeating, orderByComparator, false);
4849    
4850                            return array;
4851                    }
4852                    catch (Exception e) {
4853                            throw processException(e);
4854                    }
4855                    finally {
4856                            closeSession(session);
4857                    }
4858            }
4859    
4860            protected CalEvent getByG_T_R_PrevAndNext(Session session,
4861                    CalEvent calEvent, long groupId, String type, boolean repeating,
4862                    OrderByComparator orderByComparator, boolean previous) {
4863                    StringBundler query = null;
4864    
4865                    if (orderByComparator != null) {
4866                            query = new StringBundler(6 +
4867                                            (orderByComparator.getOrderByFields().length * 6));
4868                    }
4869                    else {
4870                            query = new StringBundler(3);
4871                    }
4872    
4873                    query.append(_SQL_SELECT_CALEVENT_WHERE);
4874    
4875                    query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
4876    
4877                    if (type == null) {
4878                            query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
4879                    }
4880                    else {
4881                            if (type.equals(StringPool.BLANK)) {
4882                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
4883                            }
4884                            else {
4885                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
4886                            }
4887                    }
4888    
4889                    query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
4890    
4891                    if (orderByComparator != null) {
4892                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4893    
4894                            if (orderByConditionFields.length > 0) {
4895                                    query.append(WHERE_AND);
4896                            }
4897    
4898                            for (int i = 0; i < orderByConditionFields.length; i++) {
4899                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4900                                    query.append(orderByConditionFields[i]);
4901    
4902                                    if ((i + 1) < orderByConditionFields.length) {
4903                                            if (orderByComparator.isAscending() ^ previous) {
4904                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4905                                            }
4906                                            else {
4907                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4908                                            }
4909                                    }
4910                                    else {
4911                                            if (orderByComparator.isAscending() ^ previous) {
4912                                                    query.append(WHERE_GREATER_THAN);
4913                                            }
4914                                            else {
4915                                                    query.append(WHERE_LESSER_THAN);
4916                                            }
4917                                    }
4918                            }
4919    
4920                            query.append(ORDER_BY_CLAUSE);
4921    
4922                            String[] orderByFields = orderByComparator.getOrderByFields();
4923    
4924                            for (int i = 0; i < orderByFields.length; i++) {
4925                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4926                                    query.append(orderByFields[i]);
4927    
4928                                    if ((i + 1) < orderByFields.length) {
4929                                            if (orderByComparator.isAscending() ^ previous) {
4930                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4931                                            }
4932                                            else {
4933                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4934                                            }
4935                                    }
4936                                    else {
4937                                            if (orderByComparator.isAscending() ^ previous) {
4938                                                    query.append(ORDER_BY_ASC);
4939                                            }
4940                                            else {
4941                                                    query.append(ORDER_BY_DESC);
4942                                            }
4943                                    }
4944                            }
4945                    }
4946    
4947                    else {
4948                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
4949                    }
4950    
4951                    String sql = query.toString();
4952    
4953                    Query q = session.createQuery(sql);
4954    
4955                    q.setFirstResult(0);
4956                    q.setMaxResults(2);
4957    
4958                    QueryPos qPos = QueryPos.getInstance(q);
4959    
4960                    qPos.add(groupId);
4961    
4962                    if (type != null) {
4963                            qPos.add(type);
4964                    }
4965    
4966                    qPos.add(repeating);
4967    
4968                    if (orderByComparator != null) {
4969                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
4970    
4971                            for (Object value : values) {
4972                                    qPos.add(value);
4973                            }
4974                    }
4975    
4976                    List<CalEvent> list = q.list();
4977    
4978                    if (list.size() == 2) {
4979                            return list.get(1);
4980                    }
4981                    else {
4982                            return null;
4983                    }
4984            }
4985    
4986            /**
4987             * Returns all the cal events where groupId = &#63; and type = any &#63; and repeating = &#63;.
4988             *
4989             * <p>
4990             * 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.
4991             * </p>
4992             *
4993             * @param groupId the group ID
4994             * @param types the types
4995             * @param repeating the repeating
4996             * @return the matching cal events
4997             * @throws SystemException if a system exception occurred
4998             */
4999            public List<CalEvent> findByG_T_R(long groupId, String[] types,
5000                    boolean repeating) throws SystemException {
5001                    return findByG_T_R(groupId, types, repeating, QueryUtil.ALL_POS,
5002                            QueryUtil.ALL_POS, null);
5003            }
5004    
5005            /**
5006             * Returns a range of all the cal events where groupId = &#63; and type = any &#63; and repeating = &#63;.
5007             *
5008             * <p>
5009             * 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.
5010             * </p>
5011             *
5012             * @param groupId the group ID
5013             * @param types the types
5014             * @param repeating the repeating
5015             * @param start the lower bound of the range of cal events
5016             * @param end the upper bound of the range of cal events (not inclusive)
5017             * @return the range of matching cal events
5018             * @throws SystemException if a system exception occurred
5019             */
5020            public List<CalEvent> findByG_T_R(long groupId, String[] types,
5021                    boolean repeating, int start, int end) throws SystemException {
5022                    return findByG_T_R(groupId, types, repeating, start, end, null);
5023            }
5024    
5025            /**
5026             * Returns an ordered range of all the cal events where groupId = &#63; and type = any &#63; and repeating = &#63;.
5027             *
5028             * <p>
5029             * 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.
5030             * </p>
5031             *
5032             * @param groupId the group ID
5033             * @param types the types
5034             * @param repeating the repeating
5035             * @param start the lower bound of the range of cal events
5036             * @param end the upper bound of the range of cal events (not inclusive)
5037             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5038             * @return the ordered range of matching cal events
5039             * @throws SystemException if a system exception occurred
5040             */
5041            public List<CalEvent> findByG_T_R(long groupId, String[] types,
5042                    boolean repeating, int start, int end,
5043                    OrderByComparator orderByComparator) throws SystemException {
5044                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R;
5045                    Object[] finderArgs = null;
5046    
5047                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5048                                    (orderByComparator == null)) {
5049                            finderArgs = new Object[] {
5050                                            groupId, StringUtil.merge(types), repeating
5051                                    };
5052                    }
5053                    else {
5054                            finderArgs = new Object[] {
5055                                            groupId, StringUtil.merge(types), repeating,
5056                                            
5057                                            start, end, orderByComparator
5058                                    };
5059                    }
5060    
5061                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
5062                                    finderArgs, this);
5063    
5064                    if ((list != null) && !list.isEmpty()) {
5065                            for (CalEvent calEvent : list) {
5066                                    if ((groupId != calEvent.getGroupId()) ||
5067                                                    !ArrayUtil.contains(types, calEvent.getType()) ||
5068                                                    (repeating != calEvent.getRepeating())) {
5069                                            list = null;
5070    
5071                                            break;
5072                                    }
5073                            }
5074                    }
5075    
5076                    if (list == null) {
5077                            StringBundler query = new StringBundler();
5078    
5079                            query.append(_SQL_SELECT_CALEVENT_WHERE);
5080    
5081                            boolean conjunctionable = false;
5082    
5083                            if (conjunctionable) {
5084                                    query.append(WHERE_AND);
5085                            }
5086    
5087                            query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);
5088    
5089                            conjunctionable = true;
5090    
5091                            if ((types == null) || (types.length > 0)) {
5092                                    if (conjunctionable) {
5093                                            query.append(WHERE_AND);
5094                                    }
5095    
5096                                    query.append(StringPool.OPEN_PARENTHESIS);
5097    
5098                                    for (int i = 0; i < types.length; i++) {
5099                                            String type = types[i];
5100    
5101                                            if (type == null) {
5102                                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
5103                                            }
5104                                            else {
5105                                                    if (type.equals(StringPool.BLANK)) {
5106                                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
5107                                                    }
5108                                                    else {
5109                                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
5110                                                    }
5111                                            }
5112    
5113                                            if ((i + 1) < types.length) {
5114                                                    query.append(WHERE_OR);
5115                                            }
5116                                    }
5117    
5118                                    query.append(StringPool.CLOSE_PARENTHESIS);
5119    
5120                                    conjunctionable = true;
5121                            }
5122    
5123                            if (conjunctionable) {
5124                                    query.append(WHERE_AND);
5125                            }
5126    
5127                            query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);
5128    
5129                            conjunctionable = true;
5130    
5131                            if (orderByComparator != null) {
5132                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5133                                            orderByComparator);
5134                            }
5135    
5136                            else {
5137                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
5138                            }
5139    
5140                            String sql = query.toString();
5141    
5142                            Session session = null;
5143    
5144                            try {
5145                                    session = openSession();
5146    
5147                                    Query q = session.createQuery(sql);
5148    
5149                                    QueryPos qPos = QueryPos.getInstance(q);
5150    
5151                                    qPos.add(groupId);
5152    
5153                                    if (types != null) {
5154                                            qPos.add(types);
5155                                    }
5156    
5157                                    qPos.add(repeating);
5158    
5159                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
5160                                                    end);
5161                            }
5162                            catch (Exception e) {
5163                                    throw processException(e);
5164                            }
5165                            finally {
5166                                    if (list == null) {
5167                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5168                                    }
5169                                    else {
5170                                            cacheResult(list);
5171    
5172                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5173                                    }
5174    
5175                                    closeSession(session);
5176                            }
5177                    }
5178    
5179                    return list;
5180            }
5181    
5182            /**
5183             * Returns all the cal events that the user has permission to view where groupId = &#63; and type = &#63; and repeating = &#63;.
5184             *
5185             * @param groupId the group ID
5186             * @param type the type
5187             * @param repeating the repeating
5188             * @return the matching cal events that the user has permission to view
5189             * @throws SystemException if a system exception occurred
5190             */
5191            public List<CalEvent> filterFindByG_T_R(long groupId, String type,
5192                    boolean repeating) throws SystemException {
5193                    return filterFindByG_T_R(groupId, type, repeating, QueryUtil.ALL_POS,
5194                            QueryUtil.ALL_POS, null);
5195            }
5196    
5197            /**
5198             * Returns a range of all the cal events that the user has permission to view where groupId = &#63; and type = &#63; and repeating = &#63;.
5199             *
5200             * <p>
5201             * 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.
5202             * </p>
5203             *
5204             * @param groupId the group ID
5205             * @param type the type
5206             * @param repeating the repeating
5207             * @param start the lower bound of the range of cal events
5208             * @param end the upper bound of the range of cal events (not inclusive)
5209             * @return the range of matching cal events that the user has permission to view
5210             * @throws SystemException if a system exception occurred
5211             */
5212            public List<CalEvent> filterFindByG_T_R(long groupId, String type,
5213                    boolean repeating, int start, int end) throws SystemException {
5214                    return filterFindByG_T_R(groupId, type, repeating, start, end, null);
5215            }
5216    
5217            /**
5218             * Returns an ordered range of all the cal events that the user has permissions to view where groupId = &#63; and type = &#63; and repeating = &#63;.
5219             *
5220             * <p>
5221             * 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.
5222             * </p>
5223             *
5224             * @param groupId the group ID
5225             * @param type the type
5226             * @param repeating the repeating
5227             * @param start the lower bound of the range of cal events
5228             * @param end the upper bound of the range of cal events (not inclusive)
5229             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5230             * @return the ordered range of matching cal events that the user has permission to view
5231             * @throws SystemException if a system exception occurred
5232             */
5233            public List<CalEvent> filterFindByG_T_R(long groupId, String type,
5234                    boolean repeating, int start, int end,
5235                    OrderByComparator orderByComparator) throws SystemException {
5236                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5237                            return findByG_T_R(groupId, type, repeating, start, end,
5238                                    orderByComparator);
5239                    }
5240    
5241                    StringBundler query = null;
5242    
5243                    if (orderByComparator != null) {
5244                            query = new StringBundler(5 +
5245                                            (orderByComparator.getOrderByFields().length * 3));
5246                    }
5247                    else {
5248                            query = new StringBundler(5);
5249                    }
5250    
5251                    if (getDB().isSupportsInlineDistinct()) {
5252                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
5253                    }
5254                    else {
5255                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
5256                    }
5257    
5258                    query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
5259    
5260                    if (type == null) {
5261                            query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
5262                    }
5263                    else {
5264                            if (type.equals(StringPool.BLANK)) {
5265                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
5266                            }
5267                            else {
5268                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
5269                            }
5270                    }
5271    
5272                    query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
5273    
5274                    if (!getDB().isSupportsInlineDistinct()) {
5275                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
5276                    }
5277    
5278                    if (orderByComparator != null) {
5279                            if (getDB().isSupportsInlineDistinct()) {
5280                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5281                                            orderByComparator);
5282                            }
5283                            else {
5284                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5285                                            orderByComparator);
5286                            }
5287                    }
5288    
5289                    else {
5290                            if (getDB().isSupportsInlineDistinct()) {
5291                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
5292                            }
5293                            else {
5294                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
5295                            }
5296                    }
5297    
5298                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5299                                    CalEvent.class.getName(),
5300                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5301    
5302                    Session session = null;
5303    
5304                    try {
5305                            session = openSession();
5306    
5307                            SQLQuery q = session.createSQLQuery(sql);
5308    
5309                            if (getDB().isSupportsInlineDistinct()) {
5310                                    q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
5311                            }
5312                            else {
5313                                    q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
5314                            }
5315    
5316                            QueryPos qPos = QueryPos.getInstance(q);
5317    
5318                            qPos.add(groupId);
5319    
5320                            if (type != null) {
5321                                    qPos.add(type);
5322                            }
5323    
5324                            qPos.add(repeating);
5325    
5326                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
5327                    }
5328                    catch (Exception e) {
5329                            throw processException(e);
5330                    }
5331                    finally {
5332                            closeSession(session);
5333                    }
5334            }
5335    
5336            /**
5337             * Returns the cal events before and after the current cal event in the ordered set of cal events that the user has permission to view where groupId = &#63; and type = &#63; and repeating = &#63;.
5338             *
5339             * @param eventId the primary key of the current cal event
5340             * @param groupId the group ID
5341             * @param type the type
5342             * @param repeating the repeating
5343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5344             * @return the previous, current, and next cal event
5345             * @throws com.liferay.portlet.calendar.NoSuchEventException if a cal event with the primary key could not be found
5346             * @throws SystemException if a system exception occurred
5347             */
5348            public CalEvent[] filterFindByG_T_R_PrevAndNext(long eventId, long groupId,
5349                    String type, boolean repeating, OrderByComparator orderByComparator)
5350                    throws NoSuchEventException, SystemException {
5351                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5352                            return findByG_T_R_PrevAndNext(eventId, groupId, type, repeating,
5353                                    orderByComparator);
5354                    }
5355    
5356                    CalEvent calEvent = findByPrimaryKey(eventId);
5357    
5358                    Session session = null;
5359    
5360                    try {
5361                            session = openSession();
5362    
5363                            CalEvent[] array = new CalEventImpl[3];
5364    
5365                            array[0] = filterGetByG_T_R_PrevAndNext(session, calEvent, groupId,
5366                                            type, repeating, orderByComparator, true);
5367    
5368                            array[1] = calEvent;
5369    
5370                            array[2] = filterGetByG_T_R_PrevAndNext(session, calEvent, groupId,
5371                                            type, repeating, orderByComparator, false);
5372    
5373                            return array;
5374                    }
5375                    catch (Exception e) {
5376                            throw processException(e);
5377                    }
5378                    finally {
5379                            closeSession(session);
5380                    }
5381            }
5382    
5383            protected CalEvent filterGetByG_T_R_PrevAndNext(Session session,
5384                    CalEvent calEvent, long groupId, String type, boolean repeating,
5385                    OrderByComparator orderByComparator, boolean previous) {
5386                    StringBundler query = null;
5387    
5388                    if (orderByComparator != null) {
5389                            query = new StringBundler(6 +
5390                                            (orderByComparator.getOrderByFields().length * 6));
5391                    }
5392                    else {
5393                            query = new StringBundler(3);
5394                    }
5395    
5396                    if (getDB().isSupportsInlineDistinct()) {
5397                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
5398                    }
5399                    else {
5400                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
5401                    }
5402    
5403                    query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
5404    
5405                    if (type == null) {
5406                            query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
5407                    }
5408                    else {
5409                            if (type.equals(StringPool.BLANK)) {
5410                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
5411                            }
5412                            else {
5413                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
5414                            }
5415                    }
5416    
5417                    query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
5418    
5419                    if (!getDB().isSupportsInlineDistinct()) {
5420                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
5421                    }
5422    
5423                    if (orderByComparator != null) {
5424                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5425    
5426                            if (orderByConditionFields.length > 0) {
5427                                    query.append(WHERE_AND);
5428                            }
5429    
5430                            for (int i = 0; i < orderByConditionFields.length; i++) {
5431                                    if (getDB().isSupportsInlineDistinct()) {
5432                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5433                                    }
5434                                    else {
5435                                            query.append(_ORDER_BY_ENTITY_TABLE);
5436                                    }
5437    
5438                                    query.append(orderByConditionFields[i]);
5439    
5440                                    if ((i + 1) < orderByConditionFields.length) {
5441                                            if (orderByComparator.isAscending() ^ previous) {
5442                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5443                                            }
5444                                            else {
5445                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5446                                            }
5447                                    }
5448                                    else {
5449                                            if (orderByComparator.isAscending() ^ previous) {
5450                                                    query.append(WHERE_GREATER_THAN);
5451                                            }
5452                                            else {
5453                                                    query.append(WHERE_LESSER_THAN);
5454                                            }
5455                                    }
5456                            }
5457    
5458                            query.append(ORDER_BY_CLAUSE);
5459    
5460                            String[] orderByFields = orderByComparator.getOrderByFields();
5461    
5462                            for (int i = 0; i < orderByFields.length; i++) {
5463                                    if (getDB().isSupportsInlineDistinct()) {
5464                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5465                                    }
5466                                    else {
5467                                            query.append(_ORDER_BY_ENTITY_TABLE);
5468                                    }
5469    
5470                                    query.append(orderByFields[i]);
5471    
5472                                    if ((i + 1) < orderByFields.length) {
5473                                            if (orderByComparator.isAscending() ^ previous) {
5474                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5475                                            }
5476                                            else {
5477                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5478                                            }
5479                                    }
5480                                    else {
5481                                            if (orderByComparator.isAscending() ^ previous) {
5482                                                    query.append(ORDER_BY_ASC);
5483                                            }
5484                                            else {
5485                                                    query.append(ORDER_BY_DESC);
5486                                            }
5487                                    }
5488                            }
5489                    }
5490    
5491                    else {
5492                            if (getDB().isSupportsInlineDistinct()) {
5493                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
5494                            }
5495                            else {
5496                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
5497                            }
5498                    }
5499    
5500                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5501                                    CalEvent.class.getName(),
5502                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5503    
5504                    SQLQuery q = session.createSQLQuery(sql);
5505    
5506                    q.setFirstResult(0);
5507                    q.setMaxResults(2);
5508    
5509                    if (getDB().isSupportsInlineDistinct()) {
5510                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
5511                    }
5512                    else {
5513                            q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
5514                    }
5515    
5516                    QueryPos qPos = QueryPos.getInstance(q);
5517    
5518                    qPos.add(groupId);
5519    
5520                    if (type != null) {
5521                            qPos.add(type);
5522                    }
5523    
5524                    qPos.add(repeating);
5525    
5526                    if (orderByComparator != null) {
5527                            Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
5528    
5529                            for (Object value : values) {
5530                                    qPos.add(value);
5531                            }
5532                    }
5533    
5534                    List<CalEvent> list = q.list();
5535    
5536                    if (list.size() == 2) {
5537                            return list.get(1);
5538                    }
5539                    else {
5540                            return null;
5541                    }
5542            }
5543    
5544            /**
5545             * Returns all the cal events that the user has permission to view where groupId = &#63; and type = any &#63; and repeating = &#63;.
5546             *
5547             * @param groupId the group ID
5548             * @param types the types
5549             * @param repeating the repeating
5550             * @return the matching cal events that the user has permission to view
5551             * @throws SystemException if a system exception occurred
5552             */
5553            public List<CalEvent> filterFindByG_T_R(long groupId, String[] types,
5554                    boolean repeating) throws SystemException {
5555                    return filterFindByG_T_R(groupId, types, repeating, QueryUtil.ALL_POS,
5556                            QueryUtil.ALL_POS, null);
5557            }
5558    
5559            /**
5560             * Returns a range of all the cal events that the user has permission to view where groupId = &#63; and type = any &#63; and repeating = &#63;.
5561             *
5562             * <p>
5563             * 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.
5564             * </p>
5565             *
5566             * @param groupId the group ID
5567             * @param types the types
5568             * @param repeating the repeating
5569             * @param start the lower bound of the range of cal events
5570             * @param end the upper bound of the range of cal events (not inclusive)
5571             * @return the range of matching cal events that the user has permission to view
5572             * @throws SystemException if a system exception occurred
5573             */
5574            public List<CalEvent> filterFindByG_T_R(long groupId, String[] types,
5575                    boolean repeating, int start, int end) throws SystemException {
5576                    return filterFindByG_T_R(groupId, types, repeating, start, end, null);
5577            }
5578    
5579            /**
5580             * Returns an ordered range of all the cal events that the user has permission to view where groupId = &#63; and type = any &#63; and repeating = &#63;.
5581             *
5582             * <p>
5583             * 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.
5584             * </p>
5585             *
5586             * @param groupId the group ID
5587             * @param types the types
5588             * @param repeating the repeating
5589             * @param start the lower bound of the range of cal events
5590             * @param end the upper bound of the range of cal events (not inclusive)
5591             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5592             * @return the ordered range of matching cal events that the user has permission to view
5593             * @throws SystemException if a system exception occurred
5594             */
5595            public List<CalEvent> filterFindByG_T_R(long groupId, String[] types,
5596                    boolean repeating, int start, int end,
5597                    OrderByComparator orderByComparator) throws SystemException {
5598                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5599                            return findByG_T_R(groupId, types, repeating, start, end,
5600                                    orderByComparator);
5601                    }
5602    
5603                    StringBundler query = new StringBundler();
5604    
5605                    if (getDB().isSupportsInlineDistinct()) {
5606                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
5607                    }
5608                    else {
5609                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
5610                    }
5611    
5612                    boolean conjunctionable = false;
5613    
5614                    if (conjunctionable) {
5615                            query.append(WHERE_AND);
5616                    }
5617    
5618                    query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);
5619    
5620                    conjunctionable = true;
5621    
5622                    if ((types == null) || (types.length > 0)) {
5623                            if (conjunctionable) {
5624                                    query.append(WHERE_AND);
5625                            }
5626    
5627                            query.append(StringPool.OPEN_PARENTHESIS);
5628    
5629                            for (int i = 0; i < types.length; i++) {
5630                                    String type = types[i];
5631    
5632                                    if (type == null) {
5633                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
5634                                    }
5635                                    else {
5636                                            if (type.equals(StringPool.BLANK)) {
5637                                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
5638                                            }
5639                                            else {
5640                                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
5641                                            }
5642                                    }
5643    
5644                                    if ((i + 1) < types.length) {
5645                                            query.append(WHERE_OR);
5646                                    }
5647                            }
5648    
5649                            query.append(StringPool.CLOSE_PARENTHESIS);
5650    
5651                            conjunctionable = true;
5652                    }
5653    
5654                    if (conjunctionable) {
5655                            query.append(WHERE_AND);
5656                    }
5657    
5658                    query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);
5659    
5660                    conjunctionable = true;
5661    
5662                    if (!getDB().isSupportsInlineDistinct()) {
5663                            query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
5664                    }
5665    
5666                    if (orderByComparator != null) {
5667                            if (getDB().isSupportsInlineDistinct()) {
5668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5669                                            orderByComparator);
5670                            }
5671                            else {
5672                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5673                                            orderByComparator);
5674                            }
5675                    }
5676    
5677                    else {
5678                            if (getDB().isSupportsInlineDistinct()) {
5679                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
5680                            }
5681                            else {
5682                                    query.append(CalEventModelImpl.ORDER_BY_SQL);
5683                            }
5684                    }
5685    
5686                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5687                                    CalEvent.class.getName(),
5688                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5689    
5690                    Session session = null;
5691    
5692                    try {
5693                            session = openSession();
5694    
5695                            SQLQuery q = session.createSQLQuery(sql);
5696    
5697                            if (getDB().isSupportsInlineDistinct()) {
5698                                    q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
5699                            }
5700                            else {
5701                                    q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
5702                            }
5703    
5704                            QueryPos qPos = QueryPos.getInstance(q);
5705    
5706                            qPos.add(groupId);
5707    
5708                            if (types != null) {
5709                                    qPos.add(types);
5710                            }
5711    
5712                            qPos.add(repeating);
5713    
5714                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
5715                    }
5716                    catch (Exception e) {
5717                            throw processException(e);
5718                    }
5719                    finally {
5720                            closeSession(session);
5721                    }
5722            }
5723    
5724            /**
5725             * Returns all the cal events.
5726             *
5727             * @return the cal events
5728             * @throws SystemException if a system exception occurred
5729             */
5730            public List<CalEvent> findAll() throws SystemException {
5731                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5732            }
5733    
5734            /**
5735             * Returns a range of all the cal events.
5736             *
5737             * <p>
5738             * 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.
5739             * </p>
5740             *
5741             * @param start the lower bound of the range of cal events
5742             * @param end the upper bound of the range of cal events (not inclusive)
5743             * @return the range of cal events
5744             * @throws SystemException if a system exception occurred
5745             */
5746            public List<CalEvent> findAll(int start, int end) throws SystemException {
5747                    return findAll(start, end, null);
5748            }
5749    
5750            /**
5751             * Returns an ordered range of all the cal events.
5752             *
5753             * <p>
5754             * 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.
5755             * </p>
5756             *
5757             * @param start the lower bound of the range of cal events
5758             * @param end the upper bound of the range of cal events (not inclusive)
5759             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5760             * @return the ordered range of cal events
5761             * @throws SystemException if a system exception occurred
5762             */
5763            public List<CalEvent> findAll(int start, int end,
5764                    OrderByComparator orderByComparator) throws SystemException {
5765                    FinderPath finderPath = null;
5766                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
5767    
5768                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5769                                    (orderByComparator == null)) {
5770                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5771                            finderArgs = FINDER_ARGS_EMPTY;
5772                    }
5773                    else {
5774                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5775                            finderArgs = new Object[] { start, end, orderByComparator };
5776                    }
5777    
5778                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
5779                                    finderArgs, this);
5780    
5781                    if (list == null) {
5782                            StringBundler query = null;
5783                            String sql = null;
5784    
5785                            if (orderByComparator != null) {
5786                                    query = new StringBundler(2 +
5787                                                    (orderByComparator.getOrderByFields().length * 3));
5788    
5789                                    query.append(_SQL_SELECT_CALEVENT);
5790    
5791                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5792                                            orderByComparator);
5793    
5794                                    sql = query.toString();
5795                            }
5796                            else {
5797                                    sql = _SQL_SELECT_CALEVENT.concat(CalEventModelImpl.ORDER_BY_JPQL);
5798                            }
5799    
5800                            Session session = null;
5801    
5802                            try {
5803                                    session = openSession();
5804    
5805                                    Query q = session.createQuery(sql);
5806    
5807                                    if (orderByComparator == null) {
5808                                            list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
5809                                                            start, end, false);
5810    
5811                                            Collections.sort(list);
5812                                    }
5813                                    else {
5814                                            list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
5815                                                            start, end);
5816                                    }
5817                            }
5818                            catch (Exception e) {
5819                                    throw processException(e);
5820                            }
5821                            finally {
5822                                    if (list == null) {
5823                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5824                                    }
5825                                    else {
5826                                            cacheResult(list);
5827    
5828                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5829                                    }
5830    
5831                                    closeSession(session);
5832                            }
5833                    }
5834    
5835                    return list;
5836            }
5837    
5838            /**
5839             * Removes all the cal events where uuid = &#63; from the database.
5840             *
5841             * @param uuid the uuid
5842             * @throws SystemException if a system exception occurred
5843             */
5844            public void removeByUuid(String uuid) throws SystemException {
5845                    for (CalEvent calEvent : findByUuid(uuid)) {
5846                            remove(calEvent);
5847                    }
5848            }
5849    
5850            /**
5851             * Removes the cal event where uuid = &#63; and groupId = &#63; from the database.
5852             *
5853             * @param uuid the uuid
5854             * @param groupId the group ID
5855             * @throws SystemException if a system exception occurred
5856             */
5857            public void removeByUUID_G(String uuid, long groupId)
5858                    throws NoSuchEventException, SystemException {
5859                    CalEvent calEvent = findByUUID_G(uuid, groupId);
5860    
5861                    remove(calEvent);
5862            }
5863    
5864            /**
5865             * Removes all the cal events where companyId = &#63; from the database.
5866             *
5867             * @param companyId the company ID
5868             * @throws SystemException if a system exception occurred
5869             */
5870            public void removeByCompanyId(long companyId) throws SystemException {
5871                    for (CalEvent calEvent : findByCompanyId(companyId)) {
5872                            remove(calEvent);
5873                    }
5874            }
5875    
5876            /**
5877             * Removes all the cal events where groupId = &#63; from the database.
5878             *
5879             * @param groupId the group ID
5880             * @throws SystemException if a system exception occurred
5881             */
5882            public void removeByGroupId(long groupId) throws SystemException {
5883                    for (CalEvent calEvent : findByGroupId(groupId)) {
5884                            remove(calEvent);
5885                    }
5886            }
5887    
5888            /**
5889             * Removes all the cal events where remindBy &ne; &#63; from the database.
5890             *
5891             * @param remindBy the remind by
5892             * @throws SystemException if a system exception occurred
5893             */
5894            public void removeByNotRemindBy(int remindBy) throws SystemException {
5895                    for (CalEvent calEvent : findByNotRemindBy(remindBy)) {
5896                            remove(calEvent);
5897                    }
5898            }
5899    
5900            /**
5901             * Removes all the cal events where groupId = &#63; and type = &#63; from the database.
5902             *
5903             * @param groupId the group ID
5904             * @param type the type
5905             * @throws SystemException if a system exception occurred
5906             */
5907            public void removeByG_T(long groupId, String type)
5908                    throws SystemException {
5909                    for (CalEvent calEvent : findByG_T(groupId, type)) {
5910                            remove(calEvent);
5911                    }
5912            }
5913    
5914            /**
5915             * Removes all the cal events where groupId = &#63; and repeating = &#63; from the database.
5916             *
5917             * @param groupId the group ID
5918             * @param repeating the repeating
5919             * @throws SystemException if a system exception occurred
5920             */
5921            public void removeByG_R(long groupId, boolean repeating)
5922                    throws SystemException {
5923                    for (CalEvent calEvent : findByG_R(groupId, repeating)) {
5924                            remove(calEvent);
5925                    }
5926            }
5927    
5928            /**
5929             * Removes all the cal events where groupId = &#63; and type = &#63; and repeating = &#63; from the database.
5930             *
5931             * @param groupId the group ID
5932             * @param type the type
5933             * @param repeating the repeating
5934             * @throws SystemException if a system exception occurred
5935             */
5936            public void removeByG_T_R(long groupId, String type, boolean repeating)
5937                    throws SystemException {
5938                    for (CalEvent calEvent : findByG_T_R(groupId, type, repeating)) {
5939                            remove(calEvent);
5940                    }
5941            }
5942    
5943            /**
5944             * Removes all the cal events from the database.
5945             *
5946             * @throws SystemException if a system exception occurred
5947             */
5948            public void removeAll() throws SystemException {
5949                    for (CalEvent calEvent : findAll()) {
5950                            remove(calEvent);
5951                    }
5952            }
5953    
5954            /**
5955             * Returns the number of cal events where uuid = &#63;.
5956             *
5957             * @param uuid the uuid
5958             * @return the number of matching cal events
5959             * @throws SystemException if a system exception occurred
5960             */
5961            public int countByUuid(String uuid) throws SystemException {
5962                    Object[] finderArgs = new Object[] { uuid };
5963    
5964                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
5965                                    finderArgs, this);
5966    
5967                    if (count == null) {
5968                            StringBundler query = new StringBundler(2);
5969    
5970                            query.append(_SQL_COUNT_CALEVENT_WHERE);
5971    
5972                            if (uuid == null) {
5973                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
5974                            }
5975                            else {
5976                                    if (uuid.equals(StringPool.BLANK)) {
5977                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
5978                                    }
5979                                    else {
5980                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
5981                                    }
5982                            }
5983    
5984                            String sql = query.toString();
5985    
5986                            Session session = null;
5987    
5988                            try {
5989                                    session = openSession();
5990    
5991                                    Query q = session.createQuery(sql);
5992    
5993                                    QueryPos qPos = QueryPos.getInstance(q);
5994    
5995                                    if (uuid != null) {
5996                                            qPos.add(uuid);
5997                                    }
5998    
5999                                    count = (Long)q.uniqueResult();
6000                            }
6001                            catch (Exception e) {
6002                                    throw processException(e);
6003                            }
6004                            finally {
6005                                    if (count == null) {
6006                                            count = Long.valueOf(0);
6007                                    }
6008    
6009                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
6010                                            finderArgs, count);
6011    
6012                                    closeSession(session);
6013                            }
6014                    }
6015    
6016                    return count.intValue();
6017            }
6018    
6019            /**
6020             * Returns the number of cal events where uuid = &#63; and groupId = &#63;.
6021             *
6022             * @param uuid the uuid
6023             * @param groupId the group ID
6024             * @return the number of matching cal events
6025             * @throws SystemException if a system exception occurred
6026             */
6027            public int countByUUID_G(String uuid, long groupId)
6028                    throws SystemException {
6029                    Object[] finderArgs = new Object[] { uuid, groupId };
6030    
6031                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
6032                                    finderArgs, this);
6033    
6034                    if (count == null) {
6035                            StringBundler query = new StringBundler(3);
6036    
6037                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6038    
6039                            if (uuid == null) {
6040                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
6041                            }
6042                            else {
6043                                    if (uuid.equals(StringPool.BLANK)) {
6044                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
6045                                    }
6046                                    else {
6047                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
6048                                    }
6049                            }
6050    
6051                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
6052    
6053                            String sql = query.toString();
6054    
6055                            Session session = null;
6056    
6057                            try {
6058                                    session = openSession();
6059    
6060                                    Query q = session.createQuery(sql);
6061    
6062                                    QueryPos qPos = QueryPos.getInstance(q);
6063    
6064                                    if (uuid != null) {
6065                                            qPos.add(uuid);
6066                                    }
6067    
6068                                    qPos.add(groupId);
6069    
6070                                    count = (Long)q.uniqueResult();
6071                            }
6072                            catch (Exception e) {
6073                                    throw processException(e);
6074                            }
6075                            finally {
6076                                    if (count == null) {
6077                                            count = Long.valueOf(0);
6078                                    }
6079    
6080                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
6081                                            finderArgs, count);
6082    
6083                                    closeSession(session);
6084                            }
6085                    }
6086    
6087                    return count.intValue();
6088            }
6089    
6090            /**
6091             * Returns the number of cal events where companyId = &#63;.
6092             *
6093             * @param companyId the company ID
6094             * @return the number of matching cal events
6095             * @throws SystemException if a system exception occurred
6096             */
6097            public int countByCompanyId(long companyId) throws SystemException {
6098                    Object[] finderArgs = new Object[] { companyId };
6099    
6100                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
6101                                    finderArgs, this);
6102    
6103                    if (count == null) {
6104                            StringBundler query = new StringBundler(2);
6105    
6106                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6107    
6108                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
6109    
6110                            String sql = query.toString();
6111    
6112                            Session session = null;
6113    
6114                            try {
6115                                    session = openSession();
6116    
6117                                    Query q = session.createQuery(sql);
6118    
6119                                    QueryPos qPos = QueryPos.getInstance(q);
6120    
6121                                    qPos.add(companyId);
6122    
6123                                    count = (Long)q.uniqueResult();
6124                            }
6125                            catch (Exception e) {
6126                                    throw processException(e);
6127                            }
6128                            finally {
6129                                    if (count == null) {
6130                                            count = Long.valueOf(0);
6131                                    }
6132    
6133                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
6134                                            finderArgs, count);
6135    
6136                                    closeSession(session);
6137                            }
6138                    }
6139    
6140                    return count.intValue();
6141            }
6142    
6143            /**
6144             * Returns the number of cal events where groupId = &#63;.
6145             *
6146             * @param groupId the group ID
6147             * @return the number of matching cal events
6148             * @throws SystemException if a system exception occurred
6149             */
6150            public int countByGroupId(long groupId) throws SystemException {
6151                    Object[] finderArgs = new Object[] { groupId };
6152    
6153                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
6154                                    finderArgs, this);
6155    
6156                    if (count == null) {
6157                            StringBundler query = new StringBundler(2);
6158    
6159                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6160    
6161                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
6162    
6163                            String sql = query.toString();
6164    
6165                            Session session = null;
6166    
6167                            try {
6168                                    session = openSession();
6169    
6170                                    Query q = session.createQuery(sql);
6171    
6172                                    QueryPos qPos = QueryPos.getInstance(q);
6173    
6174                                    qPos.add(groupId);
6175    
6176                                    count = (Long)q.uniqueResult();
6177                            }
6178                            catch (Exception e) {
6179                                    throw processException(e);
6180                            }
6181                            finally {
6182                                    if (count == null) {
6183                                            count = Long.valueOf(0);
6184                                    }
6185    
6186                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
6187                                            finderArgs, count);
6188    
6189                                    closeSession(session);
6190                            }
6191                    }
6192    
6193                    return count.intValue();
6194            }
6195    
6196            /**
6197             * Returns the number of cal events that the user has permission to view where groupId = &#63;.
6198             *
6199             * @param groupId the group ID
6200             * @return the number of matching cal events that the user has permission to view
6201             * @throws SystemException if a system exception occurred
6202             */
6203            public int filterCountByGroupId(long groupId) throws SystemException {
6204                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6205                            return countByGroupId(groupId);
6206                    }
6207    
6208                    StringBundler query = new StringBundler(2);
6209    
6210                    query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
6211    
6212                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
6213    
6214                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6215                                    CalEvent.class.getName(),
6216                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6217    
6218                    Session session = null;
6219    
6220                    try {
6221                            session = openSession();
6222    
6223                            SQLQuery q = session.createSQLQuery(sql);
6224    
6225                            q.addScalar(COUNT_COLUMN_NAME,
6226                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6227    
6228                            QueryPos qPos = QueryPos.getInstance(q);
6229    
6230                            qPos.add(groupId);
6231    
6232                            Long count = (Long)q.uniqueResult();
6233    
6234                            return count.intValue();
6235                    }
6236                    catch (Exception e) {
6237                            throw processException(e);
6238                    }
6239                    finally {
6240                            closeSession(session);
6241                    }
6242            }
6243    
6244            /**
6245             * Returns the number of cal events where remindBy &ne; &#63;.
6246             *
6247             * @param remindBy the remind by
6248             * @return the number of matching cal events
6249             * @throws SystemException if a system exception occurred
6250             */
6251            public int countByNotRemindBy(int remindBy) throws SystemException {
6252                    Object[] finderArgs = new Object[] { remindBy };
6253    
6254                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NOTREMINDBY,
6255                                    finderArgs, this);
6256    
6257                    if (count == null) {
6258                            StringBundler query = new StringBundler(2);
6259    
6260                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6261    
6262                            query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
6263    
6264                            String sql = query.toString();
6265    
6266                            Session session = null;
6267    
6268                            try {
6269                                    session = openSession();
6270    
6271                                    Query q = session.createQuery(sql);
6272    
6273                                    QueryPos qPos = QueryPos.getInstance(q);
6274    
6275                                    qPos.add(remindBy);
6276    
6277                                    count = (Long)q.uniqueResult();
6278                            }
6279                            catch (Exception e) {
6280                                    throw processException(e);
6281                            }
6282                            finally {
6283                                    if (count == null) {
6284                                            count = Long.valueOf(0);
6285                                    }
6286    
6287                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NOTREMINDBY,
6288                                            finderArgs, count);
6289    
6290                                    closeSession(session);
6291                            }
6292                    }
6293    
6294                    return count.intValue();
6295            }
6296    
6297            /**
6298             * Returns the number of cal events where groupId = &#63; and type = &#63;.
6299             *
6300             * @param groupId the group ID
6301             * @param type the type
6302             * @return the number of matching cal events
6303             * @throws SystemException if a system exception occurred
6304             */
6305            public int countByG_T(long groupId, String type) throws SystemException {
6306                    Object[] finderArgs = new Object[] { groupId, type };
6307    
6308                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
6309                                    finderArgs, this);
6310    
6311                    if (count == null) {
6312                            StringBundler query = new StringBundler(3);
6313    
6314                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6315    
6316                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
6317    
6318                            if (type == null) {
6319                                    query.append(_FINDER_COLUMN_G_T_TYPE_1);
6320                            }
6321                            else {
6322                                    if (type.equals(StringPool.BLANK)) {
6323                                            query.append(_FINDER_COLUMN_G_T_TYPE_3);
6324                                    }
6325                                    else {
6326                                            query.append(_FINDER_COLUMN_G_T_TYPE_2);
6327                                    }
6328                            }
6329    
6330                            String sql = query.toString();
6331    
6332                            Session session = null;
6333    
6334                            try {
6335                                    session = openSession();
6336    
6337                                    Query q = session.createQuery(sql);
6338    
6339                                    QueryPos qPos = QueryPos.getInstance(q);
6340    
6341                                    qPos.add(groupId);
6342    
6343                                    if (type != null) {
6344                                            qPos.add(type);
6345                                    }
6346    
6347                                    count = (Long)q.uniqueResult();
6348                            }
6349                            catch (Exception e) {
6350                                    throw processException(e);
6351                            }
6352                            finally {
6353                                    if (count == null) {
6354                                            count = Long.valueOf(0);
6355                                    }
6356    
6357                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
6358                                            count);
6359    
6360                                    closeSession(session);
6361                            }
6362                    }
6363    
6364                    return count.intValue();
6365            }
6366    
6367            /**
6368             * Returns the number of cal events where groupId = &#63; and type = any &#63;.
6369             *
6370             * @param groupId the group ID
6371             * @param types the types
6372             * @return the number of matching cal events
6373             * @throws SystemException if a system exception occurred
6374             */
6375            public int countByG_T(long groupId, String[] types)
6376                    throws SystemException {
6377                    Object[] finderArgs = new Object[] { groupId, StringUtil.merge(types) };
6378    
6379                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T,
6380                                    finderArgs, this);
6381    
6382                    if (count == null) {
6383                            StringBundler query = new StringBundler();
6384    
6385                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6386    
6387                            boolean conjunctionable = false;
6388    
6389                            if (conjunctionable) {
6390                                    query.append(WHERE_AND);
6391                            }
6392    
6393                            query.append(_FINDER_COLUMN_G_T_GROUPID_5);
6394    
6395                            conjunctionable = true;
6396    
6397                            if ((types == null) || (types.length > 0)) {
6398                                    if (conjunctionable) {
6399                                            query.append(WHERE_AND);
6400                                    }
6401    
6402                                    query.append(StringPool.OPEN_PARENTHESIS);
6403    
6404                                    for (int i = 0; i < types.length; i++) {
6405                                            String type = types[i];
6406    
6407                                            if (type == null) {
6408                                                    query.append(_FINDER_COLUMN_G_T_TYPE_4);
6409                                            }
6410                                            else {
6411                                                    if (type.equals(StringPool.BLANK)) {
6412                                                            query.append(_FINDER_COLUMN_G_T_TYPE_6);
6413                                                    }
6414                                                    else {
6415                                                            query.append(_FINDER_COLUMN_G_T_TYPE_5);
6416                                                    }
6417                                            }
6418    
6419                                            if ((i + 1) < types.length) {
6420                                                    query.append(WHERE_OR);
6421                                            }
6422                                    }
6423    
6424                                    query.append(StringPool.CLOSE_PARENTHESIS);
6425    
6426                                    conjunctionable = true;
6427                            }
6428    
6429                            String sql = query.toString();
6430    
6431                            Session session = null;
6432    
6433                            try {
6434                                    session = openSession();
6435    
6436                                    Query q = session.createQuery(sql);
6437    
6438                                    QueryPos qPos = QueryPos.getInstance(q);
6439    
6440                                    qPos.add(groupId);
6441    
6442                                    if (types != null) {
6443                                            qPos.add(types);
6444                                    }
6445    
6446                                    count = (Long)q.uniqueResult();
6447                            }
6448                            catch (Exception e) {
6449                                    throw processException(e);
6450                            }
6451                            finally {
6452                                    if (count == null) {
6453                                            count = Long.valueOf(0);
6454                                    }
6455    
6456                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T,
6457                                            finderArgs, count);
6458    
6459                                    closeSession(session);
6460                            }
6461                    }
6462    
6463                    return count.intValue();
6464            }
6465    
6466            /**
6467             * Returns the number of cal events that the user has permission to view where groupId = &#63; and type = &#63;.
6468             *
6469             * @param groupId the group ID
6470             * @param type the type
6471             * @return the number of matching cal events that the user has permission to view
6472             * @throws SystemException if a system exception occurred
6473             */
6474            public int filterCountByG_T(long groupId, String type)
6475                    throws SystemException {
6476                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6477                            return countByG_T(groupId, type);
6478                    }
6479    
6480                    StringBundler query = new StringBundler(3);
6481    
6482                    query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
6483    
6484                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
6485    
6486                    if (type == null) {
6487                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
6488                    }
6489                    else {
6490                            if (type.equals(StringPool.BLANK)) {
6491                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
6492                            }
6493                            else {
6494                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
6495                            }
6496                    }
6497    
6498                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6499                                    CalEvent.class.getName(),
6500                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6501    
6502                    Session session = null;
6503    
6504                    try {
6505                            session = openSession();
6506    
6507                            SQLQuery q = session.createSQLQuery(sql);
6508    
6509                            q.addScalar(COUNT_COLUMN_NAME,
6510                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6511    
6512                            QueryPos qPos = QueryPos.getInstance(q);
6513    
6514                            qPos.add(groupId);
6515    
6516                            if (type != null) {
6517                                    qPos.add(type);
6518                            }
6519    
6520                            Long count = (Long)q.uniqueResult();
6521    
6522                            return count.intValue();
6523                    }
6524                    catch (Exception e) {
6525                            throw processException(e);
6526                    }
6527                    finally {
6528                            closeSession(session);
6529                    }
6530            }
6531    
6532            /**
6533             * Returns the number of cal events that the user has permission to view where groupId = &#63; and type = any &#63;.
6534             *
6535             * @param groupId the group ID
6536             * @param types the types
6537             * @return the number of matching cal events that the user has permission to view
6538             * @throws SystemException if a system exception occurred
6539             */
6540            public int filterCountByG_T(long groupId, String[] types)
6541                    throws SystemException {
6542                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6543                            return countByG_T(groupId, types);
6544                    }
6545    
6546                    StringBundler query = new StringBundler();
6547    
6548                    query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
6549    
6550                    boolean conjunctionable = false;
6551    
6552                    if (conjunctionable) {
6553                            query.append(WHERE_AND);
6554                    }
6555    
6556                    query.append(_FINDER_COLUMN_G_T_GROUPID_5);
6557    
6558                    conjunctionable = true;
6559    
6560                    if ((types == null) || (types.length > 0)) {
6561                            if (conjunctionable) {
6562                                    query.append(WHERE_AND);
6563                            }
6564    
6565                            query.append(StringPool.OPEN_PARENTHESIS);
6566    
6567                            for (int i = 0; i < types.length; i++) {
6568                                    String type = types[i];
6569    
6570                                    if (type == null) {
6571                                            query.append(_FINDER_COLUMN_G_T_TYPE_4);
6572                                    }
6573                                    else {
6574                                            if (type.equals(StringPool.BLANK)) {
6575                                                    query.append(_FINDER_COLUMN_G_T_TYPE_6);
6576                                            }
6577                                            else {
6578                                                    query.append(_FINDER_COLUMN_G_T_TYPE_5);
6579                                            }
6580                                    }
6581    
6582                                    if ((i + 1) < types.length) {
6583                                            query.append(WHERE_OR);
6584                                    }
6585                            }
6586    
6587                            query.append(StringPool.CLOSE_PARENTHESIS);
6588    
6589                            conjunctionable = true;
6590                    }
6591    
6592                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6593                                    CalEvent.class.getName(),
6594                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6595    
6596                    Session session = null;
6597    
6598                    try {
6599                            session = openSession();
6600    
6601                            SQLQuery q = session.createSQLQuery(sql);
6602    
6603                            q.addScalar(COUNT_COLUMN_NAME,
6604                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6605    
6606                            QueryPos qPos = QueryPos.getInstance(q);
6607    
6608                            qPos.add(groupId);
6609    
6610                            if (types != null) {
6611                                    qPos.add(types);
6612                            }
6613    
6614                            Long count = (Long)q.uniqueResult();
6615    
6616                            return count.intValue();
6617                    }
6618                    catch (Exception e) {
6619                            throw processException(e);
6620                    }
6621                    finally {
6622                            closeSession(session);
6623                    }
6624            }
6625    
6626            /**
6627             * Returns the number of cal events where groupId = &#63; and repeating = &#63;.
6628             *
6629             * @param groupId the group ID
6630             * @param repeating the repeating
6631             * @return the number of matching cal events
6632             * @throws SystemException if a system exception occurred
6633             */
6634            public int countByG_R(long groupId, boolean repeating)
6635                    throws SystemException {
6636                    Object[] finderArgs = new Object[] { groupId, repeating };
6637    
6638                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_R,
6639                                    finderArgs, this);
6640    
6641                    if (count == null) {
6642                            StringBundler query = new StringBundler(3);
6643    
6644                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6645    
6646                            query.append(_FINDER_COLUMN_G_R_GROUPID_2);
6647    
6648                            query.append(_FINDER_COLUMN_G_R_REPEATING_2);
6649    
6650                            String sql = query.toString();
6651    
6652                            Session session = null;
6653    
6654                            try {
6655                                    session = openSession();
6656    
6657                                    Query q = session.createQuery(sql);
6658    
6659                                    QueryPos qPos = QueryPos.getInstance(q);
6660    
6661                                    qPos.add(groupId);
6662    
6663                                    qPos.add(repeating);
6664    
6665                                    count = (Long)q.uniqueResult();
6666                            }
6667                            catch (Exception e) {
6668                                    throw processException(e);
6669                            }
6670                            finally {
6671                                    if (count == null) {
6672                                            count = Long.valueOf(0);
6673                                    }
6674    
6675                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_R, finderArgs,
6676                                            count);
6677    
6678                                    closeSession(session);
6679                            }
6680                    }
6681    
6682                    return count.intValue();
6683            }
6684    
6685            /**
6686             * Returns the number of cal events that the user has permission to view where groupId = &#63; and repeating = &#63;.
6687             *
6688             * @param groupId the group ID
6689             * @param repeating the repeating
6690             * @return the number of matching cal events that the user has permission to view
6691             * @throws SystemException if a system exception occurred
6692             */
6693            public int filterCountByG_R(long groupId, boolean repeating)
6694                    throws SystemException {
6695                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6696                            return countByG_R(groupId, repeating);
6697                    }
6698    
6699                    StringBundler query = new StringBundler(3);
6700    
6701                    query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
6702    
6703                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
6704    
6705                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
6706    
6707                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6708                                    CalEvent.class.getName(),
6709                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6710    
6711                    Session session = null;
6712    
6713                    try {
6714                            session = openSession();
6715    
6716                            SQLQuery q = session.createSQLQuery(sql);
6717    
6718                            q.addScalar(COUNT_COLUMN_NAME,
6719                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6720    
6721                            QueryPos qPos = QueryPos.getInstance(q);
6722    
6723                            qPos.add(groupId);
6724    
6725                            qPos.add(repeating);
6726    
6727                            Long count = (Long)q.uniqueResult();
6728    
6729                            return count.intValue();
6730                    }
6731                    catch (Exception e) {
6732                            throw processException(e);
6733                    }
6734                    finally {
6735                            closeSession(session);
6736                    }
6737            }
6738    
6739            /**
6740             * Returns the number of cal events where groupId = &#63; and type = &#63; and repeating = &#63;.
6741             *
6742             * @param groupId the group ID
6743             * @param type the type
6744             * @param repeating the repeating
6745             * @return the number of matching cal events
6746             * @throws SystemException if a system exception occurred
6747             */
6748            public int countByG_T_R(long groupId, String type, boolean repeating)
6749                    throws SystemException {
6750                    Object[] finderArgs = new Object[] { groupId, type, repeating };
6751    
6752                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T_R,
6753                                    finderArgs, this);
6754    
6755                    if (count == null) {
6756                            StringBundler query = new StringBundler(4);
6757    
6758                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6759    
6760                            query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
6761    
6762                            if (type == null) {
6763                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
6764                            }
6765                            else {
6766                                    if (type.equals(StringPool.BLANK)) {
6767                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
6768                                    }
6769                                    else {
6770                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
6771                                    }
6772                            }
6773    
6774                            query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
6775    
6776                            String sql = query.toString();
6777    
6778                            Session session = null;
6779    
6780                            try {
6781                                    session = openSession();
6782    
6783                                    Query q = session.createQuery(sql);
6784    
6785                                    QueryPos qPos = QueryPos.getInstance(q);
6786    
6787                                    qPos.add(groupId);
6788    
6789                                    if (type != null) {
6790                                            qPos.add(type);
6791                                    }
6792    
6793                                    qPos.add(repeating);
6794    
6795                                    count = (Long)q.uniqueResult();
6796                            }
6797                            catch (Exception e) {
6798                                    throw processException(e);
6799                            }
6800                            finally {
6801                                    if (count == null) {
6802                                            count = Long.valueOf(0);
6803                                    }
6804    
6805                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T_R,
6806                                            finderArgs, count);
6807    
6808                                    closeSession(session);
6809                            }
6810                    }
6811    
6812                    return count.intValue();
6813            }
6814    
6815            /**
6816             * Returns the number of cal events where groupId = &#63; and type = any &#63; and repeating = &#63;.
6817             *
6818             * @param groupId the group ID
6819             * @param types the types
6820             * @param repeating the repeating
6821             * @return the number of matching cal events
6822             * @throws SystemException if a system exception occurred
6823             */
6824            public int countByG_T_R(long groupId, String[] types, boolean repeating)
6825                    throws SystemException {
6826                    Object[] finderArgs = new Object[] {
6827                                    groupId, StringUtil.merge(types), repeating
6828                            };
6829    
6830                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_R,
6831                                    finderArgs, this);
6832    
6833                    if (count == null) {
6834                            StringBundler query = new StringBundler();
6835    
6836                            query.append(_SQL_COUNT_CALEVENT_WHERE);
6837    
6838                            boolean conjunctionable = false;
6839    
6840                            if (conjunctionable) {
6841                                    query.append(WHERE_AND);
6842                            }
6843    
6844                            query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);
6845    
6846                            conjunctionable = true;
6847    
6848                            if ((types == null) || (types.length > 0)) {
6849                                    if (conjunctionable) {
6850                                            query.append(WHERE_AND);
6851                                    }
6852    
6853                                    query.append(StringPool.OPEN_PARENTHESIS);
6854    
6855                                    for (int i = 0; i < types.length; i++) {
6856                                            String type = types[i];
6857    
6858                                            if (type == null) {
6859                                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
6860                                            }
6861                                            else {
6862                                                    if (type.equals(StringPool.BLANK)) {
6863                                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
6864                                                    }
6865                                                    else {
6866                                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
6867                                                    }
6868                                            }
6869    
6870                                            if ((i + 1) < types.length) {
6871                                                    query.append(WHERE_OR);
6872                                            }
6873                                    }
6874    
6875                                    query.append(StringPool.CLOSE_PARENTHESIS);
6876    
6877                                    conjunctionable = true;
6878                            }
6879    
6880                            if (conjunctionable) {
6881                                    query.append(WHERE_AND);
6882                            }
6883    
6884                            query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);
6885    
6886                            conjunctionable = true;
6887    
6888                            String sql = query.toString();
6889    
6890                            Session session = null;
6891    
6892                            try {
6893                                    session = openSession();
6894    
6895                                    Query q = session.createQuery(sql);
6896    
6897                                    QueryPos qPos = QueryPos.getInstance(q);
6898    
6899                                    qPos.add(groupId);
6900    
6901                                    if (types != null) {
6902                                            qPos.add(types);
6903                                    }
6904    
6905                                    qPos.add(repeating);
6906    
6907                                    count = (Long)q.uniqueResult();
6908                            }
6909                            catch (Exception e) {
6910                                    throw processException(e);
6911                            }
6912                            finally {
6913                                    if (count == null) {
6914                                            count = Long.valueOf(0);
6915                                    }
6916    
6917                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_R,
6918                                            finderArgs, count);
6919    
6920                                    closeSession(session);
6921                            }
6922                    }
6923    
6924                    return count.intValue();
6925            }
6926    
6927            /**
6928             * Returns the number of cal events that the user has permission to view where groupId = &#63; and type = &#63; and repeating = &#63;.
6929             *
6930             * @param groupId the group ID
6931             * @param type the type
6932             * @param repeating the repeating
6933             * @return the number of matching cal events that the user has permission to view
6934             * @throws SystemException if a system exception occurred
6935             */
6936            public int filterCountByG_T_R(long groupId, String type, boolean repeating)
6937                    throws SystemException {
6938                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6939                            return countByG_T_R(groupId, type, repeating);
6940                    }
6941    
6942                    StringBundler query = new StringBundler(4);
6943    
6944                    query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
6945    
6946                    query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
6947    
6948                    if (type == null) {
6949                            query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
6950                    }
6951                    else {
6952                            if (type.equals(StringPool.BLANK)) {
6953                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
6954                            }
6955                            else {
6956                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
6957                            }
6958                    }
6959    
6960                    query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
6961    
6962                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6963                                    CalEvent.class.getName(),
6964                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6965    
6966                    Session session = null;
6967    
6968                    try {
6969                            session = openSession();
6970    
6971                            SQLQuery q = session.createSQLQuery(sql);
6972    
6973                            q.addScalar(COUNT_COLUMN_NAME,
6974                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6975    
6976                            QueryPos qPos = QueryPos.getInstance(q);
6977    
6978                            qPos.add(groupId);
6979    
6980                            if (type != null) {
6981                                    qPos.add(type);
6982                            }
6983    
6984                            qPos.add(repeating);
6985    
6986                            Long count = (Long)q.uniqueResult();
6987    
6988                            return count.intValue();
6989                    }
6990                    catch (Exception e) {
6991                            throw processException(e);
6992                    }
6993                    finally {
6994                            closeSession(session);
6995                    }
6996            }
6997    
6998            /**
6999             * Returns the number of cal events that the user has permission to view where groupId = &#63; and type = any &#63; and repeating = &#63;.
7000             *
7001             * @param groupId the group ID
7002             * @param types the types
7003             * @param repeating the repeating
7004             * @return the number of matching cal events that the user has permission to view
7005             * @throws SystemException if a system exception occurred
7006             */
7007            public int filterCountByG_T_R(long groupId, String[] types,
7008                    boolean repeating) throws SystemException {
7009                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7010                            return countByG_T_R(groupId, types, repeating);
7011                    }
7012    
7013                    StringBundler query = new StringBundler();
7014    
7015                    query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
7016    
7017                    boolean conjunctionable = false;
7018    
7019                    if (conjunctionable) {
7020                            query.append(WHERE_AND);
7021                    }
7022    
7023                    query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);
7024    
7025                    conjunctionable = true;
7026    
7027                    if ((types == null) || (types.length > 0)) {
7028                            if (conjunctionable) {
7029                                    query.append(WHERE_AND);
7030                            }
7031    
7032                            query.append(StringPool.OPEN_PARENTHESIS);
7033    
7034                            for (int i = 0; i < types.length; i++) {
7035                                    String type = types[i];
7036    
7037                                    if (type == null) {
7038                                            query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
7039                                    }
7040                                    else {
7041                                            if (type.equals(StringPool.BLANK)) {
7042                                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
7043                                            }
7044                                            else {
7045                                                    query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
7046                                            }
7047                                    }
7048    
7049                                    if ((i + 1) < types.length) {
7050                                            query.append(WHERE_OR);
7051                                    }
7052                            }
7053    
7054                            query.append(StringPool.CLOSE_PARENTHESIS);
7055    
7056                            conjunctionable = true;
7057                    }
7058    
7059                    if (conjunctionable) {
7060                            query.append(WHERE_AND);
7061                    }
7062    
7063                    query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);
7064    
7065                    conjunctionable = true;
7066    
7067                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7068                                    CalEvent.class.getName(),
7069                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7070    
7071                    Session session = null;
7072    
7073                    try {
7074                            session = openSession();
7075    
7076                            SQLQuery q = session.createSQLQuery(sql);
7077    
7078                            q.addScalar(COUNT_COLUMN_NAME,
7079                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7080    
7081                            QueryPos qPos = QueryPos.getInstance(q);
7082    
7083                            qPos.add(groupId);
7084    
7085                            if (types != null) {
7086                                    qPos.add(types);
7087                            }
7088    
7089                            qPos.add(repeating);
7090    
7091                            Long count = (Long)q.uniqueResult();
7092    
7093                            return count.intValue();
7094                    }
7095                    catch (Exception e) {
7096                            throw processException(e);
7097                    }
7098                    finally {
7099                            closeSession(session);
7100                    }
7101            }
7102    
7103            /**
7104             * Returns the number of cal events.
7105             *
7106             * @return the number of cal events
7107             * @throws SystemException if a system exception occurred
7108             */
7109            public int countAll() throws SystemException {
7110                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7111                                    FINDER_ARGS_EMPTY, this);
7112    
7113                    if (count == null) {
7114                            Session session = null;
7115    
7116                            try {
7117                                    session = openSession();
7118    
7119                                    Query q = session.createQuery(_SQL_COUNT_CALEVENT);
7120    
7121                                    count = (Long)q.uniqueResult();
7122                            }
7123                            catch (Exception e) {
7124                                    throw processException(e);
7125                            }
7126                            finally {
7127                                    if (count == null) {
7128                                            count = Long.valueOf(0);
7129                                    }
7130    
7131                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7132                                            FINDER_ARGS_EMPTY, count);
7133    
7134                                    closeSession(session);
7135                            }
7136                    }
7137    
7138                    return count.intValue();
7139            }
7140    
7141            /**
7142             * Initializes the cal event persistence.
7143             */
7144            public void afterPropertiesSet() {
7145                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7146                                            com.liferay.portal.util.PropsUtil.get(
7147                                                    "value.object.listener.com.liferay.portlet.calendar.model.CalEvent")));
7148    
7149                    if (listenerClassNames.length > 0) {
7150                            try {
7151                                    List<ModelListener<CalEvent>> listenersList = new ArrayList<ModelListener<CalEvent>>();
7152    
7153                                    for (String listenerClassName : listenerClassNames) {
7154                                            listenersList.add((ModelListener<CalEvent>)InstanceFactory.newInstance(
7155                                                            listenerClassName));
7156                                    }
7157    
7158                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
7159                            }
7160                            catch (Exception e) {
7161                                    _log.error(e);
7162                            }
7163                    }
7164            }
7165    
7166            public void destroy() {
7167                    EntityCacheUtil.removeCache(CalEventImpl.class.getName());
7168                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7169                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7170            }
7171    
7172            @BeanReference(type = CalEventPersistence.class)
7173            protected CalEventPersistence calEventPersistence;
7174            @BeanReference(type = CompanyPersistence.class)
7175            protected CompanyPersistence companyPersistence;
7176            @BeanReference(type = GroupPersistence.class)
7177            protected GroupPersistence groupPersistence;
7178            @BeanReference(type = PortletPreferencesPersistence.class)
7179            protected PortletPreferencesPersistence portletPreferencesPersistence;
7180            @BeanReference(type = ResourcePersistence.class)
7181            protected ResourcePersistence resourcePersistence;
7182            @BeanReference(type = UserPersistence.class)
7183            protected UserPersistence userPersistence;
7184            @BeanReference(type = AssetEntryPersistence.class)
7185            protected AssetEntryPersistence assetEntryPersistence;
7186            @BeanReference(type = AssetLinkPersistence.class)
7187            protected AssetLinkPersistence assetLinkPersistence;
7188            @BeanReference(type = AssetTagPersistence.class)
7189            protected AssetTagPersistence assetTagPersistence;
7190            @BeanReference(type = ExpandoValuePersistence.class)
7191            protected ExpandoValuePersistence expandoValuePersistence;
7192            @BeanReference(type = SocialActivityPersistence.class)
7193            protected SocialActivityPersistence socialActivityPersistence;
7194            private static final String _SQL_SELECT_CALEVENT = "SELECT calEvent FROM CalEvent calEvent";
7195            private static final String _SQL_SELECT_CALEVENT_WHERE = "SELECT calEvent FROM CalEvent calEvent WHERE ";
7196            private static final String _SQL_COUNT_CALEVENT = "SELECT COUNT(calEvent) FROM CalEvent calEvent";
7197            private static final String _SQL_COUNT_CALEVENT_WHERE = "SELECT COUNT(calEvent) FROM CalEvent calEvent WHERE ";
7198            private static final String _FINDER_COLUMN_UUID_UUID_1 = "calEvent.uuid IS NULL";
7199            private static final String _FINDER_COLUMN_UUID_UUID_2 = "calEvent.uuid = ?";
7200            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?)";
7201            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "calEvent.uuid IS NULL AND ";
7202            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "calEvent.uuid = ? AND ";
7203            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?) AND ";
7204            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "calEvent.groupId = ?";
7205            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "calEvent.companyId = ?";
7206            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "calEvent.groupId = ?";
7207            private static final String _FINDER_COLUMN_NOTREMINDBY_REMINDBY_2 = "calEvent.remindBy != ?";
7208            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "calEvent.groupId = ? AND ";
7209            private static final String _FINDER_COLUMN_G_T_GROUPID_5 = "(" +
7210                    _removeConjunction(_FINDER_COLUMN_G_T_GROUPID_2) + ")";
7211            private static final String _FINDER_COLUMN_G_T_TYPE_1 = "calEvent.type IS NULL";
7212            private static final String _FINDER_COLUMN_G_T_TYPE_2 = "calEvent.type = ?";
7213            private static final String _FINDER_COLUMN_G_T_TYPE_3 = "(calEvent.type IS NULL OR calEvent.type = ?)";
7214            private static final String _FINDER_COLUMN_G_T_TYPE_4 = "(" +
7215                    _removeConjunction(_FINDER_COLUMN_G_T_TYPE_1) + ")";
7216            private static final String _FINDER_COLUMN_G_T_TYPE_5 = "(" +
7217                    _removeConjunction(_FINDER_COLUMN_G_T_TYPE_2) + ")";
7218            private static final String _FINDER_COLUMN_G_T_TYPE_6 = "(" +
7219                    _removeConjunction(_FINDER_COLUMN_G_T_TYPE_3) + ")";
7220            private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "calEvent.groupId = ? AND ";
7221            private static final String _FINDER_COLUMN_G_R_REPEATING_2 = "calEvent.repeating = ?";
7222            private static final String _FINDER_COLUMN_G_T_R_GROUPID_2 = "calEvent.groupId = ? AND ";
7223            private static final String _FINDER_COLUMN_G_T_R_GROUPID_5 = "(" +
7224                    _removeConjunction(_FINDER_COLUMN_G_T_R_GROUPID_2) + ")";
7225            private static final String _FINDER_COLUMN_G_T_R_TYPE_1 = "calEvent.type IS NULL AND ";
7226            private static final String _FINDER_COLUMN_G_T_R_TYPE_2 = "calEvent.type = ? AND ";
7227            private static final String _FINDER_COLUMN_G_T_R_TYPE_3 = "(calEvent.type IS NULL OR calEvent.type = ?) AND ";
7228            private static final String _FINDER_COLUMN_G_T_R_TYPE_4 = "(" +
7229                    _removeConjunction(_FINDER_COLUMN_G_T_R_TYPE_1) + ")";
7230            private static final String _FINDER_COLUMN_G_T_R_TYPE_5 = "(" +
7231                    _removeConjunction(_FINDER_COLUMN_G_T_R_TYPE_2) + ")";
7232            private static final String _FINDER_COLUMN_G_T_R_TYPE_6 = "(" +
7233                    _removeConjunction(_FINDER_COLUMN_G_T_R_TYPE_3) + ")";
7234            private static final String _FINDER_COLUMN_G_T_R_REPEATING_2 = "calEvent.repeating = ?";
7235            private static final String _FINDER_COLUMN_G_T_R_REPEATING_5 = "(" +
7236                    _removeConjunction(_FINDER_COLUMN_G_T_R_REPEATING_2) + ")";
7237    
7238            private static String _removeConjunction(String sql) {
7239                    int pos = sql.indexOf(" AND ");
7240    
7241                    if (pos != -1) {
7242                            sql = sql.substring(0, pos);
7243                    }
7244    
7245                    return sql;
7246            }
7247    
7248            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "calEvent.eventId";
7249            private static final String _FILTER_SQL_SELECT_CALEVENT_WHERE = "SELECT DISTINCT {calEvent.*} FROM CalEvent calEvent WHERE ";
7250            private static final String _FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1 =
7251                    "SELECT {CalEvent.*} FROM (SELECT DISTINCT calEvent.eventId FROM CalEvent calEvent WHERE ";
7252            private static final String _FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2 =
7253                    ") TEMP_TABLE INNER JOIN CalEvent ON TEMP_TABLE.eventId = CalEvent.eventId";
7254            private static final String _FILTER_SQL_COUNT_CALEVENT_WHERE = "SELECT COUNT(DISTINCT calEvent.eventId) AS COUNT_VALUE FROM CalEvent calEvent WHERE ";
7255            private static final String _FILTER_ENTITY_ALIAS = "calEvent";
7256            private static final String _FILTER_ENTITY_TABLE = "CalEvent";
7257            private static final String _ORDER_BY_ENTITY_ALIAS = "calEvent.";
7258            private static final String _ORDER_BY_ENTITY_TABLE = "CalEvent.";
7259            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No CalEvent exists with the primary key ";
7260            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No CalEvent exists with the key {";
7261            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7262            private static Log _log = LogFactoryUtil.getLog(CalEventPersistenceImpl.class);
7263            private static CalEvent _nullCalEvent = new CalEventImpl() {
7264                            @Override
7265                            public Object clone() {
7266                                    return this;
7267                            }
7268    
7269                            @Override
7270                            public CacheModel<CalEvent> toCacheModel() {
7271                                    return _nullCalEventCacheModel;
7272                            }
7273                    };
7274    
7275            private static CacheModel<CalEvent> _nullCalEventCacheModel = new CacheModel<CalEvent>() {
7276                            public CalEvent toEntityModel() {
7277                                    return _nullCalEvent;
7278                            }
7279                    };
7280    }