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