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