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