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