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