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