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