001
014
015 package com.liferay.portlet.calendar.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.SQLQuery;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.sanitizer.Sanitizer;
031 import com.liferay.portal.kernel.sanitizer.SanitizerException;
032 import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
033 import com.liferay.portal.kernel.util.ArrayUtil;
034 import com.liferay.portal.kernel.util.ContentTypes;
035 import com.liferay.portal.kernel.util.GetterUtil;
036 import com.liferay.portal.kernel.util.InstanceFactory;
037 import com.liferay.portal.kernel.util.OrderByComparator;
038 import com.liferay.portal.kernel.util.StringBundler;
039 import com.liferay.portal.kernel.util.StringPool;
040 import com.liferay.portal.kernel.util.StringUtil;
041 import com.liferay.portal.kernel.util.UnmodifiableList;
042 import com.liferay.portal.kernel.util.Validator;
043 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044 import com.liferay.portal.model.CacheModel;
045 import com.liferay.portal.model.ModelListener;
046 import com.liferay.portal.security.auth.PrincipalThreadLocal;
047 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049
050 import com.liferay.portlet.calendar.NoSuchEventException;
051 import com.liferay.portlet.calendar.model.CalEvent;
052 import com.liferay.portlet.calendar.model.impl.CalEventImpl;
053 import com.liferay.portlet.calendar.model.impl.CalEventModelImpl;
054
055 import java.io.Serializable;
056
057 import java.util.ArrayList;
058 import java.util.Collections;
059 import java.util.List;
060
061
073 public class CalEventPersistenceImpl extends BasePersistenceImpl<CalEvent>
074 implements CalEventPersistence {
075
080 public static final String FINDER_CLASS_NAME_ENTITY = CalEventImpl.class.getName();
081 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List1";
083 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List2";
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
086 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
089 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
092 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
095 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
096 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097 new String[] {
098 String.class.getName(),
099
100 Integer.class.getName(), Integer.class.getName(),
101 OrderByComparator.class.getName()
102 });
103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
104 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106 new String[] { String.class.getName() },
107 CalEventModelImpl.UUID_COLUMN_BITMASK |
108 CalEventModelImpl.STARTDATE_COLUMN_BITMASK |
109 CalEventModelImpl.TITLE_COLUMN_BITMASK);
110 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
111 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
113 new String[] { String.class.getName() });
114
115
122 public List<CalEvent> findByUuid(String uuid) throws SystemException {
123 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124 }
125
126
139 public List<CalEvent> findByUuid(String uuid, int start, int end)
140 throws SystemException {
141 return findByUuid(uuid, start, end, null);
142 }
143
144
158 public List<CalEvent> findByUuid(String uuid, int start, int end,
159 OrderByComparator orderByComparator) throws SystemException {
160 boolean pagination = true;
161 FinderPath finderPath = null;
162 Object[] finderArgs = null;
163
164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165 (orderByComparator == null)) {
166 pagination = false;
167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid };
169 }
170 else {
171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
172 finderArgs = new Object[] { uuid, start, end, orderByComparator };
173 }
174
175 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
176 finderArgs, this);
177
178 if ((list != null) && !list.isEmpty()) {
179 for (CalEvent calEvent : list) {
180 if (!Validator.equals(uuid, calEvent.getUuid())) {
181 list = null;
182
183 break;
184 }
185 }
186 }
187
188 if (list == null) {
189 StringBundler query = null;
190
191 if (orderByComparator != null) {
192 query = new StringBundler(3 +
193 (orderByComparator.getOrderByFields().length * 3));
194 }
195 else {
196 query = new StringBundler(3);
197 }
198
199 query.append(_SQL_SELECT_CALEVENT_WHERE);
200
201 if (uuid == null) {
202 query.append(_FINDER_COLUMN_UUID_UUID_1);
203 }
204 else {
205 if (uuid.equals(StringPool.BLANK)) {
206 query.append(_FINDER_COLUMN_UUID_UUID_3);
207 }
208 else {
209 query.append(_FINDER_COLUMN_UUID_UUID_2);
210 }
211 }
212
213 if (orderByComparator != null) {
214 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
215 orderByComparator);
216 }
217 else
218 if (pagination) {
219 query.append(CalEventModelImpl.ORDER_BY_JPQL);
220 }
221
222 String sql = query.toString();
223
224 Session session = null;
225
226 try {
227 session = openSession();
228
229 Query q = session.createQuery(sql);
230
231 QueryPos qPos = QueryPos.getInstance(q);
232
233 if (uuid != null) {
234 qPos.add(uuid);
235 }
236
237 if (!pagination) {
238 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
239 start, end, false);
240
241 Collections.sort(list);
242
243 list = new UnmodifiableList<CalEvent>(list);
244 }
245 else {
246 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
247 start, end);
248 }
249
250 cacheResult(list);
251
252 FinderCacheUtil.putResult(finderPath, finderArgs, list);
253 }
254 catch (Exception e) {
255 FinderCacheUtil.removeResult(finderPath, finderArgs);
256
257 throw processException(e);
258 }
259 finally {
260 closeSession(session);
261 }
262 }
263
264 return list;
265 }
266
267
276 public CalEvent findByUuid_First(String uuid,
277 OrderByComparator orderByComparator)
278 throws NoSuchEventException, SystemException {
279 CalEvent calEvent = fetchByUuid_First(uuid, orderByComparator);
280
281 if (calEvent != null) {
282 return calEvent;
283 }
284
285 StringBundler msg = new StringBundler(4);
286
287 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288
289 msg.append("uuid=");
290 msg.append(uuid);
291
292 msg.append(StringPool.CLOSE_CURLY_BRACE);
293
294 throw new NoSuchEventException(msg.toString());
295 }
296
297
305 public CalEvent fetchByUuid_First(String uuid,
306 OrderByComparator orderByComparator) throws SystemException {
307 List<CalEvent> list = findByUuid(uuid, 0, 1, orderByComparator);
308
309 if (!list.isEmpty()) {
310 return list.get(0);
311 }
312
313 return null;
314 }
315
316
325 public CalEvent findByUuid_Last(String uuid,
326 OrderByComparator orderByComparator)
327 throws NoSuchEventException, SystemException {
328 CalEvent calEvent = fetchByUuid_Last(uuid, orderByComparator);
329
330 if (calEvent != null) {
331 return calEvent;
332 }
333
334 StringBundler msg = new StringBundler(4);
335
336 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337
338 msg.append("uuid=");
339 msg.append(uuid);
340
341 msg.append(StringPool.CLOSE_CURLY_BRACE);
342
343 throw new NoSuchEventException(msg.toString());
344 }
345
346
354 public CalEvent fetchByUuid_Last(String uuid,
355 OrderByComparator orderByComparator) throws SystemException {
356 int count = countByUuid(uuid);
357
358 List<CalEvent> list = findByUuid(uuid, count - 1, count,
359 orderByComparator);
360
361 if (!list.isEmpty()) {
362 return list.get(0);
363 }
364
365 return null;
366 }
367
368
378 public CalEvent[] findByUuid_PrevAndNext(long eventId, String uuid,
379 OrderByComparator orderByComparator)
380 throws NoSuchEventException, SystemException {
381 CalEvent calEvent = findByPrimaryKey(eventId);
382
383 Session session = null;
384
385 try {
386 session = openSession();
387
388 CalEvent[] array = new CalEventImpl[3];
389
390 array[0] = getByUuid_PrevAndNext(session, calEvent, uuid,
391 orderByComparator, true);
392
393 array[1] = calEvent;
394
395 array[2] = getByUuid_PrevAndNext(session, calEvent, uuid,
396 orderByComparator, false);
397
398 return array;
399 }
400 catch (Exception e) {
401 throw processException(e);
402 }
403 finally {
404 closeSession(session);
405 }
406 }
407
408 protected CalEvent getByUuid_PrevAndNext(Session session,
409 CalEvent calEvent, String uuid, OrderByComparator orderByComparator,
410 boolean previous) {
411 StringBundler query = null;
412
413 if (orderByComparator != null) {
414 query = new StringBundler(6 +
415 (orderByComparator.getOrderByFields().length * 6));
416 }
417 else {
418 query = new StringBundler(3);
419 }
420
421 query.append(_SQL_SELECT_CALEVENT_WHERE);
422
423 if (uuid == null) {
424 query.append(_FINDER_COLUMN_UUID_UUID_1);
425 }
426 else {
427 if (uuid.equals(StringPool.BLANK)) {
428 query.append(_FINDER_COLUMN_UUID_UUID_3);
429 }
430 else {
431 query.append(_FINDER_COLUMN_UUID_UUID_2);
432 }
433 }
434
435 if (orderByComparator != null) {
436 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
437
438 if (orderByConditionFields.length > 0) {
439 query.append(WHERE_AND);
440 }
441
442 for (int i = 0; i < orderByConditionFields.length; i++) {
443 query.append(_ORDER_BY_ENTITY_ALIAS);
444 query.append(orderByConditionFields[i]);
445
446 if ((i + 1) < orderByConditionFields.length) {
447 if (orderByComparator.isAscending() ^ previous) {
448 query.append(WHERE_GREATER_THAN_HAS_NEXT);
449 }
450 else {
451 query.append(WHERE_LESSER_THAN_HAS_NEXT);
452 }
453 }
454 else {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(WHERE_GREATER_THAN);
457 }
458 else {
459 query.append(WHERE_LESSER_THAN);
460 }
461 }
462 }
463
464 query.append(ORDER_BY_CLAUSE);
465
466 String[] orderByFields = orderByComparator.getOrderByFields();
467
468 for (int i = 0; i < orderByFields.length; i++) {
469 query.append(_ORDER_BY_ENTITY_ALIAS);
470 query.append(orderByFields[i]);
471
472 if ((i + 1) < orderByFields.length) {
473 if (orderByComparator.isAscending() ^ previous) {
474 query.append(ORDER_BY_ASC_HAS_NEXT);
475 }
476 else {
477 query.append(ORDER_BY_DESC_HAS_NEXT);
478 }
479 }
480 else {
481 if (orderByComparator.isAscending() ^ previous) {
482 query.append(ORDER_BY_ASC);
483 }
484 else {
485 query.append(ORDER_BY_DESC);
486 }
487 }
488 }
489 }
490 else {
491 query.append(CalEventModelImpl.ORDER_BY_JPQL);
492 }
493
494 String sql = query.toString();
495
496 Query q = session.createQuery(sql);
497
498 q.setFirstResult(0);
499 q.setMaxResults(2);
500
501 QueryPos qPos = QueryPos.getInstance(q);
502
503 if (uuid != null) {
504 qPos.add(uuid);
505 }
506
507 if (orderByComparator != null) {
508 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
509
510 for (Object value : values) {
511 qPos.add(value);
512 }
513 }
514
515 List<CalEvent> list = q.list();
516
517 if (list.size() == 2) {
518 return list.get(1);
519 }
520 else {
521 return null;
522 }
523 }
524
525
531 public void removeByUuid(String uuid) throws SystemException {
532 for (CalEvent calEvent : findByUuid(uuid, QueryUtil.ALL_POS,
533 QueryUtil.ALL_POS, null)) {
534 remove(calEvent);
535 }
536 }
537
538
545 public int countByUuid(String uuid) throws SystemException {
546 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
547
548 Object[] finderArgs = new Object[] { uuid };
549
550 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
551 this);
552
553 if (count == null) {
554 StringBundler query = new StringBundler(2);
555
556 query.append(_SQL_COUNT_CALEVENT_WHERE);
557
558 if (uuid == null) {
559 query.append(_FINDER_COLUMN_UUID_UUID_1);
560 }
561 else {
562 if (uuid.equals(StringPool.BLANK)) {
563 query.append(_FINDER_COLUMN_UUID_UUID_3);
564 }
565 else {
566 query.append(_FINDER_COLUMN_UUID_UUID_2);
567 }
568 }
569
570 String sql = query.toString();
571
572 Session session = null;
573
574 try {
575 session = openSession();
576
577 Query q = session.createQuery(sql);
578
579 QueryPos qPos = QueryPos.getInstance(q);
580
581 if (uuid != null) {
582 qPos.add(uuid);
583 }
584
585 count = (Long)q.uniqueResult();
586
587 FinderCacheUtil.putResult(finderPath, finderArgs, count);
588 }
589 catch (Exception e) {
590 FinderCacheUtil.removeResult(finderPath, finderArgs);
591
592 throw processException(e);
593 }
594 finally {
595 closeSession(session);
596 }
597 }
598
599 return count.intValue();
600 }
601
602 private static final String _FINDER_COLUMN_UUID_UUID_1 = "calEvent.uuid IS NULL";
603 private static final String _FINDER_COLUMN_UUID_UUID_2 = "calEvent.uuid = ?";
604 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?)";
605 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
606 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
607 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
608 new String[] { String.class.getName(), Long.class.getName() },
609 CalEventModelImpl.UUID_COLUMN_BITMASK |
610 CalEventModelImpl.GROUPID_COLUMN_BITMASK);
611 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
612 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
613 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
614 new String[] { String.class.getName(), Long.class.getName() });
615
616
625 public CalEvent findByUUID_G(String uuid, long groupId)
626 throws NoSuchEventException, SystemException {
627 CalEvent calEvent = fetchByUUID_G(uuid, groupId);
628
629 if (calEvent == null) {
630 StringBundler msg = new StringBundler(6);
631
632 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
633
634 msg.append("uuid=");
635 msg.append(uuid);
636
637 msg.append(", groupId=");
638 msg.append(groupId);
639
640 msg.append(StringPool.CLOSE_CURLY_BRACE);
641
642 if (_log.isWarnEnabled()) {
643 _log.warn(msg.toString());
644 }
645
646 throw new NoSuchEventException(msg.toString());
647 }
648
649 return calEvent;
650 }
651
652
660 public CalEvent fetchByUUID_G(String uuid, long groupId)
661 throws SystemException {
662 return fetchByUUID_G(uuid, groupId, true);
663 }
664
665
674 public CalEvent fetchByUUID_G(String uuid, long groupId,
675 boolean retrieveFromCache) throws SystemException {
676 Object[] finderArgs = new Object[] { uuid, groupId };
677
678 Object result = null;
679
680 if (retrieveFromCache) {
681 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
682 finderArgs, this);
683 }
684
685 if (result instanceof CalEvent) {
686 CalEvent calEvent = (CalEvent)result;
687
688 if (!Validator.equals(uuid, calEvent.getUuid()) ||
689 (groupId != calEvent.getGroupId())) {
690 result = null;
691 }
692 }
693
694 if (result == null) {
695 StringBundler query = new StringBundler(4);
696
697 query.append(_SQL_SELECT_CALEVENT_WHERE);
698
699 if (uuid == null) {
700 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
701 }
702 else {
703 if (uuid.equals(StringPool.BLANK)) {
704 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
705 }
706 else {
707 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
708 }
709 }
710
711 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
712
713 String sql = query.toString();
714
715 Session session = null;
716
717 try {
718 session = openSession();
719
720 Query q = session.createQuery(sql);
721
722 QueryPos qPos = QueryPos.getInstance(q);
723
724 if (uuid != null) {
725 qPos.add(uuid);
726 }
727
728 qPos.add(groupId);
729
730 List<CalEvent> list = q.list();
731
732 if (list.isEmpty()) {
733 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
734 finderArgs, list);
735 }
736 else {
737 CalEvent calEvent = list.get(0);
738
739 result = calEvent;
740
741 cacheResult(calEvent);
742
743 if ((calEvent.getUuid() == null) ||
744 !calEvent.getUuid().equals(uuid) ||
745 (calEvent.getGroupId() != groupId)) {
746 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
747 finderArgs, calEvent);
748 }
749 }
750 }
751 catch (Exception e) {
752 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
753 finderArgs);
754
755 throw processException(e);
756 }
757 finally {
758 closeSession(session);
759 }
760 }
761
762 if (result instanceof List<?>) {
763 return null;
764 }
765 else {
766 return (CalEvent)result;
767 }
768 }
769
770
778 public CalEvent removeByUUID_G(String uuid, long groupId)
779 throws NoSuchEventException, SystemException {
780 CalEvent calEvent = findByUUID_G(uuid, groupId);
781
782 return remove(calEvent);
783 }
784
785
793 public int countByUUID_G(String uuid, long groupId)
794 throws SystemException {
795 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
796
797 Object[] finderArgs = new Object[] { uuid, groupId };
798
799 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
800 this);
801
802 if (count == null) {
803 StringBundler query = new StringBundler(3);
804
805 query.append(_SQL_COUNT_CALEVENT_WHERE);
806
807 if (uuid == null) {
808 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
809 }
810 else {
811 if (uuid.equals(StringPool.BLANK)) {
812 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
813 }
814 else {
815 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
816 }
817 }
818
819 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
820
821 String sql = query.toString();
822
823 Session session = null;
824
825 try {
826 session = openSession();
827
828 Query q = session.createQuery(sql);
829
830 QueryPos qPos = QueryPos.getInstance(q);
831
832 if (uuid != null) {
833 qPos.add(uuid);
834 }
835
836 qPos.add(groupId);
837
838 count = (Long)q.uniqueResult();
839
840 FinderCacheUtil.putResult(finderPath, finderArgs, count);
841 }
842 catch (Exception e) {
843 FinderCacheUtil.removeResult(finderPath, finderArgs);
844
845 throw processException(e);
846 }
847 finally {
848 closeSession(session);
849 }
850 }
851
852 return count.intValue();
853 }
854
855 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "calEvent.uuid IS NULL AND ";
856 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "calEvent.uuid = ? AND ";
857 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?) AND ";
858 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "calEvent.groupId = ?";
859 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
860 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
861 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
862 new String[] {
863 String.class.getName(), Long.class.getName(),
864
865 Integer.class.getName(), Integer.class.getName(),
866 OrderByComparator.class.getName()
867 });
868 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
869 new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
870 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
871 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
872 new String[] { String.class.getName(), Long.class.getName() },
873 CalEventModelImpl.UUID_COLUMN_BITMASK |
874 CalEventModelImpl.COMPANYID_COLUMN_BITMASK |
875 CalEventModelImpl.STARTDATE_COLUMN_BITMASK |
876 CalEventModelImpl.TITLE_COLUMN_BITMASK);
877 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
878 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
879 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
880 new String[] { String.class.getName(), Long.class.getName() });
881
882
890 public List<CalEvent> findByUuid_C(String uuid, long companyId)
891 throws SystemException {
892 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
893 QueryUtil.ALL_POS, null);
894 }
895
896
910 public List<CalEvent> findByUuid_C(String uuid, long companyId, int start,
911 int end) throws SystemException {
912 return findByUuid_C(uuid, companyId, start, end, null);
913 }
914
915
930 public List<CalEvent> findByUuid_C(String uuid, long companyId, int start,
931 int end, OrderByComparator orderByComparator) throws SystemException {
932 boolean pagination = true;
933 FinderPath finderPath = null;
934 Object[] finderArgs = null;
935
936 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
937 (orderByComparator == null)) {
938 pagination = false;
939 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
940 finderArgs = new Object[] { uuid, companyId };
941 }
942 else {
943 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
944 finderArgs = new Object[] {
945 uuid, companyId,
946
947 start, end, orderByComparator
948 };
949 }
950
951 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
952 finderArgs, this);
953
954 if ((list != null) && !list.isEmpty()) {
955 for (CalEvent calEvent : list) {
956 if (!Validator.equals(uuid, calEvent.getUuid()) ||
957 (companyId != calEvent.getCompanyId())) {
958 list = null;
959
960 break;
961 }
962 }
963 }
964
965 if (list == null) {
966 StringBundler query = null;
967
968 if (orderByComparator != null) {
969 query = new StringBundler(4 +
970 (orderByComparator.getOrderByFields().length * 3));
971 }
972 else {
973 query = new StringBundler(4);
974 }
975
976 query.append(_SQL_SELECT_CALEVENT_WHERE);
977
978 if (uuid == null) {
979 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
980 }
981 else {
982 if (uuid.equals(StringPool.BLANK)) {
983 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
984 }
985 else {
986 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
987 }
988 }
989
990 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
991
992 if (orderByComparator != null) {
993 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
994 orderByComparator);
995 }
996 else
997 if (pagination) {
998 query.append(CalEventModelImpl.ORDER_BY_JPQL);
999 }
1000
1001 String sql = query.toString();
1002
1003 Session session = null;
1004
1005 try {
1006 session = openSession();
1007
1008 Query q = session.createQuery(sql);
1009
1010 QueryPos qPos = QueryPos.getInstance(q);
1011
1012 if (uuid != null) {
1013 qPos.add(uuid);
1014 }
1015
1016 qPos.add(companyId);
1017
1018 if (!pagination) {
1019 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
1020 start, end, false);
1021
1022 Collections.sort(list);
1023
1024 list = new UnmodifiableList<CalEvent>(list);
1025 }
1026 else {
1027 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
1028 start, end);
1029 }
1030
1031 cacheResult(list);
1032
1033 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1034 }
1035 catch (Exception e) {
1036 FinderCacheUtil.removeResult(finderPath, finderArgs);
1037
1038 throw processException(e);
1039 }
1040 finally {
1041 closeSession(session);
1042 }
1043 }
1044
1045 return list;
1046 }
1047
1048
1058 public CalEvent findByUuid_C_First(String uuid, long companyId,
1059 OrderByComparator orderByComparator)
1060 throws NoSuchEventException, SystemException {
1061 CalEvent calEvent = fetchByUuid_C_First(uuid, companyId,
1062 orderByComparator);
1063
1064 if (calEvent != null) {
1065 return calEvent;
1066 }
1067
1068 StringBundler msg = new StringBundler(6);
1069
1070 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1071
1072 msg.append("uuid=");
1073 msg.append(uuid);
1074
1075 msg.append(", companyId=");
1076 msg.append(companyId);
1077
1078 msg.append(StringPool.CLOSE_CURLY_BRACE);
1079
1080 throw new NoSuchEventException(msg.toString());
1081 }
1082
1083
1092 public CalEvent fetchByUuid_C_First(String uuid, long companyId,
1093 OrderByComparator orderByComparator) throws SystemException {
1094 List<CalEvent> list = findByUuid_C(uuid, companyId, 0, 1,
1095 orderByComparator);
1096
1097 if (!list.isEmpty()) {
1098 return list.get(0);
1099 }
1100
1101 return null;
1102 }
1103
1104
1114 public CalEvent findByUuid_C_Last(String uuid, long companyId,
1115 OrderByComparator orderByComparator)
1116 throws NoSuchEventException, SystemException {
1117 CalEvent calEvent = fetchByUuid_C_Last(uuid, companyId,
1118 orderByComparator);
1119
1120 if (calEvent != null) {
1121 return calEvent;
1122 }
1123
1124 StringBundler msg = new StringBundler(6);
1125
1126 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1127
1128 msg.append("uuid=");
1129 msg.append(uuid);
1130
1131 msg.append(", companyId=");
1132 msg.append(companyId);
1133
1134 msg.append(StringPool.CLOSE_CURLY_BRACE);
1135
1136 throw new NoSuchEventException(msg.toString());
1137 }
1138
1139
1148 public CalEvent fetchByUuid_C_Last(String uuid, long companyId,
1149 OrderByComparator orderByComparator) throws SystemException {
1150 int count = countByUuid_C(uuid, companyId);
1151
1152 List<CalEvent> list = findByUuid_C(uuid, companyId, count - 1, count,
1153 orderByComparator);
1154
1155 if (!list.isEmpty()) {
1156 return list.get(0);
1157 }
1158
1159 return null;
1160 }
1161
1162
1173 public CalEvent[] findByUuid_C_PrevAndNext(long eventId, String uuid,
1174 long companyId, OrderByComparator orderByComparator)
1175 throws NoSuchEventException, SystemException {
1176 CalEvent calEvent = findByPrimaryKey(eventId);
1177
1178 Session session = null;
1179
1180 try {
1181 session = openSession();
1182
1183 CalEvent[] array = new CalEventImpl[3];
1184
1185 array[0] = getByUuid_C_PrevAndNext(session, calEvent, uuid,
1186 companyId, orderByComparator, true);
1187
1188 array[1] = calEvent;
1189
1190 array[2] = getByUuid_C_PrevAndNext(session, calEvent, uuid,
1191 companyId, orderByComparator, false);
1192
1193 return array;
1194 }
1195 catch (Exception e) {
1196 throw processException(e);
1197 }
1198 finally {
1199 closeSession(session);
1200 }
1201 }
1202
1203 protected CalEvent getByUuid_C_PrevAndNext(Session session,
1204 CalEvent calEvent, String uuid, long companyId,
1205 OrderByComparator orderByComparator, boolean previous) {
1206 StringBundler query = null;
1207
1208 if (orderByComparator != null) {
1209 query = new StringBundler(6 +
1210 (orderByComparator.getOrderByFields().length * 6));
1211 }
1212 else {
1213 query = new StringBundler(3);
1214 }
1215
1216 query.append(_SQL_SELECT_CALEVENT_WHERE);
1217
1218 if (uuid == null) {
1219 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1220 }
1221 else {
1222 if (uuid.equals(StringPool.BLANK)) {
1223 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1224 }
1225 else {
1226 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1227 }
1228 }
1229
1230 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1231
1232 if (orderByComparator != null) {
1233 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1234
1235 if (orderByConditionFields.length > 0) {
1236 query.append(WHERE_AND);
1237 }
1238
1239 for (int i = 0; i < orderByConditionFields.length; i++) {
1240 query.append(_ORDER_BY_ENTITY_ALIAS);
1241 query.append(orderByConditionFields[i]);
1242
1243 if ((i + 1) < orderByConditionFields.length) {
1244 if (orderByComparator.isAscending() ^ previous) {
1245 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1246 }
1247 else {
1248 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1249 }
1250 }
1251 else {
1252 if (orderByComparator.isAscending() ^ previous) {
1253 query.append(WHERE_GREATER_THAN);
1254 }
1255 else {
1256 query.append(WHERE_LESSER_THAN);
1257 }
1258 }
1259 }
1260
1261 query.append(ORDER_BY_CLAUSE);
1262
1263 String[] orderByFields = orderByComparator.getOrderByFields();
1264
1265 for (int i = 0; i < orderByFields.length; i++) {
1266 query.append(_ORDER_BY_ENTITY_ALIAS);
1267 query.append(orderByFields[i]);
1268
1269 if ((i + 1) < orderByFields.length) {
1270 if (orderByComparator.isAscending() ^ previous) {
1271 query.append(ORDER_BY_ASC_HAS_NEXT);
1272 }
1273 else {
1274 query.append(ORDER_BY_DESC_HAS_NEXT);
1275 }
1276 }
1277 else {
1278 if (orderByComparator.isAscending() ^ previous) {
1279 query.append(ORDER_BY_ASC);
1280 }
1281 else {
1282 query.append(ORDER_BY_DESC);
1283 }
1284 }
1285 }
1286 }
1287 else {
1288 query.append(CalEventModelImpl.ORDER_BY_JPQL);
1289 }
1290
1291 String sql = query.toString();
1292
1293 Query q = session.createQuery(sql);
1294
1295 q.setFirstResult(0);
1296 q.setMaxResults(2);
1297
1298 QueryPos qPos = QueryPos.getInstance(q);
1299
1300 if (uuid != null) {
1301 qPos.add(uuid);
1302 }
1303
1304 qPos.add(companyId);
1305
1306 if (orderByComparator != null) {
1307 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
1308
1309 for (Object value : values) {
1310 qPos.add(value);
1311 }
1312 }
1313
1314 List<CalEvent> list = q.list();
1315
1316 if (list.size() == 2) {
1317 return list.get(1);
1318 }
1319 else {
1320 return null;
1321 }
1322 }
1323
1324
1331 public void removeByUuid_C(String uuid, long companyId)
1332 throws SystemException {
1333 for (CalEvent calEvent : findByUuid_C(uuid, companyId,
1334 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1335 remove(calEvent);
1336 }
1337 }
1338
1339
1347 public int countByUuid_C(String uuid, long companyId)
1348 throws SystemException {
1349 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1350
1351 Object[] finderArgs = new Object[] { uuid, companyId };
1352
1353 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1354 this);
1355
1356 if (count == null) {
1357 StringBundler query = new StringBundler(3);
1358
1359 query.append(_SQL_COUNT_CALEVENT_WHERE);
1360
1361 if (uuid == null) {
1362 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1363 }
1364 else {
1365 if (uuid.equals(StringPool.BLANK)) {
1366 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1367 }
1368 else {
1369 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1370 }
1371 }
1372
1373 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1374
1375 String sql = query.toString();
1376
1377 Session session = null;
1378
1379 try {
1380 session = openSession();
1381
1382 Query q = session.createQuery(sql);
1383
1384 QueryPos qPos = QueryPos.getInstance(q);
1385
1386 if (uuid != null) {
1387 qPos.add(uuid);
1388 }
1389
1390 qPos.add(companyId);
1391
1392 count = (Long)q.uniqueResult();
1393
1394 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1395 }
1396 catch (Exception e) {
1397 FinderCacheUtil.removeResult(finderPath, finderArgs);
1398
1399 throw processException(e);
1400 }
1401 finally {
1402 closeSession(session);
1403 }
1404 }
1405
1406 return count.intValue();
1407 }
1408
1409 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "calEvent.uuid IS NULL AND ";
1410 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "calEvent.uuid = ? AND ";
1411 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(calEvent.uuid IS NULL OR calEvent.uuid = ?) AND ";
1412 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "calEvent.companyId = ?";
1413 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1414 new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
1415 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
1416 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1417 new String[] {
1418 Long.class.getName(),
1419
1420 Integer.class.getName(), Integer.class.getName(),
1421 OrderByComparator.class.getName()
1422 });
1423 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1424 new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
1425 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
1426 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1427 new String[] { Long.class.getName() },
1428 CalEventModelImpl.COMPANYID_COLUMN_BITMASK |
1429 CalEventModelImpl.STARTDATE_COLUMN_BITMASK |
1430 CalEventModelImpl.TITLE_COLUMN_BITMASK);
1431 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
1432 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1433 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1434 new String[] { Long.class.getName() });
1435
1436
1443 public List<CalEvent> findByCompanyId(long companyId)
1444 throws SystemException {
1445 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1446 null);
1447 }
1448
1449
1462 public List<CalEvent> findByCompanyId(long companyId, int start, int end)
1463 throws SystemException {
1464 return findByCompanyId(companyId, start, end, null);
1465 }
1466
1467
1481 public List<CalEvent> findByCompanyId(long companyId, int start, int end,
1482 OrderByComparator orderByComparator) throws SystemException {
1483 boolean pagination = true;
1484 FinderPath finderPath = null;
1485 Object[] finderArgs = null;
1486
1487 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1488 (orderByComparator == null)) {
1489 pagination = false;
1490 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1491 finderArgs = new Object[] { companyId };
1492 }
1493 else {
1494 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1495 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1496 }
1497
1498 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
1499 finderArgs, this);
1500
1501 if ((list != null) && !list.isEmpty()) {
1502 for (CalEvent calEvent : list) {
1503 if ((companyId != calEvent.getCompanyId())) {
1504 list = null;
1505
1506 break;
1507 }
1508 }
1509 }
1510
1511 if (list == null) {
1512 StringBundler query = null;
1513
1514 if (orderByComparator != null) {
1515 query = new StringBundler(3 +
1516 (orderByComparator.getOrderByFields().length * 3));
1517 }
1518 else {
1519 query = new StringBundler(3);
1520 }
1521
1522 query.append(_SQL_SELECT_CALEVENT_WHERE);
1523
1524 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1525
1526 if (orderByComparator != null) {
1527 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1528 orderByComparator);
1529 }
1530 else
1531 if (pagination) {
1532 query.append(CalEventModelImpl.ORDER_BY_JPQL);
1533 }
1534
1535 String sql = query.toString();
1536
1537 Session session = null;
1538
1539 try {
1540 session = openSession();
1541
1542 Query q = session.createQuery(sql);
1543
1544 QueryPos qPos = QueryPos.getInstance(q);
1545
1546 qPos.add(companyId);
1547
1548 if (!pagination) {
1549 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
1550 start, end, false);
1551
1552 Collections.sort(list);
1553
1554 list = new UnmodifiableList<CalEvent>(list);
1555 }
1556 else {
1557 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
1558 start, end);
1559 }
1560
1561 cacheResult(list);
1562
1563 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1564 }
1565 catch (Exception e) {
1566 FinderCacheUtil.removeResult(finderPath, finderArgs);
1567
1568 throw processException(e);
1569 }
1570 finally {
1571 closeSession(session);
1572 }
1573 }
1574
1575 return list;
1576 }
1577
1578
1587 public CalEvent findByCompanyId_First(long companyId,
1588 OrderByComparator orderByComparator)
1589 throws NoSuchEventException, SystemException {
1590 CalEvent calEvent = fetchByCompanyId_First(companyId, orderByComparator);
1591
1592 if (calEvent != null) {
1593 return calEvent;
1594 }
1595
1596 StringBundler msg = new StringBundler(4);
1597
1598 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1599
1600 msg.append("companyId=");
1601 msg.append(companyId);
1602
1603 msg.append(StringPool.CLOSE_CURLY_BRACE);
1604
1605 throw new NoSuchEventException(msg.toString());
1606 }
1607
1608
1616 public CalEvent fetchByCompanyId_First(long companyId,
1617 OrderByComparator orderByComparator) throws SystemException {
1618 List<CalEvent> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1619
1620 if (!list.isEmpty()) {
1621 return list.get(0);
1622 }
1623
1624 return null;
1625 }
1626
1627
1636 public CalEvent findByCompanyId_Last(long companyId,
1637 OrderByComparator orderByComparator)
1638 throws NoSuchEventException, SystemException {
1639 CalEvent calEvent = fetchByCompanyId_Last(companyId, orderByComparator);
1640
1641 if (calEvent != null) {
1642 return calEvent;
1643 }
1644
1645 StringBundler msg = new StringBundler(4);
1646
1647 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1648
1649 msg.append("companyId=");
1650 msg.append(companyId);
1651
1652 msg.append(StringPool.CLOSE_CURLY_BRACE);
1653
1654 throw new NoSuchEventException(msg.toString());
1655 }
1656
1657
1665 public CalEvent fetchByCompanyId_Last(long companyId,
1666 OrderByComparator orderByComparator) throws SystemException {
1667 int count = countByCompanyId(companyId);
1668
1669 List<CalEvent> list = findByCompanyId(companyId, count - 1, count,
1670 orderByComparator);
1671
1672 if (!list.isEmpty()) {
1673 return list.get(0);
1674 }
1675
1676 return null;
1677 }
1678
1679
1689 public CalEvent[] findByCompanyId_PrevAndNext(long eventId, long companyId,
1690 OrderByComparator orderByComparator)
1691 throws NoSuchEventException, SystemException {
1692 CalEvent calEvent = findByPrimaryKey(eventId);
1693
1694 Session session = null;
1695
1696 try {
1697 session = openSession();
1698
1699 CalEvent[] array = new CalEventImpl[3];
1700
1701 array[0] = getByCompanyId_PrevAndNext(session, calEvent, companyId,
1702 orderByComparator, true);
1703
1704 array[1] = calEvent;
1705
1706 array[2] = getByCompanyId_PrevAndNext(session, calEvent, companyId,
1707 orderByComparator, false);
1708
1709 return array;
1710 }
1711 catch (Exception e) {
1712 throw processException(e);
1713 }
1714 finally {
1715 closeSession(session);
1716 }
1717 }
1718
1719 protected CalEvent getByCompanyId_PrevAndNext(Session session,
1720 CalEvent calEvent, long companyId, OrderByComparator orderByComparator,
1721 boolean previous) {
1722 StringBundler query = null;
1723
1724 if (orderByComparator != null) {
1725 query = new StringBundler(6 +
1726 (orderByComparator.getOrderByFields().length * 6));
1727 }
1728 else {
1729 query = new StringBundler(3);
1730 }
1731
1732 query.append(_SQL_SELECT_CALEVENT_WHERE);
1733
1734 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1735
1736 if (orderByComparator != null) {
1737 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1738
1739 if (orderByConditionFields.length > 0) {
1740 query.append(WHERE_AND);
1741 }
1742
1743 for (int i = 0; i < orderByConditionFields.length; i++) {
1744 query.append(_ORDER_BY_ENTITY_ALIAS);
1745 query.append(orderByConditionFields[i]);
1746
1747 if ((i + 1) < orderByConditionFields.length) {
1748 if (orderByComparator.isAscending() ^ previous) {
1749 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1750 }
1751 else {
1752 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1753 }
1754 }
1755 else {
1756 if (orderByComparator.isAscending() ^ previous) {
1757 query.append(WHERE_GREATER_THAN);
1758 }
1759 else {
1760 query.append(WHERE_LESSER_THAN);
1761 }
1762 }
1763 }
1764
1765 query.append(ORDER_BY_CLAUSE);
1766
1767 String[] orderByFields = orderByComparator.getOrderByFields();
1768
1769 for (int i = 0; i < orderByFields.length; i++) {
1770 query.append(_ORDER_BY_ENTITY_ALIAS);
1771 query.append(orderByFields[i]);
1772
1773 if ((i + 1) < orderByFields.length) {
1774 if (orderByComparator.isAscending() ^ previous) {
1775 query.append(ORDER_BY_ASC_HAS_NEXT);
1776 }
1777 else {
1778 query.append(ORDER_BY_DESC_HAS_NEXT);
1779 }
1780 }
1781 else {
1782 if (orderByComparator.isAscending() ^ previous) {
1783 query.append(ORDER_BY_ASC);
1784 }
1785 else {
1786 query.append(ORDER_BY_DESC);
1787 }
1788 }
1789 }
1790 }
1791 else {
1792 query.append(CalEventModelImpl.ORDER_BY_JPQL);
1793 }
1794
1795 String sql = query.toString();
1796
1797 Query q = session.createQuery(sql);
1798
1799 q.setFirstResult(0);
1800 q.setMaxResults(2);
1801
1802 QueryPos qPos = QueryPos.getInstance(q);
1803
1804 qPos.add(companyId);
1805
1806 if (orderByComparator != null) {
1807 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
1808
1809 for (Object value : values) {
1810 qPos.add(value);
1811 }
1812 }
1813
1814 List<CalEvent> list = q.list();
1815
1816 if (list.size() == 2) {
1817 return list.get(1);
1818 }
1819 else {
1820 return null;
1821 }
1822 }
1823
1824
1830 public void removeByCompanyId(long companyId) throws SystemException {
1831 for (CalEvent calEvent : findByCompanyId(companyId, QueryUtil.ALL_POS,
1832 QueryUtil.ALL_POS, null)) {
1833 remove(calEvent);
1834 }
1835 }
1836
1837
1844 public int countByCompanyId(long companyId) throws SystemException {
1845 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1846
1847 Object[] finderArgs = new Object[] { companyId };
1848
1849 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1850 this);
1851
1852 if (count == null) {
1853 StringBundler query = new StringBundler(2);
1854
1855 query.append(_SQL_COUNT_CALEVENT_WHERE);
1856
1857 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1858
1859 String sql = query.toString();
1860
1861 Session session = null;
1862
1863 try {
1864 session = openSession();
1865
1866 Query q = session.createQuery(sql);
1867
1868 QueryPos qPos = QueryPos.getInstance(q);
1869
1870 qPos.add(companyId);
1871
1872 count = (Long)q.uniqueResult();
1873
1874 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1875 }
1876 catch (Exception e) {
1877 FinderCacheUtil.removeResult(finderPath, finderArgs);
1878
1879 throw processException(e);
1880 }
1881 finally {
1882 closeSession(session);
1883 }
1884 }
1885
1886 return count.intValue();
1887 }
1888
1889 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "calEvent.companyId = ?";
1890 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
1891 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
1892 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1893 new String[] {
1894 Long.class.getName(),
1895
1896 Integer.class.getName(), Integer.class.getName(),
1897 OrderByComparator.class.getName()
1898 });
1899 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1900 new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
1901 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
1902 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1903 new String[] { Long.class.getName() },
1904 CalEventModelImpl.GROUPID_COLUMN_BITMASK |
1905 CalEventModelImpl.STARTDATE_COLUMN_BITMASK |
1906 CalEventModelImpl.TITLE_COLUMN_BITMASK);
1907 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
1908 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1909 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1910 new String[] { Long.class.getName() });
1911
1912
1919 public List<CalEvent> findByGroupId(long groupId) throws SystemException {
1920 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1921 }
1922
1923
1936 public List<CalEvent> findByGroupId(long groupId, int start, int end)
1937 throws SystemException {
1938 return findByGroupId(groupId, start, end, null);
1939 }
1940
1941
1955 public List<CalEvent> findByGroupId(long groupId, int start, int end,
1956 OrderByComparator orderByComparator) throws SystemException {
1957 boolean pagination = true;
1958 FinderPath finderPath = null;
1959 Object[] finderArgs = null;
1960
1961 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1962 (orderByComparator == null)) {
1963 pagination = false;
1964 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1965 finderArgs = new Object[] { groupId };
1966 }
1967 else {
1968 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1969 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1970 }
1971
1972 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
1973 finderArgs, this);
1974
1975 if ((list != null) && !list.isEmpty()) {
1976 for (CalEvent calEvent : list) {
1977 if ((groupId != calEvent.getGroupId())) {
1978 list = null;
1979
1980 break;
1981 }
1982 }
1983 }
1984
1985 if (list == null) {
1986 StringBundler query = null;
1987
1988 if (orderByComparator != null) {
1989 query = new StringBundler(3 +
1990 (orderByComparator.getOrderByFields().length * 3));
1991 }
1992 else {
1993 query = new StringBundler(3);
1994 }
1995
1996 query.append(_SQL_SELECT_CALEVENT_WHERE);
1997
1998 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1999
2000 if (orderByComparator != null) {
2001 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2002 orderByComparator);
2003 }
2004 else
2005 if (pagination) {
2006 query.append(CalEventModelImpl.ORDER_BY_JPQL);
2007 }
2008
2009 String sql = query.toString();
2010
2011 Session session = null;
2012
2013 try {
2014 session = openSession();
2015
2016 Query q = session.createQuery(sql);
2017
2018 QueryPos qPos = QueryPos.getInstance(q);
2019
2020 qPos.add(groupId);
2021
2022 if (!pagination) {
2023 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
2024 start, end, false);
2025
2026 Collections.sort(list);
2027
2028 list = new UnmodifiableList<CalEvent>(list);
2029 }
2030 else {
2031 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
2032 start, end);
2033 }
2034
2035 cacheResult(list);
2036
2037 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2038 }
2039 catch (Exception e) {
2040 FinderCacheUtil.removeResult(finderPath, finderArgs);
2041
2042 throw processException(e);
2043 }
2044 finally {
2045 closeSession(session);
2046 }
2047 }
2048
2049 return list;
2050 }
2051
2052
2061 public CalEvent findByGroupId_First(long groupId,
2062 OrderByComparator orderByComparator)
2063 throws NoSuchEventException, SystemException {
2064 CalEvent calEvent = fetchByGroupId_First(groupId, orderByComparator);
2065
2066 if (calEvent != null) {
2067 return calEvent;
2068 }
2069
2070 StringBundler msg = new StringBundler(4);
2071
2072 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2073
2074 msg.append("groupId=");
2075 msg.append(groupId);
2076
2077 msg.append(StringPool.CLOSE_CURLY_BRACE);
2078
2079 throw new NoSuchEventException(msg.toString());
2080 }
2081
2082
2090 public CalEvent fetchByGroupId_First(long groupId,
2091 OrderByComparator orderByComparator) throws SystemException {
2092 List<CalEvent> list = findByGroupId(groupId, 0, 1, orderByComparator);
2093
2094 if (!list.isEmpty()) {
2095 return list.get(0);
2096 }
2097
2098 return null;
2099 }
2100
2101
2110 public CalEvent findByGroupId_Last(long groupId,
2111 OrderByComparator orderByComparator)
2112 throws NoSuchEventException, SystemException {
2113 CalEvent calEvent = fetchByGroupId_Last(groupId, orderByComparator);
2114
2115 if (calEvent != null) {
2116 return calEvent;
2117 }
2118
2119 StringBundler msg = new StringBundler(4);
2120
2121 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2122
2123 msg.append("groupId=");
2124 msg.append(groupId);
2125
2126 msg.append(StringPool.CLOSE_CURLY_BRACE);
2127
2128 throw new NoSuchEventException(msg.toString());
2129 }
2130
2131
2139 public CalEvent fetchByGroupId_Last(long groupId,
2140 OrderByComparator orderByComparator) throws SystemException {
2141 int count = countByGroupId(groupId);
2142
2143 List<CalEvent> list = findByGroupId(groupId, count - 1, count,
2144 orderByComparator);
2145
2146 if (!list.isEmpty()) {
2147 return list.get(0);
2148 }
2149
2150 return null;
2151 }
2152
2153
2163 public CalEvent[] findByGroupId_PrevAndNext(long eventId, long groupId,
2164 OrderByComparator orderByComparator)
2165 throws NoSuchEventException, SystemException {
2166 CalEvent calEvent = findByPrimaryKey(eventId);
2167
2168 Session session = null;
2169
2170 try {
2171 session = openSession();
2172
2173 CalEvent[] array = new CalEventImpl[3];
2174
2175 array[0] = getByGroupId_PrevAndNext(session, calEvent, groupId,
2176 orderByComparator, true);
2177
2178 array[1] = calEvent;
2179
2180 array[2] = getByGroupId_PrevAndNext(session, calEvent, groupId,
2181 orderByComparator, false);
2182
2183 return array;
2184 }
2185 catch (Exception e) {
2186 throw processException(e);
2187 }
2188 finally {
2189 closeSession(session);
2190 }
2191 }
2192
2193 protected CalEvent getByGroupId_PrevAndNext(Session session,
2194 CalEvent calEvent, long groupId, OrderByComparator orderByComparator,
2195 boolean previous) {
2196 StringBundler query = null;
2197
2198 if (orderByComparator != null) {
2199 query = new StringBundler(6 +
2200 (orderByComparator.getOrderByFields().length * 6));
2201 }
2202 else {
2203 query = new StringBundler(3);
2204 }
2205
2206 query.append(_SQL_SELECT_CALEVENT_WHERE);
2207
2208 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2209
2210 if (orderByComparator != null) {
2211 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2212
2213 if (orderByConditionFields.length > 0) {
2214 query.append(WHERE_AND);
2215 }
2216
2217 for (int i = 0; i < orderByConditionFields.length; i++) {
2218 query.append(_ORDER_BY_ENTITY_ALIAS);
2219 query.append(orderByConditionFields[i]);
2220
2221 if ((i + 1) < orderByConditionFields.length) {
2222 if (orderByComparator.isAscending() ^ previous) {
2223 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2224 }
2225 else {
2226 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2227 }
2228 }
2229 else {
2230 if (orderByComparator.isAscending() ^ previous) {
2231 query.append(WHERE_GREATER_THAN);
2232 }
2233 else {
2234 query.append(WHERE_LESSER_THAN);
2235 }
2236 }
2237 }
2238
2239 query.append(ORDER_BY_CLAUSE);
2240
2241 String[] orderByFields = orderByComparator.getOrderByFields();
2242
2243 for (int i = 0; i < orderByFields.length; i++) {
2244 query.append(_ORDER_BY_ENTITY_ALIAS);
2245 query.append(orderByFields[i]);
2246
2247 if ((i + 1) < orderByFields.length) {
2248 if (orderByComparator.isAscending() ^ previous) {
2249 query.append(ORDER_BY_ASC_HAS_NEXT);
2250 }
2251 else {
2252 query.append(ORDER_BY_DESC_HAS_NEXT);
2253 }
2254 }
2255 else {
2256 if (orderByComparator.isAscending() ^ previous) {
2257 query.append(ORDER_BY_ASC);
2258 }
2259 else {
2260 query.append(ORDER_BY_DESC);
2261 }
2262 }
2263 }
2264 }
2265 else {
2266 query.append(CalEventModelImpl.ORDER_BY_JPQL);
2267 }
2268
2269 String sql = query.toString();
2270
2271 Query q = session.createQuery(sql);
2272
2273 q.setFirstResult(0);
2274 q.setMaxResults(2);
2275
2276 QueryPos qPos = QueryPos.getInstance(q);
2277
2278 qPos.add(groupId);
2279
2280 if (orderByComparator != null) {
2281 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
2282
2283 for (Object value : values) {
2284 qPos.add(value);
2285 }
2286 }
2287
2288 List<CalEvent> list = q.list();
2289
2290 if (list.size() == 2) {
2291 return list.get(1);
2292 }
2293 else {
2294 return null;
2295 }
2296 }
2297
2298
2305 public List<CalEvent> filterFindByGroupId(long groupId)
2306 throws SystemException {
2307 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2308 QueryUtil.ALL_POS, null);
2309 }
2310
2311
2324 public List<CalEvent> filterFindByGroupId(long groupId, int start, int end)
2325 throws SystemException {
2326 return filterFindByGroupId(groupId, start, end, null);
2327 }
2328
2329
2343 public List<CalEvent> filterFindByGroupId(long groupId, int start, int end,
2344 OrderByComparator orderByComparator) throws SystemException {
2345 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2346 return findByGroupId(groupId, start, end, orderByComparator);
2347 }
2348
2349 StringBundler query = null;
2350
2351 if (orderByComparator != null) {
2352 query = new StringBundler(3 +
2353 (orderByComparator.getOrderByFields().length * 3));
2354 }
2355 else {
2356 query = new StringBundler(3);
2357 }
2358
2359 if (getDB().isSupportsInlineDistinct()) {
2360 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
2361 }
2362 else {
2363 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
2364 }
2365
2366 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2367
2368 if (!getDB().isSupportsInlineDistinct()) {
2369 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
2370 }
2371
2372 if (orderByComparator != null) {
2373 if (getDB().isSupportsInlineDistinct()) {
2374 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2375 orderByComparator);
2376 }
2377 else {
2378 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2379 orderByComparator);
2380 }
2381 }
2382 else {
2383 if (getDB().isSupportsInlineDistinct()) {
2384 query.append(CalEventModelImpl.ORDER_BY_JPQL);
2385 }
2386 else {
2387 query.append(CalEventModelImpl.ORDER_BY_SQL);
2388 }
2389 }
2390
2391 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2392 CalEvent.class.getName(),
2393 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2394
2395 Session session = null;
2396
2397 try {
2398 session = openSession();
2399
2400 SQLQuery q = session.createSQLQuery(sql);
2401
2402 if (getDB().isSupportsInlineDistinct()) {
2403 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
2404 }
2405 else {
2406 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
2407 }
2408
2409 QueryPos qPos = QueryPos.getInstance(q);
2410
2411 qPos.add(groupId);
2412
2413 return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
2414 }
2415 catch (Exception e) {
2416 throw processException(e);
2417 }
2418 finally {
2419 closeSession(session);
2420 }
2421 }
2422
2423
2433 public CalEvent[] filterFindByGroupId_PrevAndNext(long eventId,
2434 long groupId, OrderByComparator orderByComparator)
2435 throws NoSuchEventException, SystemException {
2436 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2437 return findByGroupId_PrevAndNext(eventId, groupId, orderByComparator);
2438 }
2439
2440 CalEvent calEvent = findByPrimaryKey(eventId);
2441
2442 Session session = null;
2443
2444 try {
2445 session = openSession();
2446
2447 CalEvent[] array = new CalEventImpl[3];
2448
2449 array[0] = filterGetByGroupId_PrevAndNext(session, calEvent,
2450 groupId, orderByComparator, true);
2451
2452 array[1] = calEvent;
2453
2454 array[2] = filterGetByGroupId_PrevAndNext(session, calEvent,
2455 groupId, orderByComparator, false);
2456
2457 return array;
2458 }
2459 catch (Exception e) {
2460 throw processException(e);
2461 }
2462 finally {
2463 closeSession(session);
2464 }
2465 }
2466
2467 protected CalEvent filterGetByGroupId_PrevAndNext(Session session,
2468 CalEvent calEvent, long groupId, OrderByComparator orderByComparator,
2469 boolean previous) {
2470 StringBundler query = null;
2471
2472 if (orderByComparator != null) {
2473 query = new StringBundler(6 +
2474 (orderByComparator.getOrderByFields().length * 6));
2475 }
2476 else {
2477 query = new StringBundler(3);
2478 }
2479
2480 if (getDB().isSupportsInlineDistinct()) {
2481 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
2482 }
2483 else {
2484 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
2485 }
2486
2487 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2488
2489 if (!getDB().isSupportsInlineDistinct()) {
2490 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
2491 }
2492
2493 if (orderByComparator != null) {
2494 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2495
2496 if (orderByConditionFields.length > 0) {
2497 query.append(WHERE_AND);
2498 }
2499
2500 for (int i = 0; i < orderByConditionFields.length; i++) {
2501 if (getDB().isSupportsInlineDistinct()) {
2502 query.append(_ORDER_BY_ENTITY_ALIAS);
2503 }
2504 else {
2505 query.append(_ORDER_BY_ENTITY_TABLE);
2506 }
2507
2508 query.append(orderByConditionFields[i]);
2509
2510 if ((i + 1) < orderByConditionFields.length) {
2511 if (orderByComparator.isAscending() ^ previous) {
2512 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2513 }
2514 else {
2515 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2516 }
2517 }
2518 else {
2519 if (orderByComparator.isAscending() ^ previous) {
2520 query.append(WHERE_GREATER_THAN);
2521 }
2522 else {
2523 query.append(WHERE_LESSER_THAN);
2524 }
2525 }
2526 }
2527
2528 query.append(ORDER_BY_CLAUSE);
2529
2530 String[] orderByFields = orderByComparator.getOrderByFields();
2531
2532 for (int i = 0; i < orderByFields.length; i++) {
2533 if (getDB().isSupportsInlineDistinct()) {
2534 query.append(_ORDER_BY_ENTITY_ALIAS);
2535 }
2536 else {
2537 query.append(_ORDER_BY_ENTITY_TABLE);
2538 }
2539
2540 query.append(orderByFields[i]);
2541
2542 if ((i + 1) < orderByFields.length) {
2543 if (orderByComparator.isAscending() ^ previous) {
2544 query.append(ORDER_BY_ASC_HAS_NEXT);
2545 }
2546 else {
2547 query.append(ORDER_BY_DESC_HAS_NEXT);
2548 }
2549 }
2550 else {
2551 if (orderByComparator.isAscending() ^ previous) {
2552 query.append(ORDER_BY_ASC);
2553 }
2554 else {
2555 query.append(ORDER_BY_DESC);
2556 }
2557 }
2558 }
2559 }
2560 else {
2561 if (getDB().isSupportsInlineDistinct()) {
2562 query.append(CalEventModelImpl.ORDER_BY_JPQL);
2563 }
2564 else {
2565 query.append(CalEventModelImpl.ORDER_BY_SQL);
2566 }
2567 }
2568
2569 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2570 CalEvent.class.getName(),
2571 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2572
2573 SQLQuery q = session.createSQLQuery(sql);
2574
2575 q.setFirstResult(0);
2576 q.setMaxResults(2);
2577
2578 if (getDB().isSupportsInlineDistinct()) {
2579 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
2580 }
2581 else {
2582 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
2583 }
2584
2585 QueryPos qPos = QueryPos.getInstance(q);
2586
2587 qPos.add(groupId);
2588
2589 if (orderByComparator != null) {
2590 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
2591
2592 for (Object value : values) {
2593 qPos.add(value);
2594 }
2595 }
2596
2597 List<CalEvent> list = q.list();
2598
2599 if (list.size() == 2) {
2600 return list.get(1);
2601 }
2602 else {
2603 return null;
2604 }
2605 }
2606
2607
2613 public void removeByGroupId(long groupId) throws SystemException {
2614 for (CalEvent calEvent : findByGroupId(groupId, QueryUtil.ALL_POS,
2615 QueryUtil.ALL_POS, null)) {
2616 remove(calEvent);
2617 }
2618 }
2619
2620
2627 public int countByGroupId(long groupId) throws SystemException {
2628 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2629
2630 Object[] finderArgs = new Object[] { groupId };
2631
2632 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2633 this);
2634
2635 if (count == null) {
2636 StringBundler query = new StringBundler(2);
2637
2638 query.append(_SQL_COUNT_CALEVENT_WHERE);
2639
2640 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2641
2642 String sql = query.toString();
2643
2644 Session session = null;
2645
2646 try {
2647 session = openSession();
2648
2649 Query q = session.createQuery(sql);
2650
2651 QueryPos qPos = QueryPos.getInstance(q);
2652
2653 qPos.add(groupId);
2654
2655 count = (Long)q.uniqueResult();
2656
2657 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2658 }
2659 catch (Exception e) {
2660 FinderCacheUtil.removeResult(finderPath, finderArgs);
2661
2662 throw processException(e);
2663 }
2664 finally {
2665 closeSession(session);
2666 }
2667 }
2668
2669 return count.intValue();
2670 }
2671
2672
2679 public int filterCountByGroupId(long groupId) throws SystemException {
2680 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2681 return countByGroupId(groupId);
2682 }
2683
2684 StringBundler query = new StringBundler(2);
2685
2686 query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
2687
2688 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2689
2690 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2691 CalEvent.class.getName(),
2692 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2693
2694 Session session = null;
2695
2696 try {
2697 session = openSession();
2698
2699 SQLQuery q = session.createSQLQuery(sql);
2700
2701 q.addScalar(COUNT_COLUMN_NAME,
2702 com.liferay.portal.kernel.dao.orm.Type.LONG);
2703
2704 QueryPos qPos = QueryPos.getInstance(q);
2705
2706 qPos.add(groupId);
2707
2708 Long count = (Long)q.uniqueResult();
2709
2710 return count.intValue();
2711 }
2712 catch (Exception e) {
2713 throw processException(e);
2714 }
2715 finally {
2716 closeSession(session);
2717 }
2718 }
2719
2720 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "calEvent.groupId = ?";
2721 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTREMINDBY =
2722 new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
2723 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
2724 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNotRemindBy",
2725 new String[] {
2726 Integer.class.getName(),
2727
2728 Integer.class.getName(), Integer.class.getName(),
2729 OrderByComparator.class.getName()
2730 });
2731 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTREMINDBY =
2732 new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
2733 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
2734 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByNotRemindBy",
2735 new String[] { Integer.class.getName() });
2736
2737
2744 public List<CalEvent> findByNotRemindBy(int remindBy)
2745 throws SystemException {
2746 return findByNotRemindBy(remindBy, QueryUtil.ALL_POS,
2747 QueryUtil.ALL_POS, null);
2748 }
2749
2750
2763 public List<CalEvent> findByNotRemindBy(int remindBy, int start, int end)
2764 throws SystemException {
2765 return findByNotRemindBy(remindBy, start, end, null);
2766 }
2767
2768
2782 public List<CalEvent> findByNotRemindBy(int remindBy, int start, int end,
2783 OrderByComparator orderByComparator) throws SystemException {
2784 boolean pagination = true;
2785 FinderPath finderPath = null;
2786 Object[] finderArgs = null;
2787
2788 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTREMINDBY;
2789 finderArgs = new Object[] { remindBy, start, end, orderByComparator };
2790
2791 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
2792 finderArgs, this);
2793
2794 if ((list != null) && !list.isEmpty()) {
2795 for (CalEvent calEvent : list) {
2796 if ((remindBy != calEvent.getRemindBy())) {
2797 list = null;
2798
2799 break;
2800 }
2801 }
2802 }
2803
2804 if (list == null) {
2805 StringBundler query = null;
2806
2807 if (orderByComparator != null) {
2808 query = new StringBundler(3 +
2809 (orderByComparator.getOrderByFields().length * 3));
2810 }
2811 else {
2812 query = new StringBundler(3);
2813 }
2814
2815 query.append(_SQL_SELECT_CALEVENT_WHERE);
2816
2817 query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
2818
2819 if (orderByComparator != null) {
2820 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2821 orderByComparator);
2822 }
2823 else
2824 if (pagination) {
2825 query.append(CalEventModelImpl.ORDER_BY_JPQL);
2826 }
2827
2828 String sql = query.toString();
2829
2830 Session session = null;
2831
2832 try {
2833 session = openSession();
2834
2835 Query q = session.createQuery(sql);
2836
2837 QueryPos qPos = QueryPos.getInstance(q);
2838
2839 qPos.add(remindBy);
2840
2841 if (!pagination) {
2842 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
2843 start, end, false);
2844
2845 Collections.sort(list);
2846
2847 list = new UnmodifiableList<CalEvent>(list);
2848 }
2849 else {
2850 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
2851 start, end);
2852 }
2853
2854 cacheResult(list);
2855
2856 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2857 }
2858 catch (Exception e) {
2859 FinderCacheUtil.removeResult(finderPath, finderArgs);
2860
2861 throw processException(e);
2862 }
2863 finally {
2864 closeSession(session);
2865 }
2866 }
2867
2868 return list;
2869 }
2870
2871
2880 public CalEvent findByNotRemindBy_First(int remindBy,
2881 OrderByComparator orderByComparator)
2882 throws NoSuchEventException, SystemException {
2883 CalEvent calEvent = fetchByNotRemindBy_First(remindBy, orderByComparator);
2884
2885 if (calEvent != null) {
2886 return calEvent;
2887 }
2888
2889 StringBundler msg = new StringBundler(4);
2890
2891 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2892
2893 msg.append("remindBy=");
2894 msg.append(remindBy);
2895
2896 msg.append(StringPool.CLOSE_CURLY_BRACE);
2897
2898 throw new NoSuchEventException(msg.toString());
2899 }
2900
2901
2909 public CalEvent fetchByNotRemindBy_First(int remindBy,
2910 OrderByComparator orderByComparator) throws SystemException {
2911 List<CalEvent> list = findByNotRemindBy(remindBy, 0, 1,
2912 orderByComparator);
2913
2914 if (!list.isEmpty()) {
2915 return list.get(0);
2916 }
2917
2918 return null;
2919 }
2920
2921
2930 public CalEvent findByNotRemindBy_Last(int remindBy,
2931 OrderByComparator orderByComparator)
2932 throws NoSuchEventException, SystemException {
2933 CalEvent calEvent = fetchByNotRemindBy_Last(remindBy, orderByComparator);
2934
2935 if (calEvent != null) {
2936 return calEvent;
2937 }
2938
2939 StringBundler msg = new StringBundler(4);
2940
2941 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2942
2943 msg.append("remindBy=");
2944 msg.append(remindBy);
2945
2946 msg.append(StringPool.CLOSE_CURLY_BRACE);
2947
2948 throw new NoSuchEventException(msg.toString());
2949 }
2950
2951
2959 public CalEvent fetchByNotRemindBy_Last(int remindBy,
2960 OrderByComparator orderByComparator) throws SystemException {
2961 int count = countByNotRemindBy(remindBy);
2962
2963 List<CalEvent> list = findByNotRemindBy(remindBy, count - 1, count,
2964 orderByComparator);
2965
2966 if (!list.isEmpty()) {
2967 return list.get(0);
2968 }
2969
2970 return null;
2971 }
2972
2973
2983 public CalEvent[] findByNotRemindBy_PrevAndNext(long eventId, int remindBy,
2984 OrderByComparator orderByComparator)
2985 throws NoSuchEventException, SystemException {
2986 CalEvent calEvent = findByPrimaryKey(eventId);
2987
2988 Session session = null;
2989
2990 try {
2991 session = openSession();
2992
2993 CalEvent[] array = new CalEventImpl[3];
2994
2995 array[0] = getByNotRemindBy_PrevAndNext(session, calEvent,
2996 remindBy, orderByComparator, true);
2997
2998 array[1] = calEvent;
2999
3000 array[2] = getByNotRemindBy_PrevAndNext(session, calEvent,
3001 remindBy, orderByComparator, false);
3002
3003 return array;
3004 }
3005 catch (Exception e) {
3006 throw processException(e);
3007 }
3008 finally {
3009 closeSession(session);
3010 }
3011 }
3012
3013 protected CalEvent getByNotRemindBy_PrevAndNext(Session session,
3014 CalEvent calEvent, int remindBy, OrderByComparator orderByComparator,
3015 boolean previous) {
3016 StringBundler query = null;
3017
3018 if (orderByComparator != null) {
3019 query = new StringBundler(6 +
3020 (orderByComparator.getOrderByFields().length * 6));
3021 }
3022 else {
3023 query = new StringBundler(3);
3024 }
3025
3026 query.append(_SQL_SELECT_CALEVENT_WHERE);
3027
3028 query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
3029
3030 if (orderByComparator != null) {
3031 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3032
3033 if (orderByConditionFields.length > 0) {
3034 query.append(WHERE_AND);
3035 }
3036
3037 for (int i = 0; i < orderByConditionFields.length; i++) {
3038 query.append(_ORDER_BY_ENTITY_ALIAS);
3039 query.append(orderByConditionFields[i]);
3040
3041 if ((i + 1) < orderByConditionFields.length) {
3042 if (orderByComparator.isAscending() ^ previous) {
3043 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3044 }
3045 else {
3046 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3047 }
3048 }
3049 else {
3050 if (orderByComparator.isAscending() ^ previous) {
3051 query.append(WHERE_GREATER_THAN);
3052 }
3053 else {
3054 query.append(WHERE_LESSER_THAN);
3055 }
3056 }
3057 }
3058
3059 query.append(ORDER_BY_CLAUSE);
3060
3061 String[] orderByFields = orderByComparator.getOrderByFields();
3062
3063 for (int i = 0; i < orderByFields.length; i++) {
3064 query.append(_ORDER_BY_ENTITY_ALIAS);
3065 query.append(orderByFields[i]);
3066
3067 if ((i + 1) < orderByFields.length) {
3068 if (orderByComparator.isAscending() ^ previous) {
3069 query.append(ORDER_BY_ASC_HAS_NEXT);
3070 }
3071 else {
3072 query.append(ORDER_BY_DESC_HAS_NEXT);
3073 }
3074 }
3075 else {
3076 if (orderByComparator.isAscending() ^ previous) {
3077 query.append(ORDER_BY_ASC);
3078 }
3079 else {
3080 query.append(ORDER_BY_DESC);
3081 }
3082 }
3083 }
3084 }
3085 else {
3086 query.append(CalEventModelImpl.ORDER_BY_JPQL);
3087 }
3088
3089 String sql = query.toString();
3090
3091 Query q = session.createQuery(sql);
3092
3093 q.setFirstResult(0);
3094 q.setMaxResults(2);
3095
3096 QueryPos qPos = QueryPos.getInstance(q);
3097
3098 qPos.add(remindBy);
3099
3100 if (orderByComparator != null) {
3101 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
3102
3103 for (Object value : values) {
3104 qPos.add(value);
3105 }
3106 }
3107
3108 List<CalEvent> list = q.list();
3109
3110 if (list.size() == 2) {
3111 return list.get(1);
3112 }
3113 else {
3114 return null;
3115 }
3116 }
3117
3118
3124 public void removeByNotRemindBy(int remindBy) throws SystemException {
3125 for (CalEvent calEvent : findByNotRemindBy(remindBy, QueryUtil.ALL_POS,
3126 QueryUtil.ALL_POS, null)) {
3127 remove(calEvent);
3128 }
3129 }
3130
3131
3138 public int countByNotRemindBy(int remindBy) throws SystemException {
3139 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTREMINDBY;
3140
3141 Object[] finderArgs = new Object[] { remindBy };
3142
3143 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3144 this);
3145
3146 if (count == null) {
3147 StringBundler query = new StringBundler(2);
3148
3149 query.append(_SQL_COUNT_CALEVENT_WHERE);
3150
3151 query.append(_FINDER_COLUMN_NOTREMINDBY_REMINDBY_2);
3152
3153 String sql = query.toString();
3154
3155 Session session = null;
3156
3157 try {
3158 session = openSession();
3159
3160 Query q = session.createQuery(sql);
3161
3162 QueryPos qPos = QueryPos.getInstance(q);
3163
3164 qPos.add(remindBy);
3165
3166 count = (Long)q.uniqueResult();
3167
3168 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3169 }
3170 catch (Exception e) {
3171 FinderCacheUtil.removeResult(finderPath, finderArgs);
3172
3173 throw processException(e);
3174 }
3175 finally {
3176 closeSession(session);
3177 }
3178 }
3179
3180 return count.intValue();
3181 }
3182
3183 private static final String _FINDER_COLUMN_NOTREMINDBY_REMINDBY_2 = "calEvent.remindBy != ?";
3184 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
3185 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
3186 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_T",
3187 new String[] {
3188 Long.class.getName(), String.class.getName(),
3189
3190 Integer.class.getName(), Integer.class.getName(),
3191 OrderByComparator.class.getName()
3192 });
3193 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
3194 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
3195 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_T",
3196 new String[] { Long.class.getName(), String.class.getName() },
3197 CalEventModelImpl.GROUPID_COLUMN_BITMASK |
3198 CalEventModelImpl.TYPE_COLUMN_BITMASK |
3199 CalEventModelImpl.STARTDATE_COLUMN_BITMASK |
3200 CalEventModelImpl.TITLE_COLUMN_BITMASK);
3201 public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
3202 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
3203 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T",
3204 new String[] { Long.class.getName(), String.class.getName() });
3205 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
3206 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
3207 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_T",
3208 new String[] { Long.class.getName(), String.class.getName() });
3209
3210
3218 public List<CalEvent> findByG_T(long groupId, String type)
3219 throws SystemException {
3220 return findByG_T(groupId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3221 null);
3222 }
3223
3224
3238 public List<CalEvent> findByG_T(long groupId, String type, int start,
3239 int end) throws SystemException {
3240 return findByG_T(groupId, type, start, end, null);
3241 }
3242
3243
3258 public List<CalEvent> findByG_T(long groupId, String type, int start,
3259 int end, OrderByComparator orderByComparator) throws SystemException {
3260 boolean pagination = true;
3261 FinderPath finderPath = null;
3262 Object[] finderArgs = null;
3263
3264 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3265 (orderByComparator == null)) {
3266 pagination = false;
3267 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T;
3268 finderArgs = new Object[] { groupId, type };
3269 }
3270 else {
3271 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T;
3272 finderArgs = new Object[] {
3273 groupId, type,
3274
3275 start, end, orderByComparator
3276 };
3277 }
3278
3279 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
3280 finderArgs, this);
3281
3282 if ((list != null) && !list.isEmpty()) {
3283 for (CalEvent calEvent : list) {
3284 if ((groupId != calEvent.getGroupId()) ||
3285 !Validator.equals(type, calEvent.getType())) {
3286 list = null;
3287
3288 break;
3289 }
3290 }
3291 }
3292
3293 if (list == null) {
3294 StringBundler query = null;
3295
3296 if (orderByComparator != null) {
3297 query = new StringBundler(4 +
3298 (orderByComparator.getOrderByFields().length * 3));
3299 }
3300 else {
3301 query = new StringBundler(4);
3302 }
3303
3304 query.append(_SQL_SELECT_CALEVENT_WHERE);
3305
3306 query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3307
3308 if (type == null) {
3309 query.append(_FINDER_COLUMN_G_T_TYPE_1);
3310 }
3311 else {
3312 if (type.equals(StringPool.BLANK)) {
3313 query.append(_FINDER_COLUMN_G_T_TYPE_3);
3314 }
3315 else {
3316 query.append(_FINDER_COLUMN_G_T_TYPE_2);
3317 }
3318 }
3319
3320 if (orderByComparator != null) {
3321 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3322 orderByComparator);
3323 }
3324 else
3325 if (pagination) {
3326 query.append(CalEventModelImpl.ORDER_BY_JPQL);
3327 }
3328
3329 String sql = query.toString();
3330
3331 Session session = null;
3332
3333 try {
3334 session = openSession();
3335
3336 Query q = session.createQuery(sql);
3337
3338 QueryPos qPos = QueryPos.getInstance(q);
3339
3340 qPos.add(groupId);
3341
3342 if (type != null) {
3343 qPos.add(type);
3344 }
3345
3346 if (!pagination) {
3347 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
3348 start, end, false);
3349
3350 Collections.sort(list);
3351
3352 list = new UnmodifiableList<CalEvent>(list);
3353 }
3354 else {
3355 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
3356 start, end);
3357 }
3358
3359 cacheResult(list);
3360
3361 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3362 }
3363 catch (Exception e) {
3364 FinderCacheUtil.removeResult(finderPath, finderArgs);
3365
3366 throw processException(e);
3367 }
3368 finally {
3369 closeSession(session);
3370 }
3371 }
3372
3373 return list;
3374 }
3375
3376
3386 public CalEvent findByG_T_First(long groupId, String type,
3387 OrderByComparator orderByComparator)
3388 throws NoSuchEventException, SystemException {
3389 CalEvent calEvent = fetchByG_T_First(groupId, type, orderByComparator);
3390
3391 if (calEvent != null) {
3392 return calEvent;
3393 }
3394
3395 StringBundler msg = new StringBundler(6);
3396
3397 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3398
3399 msg.append("groupId=");
3400 msg.append(groupId);
3401
3402 msg.append(", type=");
3403 msg.append(type);
3404
3405 msg.append(StringPool.CLOSE_CURLY_BRACE);
3406
3407 throw new NoSuchEventException(msg.toString());
3408 }
3409
3410
3419 public CalEvent fetchByG_T_First(long groupId, String type,
3420 OrderByComparator orderByComparator) throws SystemException {
3421 List<CalEvent> list = findByG_T(groupId, type, 0, 1, orderByComparator);
3422
3423 if (!list.isEmpty()) {
3424 return list.get(0);
3425 }
3426
3427 return null;
3428 }
3429
3430
3440 public CalEvent findByG_T_Last(long groupId, String type,
3441 OrderByComparator orderByComparator)
3442 throws NoSuchEventException, SystemException {
3443 CalEvent calEvent = fetchByG_T_Last(groupId, type, orderByComparator);
3444
3445 if (calEvent != null) {
3446 return calEvent;
3447 }
3448
3449 StringBundler msg = new StringBundler(6);
3450
3451 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3452
3453 msg.append("groupId=");
3454 msg.append(groupId);
3455
3456 msg.append(", type=");
3457 msg.append(type);
3458
3459 msg.append(StringPool.CLOSE_CURLY_BRACE);
3460
3461 throw new NoSuchEventException(msg.toString());
3462 }
3463
3464
3473 public CalEvent fetchByG_T_Last(long groupId, String type,
3474 OrderByComparator orderByComparator) throws SystemException {
3475 int count = countByG_T(groupId, type);
3476
3477 List<CalEvent> list = findByG_T(groupId, type, count - 1, count,
3478 orderByComparator);
3479
3480 if (!list.isEmpty()) {
3481 return list.get(0);
3482 }
3483
3484 return null;
3485 }
3486
3487
3498 public CalEvent[] findByG_T_PrevAndNext(long eventId, long groupId,
3499 String type, OrderByComparator orderByComparator)
3500 throws NoSuchEventException, SystemException {
3501 CalEvent calEvent = findByPrimaryKey(eventId);
3502
3503 Session session = null;
3504
3505 try {
3506 session = openSession();
3507
3508 CalEvent[] array = new CalEventImpl[3];
3509
3510 array[0] = getByG_T_PrevAndNext(session, calEvent, groupId, type,
3511 orderByComparator, true);
3512
3513 array[1] = calEvent;
3514
3515 array[2] = getByG_T_PrevAndNext(session, calEvent, groupId, type,
3516 orderByComparator, false);
3517
3518 return array;
3519 }
3520 catch (Exception e) {
3521 throw processException(e);
3522 }
3523 finally {
3524 closeSession(session);
3525 }
3526 }
3527
3528 protected CalEvent getByG_T_PrevAndNext(Session session, CalEvent calEvent,
3529 long groupId, String type, OrderByComparator orderByComparator,
3530 boolean previous) {
3531 StringBundler query = null;
3532
3533 if (orderByComparator != null) {
3534 query = new StringBundler(6 +
3535 (orderByComparator.getOrderByFields().length * 6));
3536 }
3537 else {
3538 query = new StringBundler(3);
3539 }
3540
3541 query.append(_SQL_SELECT_CALEVENT_WHERE);
3542
3543 query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3544
3545 if (type == null) {
3546 query.append(_FINDER_COLUMN_G_T_TYPE_1);
3547 }
3548 else {
3549 if (type.equals(StringPool.BLANK)) {
3550 query.append(_FINDER_COLUMN_G_T_TYPE_3);
3551 }
3552 else {
3553 query.append(_FINDER_COLUMN_G_T_TYPE_2);
3554 }
3555 }
3556
3557 if (orderByComparator != null) {
3558 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3559
3560 if (orderByConditionFields.length > 0) {
3561 query.append(WHERE_AND);
3562 }
3563
3564 for (int i = 0; i < orderByConditionFields.length; i++) {
3565 query.append(_ORDER_BY_ENTITY_ALIAS);
3566 query.append(orderByConditionFields[i]);
3567
3568 if ((i + 1) < orderByConditionFields.length) {
3569 if (orderByComparator.isAscending() ^ previous) {
3570 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3571 }
3572 else {
3573 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3574 }
3575 }
3576 else {
3577 if (orderByComparator.isAscending() ^ previous) {
3578 query.append(WHERE_GREATER_THAN);
3579 }
3580 else {
3581 query.append(WHERE_LESSER_THAN);
3582 }
3583 }
3584 }
3585
3586 query.append(ORDER_BY_CLAUSE);
3587
3588 String[] orderByFields = orderByComparator.getOrderByFields();
3589
3590 for (int i = 0; i < orderByFields.length; i++) {
3591 query.append(_ORDER_BY_ENTITY_ALIAS);
3592 query.append(orderByFields[i]);
3593
3594 if ((i + 1) < orderByFields.length) {
3595 if (orderByComparator.isAscending() ^ previous) {
3596 query.append(ORDER_BY_ASC_HAS_NEXT);
3597 }
3598 else {
3599 query.append(ORDER_BY_DESC_HAS_NEXT);
3600 }
3601 }
3602 else {
3603 if (orderByComparator.isAscending() ^ previous) {
3604 query.append(ORDER_BY_ASC);
3605 }
3606 else {
3607 query.append(ORDER_BY_DESC);
3608 }
3609 }
3610 }
3611 }
3612 else {
3613 query.append(CalEventModelImpl.ORDER_BY_JPQL);
3614 }
3615
3616 String sql = query.toString();
3617
3618 Query q = session.createQuery(sql);
3619
3620 q.setFirstResult(0);
3621 q.setMaxResults(2);
3622
3623 QueryPos qPos = QueryPos.getInstance(q);
3624
3625 qPos.add(groupId);
3626
3627 if (type != null) {
3628 qPos.add(type);
3629 }
3630
3631 if (orderByComparator != null) {
3632 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
3633
3634 for (Object value : values) {
3635 qPos.add(value);
3636 }
3637 }
3638
3639 List<CalEvent> list = q.list();
3640
3641 if (list.size() == 2) {
3642 return list.get(1);
3643 }
3644 else {
3645 return null;
3646 }
3647 }
3648
3649
3657 public List<CalEvent> filterFindByG_T(long groupId, String type)
3658 throws SystemException {
3659 return filterFindByG_T(groupId, type, QueryUtil.ALL_POS,
3660 QueryUtil.ALL_POS, null);
3661 }
3662
3663
3677 public List<CalEvent> filterFindByG_T(long groupId, String type, int start,
3678 int end) throws SystemException {
3679 return filterFindByG_T(groupId, type, start, end, null);
3680 }
3681
3682
3697 public List<CalEvent> filterFindByG_T(long groupId, String type, int start,
3698 int end, OrderByComparator orderByComparator) throws SystemException {
3699 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3700 return findByG_T(groupId, type, start, end, orderByComparator);
3701 }
3702
3703 StringBundler query = null;
3704
3705 if (orderByComparator != null) {
3706 query = new StringBundler(4 +
3707 (orderByComparator.getOrderByFields().length * 3));
3708 }
3709 else {
3710 query = new StringBundler(4);
3711 }
3712
3713 if (getDB().isSupportsInlineDistinct()) {
3714 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
3715 }
3716 else {
3717 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
3718 }
3719
3720 query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3721
3722 if (type == null) {
3723 query.append(_FINDER_COLUMN_G_T_TYPE_1);
3724 }
3725 else {
3726 if (type.equals(StringPool.BLANK)) {
3727 query.append(_FINDER_COLUMN_G_T_TYPE_3);
3728 }
3729 else {
3730 query.append(_FINDER_COLUMN_G_T_TYPE_2);
3731 }
3732 }
3733
3734 if (!getDB().isSupportsInlineDistinct()) {
3735 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
3736 }
3737
3738 if (orderByComparator != null) {
3739 if (getDB().isSupportsInlineDistinct()) {
3740 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3741 orderByComparator);
3742 }
3743 else {
3744 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3745 orderByComparator);
3746 }
3747 }
3748 else {
3749 if (getDB().isSupportsInlineDistinct()) {
3750 query.append(CalEventModelImpl.ORDER_BY_JPQL);
3751 }
3752 else {
3753 query.append(CalEventModelImpl.ORDER_BY_SQL);
3754 }
3755 }
3756
3757 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3758 CalEvent.class.getName(),
3759 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3760
3761 Session session = null;
3762
3763 try {
3764 session = openSession();
3765
3766 SQLQuery q = session.createSQLQuery(sql);
3767
3768 if (getDB().isSupportsInlineDistinct()) {
3769 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
3770 }
3771 else {
3772 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
3773 }
3774
3775 QueryPos qPos = QueryPos.getInstance(q);
3776
3777 qPos.add(groupId);
3778
3779 if (type != null) {
3780 qPos.add(type);
3781 }
3782
3783 return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
3784 }
3785 catch (Exception e) {
3786 throw processException(e);
3787 }
3788 finally {
3789 closeSession(session);
3790 }
3791 }
3792
3793
3804 public CalEvent[] filterFindByG_T_PrevAndNext(long eventId, long groupId,
3805 String type, OrderByComparator orderByComparator)
3806 throws NoSuchEventException, SystemException {
3807 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3808 return findByG_T_PrevAndNext(eventId, groupId, type,
3809 orderByComparator);
3810 }
3811
3812 CalEvent calEvent = findByPrimaryKey(eventId);
3813
3814 Session session = null;
3815
3816 try {
3817 session = openSession();
3818
3819 CalEvent[] array = new CalEventImpl[3];
3820
3821 array[0] = filterGetByG_T_PrevAndNext(session, calEvent, groupId,
3822 type, orderByComparator, true);
3823
3824 array[1] = calEvent;
3825
3826 array[2] = filterGetByG_T_PrevAndNext(session, calEvent, groupId,
3827 type, orderByComparator, false);
3828
3829 return array;
3830 }
3831 catch (Exception e) {
3832 throw processException(e);
3833 }
3834 finally {
3835 closeSession(session);
3836 }
3837 }
3838
3839 protected CalEvent filterGetByG_T_PrevAndNext(Session session,
3840 CalEvent calEvent, long groupId, String type,
3841 OrderByComparator orderByComparator, boolean previous) {
3842 StringBundler query = null;
3843
3844 if (orderByComparator != null) {
3845 query = new StringBundler(6 +
3846 (orderByComparator.getOrderByFields().length * 6));
3847 }
3848 else {
3849 query = new StringBundler(3);
3850 }
3851
3852 if (getDB().isSupportsInlineDistinct()) {
3853 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
3854 }
3855 else {
3856 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
3857 }
3858
3859 query.append(_FINDER_COLUMN_G_T_GROUPID_2);
3860
3861 if (type == null) {
3862 query.append(_FINDER_COLUMN_G_T_TYPE_1);
3863 }
3864 else {
3865 if (type.equals(StringPool.BLANK)) {
3866 query.append(_FINDER_COLUMN_G_T_TYPE_3);
3867 }
3868 else {
3869 query.append(_FINDER_COLUMN_G_T_TYPE_2);
3870 }
3871 }
3872
3873 if (!getDB().isSupportsInlineDistinct()) {
3874 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
3875 }
3876
3877 if (orderByComparator != null) {
3878 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3879
3880 if (orderByConditionFields.length > 0) {
3881 query.append(WHERE_AND);
3882 }
3883
3884 for (int i = 0; i < orderByConditionFields.length; i++) {
3885 if (getDB().isSupportsInlineDistinct()) {
3886 query.append(_ORDER_BY_ENTITY_ALIAS);
3887 }
3888 else {
3889 query.append(_ORDER_BY_ENTITY_TABLE);
3890 }
3891
3892 query.append(orderByConditionFields[i]);
3893
3894 if ((i + 1) < orderByConditionFields.length) {
3895 if (orderByComparator.isAscending() ^ previous) {
3896 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3897 }
3898 else {
3899 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3900 }
3901 }
3902 else {
3903 if (orderByComparator.isAscending() ^ previous) {
3904 query.append(WHERE_GREATER_THAN);
3905 }
3906 else {
3907 query.append(WHERE_LESSER_THAN);
3908 }
3909 }
3910 }
3911
3912 query.append(ORDER_BY_CLAUSE);
3913
3914 String[] orderByFields = orderByComparator.getOrderByFields();
3915
3916 for (int i = 0; i < orderByFields.length; i++) {
3917 if (getDB().isSupportsInlineDistinct()) {
3918 query.append(_ORDER_BY_ENTITY_ALIAS);
3919 }
3920 else {
3921 query.append(_ORDER_BY_ENTITY_TABLE);
3922 }
3923
3924 query.append(orderByFields[i]);
3925
3926 if ((i + 1) < orderByFields.length) {
3927 if (orderByComparator.isAscending() ^ previous) {
3928 query.append(ORDER_BY_ASC_HAS_NEXT);
3929 }
3930 else {
3931 query.append(ORDER_BY_DESC_HAS_NEXT);
3932 }
3933 }
3934 else {
3935 if (orderByComparator.isAscending() ^ previous) {
3936 query.append(ORDER_BY_ASC);
3937 }
3938 else {
3939 query.append(ORDER_BY_DESC);
3940 }
3941 }
3942 }
3943 }
3944 else {
3945 if (getDB().isSupportsInlineDistinct()) {
3946 query.append(CalEventModelImpl.ORDER_BY_JPQL);
3947 }
3948 else {
3949 query.append(CalEventModelImpl.ORDER_BY_SQL);
3950 }
3951 }
3952
3953 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3954 CalEvent.class.getName(),
3955 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3956
3957 SQLQuery q = session.createSQLQuery(sql);
3958
3959 q.setFirstResult(0);
3960 q.setMaxResults(2);
3961
3962 if (getDB().isSupportsInlineDistinct()) {
3963 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
3964 }
3965 else {
3966 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
3967 }
3968
3969 QueryPos qPos = QueryPos.getInstance(q);
3970
3971 qPos.add(groupId);
3972
3973 if (type != null) {
3974 qPos.add(type);
3975 }
3976
3977 if (orderByComparator != null) {
3978 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
3979
3980 for (Object value : values) {
3981 qPos.add(value);
3982 }
3983 }
3984
3985 List<CalEvent> list = q.list();
3986
3987 if (list.size() == 2) {
3988 return list.get(1);
3989 }
3990 else {
3991 return null;
3992 }
3993 }
3994
3995
4003 public List<CalEvent> filterFindByG_T(long groupId, String[] types)
4004 throws SystemException {
4005 return filterFindByG_T(groupId, types, QueryUtil.ALL_POS,
4006 QueryUtil.ALL_POS, null);
4007 }
4008
4009
4023 public List<CalEvent> filterFindByG_T(long groupId, String[] types,
4024 int start, int end) throws SystemException {
4025 return filterFindByG_T(groupId, types, start, end, null);
4026 }
4027
4028
4043 public List<CalEvent> filterFindByG_T(long groupId, String[] types,
4044 int start, int end, OrderByComparator orderByComparator)
4045 throws SystemException {
4046 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4047 return findByG_T(groupId, types, start, end, orderByComparator);
4048 }
4049
4050 StringBundler query = new StringBundler();
4051
4052 if (getDB().isSupportsInlineDistinct()) {
4053 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
4054 }
4055 else {
4056 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
4057 }
4058
4059 boolean conjunctionable = false;
4060
4061 if (conjunctionable) {
4062 query.append(WHERE_AND);
4063 }
4064
4065 query.append(_FINDER_COLUMN_G_T_GROUPID_5);
4066
4067 conjunctionable = true;
4068
4069 if ((types == null) || (types.length > 0)) {
4070 if (conjunctionable) {
4071 query.append(WHERE_AND);
4072 }
4073
4074 query.append(StringPool.OPEN_PARENTHESIS);
4075
4076 for (int i = 0; i < types.length; i++) {
4077 String type = types[i];
4078
4079 if (type == null) {
4080 query.append(_FINDER_COLUMN_G_T_TYPE_4);
4081 }
4082 else {
4083 if (type.equals(StringPool.BLANK)) {
4084 query.append(_FINDER_COLUMN_G_T_TYPE_6);
4085 }
4086 else {
4087 query.append(_FINDER_COLUMN_G_T_TYPE_5);
4088 }
4089 }
4090
4091 if ((i + 1) < types.length) {
4092 query.append(WHERE_OR);
4093 }
4094 }
4095
4096 query.append(StringPool.CLOSE_PARENTHESIS);
4097
4098 conjunctionable = true;
4099 }
4100
4101 if (!getDB().isSupportsInlineDistinct()) {
4102 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
4103 }
4104
4105 if (orderByComparator != null) {
4106 if (getDB().isSupportsInlineDistinct()) {
4107 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4108 orderByComparator);
4109 }
4110 else {
4111 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4112 orderByComparator);
4113 }
4114 }
4115 else {
4116 if (getDB().isSupportsInlineDistinct()) {
4117 query.append(CalEventModelImpl.ORDER_BY_JPQL);
4118 }
4119 else {
4120 query.append(CalEventModelImpl.ORDER_BY_SQL);
4121 }
4122 }
4123
4124 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4125 CalEvent.class.getName(),
4126 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4127
4128 Session session = null;
4129
4130 try {
4131 session = openSession();
4132
4133 SQLQuery q = session.createSQLQuery(sql);
4134
4135 if (getDB().isSupportsInlineDistinct()) {
4136 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
4137 }
4138 else {
4139 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
4140 }
4141
4142 QueryPos qPos = QueryPos.getInstance(q);
4143
4144 qPos.add(groupId);
4145
4146 if (types != null) {
4147 qPos.add(types);
4148 }
4149
4150 return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
4151 }
4152 catch (Exception e) {
4153 throw processException(e);
4154 }
4155 finally {
4156 closeSession(session);
4157 }
4158 }
4159
4160
4172 public List<CalEvent> findByG_T(long groupId, String[] types)
4173 throws SystemException {
4174 return findByG_T(groupId, types, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4175 null);
4176 }
4177
4178
4192 public List<CalEvent> findByG_T(long groupId, String[] types, int start,
4193 int end) throws SystemException {
4194 return findByG_T(groupId, types, start, end, null);
4195 }
4196
4197
4212 public List<CalEvent> findByG_T(long groupId, String[] types, int start,
4213 int end, OrderByComparator orderByComparator) throws SystemException {
4214 if ((types != null) && (types.length == 1)) {
4215 return findByG_T(groupId, types[0], start, end, orderByComparator);
4216 }
4217
4218 boolean pagination = true;
4219 Object[] finderArgs = null;
4220
4221 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4222 (orderByComparator == null)) {
4223 pagination = false;
4224 finderArgs = new Object[] { groupId, StringUtil.merge(types) };
4225 }
4226 else {
4227 finderArgs = new Object[] {
4228 groupId, StringUtil.merge(types),
4229
4230 start, end, orderByComparator
4231 };
4232 }
4233
4234 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T,
4235 finderArgs, this);
4236
4237 if ((list != null) && !list.isEmpty()) {
4238 for (CalEvent calEvent : list) {
4239 if ((groupId != calEvent.getGroupId()) ||
4240 !ArrayUtil.contains(types, calEvent.getType())) {
4241 list = null;
4242
4243 break;
4244 }
4245 }
4246 }
4247
4248 if (list == null) {
4249 StringBundler query = new StringBundler();
4250
4251 query.append(_SQL_SELECT_CALEVENT_WHERE);
4252
4253 boolean conjunctionable = false;
4254
4255 if (conjunctionable) {
4256 query.append(WHERE_AND);
4257 }
4258
4259 query.append(_FINDER_COLUMN_G_T_GROUPID_5);
4260
4261 conjunctionable = true;
4262
4263 if ((types == null) || (types.length > 0)) {
4264 if (conjunctionable) {
4265 query.append(WHERE_AND);
4266 }
4267
4268 query.append(StringPool.OPEN_PARENTHESIS);
4269
4270 for (int i = 0; i < types.length; i++) {
4271 String type = types[i];
4272
4273 if (type == null) {
4274 query.append(_FINDER_COLUMN_G_T_TYPE_4);
4275 }
4276 else {
4277 if (type.equals(StringPool.BLANK)) {
4278 query.append(_FINDER_COLUMN_G_T_TYPE_6);
4279 }
4280 else {
4281 query.append(_FINDER_COLUMN_G_T_TYPE_5);
4282 }
4283 }
4284
4285 if ((i + 1) < types.length) {
4286 query.append(WHERE_OR);
4287 }
4288 }
4289
4290 query.append(StringPool.CLOSE_PARENTHESIS);
4291
4292 conjunctionable = true;
4293 }
4294
4295 if (orderByComparator != null) {
4296 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4297 orderByComparator);
4298 }
4299 else
4300 if (pagination) {
4301 query.append(CalEventModelImpl.ORDER_BY_JPQL);
4302 }
4303
4304 String sql = query.toString();
4305
4306 Session session = null;
4307
4308 try {
4309 session = openSession();
4310
4311 Query q = session.createQuery(sql);
4312
4313 QueryPos qPos = QueryPos.getInstance(q);
4314
4315 qPos.add(groupId);
4316
4317 if (types != null) {
4318 qPos.add(types);
4319 }
4320
4321 if (!pagination) {
4322 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
4323 start, end, false);
4324
4325 Collections.sort(list);
4326
4327 list = new UnmodifiableList<CalEvent>(list);
4328 }
4329 else {
4330 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
4331 start, end);
4332 }
4333
4334 cacheResult(list);
4335
4336 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T,
4337 finderArgs, list);
4338 }
4339 catch (Exception e) {
4340 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T,
4341 finderArgs);
4342
4343 throw processException(e);
4344 }
4345 finally {
4346 closeSession(session);
4347 }
4348 }
4349
4350 return list;
4351 }
4352
4353
4360 public void removeByG_T(long groupId, String type)
4361 throws SystemException {
4362 for (CalEvent calEvent : findByG_T(groupId, type, QueryUtil.ALL_POS,
4363 QueryUtil.ALL_POS, null)) {
4364 remove(calEvent);
4365 }
4366 }
4367
4368
4376 public int countByG_T(long groupId, String type) throws SystemException {
4377 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_T;
4378
4379 Object[] finderArgs = new Object[] { groupId, type };
4380
4381 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4382 this);
4383
4384 if (count == null) {
4385 StringBundler query = new StringBundler(3);
4386
4387 query.append(_SQL_COUNT_CALEVENT_WHERE);
4388
4389 query.append(_FINDER_COLUMN_G_T_GROUPID_2);
4390
4391 if (type == null) {
4392 query.append(_FINDER_COLUMN_G_T_TYPE_1);
4393 }
4394 else {
4395 if (type.equals(StringPool.BLANK)) {
4396 query.append(_FINDER_COLUMN_G_T_TYPE_3);
4397 }
4398 else {
4399 query.append(_FINDER_COLUMN_G_T_TYPE_2);
4400 }
4401 }
4402
4403 String sql = query.toString();
4404
4405 Session session = null;
4406
4407 try {
4408 session = openSession();
4409
4410 Query q = session.createQuery(sql);
4411
4412 QueryPos qPos = QueryPos.getInstance(q);
4413
4414 qPos.add(groupId);
4415
4416 if (type != null) {
4417 qPos.add(type);
4418 }
4419
4420 count = (Long)q.uniqueResult();
4421
4422 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4423 }
4424 catch (Exception e) {
4425 FinderCacheUtil.removeResult(finderPath, finderArgs);
4426
4427 throw processException(e);
4428 }
4429 finally {
4430 closeSession(session);
4431 }
4432 }
4433
4434 return count.intValue();
4435 }
4436
4437
4445 public int countByG_T(long groupId, String[] types)
4446 throws SystemException {
4447 Object[] finderArgs = new Object[] { groupId, StringUtil.merge(types) };
4448
4449 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T,
4450 finderArgs, this);
4451
4452 if (count == null) {
4453 StringBundler query = new StringBundler();
4454
4455 query.append(_SQL_COUNT_CALEVENT_WHERE);
4456
4457 boolean conjunctionable = false;
4458
4459 if (conjunctionable) {
4460 query.append(WHERE_AND);
4461 }
4462
4463 query.append(_FINDER_COLUMN_G_T_GROUPID_5);
4464
4465 conjunctionable = true;
4466
4467 if ((types == null) || (types.length > 0)) {
4468 if (conjunctionable) {
4469 query.append(WHERE_AND);
4470 }
4471
4472 query.append(StringPool.OPEN_PARENTHESIS);
4473
4474 for (int i = 0; i < types.length; i++) {
4475 String type = types[i];
4476
4477 if (type == null) {
4478 query.append(_FINDER_COLUMN_G_T_TYPE_4);
4479 }
4480 else {
4481 if (type.equals(StringPool.BLANK)) {
4482 query.append(_FINDER_COLUMN_G_T_TYPE_6);
4483 }
4484 else {
4485 query.append(_FINDER_COLUMN_G_T_TYPE_5);
4486 }
4487 }
4488
4489 if ((i + 1) < types.length) {
4490 query.append(WHERE_OR);
4491 }
4492 }
4493
4494 query.append(StringPool.CLOSE_PARENTHESIS);
4495
4496 conjunctionable = true;
4497 }
4498
4499 String sql = query.toString();
4500
4501 Session session = null;
4502
4503 try {
4504 session = openSession();
4505
4506 Query q = session.createQuery(sql);
4507
4508 QueryPos qPos = QueryPos.getInstance(q);
4509
4510 qPos.add(groupId);
4511
4512 if (types != null) {
4513 qPos.add(types);
4514 }
4515
4516 count = (Long)q.uniqueResult();
4517
4518 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T,
4519 finderArgs, count);
4520 }
4521 catch (Exception e) {
4522 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T,
4523 finderArgs);
4524
4525 throw processException(e);
4526 }
4527 finally {
4528 closeSession(session);
4529 }
4530 }
4531
4532 return count.intValue();
4533 }
4534
4535
4543 public int filterCountByG_T(long groupId, String type)
4544 throws SystemException {
4545 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4546 return countByG_T(groupId, type);
4547 }
4548
4549 StringBundler query = new StringBundler(3);
4550
4551 query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
4552
4553 query.append(_FINDER_COLUMN_G_T_GROUPID_2);
4554
4555 if (type == null) {
4556 query.append(_FINDER_COLUMN_G_T_TYPE_1);
4557 }
4558 else {
4559 if (type.equals(StringPool.BLANK)) {
4560 query.append(_FINDER_COLUMN_G_T_TYPE_3);
4561 }
4562 else {
4563 query.append(_FINDER_COLUMN_G_T_TYPE_2);
4564 }
4565 }
4566
4567 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4568 CalEvent.class.getName(),
4569 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4570
4571 Session session = null;
4572
4573 try {
4574 session = openSession();
4575
4576 SQLQuery q = session.createSQLQuery(sql);
4577
4578 q.addScalar(COUNT_COLUMN_NAME,
4579 com.liferay.portal.kernel.dao.orm.Type.LONG);
4580
4581 QueryPos qPos = QueryPos.getInstance(q);
4582
4583 qPos.add(groupId);
4584
4585 if (type != null) {
4586 qPos.add(type);
4587 }
4588
4589 Long count = (Long)q.uniqueResult();
4590
4591 return count.intValue();
4592 }
4593 catch (Exception e) {
4594 throw processException(e);
4595 }
4596 finally {
4597 closeSession(session);
4598 }
4599 }
4600
4601
4609 public int filterCountByG_T(long groupId, String[] types)
4610 throws SystemException {
4611 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4612 return countByG_T(groupId, types);
4613 }
4614
4615 StringBundler query = new StringBundler();
4616
4617 query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
4618
4619 boolean conjunctionable = false;
4620
4621 if (conjunctionable) {
4622 query.append(WHERE_AND);
4623 }
4624
4625 query.append(_FINDER_COLUMN_G_T_GROUPID_5);
4626
4627 conjunctionable = true;
4628
4629 if ((types == null) || (types.length > 0)) {
4630 if (conjunctionable) {
4631 query.append(WHERE_AND);
4632 }
4633
4634 query.append(StringPool.OPEN_PARENTHESIS);
4635
4636 for (int i = 0; i < types.length; i++) {
4637 String type = types[i];
4638
4639 if (type == null) {
4640 query.append(_FINDER_COLUMN_G_T_TYPE_4);
4641 }
4642 else {
4643 if (type.equals(StringPool.BLANK)) {
4644 query.append(_FINDER_COLUMN_G_T_TYPE_6);
4645 }
4646 else {
4647 query.append(_FINDER_COLUMN_G_T_TYPE_5);
4648 }
4649 }
4650
4651 if ((i + 1) < types.length) {
4652 query.append(WHERE_OR);
4653 }
4654 }
4655
4656 query.append(StringPool.CLOSE_PARENTHESIS);
4657
4658 conjunctionable = true;
4659 }
4660
4661 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4662 CalEvent.class.getName(),
4663 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4664
4665 Session session = null;
4666
4667 try {
4668 session = openSession();
4669
4670 SQLQuery q = session.createSQLQuery(sql);
4671
4672 q.addScalar(COUNT_COLUMN_NAME,
4673 com.liferay.portal.kernel.dao.orm.Type.LONG);
4674
4675 QueryPos qPos = QueryPos.getInstance(q);
4676
4677 qPos.add(groupId);
4678
4679 if (types != null) {
4680 qPos.add(types);
4681 }
4682
4683 Long count = (Long)q.uniqueResult();
4684
4685 return count.intValue();
4686 }
4687 catch (Exception e) {
4688 throw processException(e);
4689 }
4690 finally {
4691 closeSession(session);
4692 }
4693 }
4694
4695 private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "calEvent.groupId = ? AND ";
4696 private static final String _FINDER_COLUMN_G_T_GROUPID_5 = "(" +
4697 _removeConjunction(_FINDER_COLUMN_G_T_GROUPID_2) + ")";
4698 private static final String _FINDER_COLUMN_G_T_TYPE_1 = "calEvent.type IS NULL";
4699 private static final String _FINDER_COLUMN_G_T_TYPE_2 = "calEvent.type = ?";
4700 private static final String _FINDER_COLUMN_G_T_TYPE_3 = "(calEvent.type IS NULL OR calEvent.type = ?)";
4701 private static final String _FINDER_COLUMN_G_T_TYPE_4 = "(" +
4702 _removeConjunction(_FINDER_COLUMN_G_T_TYPE_1) + ")";
4703 private static final String _FINDER_COLUMN_G_T_TYPE_5 = "(" +
4704 _removeConjunction(_FINDER_COLUMN_G_T_TYPE_2) + ")";
4705 private static final String _FINDER_COLUMN_G_T_TYPE_6 = "(" +
4706 _removeConjunction(_FINDER_COLUMN_G_T_TYPE_3) + ")";
4707 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
4708 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
4709 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_R",
4710 new String[] {
4711 Long.class.getName(), Boolean.class.getName(),
4712
4713 Integer.class.getName(), Integer.class.getName(),
4714 OrderByComparator.class.getName()
4715 });
4716 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
4717 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
4718 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_R",
4719 new String[] { Long.class.getName(), Boolean.class.getName() },
4720 CalEventModelImpl.GROUPID_COLUMN_BITMASK |
4721 CalEventModelImpl.REPEATING_COLUMN_BITMASK |
4722 CalEventModelImpl.STARTDATE_COLUMN_BITMASK |
4723 CalEventModelImpl.TITLE_COLUMN_BITMASK);
4724 public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
4725 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
4726 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_R",
4727 new String[] { Long.class.getName(), Boolean.class.getName() });
4728
4729
4737 public List<CalEvent> findByG_R(long groupId, boolean repeating)
4738 throws SystemException {
4739 return findByG_R(groupId, repeating, QueryUtil.ALL_POS,
4740 QueryUtil.ALL_POS, null);
4741 }
4742
4743
4757 public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
4758 int end) throws SystemException {
4759 return findByG_R(groupId, repeating, start, end, null);
4760 }
4761
4762
4777 public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
4778 int end, OrderByComparator orderByComparator) throws SystemException {
4779 boolean pagination = true;
4780 FinderPath finderPath = null;
4781 Object[] finderArgs = null;
4782
4783 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4784 (orderByComparator == null)) {
4785 pagination = false;
4786 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R;
4787 finderArgs = new Object[] { groupId, repeating };
4788 }
4789 else {
4790 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R;
4791 finderArgs = new Object[] {
4792 groupId, repeating,
4793
4794 start, end, orderByComparator
4795 };
4796 }
4797
4798 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
4799 finderArgs, this);
4800
4801 if ((list != null) && !list.isEmpty()) {
4802 for (CalEvent calEvent : list) {
4803 if ((groupId != calEvent.getGroupId()) ||
4804 (repeating != calEvent.getRepeating())) {
4805 list = null;
4806
4807 break;
4808 }
4809 }
4810 }
4811
4812 if (list == null) {
4813 StringBundler query = null;
4814
4815 if (orderByComparator != null) {
4816 query = new StringBundler(4 +
4817 (orderByComparator.getOrderByFields().length * 3));
4818 }
4819 else {
4820 query = new StringBundler(4);
4821 }
4822
4823 query.append(_SQL_SELECT_CALEVENT_WHERE);
4824
4825 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
4826
4827 query.append(_FINDER_COLUMN_G_R_REPEATING_2);
4828
4829 if (orderByComparator != null) {
4830 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4831 orderByComparator);
4832 }
4833 else
4834 if (pagination) {
4835 query.append(CalEventModelImpl.ORDER_BY_JPQL);
4836 }
4837
4838 String sql = query.toString();
4839
4840 Session session = null;
4841
4842 try {
4843 session = openSession();
4844
4845 Query q = session.createQuery(sql);
4846
4847 QueryPos qPos = QueryPos.getInstance(q);
4848
4849 qPos.add(groupId);
4850
4851 qPos.add(repeating);
4852
4853 if (!pagination) {
4854 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
4855 start, end, false);
4856
4857 Collections.sort(list);
4858
4859 list = new UnmodifiableList<CalEvent>(list);
4860 }
4861 else {
4862 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
4863 start, end);
4864 }
4865
4866 cacheResult(list);
4867
4868 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4869 }
4870 catch (Exception e) {
4871 FinderCacheUtil.removeResult(finderPath, finderArgs);
4872
4873 throw processException(e);
4874 }
4875 finally {
4876 closeSession(session);
4877 }
4878 }
4879
4880 return list;
4881 }
4882
4883
4893 public CalEvent findByG_R_First(long groupId, boolean repeating,
4894 OrderByComparator orderByComparator)
4895 throws NoSuchEventException, SystemException {
4896 CalEvent calEvent = fetchByG_R_First(groupId, repeating,
4897 orderByComparator);
4898
4899 if (calEvent != null) {
4900 return calEvent;
4901 }
4902
4903 StringBundler msg = new StringBundler(6);
4904
4905 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4906
4907 msg.append("groupId=");
4908 msg.append(groupId);
4909
4910 msg.append(", repeating=");
4911 msg.append(repeating);
4912
4913 msg.append(StringPool.CLOSE_CURLY_BRACE);
4914
4915 throw new NoSuchEventException(msg.toString());
4916 }
4917
4918
4927 public CalEvent fetchByG_R_First(long groupId, boolean repeating,
4928 OrderByComparator orderByComparator) throws SystemException {
4929 List<CalEvent> list = findByG_R(groupId, repeating, 0, 1,
4930 orderByComparator);
4931
4932 if (!list.isEmpty()) {
4933 return list.get(0);
4934 }
4935
4936 return null;
4937 }
4938
4939
4949 public CalEvent findByG_R_Last(long groupId, boolean repeating,
4950 OrderByComparator orderByComparator)
4951 throws NoSuchEventException, SystemException {
4952 CalEvent calEvent = fetchByG_R_Last(groupId, repeating,
4953 orderByComparator);
4954
4955 if (calEvent != null) {
4956 return calEvent;
4957 }
4958
4959 StringBundler msg = new StringBundler(6);
4960
4961 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4962
4963 msg.append("groupId=");
4964 msg.append(groupId);
4965
4966 msg.append(", repeating=");
4967 msg.append(repeating);
4968
4969 msg.append(StringPool.CLOSE_CURLY_BRACE);
4970
4971 throw new NoSuchEventException(msg.toString());
4972 }
4973
4974
4983 public CalEvent fetchByG_R_Last(long groupId, boolean repeating,
4984 OrderByComparator orderByComparator) throws SystemException {
4985 int count = countByG_R(groupId, repeating);
4986
4987 List<CalEvent> list = findByG_R(groupId, repeating, count - 1, count,
4988 orderByComparator);
4989
4990 if (!list.isEmpty()) {
4991 return list.get(0);
4992 }
4993
4994 return null;
4995 }
4996
4997
5008 public CalEvent[] findByG_R_PrevAndNext(long eventId, long groupId,
5009 boolean repeating, OrderByComparator orderByComparator)
5010 throws NoSuchEventException, SystemException {
5011 CalEvent calEvent = findByPrimaryKey(eventId);
5012
5013 Session session = null;
5014
5015 try {
5016 session = openSession();
5017
5018 CalEvent[] array = new CalEventImpl[3];
5019
5020 array[0] = getByG_R_PrevAndNext(session, calEvent, groupId,
5021 repeating, orderByComparator, true);
5022
5023 array[1] = calEvent;
5024
5025 array[2] = getByG_R_PrevAndNext(session, calEvent, groupId,
5026 repeating, orderByComparator, false);
5027
5028 return array;
5029 }
5030 catch (Exception e) {
5031 throw processException(e);
5032 }
5033 finally {
5034 closeSession(session);
5035 }
5036 }
5037
5038 protected CalEvent getByG_R_PrevAndNext(Session session, CalEvent calEvent,
5039 long groupId, boolean repeating, OrderByComparator orderByComparator,
5040 boolean previous) {
5041 StringBundler query = null;
5042
5043 if (orderByComparator != null) {
5044 query = new StringBundler(6 +
5045 (orderByComparator.getOrderByFields().length * 6));
5046 }
5047 else {
5048 query = new StringBundler(3);
5049 }
5050
5051 query.append(_SQL_SELECT_CALEVENT_WHERE);
5052
5053 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
5054
5055 query.append(_FINDER_COLUMN_G_R_REPEATING_2);
5056
5057 if (orderByComparator != null) {
5058 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5059
5060 if (orderByConditionFields.length > 0) {
5061 query.append(WHERE_AND);
5062 }
5063
5064 for (int i = 0; i < orderByConditionFields.length; i++) {
5065 query.append(_ORDER_BY_ENTITY_ALIAS);
5066 query.append(orderByConditionFields[i]);
5067
5068 if ((i + 1) < orderByConditionFields.length) {
5069 if (orderByComparator.isAscending() ^ previous) {
5070 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5071 }
5072 else {
5073 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5074 }
5075 }
5076 else {
5077 if (orderByComparator.isAscending() ^ previous) {
5078 query.append(WHERE_GREATER_THAN);
5079 }
5080 else {
5081 query.append(WHERE_LESSER_THAN);
5082 }
5083 }
5084 }
5085
5086 query.append(ORDER_BY_CLAUSE);
5087
5088 String[] orderByFields = orderByComparator.getOrderByFields();
5089
5090 for (int i = 0; i < orderByFields.length; i++) {
5091 query.append(_ORDER_BY_ENTITY_ALIAS);
5092 query.append(orderByFields[i]);
5093
5094 if ((i + 1) < orderByFields.length) {
5095 if (orderByComparator.isAscending() ^ previous) {
5096 query.append(ORDER_BY_ASC_HAS_NEXT);
5097 }
5098 else {
5099 query.append(ORDER_BY_DESC_HAS_NEXT);
5100 }
5101 }
5102 else {
5103 if (orderByComparator.isAscending() ^ previous) {
5104 query.append(ORDER_BY_ASC);
5105 }
5106 else {
5107 query.append(ORDER_BY_DESC);
5108 }
5109 }
5110 }
5111 }
5112 else {
5113 query.append(CalEventModelImpl.ORDER_BY_JPQL);
5114 }
5115
5116 String sql = query.toString();
5117
5118 Query q = session.createQuery(sql);
5119
5120 q.setFirstResult(0);
5121 q.setMaxResults(2);
5122
5123 QueryPos qPos = QueryPos.getInstance(q);
5124
5125 qPos.add(groupId);
5126
5127 qPos.add(repeating);
5128
5129 if (orderByComparator != null) {
5130 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
5131
5132 for (Object value : values) {
5133 qPos.add(value);
5134 }
5135 }
5136
5137 List<CalEvent> list = q.list();
5138
5139 if (list.size() == 2) {
5140 return list.get(1);
5141 }
5142 else {
5143 return null;
5144 }
5145 }
5146
5147
5155 public List<CalEvent> filterFindByG_R(long groupId, boolean repeating)
5156 throws SystemException {
5157 return filterFindByG_R(groupId, repeating, QueryUtil.ALL_POS,
5158 QueryUtil.ALL_POS, null);
5159 }
5160
5161
5175 public List<CalEvent> filterFindByG_R(long groupId, boolean repeating,
5176 int start, int end) throws SystemException {
5177 return filterFindByG_R(groupId, repeating, start, end, null);
5178 }
5179
5180
5195 public List<CalEvent> filterFindByG_R(long groupId, boolean repeating,
5196 int start, int end, OrderByComparator orderByComparator)
5197 throws SystemException {
5198 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5199 return findByG_R(groupId, repeating, start, end, orderByComparator);
5200 }
5201
5202 StringBundler query = null;
5203
5204 if (orderByComparator != null) {
5205 query = new StringBundler(4 +
5206 (orderByComparator.getOrderByFields().length * 3));
5207 }
5208 else {
5209 query = new StringBundler(4);
5210 }
5211
5212 if (getDB().isSupportsInlineDistinct()) {
5213 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
5214 }
5215 else {
5216 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
5217 }
5218
5219 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
5220
5221 query.append(_FINDER_COLUMN_G_R_REPEATING_2);
5222
5223 if (!getDB().isSupportsInlineDistinct()) {
5224 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
5225 }
5226
5227 if (orderByComparator != null) {
5228 if (getDB().isSupportsInlineDistinct()) {
5229 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5230 orderByComparator);
5231 }
5232 else {
5233 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5234 orderByComparator);
5235 }
5236 }
5237 else {
5238 if (getDB().isSupportsInlineDistinct()) {
5239 query.append(CalEventModelImpl.ORDER_BY_JPQL);
5240 }
5241 else {
5242 query.append(CalEventModelImpl.ORDER_BY_SQL);
5243 }
5244 }
5245
5246 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5247 CalEvent.class.getName(),
5248 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5249
5250 Session session = null;
5251
5252 try {
5253 session = openSession();
5254
5255 SQLQuery q = session.createSQLQuery(sql);
5256
5257 if (getDB().isSupportsInlineDistinct()) {
5258 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
5259 }
5260 else {
5261 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
5262 }
5263
5264 QueryPos qPos = QueryPos.getInstance(q);
5265
5266 qPos.add(groupId);
5267
5268 qPos.add(repeating);
5269
5270 return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
5271 }
5272 catch (Exception e) {
5273 throw processException(e);
5274 }
5275 finally {
5276 closeSession(session);
5277 }
5278 }
5279
5280
5291 public CalEvent[] filterFindByG_R_PrevAndNext(long eventId, long groupId,
5292 boolean repeating, OrderByComparator orderByComparator)
5293 throws NoSuchEventException, SystemException {
5294 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5295 return findByG_R_PrevAndNext(eventId, groupId, repeating,
5296 orderByComparator);
5297 }
5298
5299 CalEvent calEvent = findByPrimaryKey(eventId);
5300
5301 Session session = null;
5302
5303 try {
5304 session = openSession();
5305
5306 CalEvent[] array = new CalEventImpl[3];
5307
5308 array[0] = filterGetByG_R_PrevAndNext(session, calEvent, groupId,
5309 repeating, orderByComparator, true);
5310
5311 array[1] = calEvent;
5312
5313 array[2] = filterGetByG_R_PrevAndNext(session, calEvent, groupId,
5314 repeating, orderByComparator, false);
5315
5316 return array;
5317 }
5318 catch (Exception e) {
5319 throw processException(e);
5320 }
5321 finally {
5322 closeSession(session);
5323 }
5324 }
5325
5326 protected CalEvent filterGetByG_R_PrevAndNext(Session session,
5327 CalEvent calEvent, long groupId, boolean repeating,
5328 OrderByComparator orderByComparator, boolean previous) {
5329 StringBundler query = null;
5330
5331 if (orderByComparator != null) {
5332 query = new StringBundler(6 +
5333 (orderByComparator.getOrderByFields().length * 6));
5334 }
5335 else {
5336 query = new StringBundler(3);
5337 }
5338
5339 if (getDB().isSupportsInlineDistinct()) {
5340 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
5341 }
5342 else {
5343 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
5344 }
5345
5346 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
5347
5348 query.append(_FINDER_COLUMN_G_R_REPEATING_2);
5349
5350 if (!getDB().isSupportsInlineDistinct()) {
5351 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
5352 }
5353
5354 if (orderByComparator != null) {
5355 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5356
5357 if (orderByConditionFields.length > 0) {
5358 query.append(WHERE_AND);
5359 }
5360
5361 for (int i = 0; i < orderByConditionFields.length; i++) {
5362 if (getDB().isSupportsInlineDistinct()) {
5363 query.append(_ORDER_BY_ENTITY_ALIAS);
5364 }
5365 else {
5366 query.append(_ORDER_BY_ENTITY_TABLE);
5367 }
5368
5369 query.append(orderByConditionFields[i]);
5370
5371 if ((i + 1) < orderByConditionFields.length) {
5372 if (orderByComparator.isAscending() ^ previous) {
5373 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5374 }
5375 else {
5376 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5377 }
5378 }
5379 else {
5380 if (orderByComparator.isAscending() ^ previous) {
5381 query.append(WHERE_GREATER_THAN);
5382 }
5383 else {
5384 query.append(WHERE_LESSER_THAN);
5385 }
5386 }
5387 }
5388
5389 query.append(ORDER_BY_CLAUSE);
5390
5391 String[] orderByFields = orderByComparator.getOrderByFields();
5392
5393 for (int i = 0; i < orderByFields.length; i++) {
5394 if (getDB().isSupportsInlineDistinct()) {
5395 query.append(_ORDER_BY_ENTITY_ALIAS);
5396 }
5397 else {
5398 query.append(_ORDER_BY_ENTITY_TABLE);
5399 }
5400
5401 query.append(orderByFields[i]);
5402
5403 if ((i + 1) < orderByFields.length) {
5404 if (orderByComparator.isAscending() ^ previous) {
5405 query.append(ORDER_BY_ASC_HAS_NEXT);
5406 }
5407 else {
5408 query.append(ORDER_BY_DESC_HAS_NEXT);
5409 }
5410 }
5411 else {
5412 if (orderByComparator.isAscending() ^ previous) {
5413 query.append(ORDER_BY_ASC);
5414 }
5415 else {
5416 query.append(ORDER_BY_DESC);
5417 }
5418 }
5419 }
5420 }
5421 else {
5422 if (getDB().isSupportsInlineDistinct()) {
5423 query.append(CalEventModelImpl.ORDER_BY_JPQL);
5424 }
5425 else {
5426 query.append(CalEventModelImpl.ORDER_BY_SQL);
5427 }
5428 }
5429
5430 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5431 CalEvent.class.getName(),
5432 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5433
5434 SQLQuery q = session.createSQLQuery(sql);
5435
5436 q.setFirstResult(0);
5437 q.setMaxResults(2);
5438
5439 if (getDB().isSupportsInlineDistinct()) {
5440 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
5441 }
5442 else {
5443 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
5444 }
5445
5446 QueryPos qPos = QueryPos.getInstance(q);
5447
5448 qPos.add(groupId);
5449
5450 qPos.add(repeating);
5451
5452 if (orderByComparator != null) {
5453 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
5454
5455 for (Object value : values) {
5456 qPos.add(value);
5457 }
5458 }
5459
5460 List<CalEvent> list = q.list();
5461
5462 if (list.size() == 2) {
5463 return list.get(1);
5464 }
5465 else {
5466 return null;
5467 }
5468 }
5469
5470
5477 public void removeByG_R(long groupId, boolean repeating)
5478 throws SystemException {
5479 for (CalEvent calEvent : findByG_R(groupId, repeating,
5480 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5481 remove(calEvent);
5482 }
5483 }
5484
5485
5493 public int countByG_R(long groupId, boolean repeating)
5494 throws SystemException {
5495 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_R;
5496
5497 Object[] finderArgs = new Object[] { groupId, repeating };
5498
5499 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5500 this);
5501
5502 if (count == null) {
5503 StringBundler query = new StringBundler(3);
5504
5505 query.append(_SQL_COUNT_CALEVENT_WHERE);
5506
5507 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
5508
5509 query.append(_FINDER_COLUMN_G_R_REPEATING_2);
5510
5511 String sql = query.toString();
5512
5513 Session session = null;
5514
5515 try {
5516 session = openSession();
5517
5518 Query q = session.createQuery(sql);
5519
5520 QueryPos qPos = QueryPos.getInstance(q);
5521
5522 qPos.add(groupId);
5523
5524 qPos.add(repeating);
5525
5526 count = (Long)q.uniqueResult();
5527
5528 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5529 }
5530 catch (Exception e) {
5531 FinderCacheUtil.removeResult(finderPath, finderArgs);
5532
5533 throw processException(e);
5534 }
5535 finally {
5536 closeSession(session);
5537 }
5538 }
5539
5540 return count.intValue();
5541 }
5542
5543
5551 public int filterCountByG_R(long groupId, boolean repeating)
5552 throws SystemException {
5553 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5554 return countByG_R(groupId, repeating);
5555 }
5556
5557 StringBundler query = new StringBundler(3);
5558
5559 query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
5560
5561 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
5562
5563 query.append(_FINDER_COLUMN_G_R_REPEATING_2);
5564
5565 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5566 CalEvent.class.getName(),
5567 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5568
5569 Session session = null;
5570
5571 try {
5572 session = openSession();
5573
5574 SQLQuery q = session.createSQLQuery(sql);
5575
5576 q.addScalar(COUNT_COLUMN_NAME,
5577 com.liferay.portal.kernel.dao.orm.Type.LONG);
5578
5579 QueryPos qPos = QueryPos.getInstance(q);
5580
5581 qPos.add(groupId);
5582
5583 qPos.add(repeating);
5584
5585 Long count = (Long)q.uniqueResult();
5586
5587 return count.intValue();
5588 }
5589 catch (Exception e) {
5590 throw processException(e);
5591 }
5592 finally {
5593 closeSession(session);
5594 }
5595 }
5596
5597 private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "calEvent.groupId = ? AND ";
5598 private static final String _FINDER_COLUMN_G_R_REPEATING_2 = "calEvent.repeating = ?";
5599 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
5600 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
5601 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_T_R",
5602 new String[] {
5603 Long.class.getName(), String.class.getName(),
5604 Boolean.class.getName(),
5605
5606 Integer.class.getName(), Integer.class.getName(),
5607 OrderByComparator.class.getName()
5608 });
5609 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
5610 CalEventModelImpl.FINDER_CACHE_ENABLED, CalEventImpl.class,
5611 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_T_R",
5612 new String[] {
5613 Long.class.getName(), String.class.getName(),
5614 Boolean.class.getName()
5615 },
5616 CalEventModelImpl.GROUPID_COLUMN_BITMASK |
5617 CalEventModelImpl.TYPE_COLUMN_BITMASK |
5618 CalEventModelImpl.REPEATING_COLUMN_BITMASK |
5619 CalEventModelImpl.STARTDATE_COLUMN_BITMASK |
5620 CalEventModelImpl.TITLE_COLUMN_BITMASK);
5621 public static final FinderPath FINDER_PATH_COUNT_BY_G_T_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
5622 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
5623 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T_R",
5624 new String[] {
5625 Long.class.getName(), String.class.getName(),
5626 Boolean.class.getName()
5627 });
5628 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_R = new FinderPath(CalEventModelImpl.ENTITY_CACHE_ENABLED,
5629 CalEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
5630 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_T_R",
5631 new String[] {
5632 Long.class.getName(), String.class.getName(),
5633 Boolean.class.getName()
5634 });
5635
5636
5645 public List<CalEvent> findByG_T_R(long groupId, String type,
5646 boolean repeating) throws SystemException {
5647 return findByG_T_R(groupId, type, repeating, QueryUtil.ALL_POS,
5648 QueryUtil.ALL_POS, null);
5649 }
5650
5651
5666 public List<CalEvent> findByG_T_R(long groupId, String type,
5667 boolean repeating, int start, int end) throws SystemException {
5668 return findByG_T_R(groupId, type, repeating, start, end, null);
5669 }
5670
5671
5687 public List<CalEvent> findByG_T_R(long groupId, String type,
5688 boolean repeating, int start, int end,
5689 OrderByComparator orderByComparator) throws SystemException {
5690 boolean pagination = true;
5691 FinderPath finderPath = null;
5692 Object[] finderArgs = null;
5693
5694 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5695 (orderByComparator == null)) {
5696 pagination = false;
5697 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R;
5698 finderArgs = new Object[] { groupId, type, repeating };
5699 }
5700 else {
5701 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R;
5702 finderArgs = new Object[] {
5703 groupId, type, repeating,
5704
5705 start, end, orderByComparator
5706 };
5707 }
5708
5709 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
5710 finderArgs, this);
5711
5712 if ((list != null) && !list.isEmpty()) {
5713 for (CalEvent calEvent : list) {
5714 if ((groupId != calEvent.getGroupId()) ||
5715 !Validator.equals(type, calEvent.getType()) ||
5716 (repeating != calEvent.getRepeating())) {
5717 list = null;
5718
5719 break;
5720 }
5721 }
5722 }
5723
5724 if (list == null) {
5725 StringBundler query = null;
5726
5727 if (orderByComparator != null) {
5728 query = new StringBundler(5 +
5729 (orderByComparator.getOrderByFields().length * 3));
5730 }
5731 else {
5732 query = new StringBundler(5);
5733 }
5734
5735 query.append(_SQL_SELECT_CALEVENT_WHERE);
5736
5737 query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
5738
5739 if (type == null) {
5740 query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
5741 }
5742 else {
5743 if (type.equals(StringPool.BLANK)) {
5744 query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
5745 }
5746 else {
5747 query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
5748 }
5749 }
5750
5751 query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
5752
5753 if (orderByComparator != null) {
5754 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5755 orderByComparator);
5756 }
5757 else
5758 if (pagination) {
5759 query.append(CalEventModelImpl.ORDER_BY_JPQL);
5760 }
5761
5762 String sql = query.toString();
5763
5764 Session session = null;
5765
5766 try {
5767 session = openSession();
5768
5769 Query q = session.createQuery(sql);
5770
5771 QueryPos qPos = QueryPos.getInstance(q);
5772
5773 qPos.add(groupId);
5774
5775 if (type != null) {
5776 qPos.add(type);
5777 }
5778
5779 qPos.add(repeating);
5780
5781 if (!pagination) {
5782 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
5783 start, end, false);
5784
5785 Collections.sort(list);
5786
5787 list = new UnmodifiableList<CalEvent>(list);
5788 }
5789 else {
5790 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
5791 start, end);
5792 }
5793
5794 cacheResult(list);
5795
5796 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5797 }
5798 catch (Exception e) {
5799 FinderCacheUtil.removeResult(finderPath, finderArgs);
5800
5801 throw processException(e);
5802 }
5803 finally {
5804 closeSession(session);
5805 }
5806 }
5807
5808 return list;
5809 }
5810
5811
5822 public CalEvent findByG_T_R_First(long groupId, String type,
5823 boolean repeating, OrderByComparator orderByComparator)
5824 throws NoSuchEventException, SystemException {
5825 CalEvent calEvent = fetchByG_T_R_First(groupId, type, repeating,
5826 orderByComparator);
5827
5828 if (calEvent != null) {
5829 return calEvent;
5830 }
5831
5832 StringBundler msg = new StringBundler(8);
5833
5834 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5835
5836 msg.append("groupId=");
5837 msg.append(groupId);
5838
5839 msg.append(", type=");
5840 msg.append(type);
5841
5842 msg.append(", repeating=");
5843 msg.append(repeating);
5844
5845 msg.append(StringPool.CLOSE_CURLY_BRACE);
5846
5847 throw new NoSuchEventException(msg.toString());
5848 }
5849
5850
5860 public CalEvent fetchByG_T_R_First(long groupId, String type,
5861 boolean repeating, OrderByComparator orderByComparator)
5862 throws SystemException {
5863 List<CalEvent> list = findByG_T_R(groupId, type, repeating, 0, 1,
5864 orderByComparator);
5865
5866 if (!list.isEmpty()) {
5867 return list.get(0);
5868 }
5869
5870 return null;
5871 }
5872
5873
5884 public CalEvent findByG_T_R_Last(long groupId, String type,
5885 boolean repeating, OrderByComparator orderByComparator)
5886 throws NoSuchEventException, SystemException {
5887 CalEvent calEvent = fetchByG_T_R_Last(groupId, type, repeating,
5888 orderByComparator);
5889
5890 if (calEvent != null) {
5891 return calEvent;
5892 }
5893
5894 StringBundler msg = new StringBundler(8);
5895
5896 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5897
5898 msg.append("groupId=");
5899 msg.append(groupId);
5900
5901 msg.append(", type=");
5902 msg.append(type);
5903
5904 msg.append(", repeating=");
5905 msg.append(repeating);
5906
5907 msg.append(StringPool.CLOSE_CURLY_BRACE);
5908
5909 throw new NoSuchEventException(msg.toString());
5910 }
5911
5912
5922 public CalEvent fetchByG_T_R_Last(long groupId, String type,
5923 boolean repeating, OrderByComparator orderByComparator)
5924 throws SystemException {
5925 int count = countByG_T_R(groupId, type, repeating);
5926
5927 List<CalEvent> list = findByG_T_R(groupId, type, repeating, count - 1,
5928 count, orderByComparator);
5929
5930 if (!list.isEmpty()) {
5931 return list.get(0);
5932 }
5933
5934 return null;
5935 }
5936
5937
5949 public CalEvent[] findByG_T_R_PrevAndNext(long eventId, long groupId,
5950 String type, boolean repeating, OrderByComparator orderByComparator)
5951 throws NoSuchEventException, SystemException {
5952 CalEvent calEvent = findByPrimaryKey(eventId);
5953
5954 Session session = null;
5955
5956 try {
5957 session = openSession();
5958
5959 CalEvent[] array = new CalEventImpl[3];
5960
5961 array[0] = getByG_T_R_PrevAndNext(session, calEvent, groupId, type,
5962 repeating, orderByComparator, true);
5963
5964 array[1] = calEvent;
5965
5966 array[2] = getByG_T_R_PrevAndNext(session, calEvent, groupId, type,
5967 repeating, orderByComparator, false);
5968
5969 return array;
5970 }
5971 catch (Exception e) {
5972 throw processException(e);
5973 }
5974 finally {
5975 closeSession(session);
5976 }
5977 }
5978
5979 protected CalEvent getByG_T_R_PrevAndNext(Session session,
5980 CalEvent calEvent, long groupId, String type, boolean repeating,
5981 OrderByComparator orderByComparator, boolean previous) {
5982 StringBundler query = null;
5983
5984 if (orderByComparator != null) {
5985 query = new StringBundler(6 +
5986 (orderByComparator.getOrderByFields().length * 6));
5987 }
5988 else {
5989 query = new StringBundler(3);
5990 }
5991
5992 query.append(_SQL_SELECT_CALEVENT_WHERE);
5993
5994 query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
5995
5996 if (type == null) {
5997 query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
5998 }
5999 else {
6000 if (type.equals(StringPool.BLANK)) {
6001 query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
6002 }
6003 else {
6004 query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
6005 }
6006 }
6007
6008 query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
6009
6010 if (orderByComparator != null) {
6011 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6012
6013 if (orderByConditionFields.length > 0) {
6014 query.append(WHERE_AND);
6015 }
6016
6017 for (int i = 0; i < orderByConditionFields.length; i++) {
6018 query.append(_ORDER_BY_ENTITY_ALIAS);
6019 query.append(orderByConditionFields[i]);
6020
6021 if ((i + 1) < orderByConditionFields.length) {
6022 if (orderByComparator.isAscending() ^ previous) {
6023 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6024 }
6025 else {
6026 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6027 }
6028 }
6029 else {
6030 if (orderByComparator.isAscending() ^ previous) {
6031 query.append(WHERE_GREATER_THAN);
6032 }
6033 else {
6034 query.append(WHERE_LESSER_THAN);
6035 }
6036 }
6037 }
6038
6039 query.append(ORDER_BY_CLAUSE);
6040
6041 String[] orderByFields = orderByComparator.getOrderByFields();
6042
6043 for (int i = 0; i < orderByFields.length; i++) {
6044 query.append(_ORDER_BY_ENTITY_ALIAS);
6045 query.append(orderByFields[i]);
6046
6047 if ((i + 1) < orderByFields.length) {
6048 if (orderByComparator.isAscending() ^ previous) {
6049 query.append(ORDER_BY_ASC_HAS_NEXT);
6050 }
6051 else {
6052 query.append(ORDER_BY_DESC_HAS_NEXT);
6053 }
6054 }
6055 else {
6056 if (orderByComparator.isAscending() ^ previous) {
6057 query.append(ORDER_BY_ASC);
6058 }
6059 else {
6060 query.append(ORDER_BY_DESC);
6061 }
6062 }
6063 }
6064 }
6065 else {
6066 query.append(CalEventModelImpl.ORDER_BY_JPQL);
6067 }
6068
6069 String sql = query.toString();
6070
6071 Query q = session.createQuery(sql);
6072
6073 q.setFirstResult(0);
6074 q.setMaxResults(2);
6075
6076 QueryPos qPos = QueryPos.getInstance(q);
6077
6078 qPos.add(groupId);
6079
6080 if (type != null) {
6081 qPos.add(type);
6082 }
6083
6084 qPos.add(repeating);
6085
6086 if (orderByComparator != null) {
6087 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
6088
6089 for (Object value : values) {
6090 qPos.add(value);
6091 }
6092 }
6093
6094 List<CalEvent> list = q.list();
6095
6096 if (list.size() == 2) {
6097 return list.get(1);
6098 }
6099 else {
6100 return null;
6101 }
6102 }
6103
6104
6113 public List<CalEvent> filterFindByG_T_R(long groupId, String type,
6114 boolean repeating) throws SystemException {
6115 return filterFindByG_T_R(groupId, type, repeating, QueryUtil.ALL_POS,
6116 QueryUtil.ALL_POS, null);
6117 }
6118
6119
6134 public List<CalEvent> filterFindByG_T_R(long groupId, String type,
6135 boolean repeating, int start, int end) throws SystemException {
6136 return filterFindByG_T_R(groupId, type, repeating, start, end, null);
6137 }
6138
6139
6155 public List<CalEvent> filterFindByG_T_R(long groupId, String type,
6156 boolean repeating, int start, int end,
6157 OrderByComparator orderByComparator) throws SystemException {
6158 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6159 return findByG_T_R(groupId, type, repeating, start, end,
6160 orderByComparator);
6161 }
6162
6163 StringBundler query = null;
6164
6165 if (orderByComparator != null) {
6166 query = new StringBundler(5 +
6167 (orderByComparator.getOrderByFields().length * 3));
6168 }
6169 else {
6170 query = new StringBundler(5);
6171 }
6172
6173 if (getDB().isSupportsInlineDistinct()) {
6174 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
6175 }
6176 else {
6177 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
6178 }
6179
6180 query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
6181
6182 if (type == null) {
6183 query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
6184 }
6185 else {
6186 if (type.equals(StringPool.BLANK)) {
6187 query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
6188 }
6189 else {
6190 query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
6191 }
6192 }
6193
6194 query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
6195
6196 if (!getDB().isSupportsInlineDistinct()) {
6197 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
6198 }
6199
6200 if (orderByComparator != null) {
6201 if (getDB().isSupportsInlineDistinct()) {
6202 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6203 orderByComparator);
6204 }
6205 else {
6206 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6207 orderByComparator);
6208 }
6209 }
6210 else {
6211 if (getDB().isSupportsInlineDistinct()) {
6212 query.append(CalEventModelImpl.ORDER_BY_JPQL);
6213 }
6214 else {
6215 query.append(CalEventModelImpl.ORDER_BY_SQL);
6216 }
6217 }
6218
6219 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6220 CalEvent.class.getName(),
6221 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6222
6223 Session session = null;
6224
6225 try {
6226 session = openSession();
6227
6228 SQLQuery q = session.createSQLQuery(sql);
6229
6230 if (getDB().isSupportsInlineDistinct()) {
6231 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
6232 }
6233 else {
6234 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
6235 }
6236
6237 QueryPos qPos = QueryPos.getInstance(q);
6238
6239 qPos.add(groupId);
6240
6241 if (type != null) {
6242 qPos.add(type);
6243 }
6244
6245 qPos.add(repeating);
6246
6247 return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
6248 }
6249 catch (Exception e) {
6250 throw processException(e);
6251 }
6252 finally {
6253 closeSession(session);
6254 }
6255 }
6256
6257
6269 public CalEvent[] filterFindByG_T_R_PrevAndNext(long eventId, long groupId,
6270 String type, boolean repeating, OrderByComparator orderByComparator)
6271 throws NoSuchEventException, SystemException {
6272 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6273 return findByG_T_R_PrevAndNext(eventId, groupId, type, repeating,
6274 orderByComparator);
6275 }
6276
6277 CalEvent calEvent = findByPrimaryKey(eventId);
6278
6279 Session session = null;
6280
6281 try {
6282 session = openSession();
6283
6284 CalEvent[] array = new CalEventImpl[3];
6285
6286 array[0] = filterGetByG_T_R_PrevAndNext(session, calEvent, groupId,
6287 type, repeating, orderByComparator, true);
6288
6289 array[1] = calEvent;
6290
6291 array[2] = filterGetByG_T_R_PrevAndNext(session, calEvent, groupId,
6292 type, repeating, orderByComparator, false);
6293
6294 return array;
6295 }
6296 catch (Exception e) {
6297 throw processException(e);
6298 }
6299 finally {
6300 closeSession(session);
6301 }
6302 }
6303
6304 protected CalEvent filterGetByG_T_R_PrevAndNext(Session session,
6305 CalEvent calEvent, long groupId, String type, boolean repeating,
6306 OrderByComparator orderByComparator, boolean previous) {
6307 StringBundler query = null;
6308
6309 if (orderByComparator != null) {
6310 query = new StringBundler(6 +
6311 (orderByComparator.getOrderByFields().length * 6));
6312 }
6313 else {
6314 query = new StringBundler(3);
6315 }
6316
6317 if (getDB().isSupportsInlineDistinct()) {
6318 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
6319 }
6320 else {
6321 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
6322 }
6323
6324 query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
6325
6326 if (type == null) {
6327 query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
6328 }
6329 else {
6330 if (type.equals(StringPool.BLANK)) {
6331 query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
6332 }
6333 else {
6334 query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
6335 }
6336 }
6337
6338 query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
6339
6340 if (!getDB().isSupportsInlineDistinct()) {
6341 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
6342 }
6343
6344 if (orderByComparator != null) {
6345 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6346
6347 if (orderByConditionFields.length > 0) {
6348 query.append(WHERE_AND);
6349 }
6350
6351 for (int i = 0; i < orderByConditionFields.length; i++) {
6352 if (getDB().isSupportsInlineDistinct()) {
6353 query.append(_ORDER_BY_ENTITY_ALIAS);
6354 }
6355 else {
6356 query.append(_ORDER_BY_ENTITY_TABLE);
6357 }
6358
6359 query.append(orderByConditionFields[i]);
6360
6361 if ((i + 1) < orderByConditionFields.length) {
6362 if (orderByComparator.isAscending() ^ previous) {
6363 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6364 }
6365 else {
6366 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6367 }
6368 }
6369 else {
6370 if (orderByComparator.isAscending() ^ previous) {
6371 query.append(WHERE_GREATER_THAN);
6372 }
6373 else {
6374 query.append(WHERE_LESSER_THAN);
6375 }
6376 }
6377 }
6378
6379 query.append(ORDER_BY_CLAUSE);
6380
6381 String[] orderByFields = orderByComparator.getOrderByFields();
6382
6383 for (int i = 0; i < orderByFields.length; i++) {
6384 if (getDB().isSupportsInlineDistinct()) {
6385 query.append(_ORDER_BY_ENTITY_ALIAS);
6386 }
6387 else {
6388 query.append(_ORDER_BY_ENTITY_TABLE);
6389 }
6390
6391 query.append(orderByFields[i]);
6392
6393 if ((i + 1) < orderByFields.length) {
6394 if (orderByComparator.isAscending() ^ previous) {
6395 query.append(ORDER_BY_ASC_HAS_NEXT);
6396 }
6397 else {
6398 query.append(ORDER_BY_DESC_HAS_NEXT);
6399 }
6400 }
6401 else {
6402 if (orderByComparator.isAscending() ^ previous) {
6403 query.append(ORDER_BY_ASC);
6404 }
6405 else {
6406 query.append(ORDER_BY_DESC);
6407 }
6408 }
6409 }
6410 }
6411 else {
6412 if (getDB().isSupportsInlineDistinct()) {
6413 query.append(CalEventModelImpl.ORDER_BY_JPQL);
6414 }
6415 else {
6416 query.append(CalEventModelImpl.ORDER_BY_SQL);
6417 }
6418 }
6419
6420 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6421 CalEvent.class.getName(),
6422 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6423
6424 SQLQuery q = session.createSQLQuery(sql);
6425
6426 q.setFirstResult(0);
6427 q.setMaxResults(2);
6428
6429 if (getDB().isSupportsInlineDistinct()) {
6430 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
6431 }
6432 else {
6433 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
6434 }
6435
6436 QueryPos qPos = QueryPos.getInstance(q);
6437
6438 qPos.add(groupId);
6439
6440 if (type != null) {
6441 qPos.add(type);
6442 }
6443
6444 qPos.add(repeating);
6445
6446 if (orderByComparator != null) {
6447 Object[] values = orderByComparator.getOrderByConditionValues(calEvent);
6448
6449 for (Object value : values) {
6450 qPos.add(value);
6451 }
6452 }
6453
6454 List<CalEvent> list = q.list();
6455
6456 if (list.size() == 2) {
6457 return list.get(1);
6458 }
6459 else {
6460 return null;
6461 }
6462 }
6463
6464
6473 public List<CalEvent> filterFindByG_T_R(long groupId, String[] types,
6474 boolean repeating) throws SystemException {
6475 return filterFindByG_T_R(groupId, types, repeating, QueryUtil.ALL_POS,
6476 QueryUtil.ALL_POS, null);
6477 }
6478
6479
6494 public List<CalEvent> filterFindByG_T_R(long groupId, String[] types,
6495 boolean repeating, int start, int end) throws SystemException {
6496 return filterFindByG_T_R(groupId, types, repeating, start, end, null);
6497 }
6498
6499
6515 public List<CalEvent> filterFindByG_T_R(long groupId, String[] types,
6516 boolean repeating, int start, int end,
6517 OrderByComparator orderByComparator) throws SystemException {
6518 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6519 return findByG_T_R(groupId, types, repeating, start, end,
6520 orderByComparator);
6521 }
6522
6523 StringBundler query = new StringBundler();
6524
6525 if (getDB().isSupportsInlineDistinct()) {
6526 query.append(_FILTER_SQL_SELECT_CALEVENT_WHERE);
6527 }
6528 else {
6529 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1);
6530 }
6531
6532 boolean conjunctionable = false;
6533
6534 if (conjunctionable) {
6535 query.append(WHERE_AND);
6536 }
6537
6538 query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);
6539
6540 conjunctionable = true;
6541
6542 if ((types == null) || (types.length > 0)) {
6543 if (conjunctionable) {
6544 query.append(WHERE_AND);
6545 }
6546
6547 query.append(StringPool.OPEN_PARENTHESIS);
6548
6549 for (int i = 0; i < types.length; i++) {
6550 String type = types[i];
6551
6552 if (type == null) {
6553 query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
6554 }
6555 else {
6556 if (type.equals(StringPool.BLANK)) {
6557 query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
6558 }
6559 else {
6560 query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
6561 }
6562 }
6563
6564 if ((i + 1) < types.length) {
6565 query.append(WHERE_OR);
6566 }
6567 }
6568
6569 query.append(StringPool.CLOSE_PARENTHESIS);
6570
6571 conjunctionable = true;
6572 }
6573
6574 if (conjunctionable) {
6575 query.append(WHERE_AND);
6576 }
6577
6578 query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);
6579
6580 conjunctionable = true;
6581
6582 if (!getDB().isSupportsInlineDistinct()) {
6583 query.append(_FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2);
6584 }
6585
6586 if (orderByComparator != null) {
6587 if (getDB().isSupportsInlineDistinct()) {
6588 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6589 orderByComparator);
6590 }
6591 else {
6592 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6593 orderByComparator);
6594 }
6595 }
6596 else {
6597 if (getDB().isSupportsInlineDistinct()) {
6598 query.append(CalEventModelImpl.ORDER_BY_JPQL);
6599 }
6600 else {
6601 query.append(CalEventModelImpl.ORDER_BY_SQL);
6602 }
6603 }
6604
6605 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6606 CalEvent.class.getName(),
6607 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6608
6609 Session session = null;
6610
6611 try {
6612 session = openSession();
6613
6614 SQLQuery q = session.createSQLQuery(sql);
6615
6616 if (getDB().isSupportsInlineDistinct()) {
6617 q.addEntity(_FILTER_ENTITY_ALIAS, CalEventImpl.class);
6618 }
6619 else {
6620 q.addEntity(_FILTER_ENTITY_TABLE, CalEventImpl.class);
6621 }
6622
6623 QueryPos qPos = QueryPos.getInstance(q);
6624
6625 qPos.add(groupId);
6626
6627 if (types != null) {
6628 qPos.add(types);
6629 }
6630
6631 qPos.add(repeating);
6632
6633 return (List<CalEvent>)QueryUtil.list(q, getDialect(), start, end);
6634 }
6635 catch (Exception e) {
6636 throw processException(e);
6637 }
6638 finally {
6639 closeSession(session);
6640 }
6641 }
6642
6643
6656 public List<CalEvent> findByG_T_R(long groupId, String[] types,
6657 boolean repeating) throws SystemException {
6658 return findByG_T_R(groupId, types, repeating, QueryUtil.ALL_POS,
6659 QueryUtil.ALL_POS, null);
6660 }
6661
6662
6677 public List<CalEvent> findByG_T_R(long groupId, String[] types,
6678 boolean repeating, int start, int end) throws SystemException {
6679 return findByG_T_R(groupId, types, repeating, start, end, null);
6680 }
6681
6682
6698 public List<CalEvent> findByG_T_R(long groupId, String[] types,
6699 boolean repeating, int start, int end,
6700 OrderByComparator orderByComparator) throws SystemException {
6701 if ((types != null) && (types.length == 1)) {
6702 return findByG_T_R(groupId, types[0], repeating, start, end,
6703 orderByComparator);
6704 }
6705
6706 boolean pagination = true;
6707 Object[] finderArgs = null;
6708
6709 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6710 (orderByComparator == null)) {
6711 pagination = false;
6712 finderArgs = new Object[] {
6713 groupId, StringUtil.merge(types), repeating
6714 };
6715 }
6716 else {
6717 finderArgs = new Object[] {
6718 groupId, StringUtil.merge(types), repeating,
6719
6720 start, end, orderByComparator
6721 };
6722 }
6723
6724 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R,
6725 finderArgs, this);
6726
6727 if ((list != null) && !list.isEmpty()) {
6728 for (CalEvent calEvent : list) {
6729 if ((groupId != calEvent.getGroupId()) ||
6730 !ArrayUtil.contains(types, calEvent.getType()) ||
6731 (repeating != calEvent.getRepeating())) {
6732 list = null;
6733
6734 break;
6735 }
6736 }
6737 }
6738
6739 if (list == null) {
6740 StringBundler query = new StringBundler();
6741
6742 query.append(_SQL_SELECT_CALEVENT_WHERE);
6743
6744 boolean conjunctionable = false;
6745
6746 if (conjunctionable) {
6747 query.append(WHERE_AND);
6748 }
6749
6750 query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);
6751
6752 conjunctionable = true;
6753
6754 if ((types == null) || (types.length > 0)) {
6755 if (conjunctionable) {
6756 query.append(WHERE_AND);
6757 }
6758
6759 query.append(StringPool.OPEN_PARENTHESIS);
6760
6761 for (int i = 0; i < types.length; i++) {
6762 String type = types[i];
6763
6764 if (type == null) {
6765 query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
6766 }
6767 else {
6768 if (type.equals(StringPool.BLANK)) {
6769 query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
6770 }
6771 else {
6772 query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
6773 }
6774 }
6775
6776 if ((i + 1) < types.length) {
6777 query.append(WHERE_OR);
6778 }
6779 }
6780
6781 query.append(StringPool.CLOSE_PARENTHESIS);
6782
6783 conjunctionable = true;
6784 }
6785
6786 if (conjunctionable) {
6787 query.append(WHERE_AND);
6788 }
6789
6790 query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);
6791
6792 conjunctionable = true;
6793
6794 if (orderByComparator != null) {
6795 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6796 orderByComparator);
6797 }
6798 else
6799 if (pagination) {
6800 query.append(CalEventModelImpl.ORDER_BY_JPQL);
6801 }
6802
6803 String sql = query.toString();
6804
6805 Session session = null;
6806
6807 try {
6808 session = openSession();
6809
6810 Query q = session.createQuery(sql);
6811
6812 QueryPos qPos = QueryPos.getInstance(q);
6813
6814 qPos.add(groupId);
6815
6816 if (types != null) {
6817 qPos.add(types);
6818 }
6819
6820 qPos.add(repeating);
6821
6822 if (!pagination) {
6823 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
6824 start, end, false);
6825
6826 Collections.sort(list);
6827
6828 list = new UnmodifiableList<CalEvent>(list);
6829 }
6830 else {
6831 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
6832 start, end);
6833 }
6834
6835 cacheResult(list);
6836
6837 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R,
6838 finderArgs, list);
6839 }
6840 catch (Exception e) {
6841 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_R,
6842 finderArgs);
6843
6844 throw processException(e);
6845 }
6846 finally {
6847 closeSession(session);
6848 }
6849 }
6850
6851 return list;
6852 }
6853
6854
6862 public void removeByG_T_R(long groupId, String type, boolean repeating)
6863 throws SystemException {
6864 for (CalEvent calEvent : findByG_T_R(groupId, type, repeating,
6865 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6866 remove(calEvent);
6867 }
6868 }
6869
6870
6879 public int countByG_T_R(long groupId, String type, boolean repeating)
6880 throws SystemException {
6881 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_T_R;
6882
6883 Object[] finderArgs = new Object[] { groupId, type, repeating };
6884
6885 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6886 this);
6887
6888 if (count == null) {
6889 StringBundler query = new StringBundler(4);
6890
6891 query.append(_SQL_COUNT_CALEVENT_WHERE);
6892
6893 query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
6894
6895 if (type == null) {
6896 query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
6897 }
6898 else {
6899 if (type.equals(StringPool.BLANK)) {
6900 query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
6901 }
6902 else {
6903 query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
6904 }
6905 }
6906
6907 query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
6908
6909 String sql = query.toString();
6910
6911 Session session = null;
6912
6913 try {
6914 session = openSession();
6915
6916 Query q = session.createQuery(sql);
6917
6918 QueryPos qPos = QueryPos.getInstance(q);
6919
6920 qPos.add(groupId);
6921
6922 if (type != null) {
6923 qPos.add(type);
6924 }
6925
6926 qPos.add(repeating);
6927
6928 count = (Long)q.uniqueResult();
6929
6930 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6931 }
6932 catch (Exception e) {
6933 FinderCacheUtil.removeResult(finderPath, finderArgs);
6934
6935 throw processException(e);
6936 }
6937 finally {
6938 closeSession(session);
6939 }
6940 }
6941
6942 return count.intValue();
6943 }
6944
6945
6954 public int countByG_T_R(long groupId, String[] types, boolean repeating)
6955 throws SystemException {
6956 Object[] finderArgs = new Object[] {
6957 groupId, StringUtil.merge(types), repeating
6958 };
6959
6960 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_R,
6961 finderArgs, this);
6962
6963 if (count == null) {
6964 StringBundler query = new StringBundler();
6965
6966 query.append(_SQL_COUNT_CALEVENT_WHERE);
6967
6968 boolean conjunctionable = false;
6969
6970 if (conjunctionable) {
6971 query.append(WHERE_AND);
6972 }
6973
6974 query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);
6975
6976 conjunctionable = true;
6977
6978 if ((types == null) || (types.length > 0)) {
6979 if (conjunctionable) {
6980 query.append(WHERE_AND);
6981 }
6982
6983 query.append(StringPool.OPEN_PARENTHESIS);
6984
6985 for (int i = 0; i < types.length; i++) {
6986 String type = types[i];
6987
6988 if (type == null) {
6989 query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
6990 }
6991 else {
6992 if (type.equals(StringPool.BLANK)) {
6993 query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
6994 }
6995 else {
6996 query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
6997 }
6998 }
6999
7000 if ((i + 1) < types.length) {
7001 query.append(WHERE_OR);
7002 }
7003 }
7004
7005 query.append(StringPool.CLOSE_PARENTHESIS);
7006
7007 conjunctionable = true;
7008 }
7009
7010 if (conjunctionable) {
7011 query.append(WHERE_AND);
7012 }
7013
7014 query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);
7015
7016 conjunctionable = true;
7017
7018 String sql = query.toString();
7019
7020 Session session = null;
7021
7022 try {
7023 session = openSession();
7024
7025 Query q = session.createQuery(sql);
7026
7027 QueryPos qPos = QueryPos.getInstance(q);
7028
7029 qPos.add(groupId);
7030
7031 if (types != null) {
7032 qPos.add(types);
7033 }
7034
7035 qPos.add(repeating);
7036
7037 count = (Long)q.uniqueResult();
7038
7039 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_R,
7040 finderArgs, count);
7041 }
7042 catch (Exception e) {
7043 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_R,
7044 finderArgs);
7045
7046 throw processException(e);
7047 }
7048 finally {
7049 closeSession(session);
7050 }
7051 }
7052
7053 return count.intValue();
7054 }
7055
7056
7065 public int filterCountByG_T_R(long groupId, String type, boolean repeating)
7066 throws SystemException {
7067 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7068 return countByG_T_R(groupId, type, repeating);
7069 }
7070
7071 StringBundler query = new StringBundler(4);
7072
7073 query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
7074
7075 query.append(_FINDER_COLUMN_G_T_R_GROUPID_2);
7076
7077 if (type == null) {
7078 query.append(_FINDER_COLUMN_G_T_R_TYPE_1);
7079 }
7080 else {
7081 if (type.equals(StringPool.BLANK)) {
7082 query.append(_FINDER_COLUMN_G_T_R_TYPE_3);
7083 }
7084 else {
7085 query.append(_FINDER_COLUMN_G_T_R_TYPE_2);
7086 }
7087 }
7088
7089 query.append(_FINDER_COLUMN_G_T_R_REPEATING_2);
7090
7091 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7092 CalEvent.class.getName(),
7093 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7094
7095 Session session = null;
7096
7097 try {
7098 session = openSession();
7099
7100 SQLQuery q = session.createSQLQuery(sql);
7101
7102 q.addScalar(COUNT_COLUMN_NAME,
7103 com.liferay.portal.kernel.dao.orm.Type.LONG);
7104
7105 QueryPos qPos = QueryPos.getInstance(q);
7106
7107 qPos.add(groupId);
7108
7109 if (type != null) {
7110 qPos.add(type);
7111 }
7112
7113 qPos.add(repeating);
7114
7115 Long count = (Long)q.uniqueResult();
7116
7117 return count.intValue();
7118 }
7119 catch (Exception e) {
7120 throw processException(e);
7121 }
7122 finally {
7123 closeSession(session);
7124 }
7125 }
7126
7127
7136 public int filterCountByG_T_R(long groupId, String[] types,
7137 boolean repeating) throws SystemException {
7138 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7139 return countByG_T_R(groupId, types, repeating);
7140 }
7141
7142 StringBundler query = new StringBundler();
7143
7144 query.append(_FILTER_SQL_COUNT_CALEVENT_WHERE);
7145
7146 boolean conjunctionable = false;
7147
7148 if (conjunctionable) {
7149 query.append(WHERE_AND);
7150 }
7151
7152 query.append(_FINDER_COLUMN_G_T_R_GROUPID_5);
7153
7154 conjunctionable = true;
7155
7156 if ((types == null) || (types.length > 0)) {
7157 if (conjunctionable) {
7158 query.append(WHERE_AND);
7159 }
7160
7161 query.append(StringPool.OPEN_PARENTHESIS);
7162
7163 for (int i = 0; i < types.length; i++) {
7164 String type = types[i];
7165
7166 if (type == null) {
7167 query.append(_FINDER_COLUMN_G_T_R_TYPE_4);
7168 }
7169 else {
7170 if (type.equals(StringPool.BLANK)) {
7171 query.append(_FINDER_COLUMN_G_T_R_TYPE_6);
7172 }
7173 else {
7174 query.append(_FINDER_COLUMN_G_T_R_TYPE_5);
7175 }
7176 }
7177
7178 if ((i + 1) < types.length) {
7179 query.append(WHERE_OR);
7180 }
7181 }
7182
7183 query.append(StringPool.CLOSE_PARENTHESIS);
7184
7185 conjunctionable = true;
7186 }
7187
7188 if (conjunctionable) {
7189 query.append(WHERE_AND);
7190 }
7191
7192 query.append(_FINDER_COLUMN_G_T_R_REPEATING_5);
7193
7194 conjunctionable = true;
7195
7196 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7197 CalEvent.class.getName(),
7198 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7199
7200 Session session = null;
7201
7202 try {
7203 session = openSession();
7204
7205 SQLQuery q = session.createSQLQuery(sql);
7206
7207 q.addScalar(COUNT_COLUMN_NAME,
7208 com.liferay.portal.kernel.dao.orm.Type.LONG);
7209
7210 QueryPos qPos = QueryPos.getInstance(q);
7211
7212 qPos.add(groupId);
7213
7214 if (types != null) {
7215 qPos.add(types);
7216 }
7217
7218 qPos.add(repeating);
7219
7220 Long count = (Long)q.uniqueResult();
7221
7222 return count.intValue();
7223 }
7224 catch (Exception e) {
7225 throw processException(e);
7226 }
7227 finally {
7228 closeSession(session);
7229 }
7230 }
7231
7232 private static final String _FINDER_COLUMN_G_T_R_GROUPID_2 = "calEvent.groupId = ? AND ";
7233 private static final String _FINDER_COLUMN_G_T_R_GROUPID_5 = "(" +
7234 _removeConjunction(_FINDER_COLUMN_G_T_R_GROUPID_2) + ")";
7235 private static final String _FINDER_COLUMN_G_T_R_TYPE_1 = "calEvent.type IS NULL AND ";
7236 private static final String _FINDER_COLUMN_G_T_R_TYPE_2 = "calEvent.type = ? AND ";
7237 private static final String _FINDER_COLUMN_G_T_R_TYPE_3 = "(calEvent.type IS NULL OR calEvent.type = ?) AND ";
7238 private static final String _FINDER_COLUMN_G_T_R_TYPE_4 = "(" +
7239 _removeConjunction(_FINDER_COLUMN_G_T_R_TYPE_1) + ")";
7240 private static final String _FINDER_COLUMN_G_T_R_TYPE_5 = "(" +
7241 _removeConjunction(_FINDER_COLUMN_G_T_R_TYPE_2) + ")";
7242 private static final String _FINDER_COLUMN_G_T_R_TYPE_6 = "(" +
7243 _removeConjunction(_FINDER_COLUMN_G_T_R_TYPE_3) + ")";
7244 private static final String _FINDER_COLUMN_G_T_R_REPEATING_2 = "calEvent.repeating = ?";
7245 private static final String _FINDER_COLUMN_G_T_R_REPEATING_5 = "(" +
7246 _removeConjunction(_FINDER_COLUMN_G_T_R_REPEATING_2) + ")";
7247
7248
7253 public void cacheResult(CalEvent calEvent) {
7254 EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
7255 CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
7256
7257 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7258 new Object[] { calEvent.getUuid(), Long.valueOf(
7259 calEvent.getGroupId()) }, calEvent);
7260
7261 calEvent.resetOriginalValues();
7262 }
7263
7264
7269 public void cacheResult(List<CalEvent> calEvents) {
7270 for (CalEvent calEvent : calEvents) {
7271 if (EntityCacheUtil.getResult(
7272 CalEventModelImpl.ENTITY_CACHE_ENABLED,
7273 CalEventImpl.class, calEvent.getPrimaryKey()) == null) {
7274 cacheResult(calEvent);
7275 }
7276 else {
7277 calEvent.resetOriginalValues();
7278 }
7279 }
7280 }
7281
7282
7289 @Override
7290 public void clearCache() {
7291 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7292 CacheRegistryUtil.clear(CalEventImpl.class.getName());
7293 }
7294
7295 EntityCacheUtil.clearCache(CalEventImpl.class.getName());
7296
7297 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7298 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7299 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7300 }
7301
7302
7309 @Override
7310 public void clearCache(CalEvent calEvent) {
7311 EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
7312 CalEventImpl.class, calEvent.getPrimaryKey());
7313
7314 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7315 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7316
7317 clearUniqueFindersCache(calEvent);
7318 }
7319
7320 @Override
7321 public void clearCache(List<CalEvent> calEvents) {
7322 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7323 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7324
7325 for (CalEvent calEvent : calEvents) {
7326 EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
7327 CalEventImpl.class, calEvent.getPrimaryKey());
7328
7329 clearUniqueFindersCache(calEvent);
7330 }
7331 }
7332
7333 protected void cacheUniqueFindersCache(CalEvent calEvent) {
7334 if (calEvent.isNew()) {
7335 Object[] args = new Object[] {
7336 calEvent.getUuid(), Long.valueOf(calEvent.getGroupId())
7337 };
7338
7339 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7340 Long.valueOf(1));
7341 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7342 calEvent);
7343 }
7344 else {
7345 CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
7346
7347 if ((calEventModelImpl.getColumnBitmask() &
7348 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7349 Object[] args = new Object[] {
7350 calEvent.getUuid(), Long.valueOf(calEvent.getGroupId())
7351 };
7352
7353 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7354 Long.valueOf(1));
7355 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7356 calEvent);
7357 }
7358 }
7359 }
7360
7361 protected void clearUniqueFindersCache(CalEvent calEvent) {
7362 CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
7363
7364 Object[] args = new Object[] {
7365 calEvent.getUuid(), Long.valueOf(calEvent.getGroupId())
7366 };
7367
7368 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7369 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7370
7371 if ((calEventModelImpl.getColumnBitmask() &
7372 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7373 args = new Object[] {
7374 calEventModelImpl.getOriginalUuid(),
7375 Long.valueOf(calEventModelImpl.getOriginalGroupId())
7376 };
7377
7378 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7379 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7380 }
7381 }
7382
7383
7389 public CalEvent create(long eventId) {
7390 CalEvent calEvent = new CalEventImpl();
7391
7392 calEvent.setNew(true);
7393 calEvent.setPrimaryKey(eventId);
7394
7395 String uuid = PortalUUIDUtil.generate();
7396
7397 calEvent.setUuid(uuid);
7398
7399 return calEvent;
7400 }
7401
7402
7410 public CalEvent remove(long eventId)
7411 throws NoSuchEventException, SystemException {
7412 return remove(Long.valueOf(eventId));
7413 }
7414
7415
7423 @Override
7424 public CalEvent remove(Serializable primaryKey)
7425 throws NoSuchEventException, SystemException {
7426 Session session = null;
7427
7428 try {
7429 session = openSession();
7430
7431 CalEvent calEvent = (CalEvent)session.get(CalEventImpl.class,
7432 primaryKey);
7433
7434 if (calEvent == null) {
7435 if (_log.isWarnEnabled()) {
7436 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7437 }
7438
7439 throw new NoSuchEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7440 primaryKey);
7441 }
7442
7443 return remove(calEvent);
7444 }
7445 catch (NoSuchEventException nsee) {
7446 throw nsee;
7447 }
7448 catch (Exception e) {
7449 throw processException(e);
7450 }
7451 finally {
7452 closeSession(session);
7453 }
7454 }
7455
7456 @Override
7457 protected CalEvent removeImpl(CalEvent calEvent) throws SystemException {
7458 calEvent = toUnwrappedModel(calEvent);
7459
7460 Session session = null;
7461
7462 try {
7463 session = openSession();
7464
7465 if (!session.contains(calEvent)) {
7466 calEvent = (CalEvent)session.get(CalEventImpl.class,
7467 calEvent.getPrimaryKeyObj());
7468 }
7469
7470 if (calEvent != null) {
7471 session.delete(calEvent);
7472 }
7473 }
7474 catch (Exception e) {
7475 throw processException(e);
7476 }
7477 finally {
7478 closeSession(session);
7479 }
7480
7481 if (calEvent != null) {
7482 clearCache(calEvent);
7483 }
7484
7485 return calEvent;
7486 }
7487
7488 @Override
7489 public CalEvent updateImpl(
7490 com.liferay.portlet.calendar.model.CalEvent calEvent)
7491 throws SystemException {
7492 calEvent = toUnwrappedModel(calEvent);
7493
7494 boolean isNew = calEvent.isNew();
7495
7496 CalEventModelImpl calEventModelImpl = (CalEventModelImpl)calEvent;
7497
7498 if (Validator.isNull(calEvent.getUuid())) {
7499 String uuid = PortalUUIDUtil.generate();
7500
7501 calEvent.setUuid(uuid);
7502 }
7503
7504 long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
7505
7506 if (userId > 0) {
7507 long companyId = calEvent.getCompanyId();
7508
7509 long groupId = calEvent.getGroupId();
7510
7511 long eventId = 0;
7512
7513 if (!isNew) {
7514 eventId = calEvent.getPrimaryKey();
7515 }
7516
7517 try {
7518 calEvent.setTitle(SanitizerUtil.sanitize(companyId, groupId,
7519 userId,
7520 com.liferay.portlet.calendar.model.CalEvent.class.getName(),
7521 eventId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
7522 calEvent.getTitle(), null));
7523
7524 calEvent.setDescription(SanitizerUtil.sanitize(companyId,
7525 groupId, userId,
7526 com.liferay.portlet.calendar.model.CalEvent.class.getName(),
7527 eventId, ContentTypes.TEXT_HTML, Sanitizer.MODE_ALL,
7528 calEvent.getDescription(), null));
7529 }
7530 catch (SanitizerException se) {
7531 throw new SystemException(se);
7532 }
7533 }
7534
7535 Session session = null;
7536
7537 try {
7538 session = openSession();
7539
7540 if (calEvent.isNew()) {
7541 session.save(calEvent);
7542
7543 calEvent.setNew(false);
7544 }
7545 else {
7546 session.merge(calEvent);
7547 }
7548 }
7549 catch (Exception e) {
7550 throw processException(e);
7551 }
7552 finally {
7553 closeSession(session);
7554 }
7555
7556 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7557
7558 if (isNew || !CalEventModelImpl.COLUMN_BITMASK_ENABLED) {
7559 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7560 }
7561
7562 else {
7563 if ((calEventModelImpl.getColumnBitmask() &
7564 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7565 Object[] args = new Object[] { calEventModelImpl.getOriginalUuid() };
7566
7567 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7568 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7569 args);
7570
7571 args = new Object[] { calEventModelImpl.getUuid() };
7572
7573 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7574 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7575 args);
7576 }
7577
7578 if ((calEventModelImpl.getColumnBitmask() &
7579 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7580 Object[] args = new Object[] {
7581 calEventModelImpl.getOriginalUuid(),
7582 Long.valueOf(calEventModelImpl.getOriginalCompanyId())
7583 };
7584
7585 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7586 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7587 args);
7588
7589 args = new Object[] {
7590 calEventModelImpl.getUuid(),
7591 Long.valueOf(calEventModelImpl.getCompanyId())
7592 };
7593
7594 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7595 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7596 args);
7597 }
7598
7599 if ((calEventModelImpl.getColumnBitmask() &
7600 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7601 Object[] args = new Object[] {
7602 Long.valueOf(calEventModelImpl.getOriginalCompanyId())
7603 };
7604
7605 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7606 args);
7607 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7608 args);
7609
7610 args = new Object[] {
7611 Long.valueOf(calEventModelImpl.getCompanyId())
7612 };
7613
7614 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7615 args);
7616 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7617 args);
7618 }
7619
7620 if ((calEventModelImpl.getColumnBitmask() &
7621 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
7622 Object[] args = new Object[] {
7623 Long.valueOf(calEventModelImpl.getOriginalGroupId())
7624 };
7625
7626 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7627 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7628 args);
7629
7630 args = new Object[] { Long.valueOf(calEventModelImpl.getGroupId()) };
7631
7632 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7633 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7634 args);
7635 }
7636
7637 if ((calEventModelImpl.getColumnBitmask() &
7638 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T.getColumnBitmask()) != 0) {
7639 Object[] args = new Object[] {
7640 Long.valueOf(calEventModelImpl.getOriginalGroupId()),
7641
7642 calEventModelImpl.getOriginalType()
7643 };
7644
7645 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
7646 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T,
7647 args);
7648
7649 args = new Object[] {
7650 Long.valueOf(calEventModelImpl.getGroupId()),
7651
7652 calEventModelImpl.getType()
7653 };
7654
7655 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
7656 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T,
7657 args);
7658 }
7659
7660 if ((calEventModelImpl.getColumnBitmask() &
7661 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R.getColumnBitmask()) != 0) {
7662 Object[] args = new Object[] {
7663 Long.valueOf(calEventModelImpl.getOriginalGroupId()),
7664 Boolean.valueOf(calEventModelImpl.getOriginalRepeating())
7665 };
7666
7667 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
7668 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
7669 args);
7670
7671 args = new Object[] {
7672 Long.valueOf(calEventModelImpl.getGroupId()),
7673 Boolean.valueOf(calEventModelImpl.getRepeating())
7674 };
7675
7676 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
7677 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
7678 args);
7679 }
7680
7681 if ((calEventModelImpl.getColumnBitmask() &
7682 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R.getColumnBitmask()) != 0) {
7683 Object[] args = new Object[] {
7684 Long.valueOf(calEventModelImpl.getOriginalGroupId()),
7685
7686 calEventModelImpl.getOriginalType(),
7687 Boolean.valueOf(calEventModelImpl.getOriginalRepeating())
7688 };
7689
7690 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T_R, args);
7691 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R,
7692 args);
7693
7694 args = new Object[] {
7695 Long.valueOf(calEventModelImpl.getGroupId()),
7696
7697 calEventModelImpl.getType(),
7698 Boolean.valueOf(calEventModelImpl.getRepeating())
7699 };
7700
7701 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T_R, args);
7702 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_R,
7703 args);
7704 }
7705 }
7706
7707 EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
7708 CalEventImpl.class, calEvent.getPrimaryKey(), calEvent);
7709
7710 clearUniqueFindersCache(calEvent);
7711 cacheUniqueFindersCache(calEvent);
7712
7713 return calEvent;
7714 }
7715
7716 protected CalEvent toUnwrappedModel(CalEvent calEvent) {
7717 if (calEvent instanceof CalEventImpl) {
7718 return calEvent;
7719 }
7720
7721 CalEventImpl calEventImpl = new CalEventImpl();
7722
7723 calEventImpl.setNew(calEvent.isNew());
7724 calEventImpl.setPrimaryKey(calEvent.getPrimaryKey());
7725
7726 calEventImpl.setUuid(calEvent.getUuid());
7727 calEventImpl.setEventId(calEvent.getEventId());
7728 calEventImpl.setGroupId(calEvent.getGroupId());
7729 calEventImpl.setCompanyId(calEvent.getCompanyId());
7730 calEventImpl.setUserId(calEvent.getUserId());
7731 calEventImpl.setUserName(calEvent.getUserName());
7732 calEventImpl.setCreateDate(calEvent.getCreateDate());
7733 calEventImpl.setModifiedDate(calEvent.getModifiedDate());
7734 calEventImpl.setTitle(calEvent.getTitle());
7735 calEventImpl.setDescription(calEvent.getDescription());
7736 calEventImpl.setLocation(calEvent.getLocation());
7737 calEventImpl.setStartDate(calEvent.getStartDate());
7738 calEventImpl.setEndDate(calEvent.getEndDate());
7739 calEventImpl.setDurationHour(calEvent.getDurationHour());
7740 calEventImpl.setDurationMinute(calEvent.getDurationMinute());
7741 calEventImpl.setAllDay(calEvent.isAllDay());
7742 calEventImpl.setTimeZoneSensitive(calEvent.isTimeZoneSensitive());
7743 calEventImpl.setType(calEvent.getType());
7744 calEventImpl.setRepeating(calEvent.isRepeating());
7745 calEventImpl.setRecurrence(calEvent.getRecurrence());
7746 calEventImpl.setRemindBy(calEvent.getRemindBy());
7747 calEventImpl.setFirstReminder(calEvent.getFirstReminder());
7748 calEventImpl.setSecondReminder(calEvent.getSecondReminder());
7749
7750 return calEventImpl;
7751 }
7752
7753
7761 @Override
7762 public CalEvent findByPrimaryKey(Serializable primaryKey)
7763 throws NoSuchModelException, SystemException {
7764 return findByPrimaryKey(((Long)primaryKey).longValue());
7765 }
7766
7767
7775 public CalEvent findByPrimaryKey(long eventId)
7776 throws NoSuchEventException, SystemException {
7777 CalEvent calEvent = fetchByPrimaryKey(eventId);
7778
7779 if (calEvent == null) {
7780 if (_log.isWarnEnabled()) {
7781 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + eventId);
7782 }
7783
7784 throw new NoSuchEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7785 eventId);
7786 }
7787
7788 return calEvent;
7789 }
7790
7791
7798 @Override
7799 public CalEvent fetchByPrimaryKey(Serializable primaryKey)
7800 throws SystemException {
7801 return fetchByPrimaryKey(((Long)primaryKey).longValue());
7802 }
7803
7804
7811 public CalEvent fetchByPrimaryKey(long eventId) throws SystemException {
7812 CalEvent calEvent = (CalEvent)EntityCacheUtil.getResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
7813 CalEventImpl.class, eventId);
7814
7815 if (calEvent == _nullCalEvent) {
7816 return null;
7817 }
7818
7819 if (calEvent == null) {
7820 Session session = null;
7821
7822 try {
7823 session = openSession();
7824
7825 calEvent = (CalEvent)session.get(CalEventImpl.class,
7826 Long.valueOf(eventId));
7827
7828 if (calEvent != null) {
7829 cacheResult(calEvent);
7830 }
7831 else {
7832 EntityCacheUtil.putResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
7833 CalEventImpl.class, eventId, _nullCalEvent);
7834 }
7835 }
7836 catch (Exception e) {
7837 EntityCacheUtil.removeResult(CalEventModelImpl.ENTITY_CACHE_ENABLED,
7838 CalEventImpl.class, eventId);
7839
7840 throw processException(e);
7841 }
7842 finally {
7843 closeSession(session);
7844 }
7845 }
7846
7847 return calEvent;
7848 }
7849
7850
7856 public List<CalEvent> findAll() throws SystemException {
7857 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7858 }
7859
7860
7872 public List<CalEvent> findAll(int start, int end) throws SystemException {
7873 return findAll(start, end, null);
7874 }
7875
7876
7889 public List<CalEvent> findAll(int start, int end,
7890 OrderByComparator orderByComparator) throws SystemException {
7891 boolean pagination = true;
7892 FinderPath finderPath = null;
7893 Object[] finderArgs = null;
7894
7895 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7896 (orderByComparator == null)) {
7897 pagination = false;
7898 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7899 finderArgs = FINDER_ARGS_EMPTY;
7900 }
7901 else {
7902 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7903 finderArgs = new Object[] { start, end, orderByComparator };
7904 }
7905
7906 List<CalEvent> list = (List<CalEvent>)FinderCacheUtil.getResult(finderPath,
7907 finderArgs, this);
7908
7909 if (list == null) {
7910 StringBundler query = null;
7911 String sql = null;
7912
7913 if (orderByComparator != null) {
7914 query = new StringBundler(2 +
7915 (orderByComparator.getOrderByFields().length * 3));
7916
7917 query.append(_SQL_SELECT_CALEVENT);
7918
7919 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7920 orderByComparator);
7921
7922 sql = query.toString();
7923 }
7924 else {
7925 sql = _SQL_SELECT_CALEVENT;
7926
7927 if (pagination) {
7928 sql = sql.concat(CalEventModelImpl.ORDER_BY_JPQL);
7929 }
7930 }
7931
7932 Session session = null;
7933
7934 try {
7935 session = openSession();
7936
7937 Query q = session.createQuery(sql);
7938
7939 if (!pagination) {
7940 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
7941 start, end, false);
7942
7943 Collections.sort(list);
7944
7945 list = new UnmodifiableList<CalEvent>(list);
7946 }
7947 else {
7948 list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
7949 start, end);
7950 }
7951
7952 cacheResult(list);
7953
7954 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7955 }
7956 catch (Exception e) {
7957 FinderCacheUtil.removeResult(finderPath, finderArgs);
7958
7959 throw processException(e);
7960 }
7961 finally {
7962 closeSession(session);
7963 }
7964 }
7965
7966 return list;
7967 }
7968
7969
7974 public void removeAll() throws SystemException {
7975 for (CalEvent calEvent : findAll()) {
7976 remove(calEvent);
7977 }
7978 }
7979
7980
7986 public int countAll() throws SystemException {
7987 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7988 FINDER_ARGS_EMPTY, this);
7989
7990 if (count == null) {
7991 Session session = null;
7992
7993 try {
7994 session = openSession();
7995
7996 Query q = session.createQuery(_SQL_COUNT_CALEVENT);
7997
7998 count = (Long)q.uniqueResult();
7999
8000 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
8001 FINDER_ARGS_EMPTY, count);
8002 }
8003 catch (Exception e) {
8004 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
8005 FINDER_ARGS_EMPTY);
8006
8007 throw processException(e);
8008 }
8009 finally {
8010 closeSession(session);
8011 }
8012 }
8013
8014 return count.intValue();
8015 }
8016
8017
8020 public void afterPropertiesSet() {
8021 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
8022 com.liferay.portal.util.PropsUtil.get(
8023 "value.object.listener.com.liferay.portlet.calendar.model.CalEvent")));
8024
8025 if (listenerClassNames.length > 0) {
8026 try {
8027 List<ModelListener<CalEvent>> listenersList = new ArrayList<ModelListener<CalEvent>>();
8028
8029 for (String listenerClassName : listenerClassNames) {
8030 listenersList.add((ModelListener<CalEvent>)InstanceFactory.newInstance(
8031 listenerClassName));
8032 }
8033
8034 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
8035 }
8036 catch (Exception e) {
8037 _log.error(e);
8038 }
8039 }
8040 }
8041
8042 public void destroy() {
8043 EntityCacheUtil.removeCache(CalEventImpl.class.getName());
8044 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
8045 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8046 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8047 }
8048
8049 private static final String _SQL_SELECT_CALEVENT = "SELECT calEvent FROM CalEvent calEvent";
8050 private static final String _SQL_SELECT_CALEVENT_WHERE = "SELECT calEvent FROM CalEvent calEvent WHERE ";
8051 private static final String _SQL_COUNT_CALEVENT = "SELECT COUNT(calEvent) FROM CalEvent calEvent";
8052 private static final String _SQL_COUNT_CALEVENT_WHERE = "SELECT COUNT(calEvent) FROM CalEvent calEvent WHERE ";
8053
8054 private static String _removeConjunction(String sql) {
8055 int pos = sql.indexOf(" AND ");
8056
8057 if (pos != -1) {
8058 sql = sql.substring(0, pos);
8059 }
8060
8061 return sql;
8062 }
8063
8064 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "calEvent.eventId";
8065 private static final String _FILTER_SQL_SELECT_CALEVENT_WHERE = "SELECT DISTINCT {calEvent.*} FROM CalEvent calEvent WHERE ";
8066 private static final String _FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_1 =
8067 "SELECT {CalEvent.*} FROM (SELECT DISTINCT calEvent.eventId FROM CalEvent calEvent WHERE ";
8068 private static final String _FILTER_SQL_SELECT_CALEVENT_NO_INLINE_DISTINCT_WHERE_2 =
8069 ") TEMP_TABLE INNER JOIN CalEvent ON TEMP_TABLE.eventId = CalEvent.eventId";
8070 private static final String _FILTER_SQL_COUNT_CALEVENT_WHERE = "SELECT COUNT(DISTINCT calEvent.eventId) AS COUNT_VALUE FROM CalEvent calEvent WHERE ";
8071 private static final String _FILTER_ENTITY_ALIAS = "calEvent";
8072 private static final String _FILTER_ENTITY_TABLE = "CalEvent";
8073 private static final String _ORDER_BY_ENTITY_ALIAS = "calEvent.";
8074 private static final String _ORDER_BY_ENTITY_TABLE = "CalEvent.";
8075 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No CalEvent exists with the primary key ";
8076 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No CalEvent exists with the key {";
8077 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
8078 private static Log _log = LogFactoryUtil.getLog(CalEventPersistenceImpl.class);
8079 private static CalEvent _nullCalEvent = new CalEventImpl() {
8080 @Override
8081 public Object clone() {
8082 return this;
8083 }
8084
8085 @Override
8086 public CacheModel<CalEvent> toCacheModel() {
8087 return _nullCalEventCacheModel;
8088 }
8089 };
8090
8091 private static CacheModel<CalEvent> _nullCalEventCacheModel = new CacheModel<CalEvent>() {
8092 public CalEvent toEntityModel() {
8093 return _nullCalEvent;
8094 }
8095 };
8096 }