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