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