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