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