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