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