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