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