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