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