001    /**
002     * Copyright (c) 2000-2010 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;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.CompanyPersistence;
043    import com.liferay.portal.service.persistence.GroupPersistence;
044    import com.liferay.portal.service.persistence.PortletPreferencesPersistence;
045    import com.liferay.portal.service.persistence.ResourcePersistence;
046    import com.liferay.portal.service.persistence.UserPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
050    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
051    import com.liferay.portlet.calendar.NoSuchEventException;
052    import com.liferay.portlet.calendar.model.CalEvent;
053    import com.liferay.portlet.calendar.model.impl.CalEventImpl;
054    import com.liferay.portlet.calendar.model.impl.CalEventModelImpl;
055    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
056    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
057    
058    import java.io.Serializable;
059    
060    import java.util.ArrayList;
061    import java.util.Collections;
062    import java.util.List;
063    
064    /**
065     * @author    Brian Wing Shun Chan
066     * @see       CalEventPersistence
067     * @see       CalEventUtil
068     * @generated
069     */
070    public class CalEventPersistenceImpl extends BasePersistenceImpl<CalEvent>
071            implements CalEventPersistence {
072            public static final String FINDER_CLASS_NAME_ENTITY = CalEventImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
074                    ".List";
075            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
076                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
077                            "findByUuid",
078                            new String[] {
079                                    String.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
085                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
086                            "countByUuid", new String[] { String.class.getName() });
087            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
088                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
089                            "fetchByUUID_G",
090                            new String[] { String.class.getName(), Long.class.getName() });
091            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
092                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093                            "countByUUID_G",
094                            new String[] { String.class.getName(), Long.class.getName() });
095            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
096                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097                            "findByCompanyId",
098                            new String[] {
099                                    Long.class.getName(),
100                                    
101                            "java.lang.Integer", "java.lang.Integer",
102                                    "com.liferay.portal.kernel.util.OrderByComparator"
103                            });
104            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
105                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106                            "countByCompanyId", new String[] { Long.class.getName() });
107            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
108                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109                            "findByGroupId",
110                            new String[] {
111                                    Long.class.getName(),
112                                    
113                            "java.lang.Integer", "java.lang.Integer",
114                                    "com.liferay.portal.kernel.util.OrderByComparator"
115                            });
116            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
117                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
118                            "countByGroupId", new String[] { Long.class.getName() });
119            public static final FinderPath FINDER_PATH_FIND_BY_NOTREMINDBY = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
120                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121                            "findByNotRemindBy",
122                            new String[] {
123                                    Integer.class.getName(),
124                                    
125                            "java.lang.Integer", "java.lang.Integer",
126                                    "com.liferay.portal.kernel.util.OrderByComparator"
127                            });
128            public static final FinderPath FINDER_PATH_COUNT_BY_NOTREMINDBY = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
129                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130                            "countByNotRemindBy", new String[] { Integer.class.getName() });
131            public static final FinderPath FINDER_PATH_FIND_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
132                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133                            "findByG_T",
134                            new String[] {
135                                    Long.class.getName(), String.class.getName(),
136                                    
137                            "java.lang.Integer", "java.lang.Integer",
138                                    "com.liferay.portal.kernel.util.OrderByComparator"
139                            });
140            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
141                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
142                            "countByG_T",
143                            new String[] { Long.class.getName(), String.class.getName() });
144            public static final FinderPath FINDER_PATH_FIND_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
145                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
146                            "findByG_R",
147                            new String[] {
148                                    Long.class.getName(), Boolean.class.getName(),
149                                    
150                            "java.lang.Integer", "java.lang.Integer",
151                                    "com.liferay.portal.kernel.util.OrderByComparator"
152                            });
153            public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
154                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
155                            "countByG_R",
156                            new String[] { Long.class.getName(), Boolean.class.getName() });
157            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
158                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
159                            "findAll", new String[0]);
160            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
161                            CalEventModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
162                            "countAll", new String[0]);
163    
164            public void cacheResult(CalEvent calEvent) {
165                    EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
166                            CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
167    
168                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
169                            new Object[] { calEvent.getUuid(), new Long(calEvent.getGroupId()) },
170                            calEvent);
171            }
172    
173            public void cacheResult(List<CalEvent> calEvents) {
174                    for (CalEvent calEvent : calEvents) {
175                            if (EntityCacheUtil.getResult(
176                                                    CalEventModelImpl.ENTITY_CACHE_ENABLED,
177                                                    CalEventImpl.class, calEvent.getPrimaryKey(), this) == null) {
178                                    cacheResult(calEvent);
179                            }
180                    }
181            }
182    
183            public void clearCache() {
184                    CacheRegistryUtil.clear(CalEventImpl.class.getName());
185                    EntityCacheUtil.clearCache(CalEventImpl.class.getName());
186                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
187                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
188            }
189    
190            public void clearCache(CalEvent calEvent) {
191                    EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
192                            CalEventImpl.class, calEvent.getPrimaryKey());
193    
194                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
195                            new Object[] { calEvent.getUuid(), new Long(calEvent.getGroupId()) });
196            }
197    
198            public CalEvent create(long eventId) {
199                    CalEvent calEvent = new CalEventImpl();
200    
201                    calEvent.setNew(true);
202                    calEvent.setPrimaryKey(eventId);
203    
204                    String uuid = PortalUUIDUtil.generate();
205    
206                    calEvent.setUuid(uuid);
207    
208                    return calEvent;
209            }
210    
211            public CalEvent remove(Serializable primaryKey)
212                    throws NoSuchModelException, SystemException {
213                    return remove(((Long)primaryKey).longValue());
214            }
215    
216            public CalEvent remove(long eventId)
217                    throws NoSuchEventException, SystemException {
218                    Session session = null;
219    
220                    try {
221                            session = openSession();
222    
223                            CalEvent calEvent = (CalEvent)session.get(CalEventImpl.class,
224                                            new Long(eventId));
225    
226                            if (calEvent == null) {
227                                    if (_log.isWarnEnabled()) {
228                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + eventId);
229                                    }
230    
231                                    throw new NoSuchEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
232                                            eventId);
233                            }
234    
235                            return remove(calEvent);
236                    }
237                    catch (NoSuchEventException nsee) {
238                            throw nsee;
239                    }
240                    catch (Exception e) {
241                            throw processException(e);
242                    }
243                    finally {
244                            closeSession(session);
245                    }
246            }
247    
248            protected CalEvent removeImpl(CalEvent calEvent) throws SystemException {
249                    calEvent = toUnwrappedModel(calEvent);
250    
251                    Session session = null;
252    
253                    try {
254                            session = openSession();
255    
256                            if (calEvent.isCachedModel() || BatchSessionUtil.isEnabled()) {
257                                    Object staleObject = session.get(CalEventImpl.class,
258                                                    calEvent.getPrimaryKeyObj());
259    
260                                    if (staleObject != null) {
261                                            session.evict(staleObject);
262                                    }
263                            }
264    
265                            session.delete(calEvent);
266    
267                            session.flush();
268                    }
269                    catch (Exception e) {
270                            throw processException(e);
271                    }
272                    finally {
273                            closeSession(session);
274                    }
275    
276                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
277    
278                    CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
279    
280                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
281                            new Object[] {
282                                    calEventModelImpl.getOriginalUuid(),
283                                    new Long(calEventModelImpl.getOriginalGroupId())
284                            });
285    
286                    EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
287                            CalEventImpl.class, calEvent.getPrimaryKey());
288    
289                    return calEvent;
290            }
291    
292            public CalEvent updateImpl(
293                    com.liferay.portlet.calendar.model.CalEvent calEvent, boolean merge)
294                    throws SystemException {
295                    calEvent = toUnwrappedModel(calEvent);
296    
297                    boolean isNew = calEvent.isNew();
298    
299                    CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
300    
301                    if (Validator.isNull(calEvent.getUuid())) {
302                            String uuid = PortalUUIDUtil.generate();
303    
304                            calEvent.setUuid(uuid);
305                    }
306    
307                    Session session = null;
308    
309                    try {
310                            session = openSession();
311    
312                            BatchSessionUtil.update(session, calEvent, merge);
313    
314                            calEvent.setNew(false);
315                    }
316                    catch (Exception e) {
317                            throw processException(e);
318                    }
319                    finally {
320                            closeSession(session);
321                    }
322    
323                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
324    
325                    EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
326                            CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
327    
328                    if (!isNew &&
329                                    (!Validator.equals(calEvent.getUuid(),
330                                            calEventModelImpl.getOriginalUuid()) ||
331                                    (calEvent.getGroupId() != calEventModelImpl.getOriginalGroupId()))) {
332                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
333                                    new Object[] {
334                                            calEventModelImpl.getOriginalUuid(),
335                                            new Long(calEventModelImpl.getOriginalGroupId())
336                                    });
337                    }
338    
339                    if (isNew ||
340                                    (!Validator.equals(calEvent.getUuid(),
341                                            calEventModelImpl.getOriginalUuid()) ||
342                                    (calEvent.getGroupId() != calEventModelImpl.getOriginalGroupId()))) {
343                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
344                                    new Object[] { calEvent.getUuid(), new Long(
345                                                    calEvent.getGroupId()) }, calEvent);
346                    }
347    
348                    return calEvent;
349            }
350    
351            protected CalEvent toUnwrappedModel(CalEvent calEvent) {
352                    if (calEvent instanceof CalEventImpl) {
353                            return calEvent;
354                    }
355    
356                    CalEventImpl calEventImpl = new CalEventImpl();
357    
358                    calEventImpl.setNew(calEvent.isNew());
359                    calEventImpl.setPrimaryKey(calEvent.getPrimaryKey());
360    
361                    calEventImpl.setUuid(calEvent.getUuid());
362                    calEventImpl.setEventId(calEvent.getEventId());
363                    calEventImpl.setGroupId(calEvent.getGroupId());
364                    calEventImpl.setCompanyId(calEvent.getCompanyId());
365                    calEventImpl.setUserId(calEvent.getUserId());
366                    calEventImpl.setUserName(calEvent.getUserName());
367                    calEventImpl.setCreateDate(calEvent.getCreateDate());
368                    calEventImpl.setModifiedDate(calEvent.getModifiedDate());
369                    calEventImpl.setTitle(calEvent.getTitle());
370                    calEventImpl.setDescription(calEvent.getDescription());
371                    calEventImpl.setStartDate(calEvent.getStartDate());
372                    calEventImpl.setEndDate(calEvent.getEndDate());
373                    calEventImpl.setDurationHour(calEvent.getDurationHour());
374                    calEventImpl.setDurationMinute(calEvent.getDurationMinute());
375                    calEventImpl.setAllDay(calEvent.isAllDay());
376                    calEventImpl.setTimeZoneSensitive(calEvent.isTimeZoneSensitive());
377                    calEventImpl.setType(calEvent.getType());
378                    calEventImpl.setRepeating(calEvent.isRepeating());
379                    calEventImpl.setRecurrence(calEvent.getRecurrence());
380                    calEventImpl.setRemindBy(calEvent.getRemindBy());
381                    calEventImpl.setFirstReminder(calEvent.getFirstReminder());
382                    calEventImpl.setSecondReminder(calEvent.getSecondReminder());
383    
384                    return calEventImpl;
385            }
386    
387            public CalEvent findByPrimaryKey(Serializable primaryKey)
388                    throws NoSuchModelException, SystemException {
389                    return findByPrimaryKey(((Long)primaryKey).longValue());
390            }
391    
392            public CalEvent findByPrimaryKey(long eventId)
393                    throws NoSuchEventException, SystemException {
394                    CalEvent calEvent = fetchByPrimaryKey(eventId);
395    
396                    if (calEvent == null) {
397                            if (_log.isWarnEnabled()) {
398                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + eventId);
399                            }
400    
401                            throw new NoSuchEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
402                                    eventId);
403                    }
404    
405                    return calEvent;
406            }
407    
408            public CalEvent fetchByPrimaryKey(Serializable primaryKey)
409                    throws SystemException {
410                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
411            }
412    
413            public CalEvent fetchByPrimaryKey(long eventId) throws SystemException {
414                    CalEvent calEvent = (CalEvent)EntityCacheUtil.getResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
415                                    CalEventImpl.class, eventId, this);
416    
417                    if (calEvent == null) {
418                            Session session = null;
419    
420                            try {
421                                    session = openSession();
422    
423                                    calEvent = (CalEvent)session.get(CalEventImpl.class,
424                                                    new Long(eventId));
425                            }
426                            catch (Exception e) {
427                                    throw processException(e);
428                            }
429                            finally {
430                                    if (calEvent != null) {
431                                            cacheResult(calEvent);
432                                    }
433    
434                                    closeSession(session);
435                            }
436                    }
437    
438                    return calEvent;
439            }
440    
441            public List<CalEvent> findByUuid(String uuid) throws SystemException {
442                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
443            }
444    
445            public List<CalEvent> findByUuid(String uuid, int start, int end)
446                    throws SystemException {
447                    return findByUuid(uuid, start, end, null);
448            }
449    
450            public List<CalEvent> findByUuid(String uuid, int start, int end,
451                    OrderByComparator orderByComparator) throws SystemException {
452                    Object[] finderArgs = new Object[] {
453                                    uuid,
454                                    
455                                    String.valueOf(start), String.valueOf(end),
456                                    String.valueOf(orderByComparator)
457                            };
458    
459                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
460                                    finderArgs, this);
461    
462                    if (list == null) {
463                            Session session = null;
464    
465                            try {
466                                    session = openSession();
467    
468                                    StringBundler query = null;
469    
470                                    if (orderByComparator != null) {
471                                            query = new StringBundler(3 +
472                                                            (orderByComparator.getOrderByFields().length * 3));
473                                    }
474                                    else {
475                                            query = new StringBundler(3);
476                                    }
477    
478                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
479    
480                                    if (uuid == null) {
481                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
482                                    }
483                                    else {
484                                            if (uuid.equals(StringPool.BLANK)) {
485                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
486                                            }
487                                            else {
488                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
489                                            }
490                                    }
491    
492                                    if (orderByComparator != null) {
493                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
494                                                    orderByComparator);
495                                    }
496    
497                                    else {
498                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
499                                    }
500    
501                                    String sql = query.toString();
502    
503                                    Query q = session.createQuery(sql);
504    
505                                    QueryPos qPos = QueryPos.getInstance(q);
506    
507                                    if (uuid != null) {
508                                            qPos.add(uuid);
509                                    }
510    
511                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
512                                                    end);
513                            }
514                            catch (Exception e) {
515                                    throw processException(e);
516                            }
517                            finally {
518                                    if (list == null) {
519                                            list = new ArrayList<CalEvent>();
520                                    }
521    
522                                    cacheResult(list);
523    
524                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
525                                            list);
526    
527                                    closeSession(session);
528                            }
529                    }
530    
531                    return list;
532            }
533    
534            public CalEvent findByUuid_First(String uuid,
535                    OrderByComparator orderByComparator)
536                    throws NoSuchEventException, SystemException {
537                    List<CalEvent> list = findByUuid(uuid, 0, 1, orderByComparator);
538    
539                    if (list.isEmpty()) {
540                            StringBundler msg = new StringBundler(4);
541    
542                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
543    
544                            msg.append("uuid=");
545                            msg.append(uuid);
546    
547                            msg.append(StringPool.CLOSE_CURLY_BRACE);
548    
549                            throw new NoSuchEventException(msg.toString());
550                    }
551                    else {
552                            return list.get(0);
553                    }
554            }
555    
556            public CalEvent findByUuid_Last(String uuid,
557                    OrderByComparator orderByComparator)
558                    throws NoSuchEventException, SystemException {
559                    int count = countByUuid(uuid);
560    
561                    List<CalEvent> list = findByUuid(uuid, count - 1, count,
562                                    orderByComparator);
563    
564                    if (list.isEmpty()) {
565                            StringBundler msg = new StringBundler(4);
566    
567                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
568    
569                            msg.append("uuid=");
570                            msg.append(uuid);
571    
572                            msg.append(StringPool.CLOSE_CURLY_BRACE);
573    
574                            throw new NoSuchEventException(msg.toString());
575                    }
576                    else {
577                            return list.get(0);
578                    }
579            }
580    
581            public CalEvent[] findByUuid_PrevAndNext(long eventId, String uuid,
582                    OrderByComparator orderByComparator)
583                    throws NoSuchEventException, SystemException {
584                    CalEvent calEvent = findByPrimaryKey(eventId);
585    
586                    Session session = null;
587    
588                    try {
589                            session = openSession();
590    
591                            CalEvent[] array = new CalEventImpl[3];
592    
593                            array[0] = getByUuid_PrevAndNext(session, calEvent, uuid,
594                                            orderByComparator, true);
595    
596                            array[1] = calEvent;
597    
598                            array[2] = getByUuid_PrevAndNext(session, calEvent, uuid,
599                                            orderByComparator, false);
600    
601                            return array;
602                    }
603                    catch (Exception e) {
604                            throw processException(e);
605                    }
606                    finally {
607                            closeSession(session);
608                    }
609            }
610    
611            protected CalEvent getByUuid_PrevAndNext(Session session,
612                    CalEvent calEvent, String uuid, OrderByComparator orderByComparator,
613                    boolean previous) {
614                    StringBundler query = null;
615    
616                    if (orderByComparator != null) {
617                            query = new StringBundler(6 +
618                                            (orderByComparator.getOrderByFields().length * 6));
619                    }
620                    else {
621                            query = new StringBundler(3);
622                    }
623    
624                    query.append(_SQL_SELECT_CALEVENT_WHERE);
625    
626                    if (uuid == null) {
627                            query.append(_FINDER_COLUMN_UUID_UUID_1);
628                    }
629                    else {
630                            if (uuid.equals(StringPool.BLANK)) {
631                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
632                            }
633                            else {
634                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
635                            }
636                    }
637    
638                    if (orderByComparator != null) {
639                            String[] orderByFields = orderByComparator.getOrderByFields();
640    
641                            if (orderByFields.length > 0) {
642                                    query.append(WHERE_AND);
643                            }
644    
645                            for (int i = 0; i < orderByFields.length; i++) {
646                                    query.append(_ORDER_BY_ENTITY_ALIAS);
647                                    query.append(orderByFields[i]);
648    
649                                    if ((i + 1) < orderByFields.length) {
650                                            if (orderByComparator.isAscending() ^ previous) {
651                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
652                                            }
653                                            else {
654                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
655                                            }
656                                    }
657                                    else {
658                                            if (orderByComparator.isAscending() ^ previous) {
659                                                    query.append(WHERE_GREATER_THAN);
660                                            }
661                                            else {
662                                                    query.append(WHERE_LESSER_THAN);
663                                            }
664                                    }
665                            }
666    
667                            query.append(ORDER_BY_CLAUSE);
668    
669                            for (int i = 0; i < orderByFields.length; i++) {
670                                    query.append(_ORDER_BY_ENTITY_ALIAS);
671                                    query.append(orderByFields[i]);
672    
673                                    if ((i + 1) < orderByFields.length) {
674                                            if (orderByComparator.isAscending() ^ previous) {
675                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
676                                            }
677                                            else {
678                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
679                                            }
680                                    }
681                                    else {
682                                            if (orderByComparator.isAscending() ^ previous) {
683                                                    query.append(ORDER_BY_ASC);
684                                            }
685                                            else {
686                                                    query.append(ORDER_BY_DESC);
687                                            }
688                                    }
689                            }
690                    }
691    
692                    else {
693                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
694                    }
695    
696                    String sql = query.toString();
697    
698                    Query q = session.createQuery(sql);
699    
700                    q.setFirstResult(0);
701                    q.setMaxResults(2);
702    
703                    QueryPos qPos = QueryPos.getInstance(q);
704    
705                    if (uuid != null) {
706                            qPos.add(uuid);
707                    }
708    
709                    if (orderByComparator != null) {
710                            Object[] values = orderByComparator.getOrderByValues(calEvent);
711    
712                            for (Object value : values) {
713                                    qPos.add(value);
714                            }
715                    }
716    
717                    List<CalEvent> list = q.list();
718    
719                    if (list.size() == 2) {
720                            return list.get(1);
721                    }
722                    else {
723                            return null;
724                    }
725            }
726    
727            public CalEvent findByUUID_G(String uuid, long groupId)
728                    throws NoSuchEventException, SystemException {
729                    CalEvent calEvent = fetchByUUID_G(uuid, groupId);
730    
731                    if (calEvent == null) {
732                            StringBundler msg = new StringBundler(6);
733    
734                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
735    
736                            msg.append("uuid=");
737                            msg.append(uuid);
738    
739                            msg.append(", groupId=");
740                            msg.append(groupId);
741    
742                            msg.append(StringPool.CLOSE_CURLY_BRACE);
743    
744                            if (_log.isWarnEnabled()) {
745                                    _log.warn(msg.toString());
746                            }
747    
748                            throw new NoSuchEventException(msg.toString());
749                    }
750    
751                    return calEvent;
752            }
753    
754            public CalEvent fetchByUUID_G(String uuid, long groupId)
755                    throws SystemException {
756                    return fetchByUUID_G(uuid, groupId, true);
757            }
758    
759            public CalEvent fetchByUUID_G(String uuid, long groupId,
760                    boolean retrieveFromCache) throws SystemException {
761                    Object[] finderArgs = new Object[] { uuid, groupId };
762    
763                    Object result = null;
764    
765                    if (retrieveFromCache) {
766                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
767                                            finderArgs, this);
768                    }
769    
770                    if (result == null) {
771                            Session session = null;
772    
773                            try {
774                                    session = openSession();
775    
776                                    StringBundler query = new StringBundler(4);
777    
778                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
779    
780                                    if (uuid == null) {
781                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
782                                    }
783                                    else {
784                                            if (uuid.equals(StringPool.BLANK)) {
785                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
786                                            }
787                                            else {
788                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
789                                            }
790                                    }
791    
792                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
793    
794                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
795    
796                                    String sql = query.toString();
797    
798                                    Query q = session.createQuery(sql);
799    
800                                    QueryPos qPos = QueryPos.getInstance(q);
801    
802                                    if (uuid != null) {
803                                            qPos.add(uuid);
804                                    }
805    
806                                    qPos.add(groupId);
807    
808                                    List<CalEvent> list = q.list();
809    
810                                    result = list;
811    
812                                    CalEvent calEvent = null;
813    
814                                    if (list.isEmpty()) {
815                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
816                                                    finderArgs, list);
817                                    }
818                                    else {
819                                            calEvent = list.get(0);
820    
821                                            cacheResult(calEvent);
822    
823                                            if ((calEvent.getUuid() == null) ||
824                                                            !calEvent.getUuid().equals(uuid) ||
825                                                            (calEvent.getGroupId() != groupId)) {
826                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
827                                                            finderArgs, calEvent);
828                                            }
829                                    }
830    
831                                    return calEvent;
832                            }
833                            catch (Exception e) {
834                                    throw processException(e);
835                            }
836                            finally {
837                                    if (result == null) {
838                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
839                                                    finderArgs, new ArrayList<CalEvent>());
840                                    }
841    
842                                    closeSession(session);
843                            }
844                    }
845                    else {
846                            if (result instanceof List<?>) {
847                                    return null;
848                            }
849                            else {
850                                    return (CalEvent)result;
851                            }
852                    }
853            }
854    
855            public List<CalEvent> findByCompanyId(long companyId)
856                    throws SystemException {
857                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
858                            null);
859            }
860    
861            public List<CalEvent> findByCompanyId(long companyId, int start, int end)
862                    throws SystemException {
863                    return findByCompanyId(companyId, start, end, null);
864            }
865    
866            public List<CalEvent> findByCompanyId(long companyId, int start, int end,
867                    OrderByComparator orderByComparator) throws SystemException {
868                    Object[] finderArgs = new Object[] {
869                                    companyId,
870                                    
871                                    String.valueOf(start), String.valueOf(end),
872                                    String.valueOf(orderByComparator)
873                            };
874    
875                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
876                                    finderArgs, this);
877    
878                    if (list == null) {
879                            Session session = null;
880    
881                            try {
882                                    session = openSession();
883    
884                                    StringBundler query = null;
885    
886                                    if (orderByComparator != null) {
887                                            query = new StringBundler(3 +
888                                                            (orderByComparator.getOrderByFields().length * 3));
889                                    }
890                                    else {
891                                            query = new StringBundler(3);
892                                    }
893    
894                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
895    
896                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
897    
898                                    if (orderByComparator != null) {
899                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
900                                                    orderByComparator);
901                                    }
902    
903                                    else {
904                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
905                                    }
906    
907                                    String sql = query.toString();
908    
909                                    Query q = session.createQuery(sql);
910    
911                                    QueryPos qPos = QueryPos.getInstance(q);
912    
913                                    qPos.add(companyId);
914    
915                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
916                                                    end);
917                            }
918                            catch (Exception e) {
919                                    throw processException(e);
920                            }
921                            finally {
922                                    if (list == null) {
923                                            list = new ArrayList<CalEvent>();
924                                    }
925    
926                                    cacheResult(list);
927    
928                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
929                                            finderArgs, list);
930    
931                                    closeSession(session);
932                            }
933                    }
934    
935                    return list;
936            }
937    
938            public CalEvent findByCompanyId_First(long companyId,
939                    OrderByComparator orderByComparator)
940                    throws NoSuchEventException, SystemException {
941                    List<CalEvent> list = findByCompanyId(companyId, 0, 1, orderByComparator);
942    
943                    if (list.isEmpty()) {
944                            StringBundler msg = new StringBundler(4);
945    
946                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
947    
948                            msg.append("companyId=");
949                            msg.append(companyId);
950    
951                            msg.append(StringPool.CLOSE_CURLY_BRACE);
952    
953                            throw new NoSuchEventException(msg.toString());
954                    }
955                    else {
956                            return list.get(0);
957                    }
958            }
959    
960            public CalEvent findByCompanyId_Last(long companyId,
961                    OrderByComparator orderByComparator)
962                    throws NoSuchEventException, SystemException {
963                    int count = countByCompanyId(companyId);
964    
965                    List<CalEvent> list = findByCompanyId(companyId, count - 1, count,
966                                    orderByComparator);
967    
968                    if (list.isEmpty()) {
969                            StringBundler msg = new StringBundler(4);
970    
971                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
972    
973                            msg.append("companyId=");
974                            msg.append(companyId);
975    
976                            msg.append(StringPool.CLOSE_CURLY_BRACE);
977    
978                            throw new NoSuchEventException(msg.toString());
979                    }
980                    else {
981                            return list.get(0);
982                    }
983            }
984    
985            public CalEvent[] findByCompanyId_PrevAndNext(long eventId, long companyId,
986                    OrderByComparator orderByComparator)
987                    throws NoSuchEventException, SystemException {
988                    CalEvent calEvent = findByPrimaryKey(eventId);
989    
990                    Session session = null;
991    
992                    try {
993                            session = openSession();
994    
995                            CalEvent[] array = new CalEventImpl[3];
996    
997                            array[0] = getByCompanyId_PrevAndNext(session, calEvent, companyId,
998                                            orderByComparator, true);
999    
1000                            array[1] = calEvent;
1001    
1002                            array[2] = getByCompanyId_PrevAndNext(session, calEvent, companyId,
1003                                            orderByComparator, false);
1004    
1005                            return array;
1006                    }
1007                    catch (Exception e) {
1008                            throw processException(e);
1009                    }
1010                    finally {
1011                            closeSession(session);
1012                    }
1013            }
1014    
1015            protected CalEvent getByCompanyId_PrevAndNext(Session session,
1016                    CalEvent calEvent, long companyId, OrderByComparator orderByComparator,
1017                    boolean previous) {
1018                    StringBundler query = null;
1019    
1020                    if (orderByComparator != null) {
1021                            query = new StringBundler(6 +
1022                                            (orderByComparator.getOrderByFields().length * 6));
1023                    }
1024                    else {
1025                            query = new StringBundler(3);
1026                    }
1027    
1028                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1029    
1030                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1031    
1032                    if (orderByComparator != null) {
1033                            String[] orderByFields = orderByComparator.getOrderByFields();
1034    
1035                            if (orderByFields.length > 0) {
1036                                    query.append(WHERE_AND);
1037                            }
1038    
1039                            for (int i = 0; i < orderByFields.length; i++) {
1040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1041                                    query.append(orderByFields[i]);
1042    
1043                                    if ((i + 1) < orderByFields.length) {
1044                                            if (orderByComparator.isAscending() ^ previous) {
1045                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1046                                            }
1047                                            else {
1048                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1049                                            }
1050                                    }
1051                                    else {
1052                                            if (orderByComparator.isAscending() ^ previous) {
1053                                                    query.append(WHERE_GREATER_THAN);
1054                                            }
1055                                            else {
1056                                                    query.append(WHERE_LESSER_THAN);
1057                                            }
1058                                    }
1059                            }
1060    
1061                            query.append(ORDER_BY_CLAUSE);
1062    
1063                            for (int i = 0; i < orderByFields.length; i++) {
1064                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1065                                    query.append(orderByFields[i]);
1066    
1067                                    if ((i + 1) < orderByFields.length) {
1068                                            if (orderByComparator.isAscending() ^ previous) {
1069                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1070                                            }
1071                                            else {
1072                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1073                                            }
1074                                    }
1075                                    else {
1076                                            if (orderByComparator.isAscending() ^ previous) {
1077                                                    query.append(ORDER_BY_ASC);
1078                                            }
1079                                            else {
1080                                                    query.append(ORDER_BY_DESC);
1081                                            }
1082                                    }
1083                            }
1084                    }
1085    
1086                    else {
1087                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1088                    }
1089    
1090                    String sql = query.toString();
1091    
1092                    Query q = session.createQuery(sql);
1093    
1094                    q.setFirstResult(0);
1095                    q.setMaxResults(2);
1096    
1097                    QueryPos qPos = QueryPos.getInstance(q);
1098    
1099                    qPos.add(companyId);
1100    
1101                    if (orderByComparator != null) {
1102                            Object[] values = orderByComparator.getOrderByValues(calEvent);
1103    
1104                            for (Object value : values) {
1105                                    qPos.add(value);
1106                            }
1107                    }
1108    
1109                    List<CalEvent> list = q.list();
1110    
1111                    if (list.size() == 2) {
1112                            return list.get(1);
1113                    }
1114                    else {
1115                            return null;
1116                    }
1117            }
1118    
1119            public List<CalEvent> findByGroupId(long groupId) throws SystemException {
1120                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1121            }
1122    
1123            public List<CalEvent> findByGroupId(long groupId, int start, int end)
1124                    throws SystemException {
1125                    return findByGroupId(groupId, start, end, null);
1126            }
1127    
1128            public List<CalEvent> findByGroupId(long groupId, int start, int end,
1129                    OrderByComparator orderByComparator) throws SystemException {
1130                    Object[] finderArgs = new Object[] {
1131                                    groupId,
1132                                    
1133                                    String.valueOf(start), String.valueOf(end),
1134                                    String.valueOf(orderByComparator)
1135                            };
1136    
1137                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1138                                    finderArgs, this);
1139    
1140                    if (list == null) {
1141                            Session session = null;
1142    
1143                            try {
1144                                    session = openSession();
1145    
1146                                    StringBundler query = null;
1147    
1148                                    if (orderByComparator != null) {
1149                                            query = new StringBundler(3 +
1150                                                            (orderByComparator.getOrderByFields().length * 3));
1151                                    }
1152                                    else {
1153                                            query = new StringBundler(3);
1154                                    }
1155    
1156                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1157    
1158                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1159    
1160                                    if (orderByComparator != null) {
1161                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1162                                                    orderByComparator);
1163                                    }
1164    
1165                                    else {
1166                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1167                                    }
1168    
1169                                    String sql = query.toString();
1170    
1171                                    Query q = session.createQuery(sql);
1172    
1173                                    QueryPos qPos = QueryPos.getInstance(q);
1174    
1175                                    qPos.add(groupId);
1176    
1177                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1178                                                    end);
1179                            }
1180                            catch (Exception e) {
1181                                    throw processException(e);
1182                            }
1183                            finally {
1184                                    if (list == null) {
1185                                            list = new ArrayList<CalEvent>();
1186                                    }
1187    
1188                                    cacheResult(list);
1189    
1190                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1191                                            finderArgs, list);
1192    
1193                                    closeSession(session);
1194                            }
1195                    }
1196    
1197                    return list;
1198            }
1199    
1200            public CalEvent findByGroupId_First(long groupId,
1201                    OrderByComparator orderByComparator)
1202                    throws NoSuchEventException, SystemException {
1203                    List<CalEvent> list = findByGroupId(groupId, 0, 1, orderByComparator);
1204    
1205                    if (list.isEmpty()) {
1206                            StringBundler msg = new StringBundler(4);
1207    
1208                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1209    
1210                            msg.append("groupId=");
1211                            msg.append(groupId);
1212    
1213                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1214    
1215                            throw new NoSuchEventException(msg.toString());
1216                    }
1217                    else {
1218                            return list.get(0);
1219                    }
1220            }
1221    
1222            public CalEvent findByGroupId_Last(long groupId,
1223                    OrderByComparator orderByComparator)
1224                    throws NoSuchEventException, SystemException {
1225                    int count = countByGroupId(groupId);
1226    
1227                    List<CalEvent> list = findByGroupId(groupId, count - 1, count,
1228                                    orderByComparator);
1229    
1230                    if (list.isEmpty()) {
1231                            StringBundler msg = new StringBundler(4);
1232    
1233                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1234    
1235                            msg.append("groupId=");
1236                            msg.append(groupId);
1237    
1238                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1239    
1240                            throw new NoSuchEventException(msg.toString());
1241                    }
1242                    else {
1243                            return list.get(0);
1244                    }
1245            }
1246    
1247            public CalEvent[] findByGroupId_PrevAndNext(long eventId, long groupId,
1248                    OrderByComparator orderByComparator)
1249                    throws NoSuchEventException, SystemException {
1250                    CalEvent calEvent = findByPrimaryKey(eventId);
1251    
1252                    Session session = null;
1253    
1254                    try {
1255                            session = openSession();
1256    
1257                            CalEvent[] array = new CalEventImpl[3];
1258    
1259                            array[0] = getByGroupId_PrevAndNext(session, calEvent, groupId,
1260                                            orderByComparator, true);
1261    
1262                            array[1] = calEvent;
1263    
1264                            array[2] = getByGroupId_PrevAndNext(session, calEvent, groupId,
1265                                            orderByComparator, false);
1266    
1267                            return array;
1268                    }
1269                    catch (Exception e) {
1270                            throw processException(e);
1271                    }
1272                    finally {
1273                            closeSession(session);
1274                    }
1275            }
1276    
1277            protected CalEvent getByGroupId_PrevAndNext(Session session,
1278                    CalEvent calEvent, long groupId, OrderByComparator orderByComparator,
1279                    boolean previous) {
1280                    StringBundler query = null;
1281    
1282                    if (orderByComparator != null) {
1283                            query = new StringBundler(6 +
1284                                            (orderByComparator.getOrderByFields().length * 6));
1285                    }
1286                    else {
1287                            query = new StringBundler(3);
1288                    }
1289    
1290                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1291    
1292                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1293    
1294                    if (orderByComparator != null) {
1295                            String[] orderByFields = orderByComparator.getOrderByFields();
1296    
1297                            if (orderByFields.length > 0) {
1298                                    query.append(WHERE_AND);
1299                            }
1300    
1301                            for (int i = 0; i < orderByFields.length; i++) {
1302                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1303                                    query.append(orderByFields[i]);
1304    
1305                                    if ((i + 1) < orderByFields.length) {
1306                                            if (orderByComparator.isAscending() ^ previous) {
1307                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1308                                            }
1309                                            else {
1310                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1311                                            }
1312                                    }
1313                                    else {
1314                                            if (orderByComparator.isAscending() ^ previous) {
1315                                                    query.append(WHERE_GREATER_THAN);
1316                                            }
1317                                            else {
1318                                                    query.append(WHERE_LESSER_THAN);
1319                                            }
1320                                    }
1321                            }
1322    
1323                            query.append(ORDER_BY_CLAUSE);
1324    
1325                            for (int i = 0; i < orderByFields.length; i++) {
1326                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1327                                    query.append(orderByFields[i]);
1328    
1329                                    if ((i + 1) < orderByFields.length) {
1330                                            if (orderByComparator.isAscending() ^ previous) {
1331                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1332                                            }
1333                                            else {
1334                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1335                                            }
1336                                    }
1337                                    else {
1338                                            if (orderByComparator.isAscending() ^ previous) {
1339                                                    query.append(ORDER_BY_ASC);
1340                                            }
1341                                            else {
1342                                                    query.append(ORDER_BY_DESC);
1343                                            }
1344                                    }
1345                            }
1346                    }
1347    
1348                    else {
1349                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1350                    }
1351    
1352                    String sql = query.toString();
1353    
1354                    Query q = session.createQuery(sql);
1355    
1356                    q.setFirstResult(0);
1357                    q.setMaxResults(2);
1358    
1359                    QueryPos qPos = QueryPos.getInstance(q);
1360    
1361                    qPos.add(groupId);
1362    
1363                    if (orderByComparator != null) {
1364                            Object[] values = orderByComparator.getOrderByValues(calEvent);
1365    
1366                            for (Object value : values) {
1367                                    qPos.add(value);
1368                            }
1369                    }
1370    
1371                    List<CalEvent> list = q.list();
1372    
1373                    if (list.size() == 2) {
1374                            return list.get(1);
1375                    }
1376                    else {
1377                            return null;
1378                    }
1379            }
1380    
1381            public List<CalEvent> filterFindByGroupId(long groupId)
1382                    throws SystemException {
1383                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1384                            QueryUtil.ALL_POS, null);
1385            }
1386    
1387            public List<CalEvent> filterFindByGroupId(long groupId, int start, int end)
1388                    throws SystemException {
1389                    return filterFindByGroupId(groupId, start, end, null);
1390            }
1391    
1392            public List<CalEvent> filterFindByGroupId(long groupId, int start, int end,
1393                    OrderByComparator orderByComparator) throws SystemException {
1394                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1395                            return findByGroupId(groupId, start, end, orderByComparator);
1396                    }
1397    
1398                    Session session = null;
1399    
1400                    try {
1401                            session = openSession();
1402    
1403                            StringBundler query = null;
1404    
1405                            if (orderByComparator != null) {
1406                                    query = new StringBundler(3 +
1407                                                    (orderByComparator.getOrderByFields().length * 3));
1408                            }
1409                            else {
1410                                    query = new StringBundler(3);
1411                            }
1412    
1413                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
1414    
1415                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1416    
1417                            if (orderByComparator != null) {
1418                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1419                                            orderByComparator);
1420                            }
1421    
1422                            else {
1423                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
1424                            }
1425    
1426                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1427                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
1428                                            _FILTER_COLUMN_USERID, groupId);
1429    
1430                            SQLQuery q = session.createSQLQuery(sql);
1431    
1432                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
1433    
1434                            QueryPos qPos = QueryPos.getInstance(q);
1435    
1436                            qPos.add(groupId);
1437    
1438                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
1439                    }
1440                    catch (Exception e) {
1441                            throw processException(e);
1442                    }
1443                    finally {
1444                            closeSession(session);
1445                    }
1446            }
1447    
1448            public List<CalEvent> findByNotRemindBy(int remindBy)
1449                    throws SystemException {
1450                    return findByNotRemindBy(remindBy, QueryUtil.ALL_POS,
1451                            QueryUtil.ALL_POS, null);
1452            }
1453    
1454            public List<CalEvent> findByNotRemindBy(int remindBy, int start, int end)
1455                    throws SystemException {
1456                    return findByNotRemindBy(remindBy, start, end, null);
1457            }
1458    
1459            public List<CalEvent> findByNotRemindBy(int remindBy, int start, int end,
1460                    OrderByComparator orderByComparator) throws SystemException {
1461                    Object[] finderArgs = new Object[] {
1462                                    remindBy,
1463                                    
1464                                    String.valueOf(start), String.valueOf(end),
1465                                    String.valueOf(orderByComparator)
1466                            };
1467    
1468                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NOTREMINDBY,
1469                                    finderArgs, this);
1470    
1471                    if (list == null) {
1472                            Session session = null;
1473    
1474                            try {
1475                                    session = openSession();
1476    
1477                                    StringBundler query = null;
1478    
1479                                    if (orderByComparator != null) {
1480                                            query = new StringBundler(3 +
1481                                                            (orderByComparator.getOrderByFields().length * 3));
1482                                    }
1483                                    else {
1484                                            query = new StringBundler(3);
1485                                    }
1486    
1487                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1488    
1489                                    query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
1490    
1491                                    if (orderByComparator != null) {
1492                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1493                                                    orderByComparator);
1494                                    }
1495    
1496                                    else {
1497                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1498                                    }
1499    
1500                                    String sql = query.toString();
1501    
1502                                    Query q = session.createQuery(sql);
1503    
1504                                    QueryPos qPos = QueryPos.getInstance(q);
1505    
1506                                    qPos.add(remindBy);
1507    
1508                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1509                                                    end);
1510                            }
1511                            catch (Exception e) {
1512                                    throw processException(e);
1513                            }
1514                            finally {
1515                                    if (list == null) {
1516                                            list = new ArrayList<CalEvent>();
1517                                    }
1518    
1519                                    cacheResult(list);
1520    
1521                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NOTREMINDBY,
1522                                            finderArgs, list);
1523    
1524                                    closeSession(session);
1525                            }
1526                    }
1527    
1528                    return list;
1529            }
1530    
1531            public CalEvent findByNotRemindBy_First(int remindBy,
1532                    OrderByComparator orderByComparator)
1533                    throws NoSuchEventException, SystemException {
1534                    List<CalEvent> list = findByNotRemindBy(remindBy, 0, 1,
1535                                    orderByComparator);
1536    
1537                    if (list.isEmpty()) {
1538                            StringBundler msg = new StringBundler(4);
1539    
1540                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1541    
1542                            msg.append("remindBy=");
1543                            msg.append(remindBy);
1544    
1545                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1546    
1547                            throw new NoSuchEventException(msg.toString());
1548                    }
1549                    else {
1550                            return list.get(0);
1551                    }
1552            }
1553    
1554            public CalEvent findByNotRemindBy_Last(int remindBy,
1555                    OrderByComparator orderByComparator)
1556                    throws NoSuchEventException, SystemException {
1557                    int count = countByNotRemindBy(remindBy);
1558    
1559                    List<CalEvent> list = findByNotRemindBy(remindBy, count - 1, count,
1560                                    orderByComparator);
1561    
1562                    if (list.isEmpty()) {
1563                            StringBundler msg = new StringBundler(4);
1564    
1565                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1566    
1567                            msg.append("remindBy=");
1568                            msg.append(remindBy);
1569    
1570                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1571    
1572                            throw new NoSuchEventException(msg.toString());
1573                    }
1574                    else {
1575                            return list.get(0);
1576                    }
1577            }
1578    
1579            public CalEvent[] findByNotRemindBy_PrevAndNext(long eventId, int remindBy,
1580                    OrderByComparator orderByComparator)
1581                    throws NoSuchEventException, SystemException {
1582                    CalEvent calEvent = findByPrimaryKey(eventId);
1583    
1584                    Session session = null;
1585    
1586                    try {
1587                            session = openSession();
1588    
1589                            CalEvent[] array = new CalEventImpl[3];
1590    
1591                            array[0] = getByNotRemindBy_PrevAndNext(session, calEvent,
1592                                            remindBy, orderByComparator, true);
1593    
1594                            array[1] = calEvent;
1595    
1596                            array[2] = getByNotRemindBy_PrevAndNext(session, calEvent,
1597                                            remindBy, orderByComparator, false);
1598    
1599                            return array;
1600                    }
1601                    catch (Exception e) {
1602                            throw processException(e);
1603                    }
1604                    finally {
1605                            closeSession(session);
1606                    }
1607            }
1608    
1609            protected CalEvent getByNotRemindBy_PrevAndNext(Session session,
1610                    CalEvent calEvent, int remindBy, OrderByComparator orderByComparator,
1611                    boolean previous) {
1612                    StringBundler query = null;
1613    
1614                    if (orderByComparator != null) {
1615                            query = new StringBundler(6 +
1616                                            (orderByComparator.getOrderByFields().length * 6));
1617                    }
1618                    else {
1619                            query = new StringBundler(3);
1620                    }
1621    
1622                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1623    
1624                    query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
1625    
1626                    if (orderByComparator != null) {
1627                            String[] orderByFields = orderByComparator.getOrderByFields();
1628    
1629                            if (orderByFields.length > 0) {
1630                                    query.append(WHERE_AND);
1631                            }
1632    
1633                            for (int i = 0; i < orderByFields.length; i++) {
1634                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1635                                    query.append(orderByFields[i]);
1636    
1637                                    if ((i + 1) < orderByFields.length) {
1638                                            if (orderByComparator.isAscending() ^ previous) {
1639                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1640                                            }
1641                                            else {
1642                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1643                                            }
1644                                    }
1645                                    else {
1646                                            if (orderByComparator.isAscending() ^ previous) {
1647                                                    query.append(WHERE_GREATER_THAN);
1648                                            }
1649                                            else {
1650                                                    query.append(WHERE_LESSER_THAN);
1651                                            }
1652                                    }
1653                            }
1654    
1655                            query.append(ORDER_BY_CLAUSE);
1656    
1657                            for (int i = 0; i < orderByFields.length; i++) {
1658                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1659                                    query.append(orderByFields[i]);
1660    
1661                                    if ((i + 1) < orderByFields.length) {
1662                                            if (orderByComparator.isAscending() ^ previous) {
1663                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1664                                            }
1665                                            else {
1666                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1667                                            }
1668                                    }
1669                                    else {
1670                                            if (orderByComparator.isAscending() ^ previous) {
1671                                                    query.append(ORDER_BY_ASC);
1672                                            }
1673                                            else {
1674                                                    query.append(ORDER_BY_DESC);
1675                                            }
1676                                    }
1677                            }
1678                    }
1679    
1680                    else {
1681                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1682                    }
1683    
1684                    String sql = query.toString();
1685    
1686                    Query q = session.createQuery(sql);
1687    
1688                    q.setFirstResult(0);
1689                    q.setMaxResults(2);
1690    
1691                    QueryPos qPos = QueryPos.getInstance(q);
1692    
1693                    qPos.add(remindBy);
1694    
1695                    if (orderByComparator != null) {
1696                            Object[] values = orderByComparator.getOrderByValues(calEvent);
1697    
1698                            for (Object value : values) {
1699                                    qPos.add(value);
1700                            }
1701                    }
1702    
1703                    List<CalEvent> list = q.list();
1704    
1705                    if (list.size() == 2) {
1706                            return list.get(1);
1707                    }
1708                    else {
1709                            return null;
1710                    }
1711            }
1712    
1713            public List<CalEvent> findByG_T(long groupId, String type)
1714                    throws SystemException {
1715                    return findByG_T(groupId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1716                            null);
1717            }
1718    
1719            public List<CalEvent> findByG_T(long groupId, String type, int start,
1720                    int end) throws SystemException {
1721                    return findByG_T(groupId, type, start, end, null);
1722            }
1723    
1724            public List<CalEvent> findByG_T(long groupId, String type, int start,
1725                    int end, OrderByComparator orderByComparator) throws SystemException {
1726                    Object[] finderArgs = new Object[] {
1727                                    groupId, type,
1728                                    
1729                                    String.valueOf(start), String.valueOf(end),
1730                                    String.valueOf(orderByComparator)
1731                            };
1732    
1733                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_T,
1734                                    finderArgs, this);
1735    
1736                    if (list == null) {
1737                            Session session = null;
1738    
1739                            try {
1740                                    session = openSession();
1741    
1742                                    StringBundler query = null;
1743    
1744                                    if (orderByComparator != null) {
1745                                            query = new StringBundler(4 +
1746                                                            (orderByComparator.getOrderByFields().length * 3));
1747                                    }
1748                                    else {
1749                                            query = new StringBundler(4);
1750                                    }
1751    
1752                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1753    
1754                                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
1755    
1756                                    if (type == null) {
1757                                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
1758                                    }
1759                                    else {
1760                                            if (type.equals(StringPool.BLANK)) {
1761                                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
1762                                            }
1763                                            else {
1764                                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
1765                                            }
1766                                    }
1767    
1768                                    if (orderByComparator != null) {
1769                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1770                                                    orderByComparator);
1771                                    }
1772    
1773                                    else {
1774                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1775                                    }
1776    
1777                                    String sql = query.toString();
1778    
1779                                    Query q = session.createQuery(sql);
1780    
1781                                    QueryPos qPos = QueryPos.getInstance(q);
1782    
1783                                    qPos.add(groupId);
1784    
1785                                    if (type != null) {
1786                                            qPos.add(type);
1787                                    }
1788    
1789                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
1790                                                    end);
1791                            }
1792                            catch (Exception e) {
1793                                    throw processException(e);
1794                            }
1795                            finally {
1796                                    if (list == null) {
1797                                            list = new ArrayList<CalEvent>();
1798                                    }
1799    
1800                                    cacheResult(list);
1801    
1802                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_T, finderArgs,
1803                                            list);
1804    
1805                                    closeSession(session);
1806                            }
1807                    }
1808    
1809                    return list;
1810            }
1811    
1812            public CalEvent findByG_T_First(long groupId, String type,
1813                    OrderByComparator orderByComparator)
1814                    throws NoSuchEventException, SystemException {
1815                    List<CalEvent> list = findByG_T(groupId, type, 0, 1, orderByComparator);
1816    
1817                    if (list.isEmpty()) {
1818                            StringBundler msg = new StringBundler(6);
1819    
1820                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1821    
1822                            msg.append("groupId=");
1823                            msg.append(groupId);
1824    
1825                            msg.append(", type=");
1826                            msg.append(type);
1827    
1828                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1829    
1830                            throw new NoSuchEventException(msg.toString());
1831                    }
1832                    else {
1833                            return list.get(0);
1834                    }
1835            }
1836    
1837            public CalEvent findByG_T_Last(long groupId, String type,
1838                    OrderByComparator orderByComparator)
1839                    throws NoSuchEventException, SystemException {
1840                    int count = countByG_T(groupId, type);
1841    
1842                    List<CalEvent> list = findByG_T(groupId, type, count - 1, count,
1843                                    orderByComparator);
1844    
1845                    if (list.isEmpty()) {
1846                            StringBundler msg = new StringBundler(6);
1847    
1848                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1849    
1850                            msg.append("groupId=");
1851                            msg.append(groupId);
1852    
1853                            msg.append(", type=");
1854                            msg.append(type);
1855    
1856                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1857    
1858                            throw new NoSuchEventException(msg.toString());
1859                    }
1860                    else {
1861                            return list.get(0);
1862                    }
1863            }
1864    
1865            public CalEvent[] findByG_T_PrevAndNext(long eventId, long groupId,
1866                    String type, OrderByComparator orderByComparator)
1867                    throws NoSuchEventException, SystemException {
1868                    CalEvent calEvent = findByPrimaryKey(eventId);
1869    
1870                    Session session = null;
1871    
1872                    try {
1873                            session = openSession();
1874    
1875                            CalEvent[] array = new CalEventImpl[3];
1876    
1877                            array[0] = getByG_T_PrevAndNext(session, calEvent, groupId, type,
1878                                            orderByComparator, true);
1879    
1880                            array[1] = calEvent;
1881    
1882                            array[2] = getByG_T_PrevAndNext(session, calEvent, groupId, type,
1883                                            orderByComparator, false);
1884    
1885                            return array;
1886                    }
1887                    catch (Exception e) {
1888                            throw processException(e);
1889                    }
1890                    finally {
1891                            closeSession(session);
1892                    }
1893            }
1894    
1895            protected CalEvent getByG_T_PrevAndNext(Session session, CalEvent calEvent,
1896                    long groupId, String type, OrderByComparator orderByComparator,
1897                    boolean previous) {
1898                    StringBundler query = null;
1899    
1900                    if (orderByComparator != null) {
1901                            query = new StringBundler(6 +
1902                                            (orderByComparator.getOrderByFields().length * 6));
1903                    }
1904                    else {
1905                            query = new StringBundler(3);
1906                    }
1907    
1908                    query.append(_SQL_SELECT_CALEVENT_WHERE);
1909    
1910                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
1911    
1912                    if (type == null) {
1913                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
1914                    }
1915                    else {
1916                            if (type.equals(StringPool.BLANK)) {
1917                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
1918                            }
1919                            else {
1920                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
1921                            }
1922                    }
1923    
1924                    if (orderByComparator != null) {
1925                            String[] orderByFields = orderByComparator.getOrderByFields();
1926    
1927                            if (orderByFields.length > 0) {
1928                                    query.append(WHERE_AND);
1929                            }
1930    
1931                            for (int i = 0; i < orderByFields.length; i++) {
1932                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1933                                    query.append(orderByFields[i]);
1934    
1935                                    if ((i + 1) < orderByFields.length) {
1936                                            if (orderByComparator.isAscending() ^ previous) {
1937                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1938                                            }
1939                                            else {
1940                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1941                                            }
1942                                    }
1943                                    else {
1944                                            if (orderByComparator.isAscending() ^ previous) {
1945                                                    query.append(WHERE_GREATER_THAN);
1946                                            }
1947                                            else {
1948                                                    query.append(WHERE_LESSER_THAN);
1949                                            }
1950                                    }
1951                            }
1952    
1953                            query.append(ORDER_BY_CLAUSE);
1954    
1955                            for (int i = 0; i < orderByFields.length; i++) {
1956                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1957                                    query.append(orderByFields[i]);
1958    
1959                                    if ((i + 1) < orderByFields.length) {
1960                                            if (orderByComparator.isAscending() ^ previous) {
1961                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1962                                            }
1963                                            else {
1964                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1965                                            }
1966                                    }
1967                                    else {
1968                                            if (orderByComparator.isAscending() ^ previous) {
1969                                                    query.append(ORDER_BY_ASC);
1970                                            }
1971                                            else {
1972                                                    query.append(ORDER_BY_DESC);
1973                                            }
1974                                    }
1975                            }
1976                    }
1977    
1978                    else {
1979                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
1980                    }
1981    
1982                    String sql = query.toString();
1983    
1984                    Query q = session.createQuery(sql);
1985    
1986                    q.setFirstResult(0);
1987                    q.setMaxResults(2);
1988    
1989                    QueryPos qPos = QueryPos.getInstance(q);
1990    
1991                    qPos.add(groupId);
1992    
1993                    if (type != null) {
1994                            qPos.add(type);
1995                    }
1996    
1997                    if (orderByComparator != null) {
1998                            Object[] values = orderByComparator.getOrderByValues(calEvent);
1999    
2000                            for (Object value : values) {
2001                                    qPos.add(value);
2002                            }
2003                    }
2004    
2005                    List<CalEvent> list = q.list();
2006    
2007                    if (list.size() == 2) {
2008                            return list.get(1);
2009                    }
2010                    else {
2011                            return null;
2012                    }
2013            }
2014    
2015            public List<CalEvent> filterFindByG_T(long groupId, String type)
2016                    throws SystemException {
2017                    return filterFindByG_T(groupId, type, QueryUtil.ALL_POS,
2018                            QueryUtil.ALL_POS, null);
2019            }
2020    
2021            public List<CalEvent> filterFindByG_T(long groupId, String type, int start,
2022                    int end) throws SystemException {
2023                    return filterFindByG_T(groupId, type, start, end, null);
2024            }
2025    
2026            public List<CalEvent> filterFindByG_T(long groupId, String type, int start,
2027                    int end, OrderByComparator orderByComparator) throws SystemException {
2028                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2029                            return findByG_T(groupId, type, start, end, orderByComparator);
2030                    }
2031    
2032                    Session session = null;
2033    
2034                    try {
2035                            session = openSession();
2036    
2037                            StringBundler query = null;
2038    
2039                            if (orderByComparator != null) {
2040                                    query = new StringBundler(4 +
2041                                                    (orderByComparator.getOrderByFields().length * 3));
2042                            }
2043                            else {
2044                                    query = new StringBundler(4);
2045                            }
2046    
2047                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
2048    
2049                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2050    
2051                            if (type == null) {
2052                                    query.append(_FINDER_COLUMN_G_T_TYPE_1);
2053                            }
2054                            else {
2055                                    if (type.equals(StringPool.BLANK)) {
2056                                            query.append(_FINDER_COLUMN_G_T_TYPE_3);
2057                                    }
2058                                    else {
2059                                            query.append(_FINDER_COLUMN_G_T_TYPE_2);
2060                                    }
2061                            }
2062    
2063                            if (orderByComparator != null) {
2064                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2065                                            orderByComparator);
2066                            }
2067    
2068                            else {
2069                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
2070                            }
2071    
2072                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2073                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
2074                                            _FILTER_COLUMN_USERID, groupId);
2075    
2076                            SQLQuery q = session.createSQLQuery(sql);
2077    
2078                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
2079    
2080                            QueryPos qPos = QueryPos.getInstance(q);
2081    
2082                            qPos.add(groupId);
2083    
2084                            if (type != null) {
2085                                    qPos.add(type);
2086                            }
2087    
2088                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
2089                    }
2090                    catch (Exception e) {
2091                            throw processException(e);
2092                    }
2093                    finally {
2094                            closeSession(session);
2095                    }
2096            }
2097    
2098            public List<CalEvent> findByG_R(long groupId, boolean repeating)
2099                    throws SystemException {
2100                    return findByG_R(groupId, repeating, QueryUtil.ALL_POS,
2101                            QueryUtil.ALL_POS, null);
2102            }
2103    
2104            public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
2105                    int end) throws SystemException {
2106                    return findByG_R(groupId, repeating, start, end, null);
2107            }
2108    
2109            public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
2110                    int end, OrderByComparator orderByComparator) throws SystemException {
2111                    Object[] finderArgs = new Object[] {
2112                                    groupId, repeating,
2113                                    
2114                                    String.valueOf(start), String.valueOf(end),
2115                                    String.valueOf(orderByComparator)
2116                            };
2117    
2118                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_R,
2119                                    finderArgs, this);
2120    
2121                    if (list == null) {
2122                            Session session = null;
2123    
2124                            try {
2125                                    session = openSession();
2126    
2127                                    StringBundler query = null;
2128    
2129                                    if (orderByComparator != null) {
2130                                            query = new StringBundler(4 +
2131                                                            (orderByComparator.getOrderByFields().length * 3));
2132                                    }
2133                                    else {
2134                                            query = new StringBundler(4);
2135                                    }
2136    
2137                                    query.append(_SQL_SELECT_CALEVENT_WHERE);
2138    
2139                                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2140    
2141                                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
2142    
2143                                    if (orderByComparator != null) {
2144                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2145                                                    orderByComparator);
2146                                    }
2147    
2148                                    else {
2149                                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2150                                    }
2151    
2152                                    String sql = query.toString();
2153    
2154                                    Query q = session.createQuery(sql);
2155    
2156                                    QueryPos qPos = QueryPos.getInstance(q);
2157    
2158                                    qPos.add(groupId);
2159    
2160                                    qPos.add(repeating);
2161    
2162                                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(), start,
2163                                                    end);
2164                            }
2165                            catch (Exception e) {
2166                                    throw processException(e);
2167                            }
2168                            finally {
2169                                    if (list == null) {
2170                                            list = new ArrayList<CalEvent>();
2171                                    }
2172    
2173                                    cacheResult(list);
2174    
2175                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_R, finderArgs,
2176                                            list);
2177    
2178                                    closeSession(session);
2179                            }
2180                    }
2181    
2182                    return list;
2183            }
2184    
2185            public CalEvent findByG_R_First(long groupId, boolean repeating,
2186                    OrderByComparator orderByComparator)
2187                    throws NoSuchEventException, SystemException {
2188                    List<CalEvent> list = findByG_R(groupId, repeating, 0, 1,
2189                                    orderByComparator);
2190    
2191                    if (list.isEmpty()) {
2192                            StringBundler msg = new StringBundler(6);
2193    
2194                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2195    
2196                            msg.append("groupId=");
2197                            msg.append(groupId);
2198    
2199                            msg.append(", repeating=");
2200                            msg.append(repeating);
2201    
2202                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2203    
2204                            throw new NoSuchEventException(msg.toString());
2205                    }
2206                    else {
2207                            return list.get(0);
2208                    }
2209            }
2210    
2211            public CalEvent findByG_R_Last(long groupId, boolean repeating,
2212                    OrderByComparator orderByComparator)
2213                    throws NoSuchEventException, SystemException {
2214                    int count = countByG_R(groupId, repeating);
2215    
2216                    List<CalEvent> list = findByG_R(groupId, repeating, count - 1, count,
2217                                    orderByComparator);
2218    
2219                    if (list.isEmpty()) {
2220                            StringBundler msg = new StringBundler(6);
2221    
2222                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2223    
2224                            msg.append("groupId=");
2225                            msg.append(groupId);
2226    
2227                            msg.append(", repeating=");
2228                            msg.append(repeating);
2229    
2230                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2231    
2232                            throw new NoSuchEventException(msg.toString());
2233                    }
2234                    else {
2235                            return list.get(0);
2236                    }
2237            }
2238    
2239            public CalEvent[] findByG_R_PrevAndNext(long eventId, long groupId,
2240                    boolean repeating, OrderByComparator orderByComparator)
2241                    throws NoSuchEventException, SystemException {
2242                    CalEvent calEvent = findByPrimaryKey(eventId);
2243    
2244                    Session session = null;
2245    
2246                    try {
2247                            session = openSession();
2248    
2249                            CalEvent[] array = new CalEventImpl[3];
2250    
2251                            array[0] = getByG_R_PrevAndNext(session, calEvent, groupId,
2252                                            repeating, orderByComparator, true);
2253    
2254                            array[1] = calEvent;
2255    
2256                            array[2] = getByG_R_PrevAndNext(session, calEvent, groupId,
2257                                            repeating, orderByComparator, false);
2258    
2259                            return array;
2260                    }
2261                    catch (Exception e) {
2262                            throw processException(e);
2263                    }
2264                    finally {
2265                            closeSession(session);
2266                    }
2267            }
2268    
2269            protected CalEvent getByG_R_PrevAndNext(Session session, CalEvent calEvent,
2270                    long groupId, boolean repeating, OrderByComparator orderByComparator,
2271                    boolean previous) {
2272                    StringBundler query = null;
2273    
2274                    if (orderByComparator != null) {
2275                            query = new StringBundler(6 +
2276                                            (orderByComparator.getOrderByFields().length * 6));
2277                    }
2278                    else {
2279                            query = new StringBundler(3);
2280                    }
2281    
2282                    query.append(_SQL_SELECT_CALEVENT_WHERE);
2283    
2284                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2285    
2286                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
2287    
2288                    if (orderByComparator != null) {
2289                            String[] orderByFields = orderByComparator.getOrderByFields();
2290    
2291                            if (orderByFields.length > 0) {
2292                                    query.append(WHERE_AND);
2293                            }
2294    
2295                            for (int i = 0; i < orderByFields.length; i++) {
2296                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2297                                    query.append(orderByFields[i]);
2298    
2299                                    if ((i + 1) < orderByFields.length) {
2300                                            if (orderByComparator.isAscending() ^ previous) {
2301                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2302                                            }
2303                                            else {
2304                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2305                                            }
2306                                    }
2307                                    else {
2308                                            if (orderByComparator.isAscending() ^ previous) {
2309                                                    query.append(WHERE_GREATER_THAN);
2310                                            }
2311                                            else {
2312                                                    query.append(WHERE_LESSER_THAN);
2313                                            }
2314                                    }
2315                            }
2316    
2317                            query.append(ORDER_BY_CLAUSE);
2318    
2319                            for (int i = 0; i < orderByFields.length; i++) {
2320                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2321                                    query.append(orderByFields[i]);
2322    
2323                                    if ((i + 1) < orderByFields.length) {
2324                                            if (orderByComparator.isAscending() ^ previous) {
2325                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2326                                            }
2327                                            else {
2328                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2329                                            }
2330                                    }
2331                                    else {
2332                                            if (orderByComparator.isAscending() ^ previous) {
2333                                                    query.append(ORDER_BY_ASC);
2334                                            }
2335                                            else {
2336                                                    query.append(ORDER_BY_DESC);
2337                                            }
2338                                    }
2339                            }
2340                    }
2341    
2342                    else {
2343                            query.append(CalEventModelImpl.ORDER_BY_JPQL);
2344                    }
2345    
2346                    String sql = query.toString();
2347    
2348                    Query q = session.createQuery(sql);
2349    
2350                    q.setFirstResult(0);
2351                    q.setMaxResults(2);
2352    
2353                    QueryPos qPos = QueryPos.getInstance(q);
2354    
2355                    qPos.add(groupId);
2356    
2357                    qPos.add(repeating);
2358    
2359                    if (orderByComparator != null) {
2360                            Object[] values = orderByComparator.getOrderByValues(calEvent);
2361    
2362                            for (Object value : values) {
2363                                    qPos.add(value);
2364                            }
2365                    }
2366    
2367                    List<CalEvent> list = q.list();
2368    
2369                    if (list.size() == 2) {
2370                            return list.get(1);
2371                    }
2372                    else {
2373                            return null;
2374                    }
2375            }
2376    
2377            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating)
2378                    throws SystemException {
2379                    return filterFindByG_R(groupId, repeating, QueryUtil.ALL_POS,
2380                            QueryUtil.ALL_POS, null);
2381            }
2382    
2383            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating,
2384                    int start, int end) throws SystemException {
2385                    return filterFindByG_R(groupId, repeating, start, end, null);
2386            }
2387    
2388            public List<CalEvent> filterFindByG_R(long groupId, boolean repeating,
2389                    int start, int end, OrderByComparator orderByComparator)
2390                    throws SystemException {
2391                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2392                            return findByG_R(groupId, repeating, start, end, orderByComparator);
2393                    }
2394    
2395                    Session session = null;
2396    
2397                    try {
2398                            session = openSession();
2399    
2400                            StringBundler query = null;
2401    
2402                            if (orderByComparator != null) {
2403                                    query = new StringBundler(4 +
2404                                                    (orderByComparator.getOrderByFields().length * 3));
2405                            }
2406                            else {
2407                                    query = new StringBundler(4);
2408                            }
2409    
2410                            query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
2411    
2412                            query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2413    
2414                            query.append(_FINDER_COLUMN_G_R_REPEATING_2);
2415    
2416                            if (orderByComparator != null) {
2417                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2418                                            orderByComparator);
2419                            }
2420    
2421                            else {
2422                                    query.append(CalEventModelImpl.ORDER_BY_JPQL);
2423                            }
2424    
2425                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2426                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
2427                                            _FILTER_COLUMN_USERID, groupId);
2428    
2429                            SQLQuery q = session.createSQLQuery(sql);
2430    
2431                            q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
2432    
2433                            QueryPos qPos = QueryPos.getInstance(q);
2434    
2435                            qPos.add(groupId);
2436    
2437                            qPos.add(repeating);
2438    
2439                            return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
2440                    }
2441                    catch (Exception e) {
2442                            throw processException(e);
2443                    }
2444                    finally {
2445                            closeSession(session);
2446                    }
2447            }
2448    
2449            public List<CalEvent> findAll() throws SystemException {
2450                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2451            }
2452    
2453            public List<CalEvent> findAll(int start, int end) throws SystemException {
2454                    return findAll(start, end, null);
2455            }
2456    
2457            public List<CalEvent> findAll(int start, int end,
2458                    OrderByComparator orderByComparator) throws SystemException {
2459                    Object[] finderArgs = new Object[] {
2460                                    String.valueOf(start), String.valueOf(end),
2461                                    String.valueOf(orderByComparator)
2462                            };
2463    
2464                    List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2465                                    finderArgs, this);
2466    
2467                    if (list == null) {
2468                            Session session = null;
2469    
2470                            try {
2471                                    session = openSession();
2472    
2473                                    StringBundler query = null;
2474                                    String sql = null;
2475    
2476                                    if (orderByComparator != null) {
2477                                            query = new StringBundler(2 +
2478                                                            (orderByComparator.getOrderByFields().length * 3));
2479    
2480                                            query.append(_SQL_SELECT_CALEVENT);
2481    
2482                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2483                                                    orderByComparator);
2484    
2485                                            sql = query.toString();
2486                                    }
2487                                    else {
2488                                            sql = _SQL_SELECT_CALEVENT.concat(CalEventModelImpl.ORDER_BY_JPQL);
2489                                    }
2490    
2491                                    Query q = session.createQuery(sql);
2492    
2493                                    if (orderByComparator == null) {
2494                                            list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
2495                                                            start, end, false);
2496    
2497                                            Collections.sort(list);
2498                                    }
2499                                    else {
2500                                            list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
2501                                                            start, end);
2502                                    }
2503                            }
2504                            catch (Exception e) {
2505                                    throw processException(e);
2506                            }
2507                            finally {
2508                                    if (list == null) {
2509                                            list = new ArrayList<CalEvent>();
2510                                    }
2511    
2512                                    cacheResult(list);
2513    
2514                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2515    
2516                                    closeSession(session);
2517                            }
2518                    }
2519    
2520                    return list;
2521            }
2522    
2523            public void removeByUuid(String uuid) throws SystemException {
2524                    for (CalEvent calEvent : findByUuid(uuid)) {
2525                            remove(calEvent);
2526                    }
2527            }
2528    
2529            public void removeByUUID_G(String uuid, long groupId)
2530                    throws NoSuchEventException, SystemException {
2531                    CalEvent calEvent = findByUUID_G(uuid, groupId);
2532    
2533                    remove(calEvent);
2534            }
2535    
2536            public void removeByCompanyId(long companyId) throws SystemException {
2537                    for (CalEvent calEvent : findByCompanyId(companyId)) {
2538                            remove(calEvent);
2539                    }
2540            }
2541    
2542            public void removeByGroupId(long groupId) throws SystemException {
2543                    for (CalEvent calEvent : findByGroupId(groupId)) {
2544                            remove(calEvent);
2545                    }
2546            }
2547    
2548            public void removeByNotRemindBy(int remindBy) throws SystemException {
2549                    for (CalEvent calEvent : findByNotRemindBy(remindBy)) {
2550                            remove(calEvent);
2551                    }
2552            }
2553    
2554            public void removeByG_T(long groupId, String type)
2555                    throws SystemException {
2556                    for (CalEvent calEvent : findByG_T(groupId, type)) {
2557                            remove(calEvent);
2558                    }
2559            }
2560    
2561            public void removeByG_R(long groupId, boolean repeating)
2562                    throws SystemException {
2563                    for (CalEvent calEvent : findByG_R(groupId, repeating)) {
2564                            remove(calEvent);
2565                    }
2566            }
2567    
2568            public void removeAll() throws SystemException {
2569                    for (CalEvent calEvent : findAll()) {
2570                            remove(calEvent);
2571                    }
2572            }
2573    
2574            public int countByUuid(String uuid) throws SystemException {
2575                    Object[] finderArgs = new Object[] { uuid };
2576    
2577                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2578                                    finderArgs, this);
2579    
2580                    if (count == null) {
2581                            Session session = null;
2582    
2583                            try {
2584                                    session = openSession();
2585    
2586                                    StringBundler query = new StringBundler(2);
2587    
2588                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
2589    
2590                                    if (uuid == null) {
2591                                            query.append(_FINDER_COLUMN_UUID_UUID_1);
2592                                    }
2593                                    else {
2594                                            if (uuid.equals(StringPool.BLANK)) {
2595                                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
2596                                            }
2597                                            else {
2598                                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
2599                                            }
2600                                    }
2601    
2602                                    String sql = query.toString();
2603    
2604                                    Query q = session.createQuery(sql);
2605    
2606                                    QueryPos qPos = QueryPos.getInstance(q);
2607    
2608                                    if (uuid != null) {
2609                                            qPos.add(uuid);
2610                                    }
2611    
2612                                    count = (Long)q.uniqueResult();
2613                            }
2614                            catch (Exception e) {
2615                                    throw processException(e);
2616                            }
2617                            finally {
2618                                    if (count == null) {
2619                                            count = Long.valueOf(0);
2620                                    }
2621    
2622                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2623                                            finderArgs, count);
2624    
2625                                    closeSession(session);
2626                            }
2627                    }
2628    
2629                    return count.intValue();
2630            }
2631    
2632            public int countByUUID_G(String uuid, long groupId)
2633                    throws SystemException {
2634                    Object[] finderArgs = new Object[] { uuid, groupId };
2635    
2636                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2637                                    finderArgs, this);
2638    
2639                    if (count == null) {
2640                            Session session = null;
2641    
2642                            try {
2643                                    session = openSession();
2644    
2645                                    StringBundler query = new StringBundler(3);
2646    
2647                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
2648    
2649                                    if (uuid == null) {
2650                                            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2651                                    }
2652                                    else {
2653                                            if (uuid.equals(StringPool.BLANK)) {
2654                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2655                                            }
2656                                            else {
2657                                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2658                                            }
2659                                    }
2660    
2661                                    query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2662    
2663                                    String sql = query.toString();
2664    
2665                                    Query q = session.createQuery(sql);
2666    
2667                                    QueryPos qPos = QueryPos.getInstance(q);
2668    
2669                                    if (uuid != null) {
2670                                            qPos.add(uuid);
2671                                    }
2672    
2673                                    qPos.add(groupId);
2674    
2675                                    count = (Long)q.uniqueResult();
2676                            }
2677                            catch (Exception e) {
2678                                    throw processException(e);
2679                            }
2680                            finally {
2681                                    if (count == null) {
2682                                            count = Long.valueOf(0);
2683                                    }
2684    
2685                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2686                                            finderArgs, count);
2687    
2688                                    closeSession(session);
2689                            }
2690                    }
2691    
2692                    return count.intValue();
2693            }
2694    
2695            public int countByCompanyId(long companyId) throws SystemException {
2696                    Object[] finderArgs = new Object[] { companyId };
2697    
2698                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2699                                    finderArgs, this);
2700    
2701                    if (count == null) {
2702                            Session session = null;
2703    
2704                            try {
2705                                    session = openSession();
2706    
2707                                    StringBundler query = new StringBundler(2);
2708    
2709                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
2710    
2711                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2712    
2713                                    String sql = query.toString();
2714    
2715                                    Query q = session.createQuery(sql);
2716    
2717                                    QueryPos qPos = QueryPos.getInstance(q);
2718    
2719                                    qPos.add(companyId);
2720    
2721                                    count = (Long)q.uniqueResult();
2722                            }
2723                            catch (Exception e) {
2724                                    throw processException(e);
2725                            }
2726                            finally {
2727                                    if (count == null) {
2728                                            count = Long.valueOf(0);
2729                                    }
2730    
2731                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2732                                            finderArgs, count);
2733    
2734                                    closeSession(session);
2735                            }
2736                    }
2737    
2738                    return count.intValue();
2739            }
2740    
2741            public int countByGroupId(long groupId) throws SystemException {
2742                    Object[] finderArgs = new Object[] { groupId };
2743    
2744                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2745                                    finderArgs, this);
2746    
2747                    if (count == null) {
2748                            Session session = null;
2749    
2750                            try {
2751                                    session = openSession();
2752    
2753                                    StringBundler query = new StringBundler(2);
2754    
2755                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
2756    
2757                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2758    
2759                                    String sql = query.toString();
2760    
2761                                    Query q = session.createQuery(sql);
2762    
2763                                    QueryPos qPos = QueryPos.getInstance(q);
2764    
2765                                    qPos.add(groupId);
2766    
2767                                    count = (Long)q.uniqueResult();
2768                            }
2769                            catch (Exception e) {
2770                                    throw processException(e);
2771                            }
2772                            finally {
2773                                    if (count == null) {
2774                                            count = Long.valueOf(0);
2775                                    }
2776    
2777                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2778                                            finderArgs, count);
2779    
2780                                    closeSession(session);
2781                            }
2782                    }
2783    
2784                    return count.intValue();
2785            }
2786    
2787            public int filterCountByGroupId(long groupId) throws SystemException {
2788                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2789                            return countByGroupId(groupId);
2790                    }
2791    
2792                    Session session = null;
2793    
2794                    try {
2795                            session = openSession();
2796    
2797                            StringBundler query = new StringBundler(2);
2798    
2799                            query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
2800    
2801                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2802    
2803                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2804                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
2805                                            _FILTER_COLUMN_USERID, groupId);
2806    
2807                            SQLQuery q = session.createSQLQuery(sql);
2808    
2809                            q.addScalar(COUNT_COLUMN_NAME,
2810                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2811    
2812                            QueryPos qPos = QueryPos.getInstance(q);
2813    
2814                            qPos.add(groupId);
2815    
2816                            Long count = (Long)q.uniqueResult();
2817    
2818                            return count.intValue();
2819                    }
2820                    catch (Exception e) {
2821                            throw processException(e);
2822                    }
2823                    finally {
2824                            closeSession(session);
2825                    }
2826            }
2827    
2828            public int countByNotRemindBy(int remindBy) throws SystemException {
2829                    Object[] finderArgs = new Object[] { remindBy };
2830    
2831                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NOTREMINDBY,
2832                                    finderArgs, this);
2833    
2834                    if (count == null) {
2835                            Session session = null;
2836    
2837                            try {
2838                                    session = openSession();
2839    
2840                                    StringBundler query = new StringBundler(2);
2841    
2842                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
2843    
2844                                    query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
2845    
2846                                    String sql = query.toString();
2847    
2848                                    Query q = session.createQuery(sql);
2849    
2850                                    QueryPos qPos = QueryPos.getInstance(q);
2851    
2852                                    qPos.add(remindBy);
2853    
2854                                    count = (Long)q.uniqueResult();
2855                            }
2856                            catch (Exception e) {
2857                                    throw processException(e);
2858                            }
2859                            finally {
2860                                    if (count == null) {
2861                                            count = Long.valueOf(0);
2862                                    }
2863    
2864                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NOTREMINDBY,
2865                                            finderArgs, count);
2866    
2867                                    closeSession(session);
2868                            }
2869                    }
2870    
2871                    return count.intValue();
2872            }
2873    
2874            public int countByG_T(long groupId, String type) throws SystemException {
2875                    Object[] finderArgs = new Object[] { groupId, type };
2876    
2877                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_T,
2878                                    finderArgs, this);
2879    
2880                    if (count == null) {
2881                            Session session = null;
2882    
2883                            try {
2884                                    session = openSession();
2885    
2886                                    StringBundler query = new StringBundler(3);
2887    
2888                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
2889    
2890                                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2891    
2892                                    if (type == null) {
2893                                            query.append(_FINDER_COLUMN_G_T_TYPE_1);
2894                                    }
2895                                    else {
2896                                            if (type.equals(StringPool.BLANK)) {
2897                                                    query.append(_FINDER_COLUMN_G_T_TYPE_3);
2898                                            }
2899                                            else {
2900                                                    query.append(_FINDER_COLUMN_G_T_TYPE_2);
2901                                            }
2902                                    }
2903    
2904                                    String sql = query.toString();
2905    
2906                                    Query q = session.createQuery(sql);
2907    
2908                                    QueryPos qPos = QueryPos.getInstance(q);
2909    
2910                                    qPos.add(groupId);
2911    
2912                                    if (type != null) {
2913                                            qPos.add(type);
2914                                    }
2915    
2916                                    count = (Long)q.uniqueResult();
2917                            }
2918                            catch (Exception e) {
2919                                    throw processException(e);
2920                            }
2921                            finally {
2922                                    if (count == null) {
2923                                            count = Long.valueOf(0);
2924                                    }
2925    
2926                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_T, finderArgs,
2927                                            count);
2928    
2929                                    closeSession(session);
2930                            }
2931                    }
2932    
2933                    return count.intValue();
2934            }
2935    
2936            public int filterCountByG_T(long groupId, String type)
2937                    throws SystemException {
2938                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2939                            return countByG_T(groupId, type);
2940                    }
2941    
2942                    Session session = null;
2943    
2944                    try {
2945                            session = openSession();
2946    
2947                            StringBundler query = new StringBundler(3);
2948    
2949                            query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
2950    
2951                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2952    
2953                            if (type == null) {
2954                                    query.append(_FINDER_COLUMN_G_T_TYPE_1);
2955                            }
2956                            else {
2957                                    if (type.equals(StringPool.BLANK)) {
2958                                            query.append(_FINDER_COLUMN_G_T_TYPE_3);
2959                                    }
2960                                    else {
2961                                            query.append(_FINDER_COLUMN_G_T_TYPE_2);
2962                                    }
2963                            }
2964    
2965                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2966                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
2967                                            _FILTER_COLUMN_USERID, groupId);
2968    
2969                            SQLQuery q = session.createSQLQuery(sql);
2970    
2971                            q.addScalar(COUNT_COLUMN_NAME,
2972                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2973    
2974                            QueryPos qPos = QueryPos.getInstance(q);
2975    
2976                            qPos.add(groupId);
2977    
2978                            if (type != null) {
2979                                    qPos.add(type);
2980                            }
2981    
2982                            Long count = (Long)q.uniqueResult();
2983    
2984                            return count.intValue();
2985                    }
2986                    catch (Exception e) {
2987                            throw processException(e);
2988                    }
2989                    finally {
2990                            closeSession(session);
2991                    }
2992            }
2993    
2994            public int countByG_R(long groupId, boolean repeating)
2995                    throws SystemException {
2996                    Object[] finderArgs = new Object[] { groupId, repeating };
2997    
2998                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_R,
2999                                    finderArgs, this);
3000    
3001                    if (count == null) {
3002                            Session session = null;
3003    
3004                            try {
3005                                    session = openSession();
3006    
3007                                    StringBundler query = new StringBundler(3);
3008    
3009                                    query.append(_SQL_COUNT_CALEVENT_WHERE);
3010    
3011                                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
3012    
3013                                    query.append(_FINDER_COLUMN_G_R_REPEATING_2);
3014    
3015                                    String sql = query.toString();
3016    
3017                                    Query q = session.createQuery(sql);
3018    
3019                                    QueryPos qPos = QueryPos.getInstance(q);
3020    
3021                                    qPos.add(groupId);
3022    
3023                                    qPos.add(repeating);
3024    
3025                                    count = (Long)q.uniqueResult();
3026                            }
3027                            catch (Exception e) {
3028                                    throw processException(e);
3029                            }
3030                            finally {
3031                                    if (count == null) {
3032                                            count = Long.valueOf(0);
3033                                    }
3034    
3035                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_R, finderArgs,
3036                                            count);
3037    
3038                                    closeSession(session);
3039                            }
3040                    }
3041    
3042                    return count.intValue();
3043            }
3044    
3045            public int filterCountByG_R(long groupId, boolean repeating)
3046                    throws SystemException {
3047                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3048                            return countByG_R(groupId, repeating);
3049                    }
3050    
3051                    Session session = null;
3052    
3053                    try {
3054                            session = openSession();
3055    
3056                            StringBundler query = new StringBundler(3);
3057    
3058                            query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
3059    
3060                            query.append(_FINDER_COLUMN_G_R_GROUPID_2);
3061    
3062                            query.append(_FINDER_COLUMN_G_R_REPEATING_2);
3063    
3064                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3065                                            CalEvent.class.getName(), _FILTER_COLUMN_PK,
3066                                            _FILTER_COLUMN_USERID, groupId);
3067    
3068                            SQLQuery q = session.createSQLQuery(sql);
3069    
3070                            q.addScalar(COUNT_COLUMN_NAME,
3071                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3072    
3073                            QueryPos qPos = QueryPos.getInstance(q);
3074    
3075                            qPos.add(groupId);
3076    
3077                            qPos.add(repeating);
3078    
3079                            Long count = (Long)q.uniqueResult();
3080    
3081                            return count.intValue();
3082                    }
3083                    catch (Exception e) {
3084                            throw processException(e);
3085                    }
3086                    finally {
3087                            closeSession(session);
3088                    }
3089            }
3090    
3091            public int countAll() throws SystemException {
3092                    Object[] finderArgs = new Object[0];
3093    
3094                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3095                                    finderArgs, this);
3096    
3097                    if (count == null) {
3098                            Session session = null;
3099    
3100                            try {
3101                                    session = openSession();
3102    
3103                                    Query q = session.createQuery(_SQL_COUNT_CALEVENT);
3104    
3105                                    count = (Long)q.uniqueResult();
3106                            }
3107                            catch (Exception e) {
3108                                    throw processException(e);
3109                            }
3110                            finally {
3111                                    if (count == null) {
3112                                            count = Long.valueOf(0);
3113                                    }
3114    
3115                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3116                                            count);
3117    
3118                                    closeSession(session);
3119                            }
3120                    }
3121    
3122                    return count.intValue();
3123            }
3124    
3125            public void afterPropertiesSet() {
3126                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3127                                            com.liferay.portal.util.PropsUtil.get(
3128                                                    "value.object.listener.com.liferay.portlet.calendar.model.CalEvent")));
3129    
3130                    if (listenerClassNames.length > 0) {
3131                            try {
3132                                    List<ModelListener<CalEvent>> listenersList = new ArrayList<ModelListener<CalEvent>>();
3133    
3134                                    for (String listenerClassName : listenerClassNames) {
3135                                            listenersList.add((ModelListener<CalEvent>)InstanceFactory.newInstance(
3136                                                            listenerClassName));
3137                                    }
3138    
3139                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3140                            }
3141                            catch (Exception e) {
3142                                    _log.error(e);
3143                            }
3144                    }
3145            }
3146    
3147            @BeanReference(type = CalEventPersistence.class)
3148            protected CalEventPersistence calEventPersistence;
3149            @BeanReference(type = CompanyPersistence.class)
3150            protected CompanyPersistence companyPersistence;
3151            @BeanReference(type = GroupPersistence.class)
3152            protected GroupPersistence groupPersistence;
3153            @BeanReference(type = PortletPreferencesPersistence.class)
3154            protected PortletPreferencesPersistence portletPreferencesPersistence;
3155            @BeanReference(type = ResourcePersistence.class)
3156            protected ResourcePersistence resourcePersistence;
3157            @BeanReference(type = UserPersistence.class)
3158            protected UserPersistence userPersistence;
3159            @BeanReference(type = AssetEntryPersistence.class)
3160            protected AssetEntryPersistence assetEntryPersistence;
3161            @BeanReference(type = AssetTagPersistence.class)
3162            protected AssetTagPersistence assetTagPersistence;
3163            @BeanReference(type = ExpandoValuePersistence.class)
3164            protected ExpandoValuePersistence expandoValuePersistence;
3165            @BeanReference(type = SocialActivityPersistence.class)
3166            protected SocialActivityPersistence socialActivityPersistence;
3167            private static final String _SQL_SELECT_CALEVENT = "SELECT calEvent FROM CalEvent calEvent";
3168            private static final String _SQL_SELECT_CALEVENT_WHERE = "SELECT calEvent FROM CalEvent calEvent WHERE ";
3169            private static final String _SQL_COUNT_CALEVENT = "SELECT COUNT(calEvent) FROM CalEvent calEvent";
3170            private static final String _SQL_COUNT_CALEVENT_WHERE = "SELECT COUNT(calEvent) FROM CalEvent calEvent WHERE ";
3171            private static final String _FINDER_COLUMN_UUID_UUID_1 = "calEvent.uuid IS NULL";
3172            private static final String _FINDER_COLUMN_UUID_UUID_2 = "calEvent.uuid = ?";
3173            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?)";
3174            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "calEvent.uuid IS NULL AND ";
3175            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "calEvent.uuid = ? AND ";
3176            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?) AND ";
3177            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "calEvent.groupId = ?";
3178            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "calEvent.companyId = ?";
3179            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "calEvent.groupId = ?";
3180            private static final String _FINDER_COLUMN_NOTREMINDBY_REMINDBY_2 = "calEvent.remindBy != ?";
3181            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "calEvent.groupId = ? AND ";
3182            private static final String _FINDER_COLUMN_G_T_TYPE_1 = "calEvent.type IS NULL";
3183            private static final String _FINDER_COLUMN_G_T_TYPE_2 = "calEvent.type = ?";
3184            private static final String _FINDER_COLUMN_G_T_TYPE_3 = "(calEvent.type IS NULL OR calEvent.type = ?)";
3185            private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "calEvent.groupId = ? AND ";
3186            private static final String _FINDER_COLUMN_G_R_REPEATING_2 = "calEvent.repeating = ?";
3187            private static final String _FILTER_SQL_SELECT_CALEVENT_WHERE = "SELECT DISTINCT {calEvent.*} FROM CalEvent calEvent WHERE ";
3188            private static final String _FILTER_SQL_COUNT_CALEVENT_WHERE = "SELECT COUNT(DISTINCT calEvent.eventId) AS COUNT_VALUE FROM CalEvent calEvent WHERE ";
3189            private static final String _FILTER_COLUMN_PK = "calEvent.eventId";
3190            private static final String _FILTER_COLUMN_USERID = "calEvent.userId";
3191            private static final String _FILTER_ENTITY_ALIAS = "calEvent";
3192            private static final String _ORDER_BY_ENTITY_ALIAS = "calEvent.";
3193            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No CalEvent exists with the primary key ";
3194            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No CalEvent exists with the key {";
3195            private static Log _log = LogFactoryUtil.getLog(CalEventPersistenceImpl.class);
3196    }