1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
17   * SOFTWARE.
18   */
19  
20  package com.liferay.portlet.calendar.service.persistence;
21  
22  import com.liferay.portal.SystemException;
23  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
24  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringPool;
34  import com.liferay.portal.kernel.util.StringUtil;
35  import com.liferay.portal.kernel.util.Validator;
36  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
37  import com.liferay.portal.model.ModelListener;
38  import com.liferay.portal.service.persistence.BatchSessionUtil;
39  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40  
41  import com.liferay.portlet.calendar.NoSuchEventException;
42  import com.liferay.portlet.calendar.model.CalEvent;
43  import com.liferay.portlet.calendar.model.impl.CalEventImpl;
44  import com.liferay.portlet.calendar.model.impl.CalEventModelImpl;
45  
46  import java.util.ArrayList;
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="CalEventPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class CalEventPersistenceImpl extends BasePersistenceImpl
58      implements CalEventPersistence {
59      public CalEvent create(long eventId) {
60          CalEvent calEvent = new CalEventImpl();
61  
62          calEvent.setNew(true);
63          calEvent.setPrimaryKey(eventId);
64  
65          String uuid = PortalUUIDUtil.generate();
66  
67          calEvent.setUuid(uuid);
68  
69          return calEvent;
70      }
71  
72      public CalEvent remove(long eventId)
73          throws NoSuchEventException, SystemException {
74          Session session = null;
75  
76          try {
77              session = openSession();
78  
79              CalEvent calEvent = (CalEvent)session.get(CalEventImpl.class,
80                      new Long(eventId));
81  
82              if (calEvent == null) {
83                  if (_log.isWarnEnabled()) {
84                      _log.warn("No CalEvent exists with the primary key " +
85                          eventId);
86                  }
87  
88                  throw new NoSuchEventException(
89                      "No CalEvent exists with the primary key " + eventId);
90              }
91  
92              return remove(calEvent);
93          }
94          catch (NoSuchEventException nsee) {
95              throw nsee;
96          }
97          catch (Exception e) {
98              throw processException(e);
99          }
100         finally {
101             closeSession(session);
102         }
103     }
104 
105     public CalEvent remove(CalEvent calEvent) throws SystemException {
106         for (ModelListener listener : listeners) {
107             listener.onBeforeRemove(calEvent);
108         }
109 
110         calEvent = removeImpl(calEvent);
111 
112         for (ModelListener listener : listeners) {
113             listener.onAfterRemove(calEvent);
114         }
115 
116         return calEvent;
117     }
118 
119     protected CalEvent removeImpl(CalEvent calEvent) throws SystemException {
120         Session session = null;
121 
122         try {
123             session = openSession();
124 
125             if (BatchSessionUtil.isEnabled()) {
126                 Object staleObject = session.get(CalEventImpl.class,
127                         calEvent.getPrimaryKeyObj());
128 
129                 if (staleObject != null) {
130                     session.evict(staleObject);
131                 }
132             }
133 
134             session.delete(calEvent);
135 
136             session.flush();
137 
138             return calEvent;
139         }
140         catch (Exception e) {
141             throw processException(e);
142         }
143         finally {
144             closeSession(session);
145 
146             FinderCacheUtil.clearCache(CalEvent.class.getName());
147         }
148     }
149 
150     /**
151      * @deprecated Use <code>update(CalEvent calEvent, boolean merge)</code>.
152      */
153     public CalEvent update(CalEvent calEvent) throws SystemException {
154         if (_log.isWarnEnabled()) {
155             _log.warn(
156                 "Using the deprecated update(CalEvent calEvent) method. Use update(CalEvent calEvent, boolean merge) instead.");
157         }
158 
159         return update(calEvent, false);
160     }
161 
162     /**
163      * Add, update, or merge, the entity. This method also calls the model
164      * listeners to trigger the proper events associated with adding, deleting,
165      * or updating an entity.
166      *
167      * @param        calEvent the entity to add, update, or merge
168      * @param        merge boolean value for whether to merge the entity. The
169      *                default value is false. Setting merge to true is more
170      *                expensive and should only be true when calEvent is
171      *                transient. See LEP-5473 for a detailed discussion of this
172      *                method.
173      * @return        true if the portlet can be displayed via Ajax
174      */
175     public CalEvent update(CalEvent calEvent, boolean merge)
176         throws SystemException {
177         boolean isNew = calEvent.isNew();
178 
179         for (ModelListener listener : listeners) {
180             if (isNew) {
181                 listener.onBeforeCreate(calEvent);
182             }
183             else {
184                 listener.onBeforeUpdate(calEvent);
185             }
186         }
187 
188         calEvent = updateImpl(calEvent, merge);
189 
190         for (ModelListener listener : listeners) {
191             if (isNew) {
192                 listener.onAfterCreate(calEvent);
193             }
194             else {
195                 listener.onAfterUpdate(calEvent);
196             }
197         }
198 
199         return calEvent;
200     }
201 
202     public CalEvent updateImpl(
203         com.liferay.portlet.calendar.model.CalEvent calEvent, boolean merge)
204         throws SystemException {
205         if (Validator.isNull(calEvent.getUuid())) {
206             String uuid = PortalUUIDUtil.generate();
207 
208             calEvent.setUuid(uuid);
209         }
210 
211         Session session = null;
212 
213         try {
214             session = openSession();
215 
216             BatchSessionUtil.update(session, calEvent, merge);
217 
218             calEvent.setNew(false);
219 
220             return calEvent;
221         }
222         catch (Exception e) {
223             throw processException(e);
224         }
225         finally {
226             closeSession(session);
227 
228             FinderCacheUtil.clearCache(CalEvent.class.getName());
229         }
230     }
231 
232     public CalEvent findByPrimaryKey(long eventId)
233         throws NoSuchEventException, SystemException {
234         CalEvent calEvent = fetchByPrimaryKey(eventId);
235 
236         if (calEvent == null) {
237             if (_log.isWarnEnabled()) {
238                 _log.warn("No CalEvent exists with the primary key " + eventId);
239             }
240 
241             throw new NoSuchEventException(
242                 "No CalEvent exists with the primary key " + eventId);
243         }
244 
245         return calEvent;
246     }
247 
248     public CalEvent fetchByPrimaryKey(long eventId) throws SystemException {
249         Session session = null;
250 
251         try {
252             session = openSession();
253 
254             return (CalEvent)session.get(CalEventImpl.class, new Long(eventId));
255         }
256         catch (Exception e) {
257             throw processException(e);
258         }
259         finally {
260             closeSession(session);
261         }
262     }
263 
264     public List<CalEvent> findByUuid(String uuid) throws SystemException {
265         boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
266         String finderClassName = CalEvent.class.getName();
267         String finderMethodName = "findByUuid";
268         String[] finderParams = new String[] { String.class.getName() };
269         Object[] finderArgs = new Object[] { uuid };
270 
271         Object result = null;
272 
273         if (finderClassNameCacheEnabled) {
274             result = FinderCacheUtil.getResult(finderClassName,
275                     finderMethodName, finderParams, finderArgs, this);
276         }
277 
278         if (result == null) {
279             Session session = null;
280 
281             try {
282                 session = openSession();
283 
284                 StringBuilder query = new StringBuilder();
285 
286                 query.append(
287                     "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
288 
289                 if (uuid == null) {
290                     query.append("uuid_ IS NULL");
291                 }
292                 else {
293                     query.append("uuid_ = ?");
294                 }
295 
296                 query.append(" ");
297 
298                 query.append("ORDER BY ");
299 
300                 query.append("startDate ASC, ");
301                 query.append("title ASC");
302 
303                 Query q = session.createQuery(query.toString());
304 
305                 QueryPos qPos = QueryPos.getInstance(q);
306 
307                 if (uuid != null) {
308                     qPos.add(uuid);
309                 }
310 
311                 List<CalEvent> list = q.list();
312 
313                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
314                     finderClassName, finderMethodName, finderParams,
315                     finderArgs, list);
316 
317                 return list;
318             }
319             catch (Exception e) {
320                 throw processException(e);
321             }
322             finally {
323                 closeSession(session);
324             }
325         }
326         else {
327             return (List<CalEvent>)result;
328         }
329     }
330 
331     public List<CalEvent> findByUuid(String uuid, int start, int end)
332         throws SystemException {
333         return findByUuid(uuid, start, end, null);
334     }
335 
336     public List<CalEvent> findByUuid(String uuid, int start, int end,
337         OrderByComparator obc) throws SystemException {
338         boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
339         String finderClassName = CalEvent.class.getName();
340         String finderMethodName = "findByUuid";
341         String[] finderParams = new String[] {
342                 String.class.getName(),
343                 
344                 "java.lang.Integer", "java.lang.Integer",
345                 "com.liferay.portal.kernel.util.OrderByComparator"
346             };
347         Object[] finderArgs = new Object[] {
348                 uuid,
349                 
350                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
351             };
352 
353         Object result = null;
354 
355         if (finderClassNameCacheEnabled) {
356             result = FinderCacheUtil.getResult(finderClassName,
357                     finderMethodName, finderParams, finderArgs, this);
358         }
359 
360         if (result == null) {
361             Session session = null;
362 
363             try {
364                 session = openSession();
365 
366                 StringBuilder query = new StringBuilder();
367 
368                 query.append(
369                     "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
370 
371                 if (uuid == null) {
372                     query.append("uuid_ IS NULL");
373                 }
374                 else {
375                     query.append("uuid_ = ?");
376                 }
377 
378                 query.append(" ");
379 
380                 if (obc != null) {
381                     query.append("ORDER BY ");
382                     query.append(obc.getOrderBy());
383                 }
384 
385                 else {
386                     query.append("ORDER BY ");
387 
388                     query.append("startDate ASC, ");
389                     query.append("title ASC");
390                 }
391 
392                 Query q = session.createQuery(query.toString());
393 
394                 QueryPos qPos = QueryPos.getInstance(q);
395 
396                 if (uuid != null) {
397                     qPos.add(uuid);
398                 }
399 
400                 List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
401                         getDialect(), start, end);
402 
403                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
404                     finderClassName, finderMethodName, finderParams,
405                     finderArgs, list);
406 
407                 return list;
408             }
409             catch (Exception e) {
410                 throw processException(e);
411             }
412             finally {
413                 closeSession(session);
414             }
415         }
416         else {
417             return (List<CalEvent>)result;
418         }
419     }
420 
421     public CalEvent findByUuid_First(String uuid, OrderByComparator obc)
422         throws NoSuchEventException, SystemException {
423         List<CalEvent> list = findByUuid(uuid, 0, 1, obc);
424 
425         if (list.size() == 0) {
426             StringBuilder msg = new StringBuilder();
427 
428             msg.append("No CalEvent exists with the key {");
429 
430             msg.append("uuid=" + uuid);
431 
432             msg.append(StringPool.CLOSE_CURLY_BRACE);
433 
434             throw new NoSuchEventException(msg.toString());
435         }
436         else {
437             return list.get(0);
438         }
439     }
440 
441     public CalEvent findByUuid_Last(String uuid, OrderByComparator obc)
442         throws NoSuchEventException, SystemException {
443         int count = countByUuid(uuid);
444 
445         List<CalEvent> list = findByUuid(uuid, count - 1, count, obc);
446 
447         if (list.size() == 0) {
448             StringBuilder msg = new StringBuilder();
449 
450             msg.append("No CalEvent exists with the key {");
451 
452             msg.append("uuid=" + uuid);
453 
454             msg.append(StringPool.CLOSE_CURLY_BRACE);
455 
456             throw new NoSuchEventException(msg.toString());
457         }
458         else {
459             return list.get(0);
460         }
461     }
462 
463     public CalEvent[] findByUuid_PrevAndNext(long eventId, String uuid,
464         OrderByComparator obc) throws NoSuchEventException, SystemException {
465         CalEvent calEvent = findByPrimaryKey(eventId);
466 
467         int count = countByUuid(uuid);
468 
469         Session session = null;
470 
471         try {
472             session = openSession();
473 
474             StringBuilder query = new StringBuilder();
475 
476             query.append(
477                 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
478 
479             if (uuid == null) {
480                 query.append("uuid_ IS NULL");
481             }
482             else {
483                 query.append("uuid_ = ?");
484             }
485 
486             query.append(" ");
487 
488             if (obc != null) {
489                 query.append("ORDER BY ");
490                 query.append(obc.getOrderBy());
491             }
492 
493             else {
494                 query.append("ORDER BY ");
495 
496                 query.append("startDate ASC, ");
497                 query.append("title ASC");
498             }
499 
500             Query q = session.createQuery(query.toString());
501 
502             QueryPos qPos = QueryPos.getInstance(q);
503 
504             if (uuid != null) {
505                 qPos.add(uuid);
506             }
507 
508             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
509 
510             CalEvent[] array = new CalEventImpl[3];
511 
512             array[0] = (CalEvent)objArray[0];
513             array[1] = (CalEvent)objArray[1];
514             array[2] = (CalEvent)objArray[2];
515 
516             return array;
517         }
518         catch (Exception e) {
519             throw processException(e);
520         }
521         finally {
522             closeSession(session);
523         }
524     }
525 
526     public CalEvent findByUUID_G(String uuid, long groupId)
527         throws NoSuchEventException, SystemException {
528         CalEvent calEvent = fetchByUUID_G(uuid, groupId);
529 
530         if (calEvent == null) {
531             StringBuilder msg = new StringBuilder();
532 
533             msg.append("No CalEvent exists with the key {");
534 
535             msg.append("uuid=" + uuid);
536 
537             msg.append(", ");
538             msg.append("groupId=" + groupId);
539 
540             msg.append(StringPool.CLOSE_CURLY_BRACE);
541 
542             if (_log.isWarnEnabled()) {
543                 _log.warn(msg.toString());
544             }
545 
546             throw new NoSuchEventException(msg.toString());
547         }
548 
549         return calEvent;
550     }
551 
552     public CalEvent fetchByUUID_G(String uuid, long groupId)
553         throws SystemException {
554         boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
555         String finderClassName = CalEvent.class.getName();
556         String finderMethodName = "fetchByUUID_G";
557         String[] finderParams = new String[] {
558                 String.class.getName(), Long.class.getName()
559             };
560         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
561 
562         Object result = null;
563 
564         if (finderClassNameCacheEnabled) {
565             result = FinderCacheUtil.getResult(finderClassName,
566                     finderMethodName, finderParams, finderArgs, this);
567         }
568 
569         if (result == null) {
570             Session session = null;
571 
572             try {
573                 session = openSession();
574 
575                 StringBuilder query = new StringBuilder();
576 
577                 query.append(
578                     "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
579 
580                 if (uuid == null) {
581                     query.append("uuid_ IS NULL");
582                 }
583                 else {
584                     query.append("uuid_ = ?");
585                 }
586 
587                 query.append(" AND ");
588 
589                 query.append("groupId = ?");
590 
591                 query.append(" ");
592 
593                 query.append("ORDER BY ");
594 
595                 query.append("startDate ASC, ");
596                 query.append("title ASC");
597 
598                 Query q = session.createQuery(query.toString());
599 
600                 QueryPos qPos = QueryPos.getInstance(q);
601 
602                 if (uuid != null) {
603                     qPos.add(uuid);
604                 }
605 
606                 qPos.add(groupId);
607 
608                 List<CalEvent> list = q.list();
609 
610                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
611                     finderClassName, finderMethodName, finderParams,
612                     finderArgs, list);
613 
614                 if (list.size() == 0) {
615                     return null;
616                 }
617                 else {
618                     return list.get(0);
619                 }
620             }
621             catch (Exception e) {
622                 throw processException(e);
623             }
624             finally {
625                 closeSession(session);
626             }
627         }
628         else {
629             List<CalEvent> list = (List<CalEvent>)result;
630 
631             if (list.size() == 0) {
632                 return null;
633             }
634             else {
635                 return list.get(0);
636             }
637         }
638     }
639 
640     public List<CalEvent> findByGroupId(long groupId) throws SystemException {
641         boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
642         String finderClassName = CalEvent.class.getName();
643         String finderMethodName = "findByGroupId";
644         String[] finderParams = new String[] { Long.class.getName() };
645         Object[] finderArgs = new Object[] { new Long(groupId) };
646 
647         Object result = null;
648 
649         if (finderClassNameCacheEnabled) {
650             result = FinderCacheUtil.getResult(finderClassName,
651                     finderMethodName, finderParams, finderArgs, this);
652         }
653 
654         if (result == null) {
655             Session session = null;
656 
657             try {
658                 session = openSession();
659 
660                 StringBuilder query = new StringBuilder();
661 
662                 query.append(
663                     "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
664 
665                 query.append("groupId = ?");
666 
667                 query.append(" ");
668 
669                 query.append("ORDER BY ");
670 
671                 query.append("startDate ASC, ");
672                 query.append("title ASC");
673 
674                 Query q = session.createQuery(query.toString());
675 
676                 QueryPos qPos = QueryPos.getInstance(q);
677 
678                 qPos.add(groupId);
679 
680                 List<CalEvent> list = q.list();
681 
682                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
683                     finderClassName, finderMethodName, finderParams,
684                     finderArgs, list);
685 
686                 return list;
687             }
688             catch (Exception e) {
689                 throw processException(e);
690             }
691             finally {
692                 closeSession(session);
693             }
694         }
695         else {
696             return (List<CalEvent>)result;
697         }
698     }
699 
700     public List<CalEvent> findByGroupId(long groupId, int start, int end)
701         throws SystemException {
702         return findByGroupId(groupId, start, end, null);
703     }
704 
705     public List<CalEvent> findByGroupId(long groupId, int start, int end,
706         OrderByComparator obc) throws SystemException {
707         boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
708         String finderClassName = CalEvent.class.getName();
709         String finderMethodName = "findByGroupId";
710         String[] finderParams = new String[] {
711                 Long.class.getName(),
712                 
713                 "java.lang.Integer", "java.lang.Integer",
714                 "com.liferay.portal.kernel.util.OrderByComparator"
715             };
716         Object[] finderArgs = new Object[] {
717                 new Long(groupId),
718                 
719                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
720             };
721 
722         Object result = null;
723 
724         if (finderClassNameCacheEnabled) {
725             result = FinderCacheUtil.getResult(finderClassName,
726                     finderMethodName, finderParams, finderArgs, this);
727         }
728 
729         if (result == null) {
730             Session session = null;
731 
732             try {
733                 session = openSession();
734 
735                 StringBuilder query = new StringBuilder();
736 
737                 query.append(
738                     "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
739 
740                 query.append("groupId = ?");
741 
742                 query.append(" ");
743 
744                 if (obc != null) {
745                     query.append("ORDER BY ");
746                     query.append(obc.getOrderBy());
747                 }
748 
749                 else {
750                     query.append("ORDER BY ");
751 
752                     query.append("startDate ASC, ");
753                     query.append("title ASC");
754                 }
755 
756                 Query q = session.createQuery(query.toString());
757 
758                 QueryPos qPos = QueryPos.getInstance(q);
759 
760                 qPos.add(groupId);
761 
762                 List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
763                         getDialect(), start, end);
764 
765                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
766                     finderClassName, finderMethodName, finderParams,
767                     finderArgs, list);
768 
769                 return list;
770             }
771             catch (Exception e) {
772                 throw processException(e);
773             }
774             finally {
775                 closeSession(session);
776             }
777         }
778         else {
779             return (List<CalEvent>)result;
780         }
781     }
782 
783     public CalEvent findByGroupId_First(long groupId, OrderByComparator obc)
784         throws NoSuchEventException, SystemException {
785         List<CalEvent> list = findByGroupId(groupId, 0, 1, obc);
786 
787         if (list.size() == 0) {
788             StringBuilder msg = new StringBuilder();
789 
790             msg.append("No CalEvent exists with the key {");
791 
792             msg.append("groupId=" + groupId);
793 
794             msg.append(StringPool.CLOSE_CURLY_BRACE);
795 
796             throw new NoSuchEventException(msg.toString());
797         }
798         else {
799             return list.get(0);
800         }
801     }
802 
803     public CalEvent findByGroupId_Last(long groupId, OrderByComparator obc)
804         throws NoSuchEventException, SystemException {
805         int count = countByGroupId(groupId);
806 
807         List<CalEvent> list = findByGroupId(groupId, count - 1, count, obc);
808 
809         if (list.size() == 0) {
810             StringBuilder msg = new StringBuilder();
811 
812             msg.append("No CalEvent exists with the key {");
813 
814             msg.append("groupId=" + groupId);
815 
816             msg.append(StringPool.CLOSE_CURLY_BRACE);
817 
818             throw new NoSuchEventException(msg.toString());
819         }
820         else {
821             return list.get(0);
822         }
823     }
824 
825     public CalEvent[] findByGroupId_PrevAndNext(long eventId, long groupId,
826         OrderByComparator obc) throws NoSuchEventException, SystemException {
827         CalEvent calEvent = findByPrimaryKey(eventId);
828 
829         int count = countByGroupId(groupId);
830 
831         Session session = null;
832 
833         try {
834             session = openSession();
835 
836             StringBuilder query = new StringBuilder();
837 
838             query.append(
839                 "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
840 
841             query.append("groupId = ?");
842 
843             query.append(" ");
844 
845             if (obc != null) {
846                 query.append("ORDER BY ");
847                 query.append(obc.getOrderBy());
848             }
849 
850             else {
851                 query.append("ORDER BY ");
852 
853                 query.append("startDate ASC, ");
854                 query.append("title ASC");
855             }
856 
857             Query q = session.createQuery(query.toString());
858 
859             QueryPos qPos = QueryPos.getInstance(q);
860 
861             qPos.add(groupId);
862 
863             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
864 
865             CalEvent[] array = new CalEventImpl[3];
866 
867             array[0] = (CalEvent)objArray[0];
868             array[1] = (CalEvent)objArray[1];
869             array[2] = (CalEvent)objArray[2];
870 
871             return array;
872         }
873         catch (Exception e) {
874             throw processException(e);
875         }
876         finally {
877             closeSession(session);
878         }
879     }
880 
881     public List<CalEvent> findByG_T(long groupId, String type)
882         throws SystemException {
883         boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
884         String finderClassName = CalEvent.class.getName();
885         String finderMethodName = "findByG_T";
886         String[] finderParams = new String[] {
887                 Long.class.getName(), String.class.getName()
888             };
889         Object[] finderArgs = new Object[] { new Long(groupId), type };
890 
891         Object result = null;
892 
893         if (finderClassNameCacheEnabled) {
894             result = FinderCacheUtil.getResult(finderClassName,
895                     finderMethodName, finderParams, finderArgs, this);
896         }
897 
898         if (result == null) {
899             Session session = null;
900 
901             try {
902                 session = openSession();
903 
904                 StringBuilder query = new StringBuilder();
905 
906                 query.append(
907                     "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
908 
909                 query.append("groupId = ?");
910 
911                 query.append(" AND ");
912 
913                 if (type == null) {
914                     query.append("type_ IS NULL");
915                 }
916                 else {
917                     query.append("type_ = ?");
918                 }
919 
920                 query.append(" ");
921 
922                 query.append("ORDER BY ");
923 
924                 query.append("startDate ASC, ");
925                 query.append("title ASC");
926 
927                 Query q = session.createQuery(query.toString());
928 
929                 QueryPos qPos = QueryPos.getInstance(q);
930 
931                 qPos.add(groupId);
932 
933                 if (type != null) {
934                     qPos.add(type);
935                 }
936 
937                 List<CalEvent> list = q.list();
938 
939                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
940                     finderClassName, finderMethodName, finderParams,
941                     finderArgs, list);
942 
943                 return list;
944             }
945             catch (Exception e) {
946                 throw processException(e);
947             }
948             finally {
949                 closeSession(session);
950             }
951         }
952         else {
953             return (List<CalEvent>)result;
954         }
955     }
956 
957     public List<CalEvent> findByG_T(long groupId, String type, int start,
958         int end) throws SystemException {
959         return findByG_T(groupId, type, start, end, null);
960     }
961 
962     public List<CalEvent> findByG_T(long groupId, String type, int start,
963         int end, OrderByComparator obc) throws SystemException {
964         boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
965         String finderClassName = CalEvent.class.getName();
966         String finderMethodName = "findByG_T";
967         String[] finderParams = new String[] {
968                 Long.class.getName(), String.class.getName(),
969                 
970                 "java.lang.Integer", "java.lang.Integer",
971                 "com.liferay.portal.kernel.util.OrderByComparator"
972             };
973         Object[] finderArgs = new Object[] {
974                 new Long(groupId),
975                 
976                 type,
977                 
978                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
979             };
980 
981         Object result = null;
982 
983         if (finderClassNameCacheEnabled) {
984             result = FinderCacheUtil.getResult(finderClassName,
985                     finderMethodName, finderParams, finderArgs, this);
986         }
987 
988         if (result == null) {
989             Session session = null;
990 
991             try {
992                 session = openSession();
993 
994                 StringBuilder query = new StringBuilder();
995 
996                 query.append(
997                     "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
998 
999                 query.append("groupId = ?");
1000
1001                query.append(" AND ");
1002
1003                if (type == null) {
1004                    query.append("type_ IS NULL");
1005                }
1006                else {
1007                    query.append("type_ = ?");
1008                }
1009
1010                query.append(" ");
1011
1012                if (obc != null) {
1013                    query.append("ORDER BY ");
1014                    query.append(obc.getOrderBy());
1015                }
1016
1017                else {
1018                    query.append("ORDER BY ");
1019
1020                    query.append("startDate ASC, ");
1021                    query.append("title ASC");
1022                }
1023
1024                Query q = session.createQuery(query.toString());
1025
1026                QueryPos qPos = QueryPos.getInstance(q);
1027
1028                qPos.add(groupId);
1029
1030                if (type != null) {
1031                    qPos.add(type);
1032                }
1033
1034                List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
1035                        getDialect(), start, end);
1036
1037                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1038                    finderClassName, finderMethodName, finderParams,
1039                    finderArgs, list);
1040
1041                return list;
1042            }
1043            catch (Exception e) {
1044                throw processException(e);
1045            }
1046            finally {
1047                closeSession(session);
1048            }
1049        }
1050        else {
1051            return (List<CalEvent>)result;
1052        }
1053    }
1054
1055    public CalEvent findByG_T_First(long groupId, String type,
1056        OrderByComparator obc) throws NoSuchEventException, SystemException {
1057        List<CalEvent> list = findByG_T(groupId, type, 0, 1, obc);
1058
1059        if (list.size() == 0) {
1060            StringBuilder msg = new StringBuilder();
1061
1062            msg.append("No CalEvent exists with the key {");
1063
1064            msg.append("groupId=" + groupId);
1065
1066            msg.append(", ");
1067            msg.append("type=" + type);
1068
1069            msg.append(StringPool.CLOSE_CURLY_BRACE);
1070
1071            throw new NoSuchEventException(msg.toString());
1072        }
1073        else {
1074            return list.get(0);
1075        }
1076    }
1077
1078    public CalEvent findByG_T_Last(long groupId, String type,
1079        OrderByComparator obc) throws NoSuchEventException, SystemException {
1080        int count = countByG_T(groupId, type);
1081
1082        List<CalEvent> list = findByG_T(groupId, type, count - 1, count, obc);
1083
1084        if (list.size() == 0) {
1085            StringBuilder msg = new StringBuilder();
1086
1087            msg.append("No CalEvent exists with the key {");
1088
1089            msg.append("groupId=" + groupId);
1090
1091            msg.append(", ");
1092            msg.append("type=" + type);
1093
1094            msg.append(StringPool.CLOSE_CURLY_BRACE);
1095
1096            throw new NoSuchEventException(msg.toString());
1097        }
1098        else {
1099            return list.get(0);
1100        }
1101    }
1102
1103    public CalEvent[] findByG_T_PrevAndNext(long eventId, long groupId,
1104        String type, OrderByComparator obc)
1105        throws NoSuchEventException, SystemException {
1106        CalEvent calEvent = findByPrimaryKey(eventId);
1107
1108        int count = countByG_T(groupId, type);
1109
1110        Session session = null;
1111
1112        try {
1113            session = openSession();
1114
1115            StringBuilder query = new StringBuilder();
1116
1117            query.append(
1118                "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1119
1120            query.append("groupId = ?");
1121
1122            query.append(" AND ");
1123
1124            if (type == null) {
1125                query.append("type_ IS NULL");
1126            }
1127            else {
1128                query.append("type_ = ?");
1129            }
1130
1131            query.append(" ");
1132
1133            if (obc != null) {
1134                query.append("ORDER BY ");
1135                query.append(obc.getOrderBy());
1136            }
1137
1138            else {
1139                query.append("ORDER BY ");
1140
1141                query.append("startDate ASC, ");
1142                query.append("title ASC");
1143            }
1144
1145            Query q = session.createQuery(query.toString());
1146
1147            QueryPos qPos = QueryPos.getInstance(q);
1148
1149            qPos.add(groupId);
1150
1151            if (type != null) {
1152                qPos.add(type);
1153            }
1154
1155            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
1156
1157            CalEvent[] array = new CalEventImpl[3];
1158
1159            array[0] = (CalEvent)objArray[0];
1160            array[1] = (CalEvent)objArray[1];
1161            array[2] = (CalEvent)objArray[2];
1162
1163            return array;
1164        }
1165        catch (Exception e) {
1166            throw processException(e);
1167        }
1168        finally {
1169            closeSession(session);
1170        }
1171    }
1172
1173    public List<CalEvent> findByG_R(long groupId, boolean repeating)
1174        throws SystemException {
1175        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1176        String finderClassName = CalEvent.class.getName();
1177        String finderMethodName = "findByG_R";
1178        String[] finderParams = new String[] {
1179                Long.class.getName(), Boolean.class.getName()
1180            };
1181        Object[] finderArgs = new Object[] {
1182                new Long(groupId), Boolean.valueOf(repeating)
1183            };
1184
1185        Object result = null;
1186
1187        if (finderClassNameCacheEnabled) {
1188            result = FinderCacheUtil.getResult(finderClassName,
1189                    finderMethodName, finderParams, finderArgs, this);
1190        }
1191
1192        if (result == null) {
1193            Session session = null;
1194
1195            try {
1196                session = openSession();
1197
1198                StringBuilder query = new StringBuilder();
1199
1200                query.append(
1201                    "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1202
1203                query.append("groupId = ?");
1204
1205                query.append(" AND ");
1206
1207                query.append("repeating = ?");
1208
1209                query.append(" ");
1210
1211                query.append("ORDER BY ");
1212
1213                query.append("startDate ASC, ");
1214                query.append("title ASC");
1215
1216                Query q = session.createQuery(query.toString());
1217
1218                QueryPos qPos = QueryPos.getInstance(q);
1219
1220                qPos.add(groupId);
1221
1222                qPos.add(repeating);
1223
1224                List<CalEvent> list = q.list();
1225
1226                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1227                    finderClassName, finderMethodName, finderParams,
1228                    finderArgs, list);
1229
1230                return list;
1231            }
1232            catch (Exception e) {
1233                throw processException(e);
1234            }
1235            finally {
1236                closeSession(session);
1237            }
1238        }
1239        else {
1240            return (List<CalEvent>)result;
1241        }
1242    }
1243
1244    public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
1245        int end) throws SystemException {
1246        return findByG_R(groupId, repeating, start, end, null);
1247    }
1248
1249    public List<CalEvent> findByG_R(long groupId, boolean repeating, int start,
1250        int end, OrderByComparator obc) throws SystemException {
1251        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1252        String finderClassName = CalEvent.class.getName();
1253        String finderMethodName = "findByG_R";
1254        String[] finderParams = new String[] {
1255                Long.class.getName(), Boolean.class.getName(),
1256                
1257                "java.lang.Integer", "java.lang.Integer",
1258                "com.liferay.portal.kernel.util.OrderByComparator"
1259            };
1260        Object[] finderArgs = new Object[] {
1261                new Long(groupId), Boolean.valueOf(repeating),
1262                
1263                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1264            };
1265
1266        Object result = null;
1267
1268        if (finderClassNameCacheEnabled) {
1269            result = FinderCacheUtil.getResult(finderClassName,
1270                    finderMethodName, finderParams, finderArgs, this);
1271        }
1272
1273        if (result == null) {
1274            Session session = null;
1275
1276            try {
1277                session = openSession();
1278
1279                StringBuilder query = new StringBuilder();
1280
1281                query.append(
1282                    "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1283
1284                query.append("groupId = ?");
1285
1286                query.append(" AND ");
1287
1288                query.append("repeating = ?");
1289
1290                query.append(" ");
1291
1292                if (obc != null) {
1293                    query.append("ORDER BY ");
1294                    query.append(obc.getOrderBy());
1295                }
1296
1297                else {
1298                    query.append("ORDER BY ");
1299
1300                    query.append("startDate ASC, ");
1301                    query.append("title ASC");
1302                }
1303
1304                Query q = session.createQuery(query.toString());
1305
1306                QueryPos qPos = QueryPos.getInstance(q);
1307
1308                qPos.add(groupId);
1309
1310                qPos.add(repeating);
1311
1312                List<CalEvent> list = (List<CalEvent>)QueryUtil.list(q,
1313                        getDialect(), start, end);
1314
1315                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1316                    finderClassName, finderMethodName, finderParams,
1317                    finderArgs, list);
1318
1319                return list;
1320            }
1321            catch (Exception e) {
1322                throw processException(e);
1323            }
1324            finally {
1325                closeSession(session);
1326            }
1327        }
1328        else {
1329            return (List<CalEvent>)result;
1330        }
1331    }
1332
1333    public CalEvent findByG_R_First(long groupId, boolean repeating,
1334        OrderByComparator obc) throws NoSuchEventException, SystemException {
1335        List<CalEvent> list = findByG_R(groupId, repeating, 0, 1, obc);
1336
1337        if (list.size() == 0) {
1338            StringBuilder msg = new StringBuilder();
1339
1340            msg.append("No CalEvent exists with the key {");
1341
1342            msg.append("groupId=" + groupId);
1343
1344            msg.append(", ");
1345            msg.append("repeating=" + repeating);
1346
1347            msg.append(StringPool.CLOSE_CURLY_BRACE);
1348
1349            throw new NoSuchEventException(msg.toString());
1350        }
1351        else {
1352            return list.get(0);
1353        }
1354    }
1355
1356    public CalEvent findByG_R_Last(long groupId, boolean repeating,
1357        OrderByComparator obc) throws NoSuchEventException, SystemException {
1358        int count = countByG_R(groupId, repeating);
1359
1360        List<CalEvent> list = findByG_R(groupId, repeating, count - 1, count,
1361                obc);
1362
1363        if (list.size() == 0) {
1364            StringBuilder msg = new StringBuilder();
1365
1366            msg.append("No CalEvent exists with the key {");
1367
1368            msg.append("groupId=" + groupId);
1369
1370            msg.append(", ");
1371            msg.append("repeating=" + repeating);
1372
1373            msg.append(StringPool.CLOSE_CURLY_BRACE);
1374
1375            throw new NoSuchEventException(msg.toString());
1376        }
1377        else {
1378            return list.get(0);
1379        }
1380    }
1381
1382    public CalEvent[] findByG_R_PrevAndNext(long eventId, long groupId,
1383        boolean repeating, OrderByComparator obc)
1384        throws NoSuchEventException, SystemException {
1385        CalEvent calEvent = findByPrimaryKey(eventId);
1386
1387        int count = countByG_R(groupId, repeating);
1388
1389        Session session = null;
1390
1391        try {
1392            session = openSession();
1393
1394            StringBuilder query = new StringBuilder();
1395
1396            query.append(
1397                "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1398
1399            query.append("groupId = ?");
1400
1401            query.append(" AND ");
1402
1403            query.append("repeating = ?");
1404
1405            query.append(" ");
1406
1407            if (obc != null) {
1408                query.append("ORDER BY ");
1409                query.append(obc.getOrderBy());
1410            }
1411
1412            else {
1413                query.append("ORDER BY ");
1414
1415                query.append("startDate ASC, ");
1416                query.append("title ASC");
1417            }
1418
1419            Query q = session.createQuery(query.toString());
1420
1421            QueryPos qPos = QueryPos.getInstance(q);
1422
1423            qPos.add(groupId);
1424
1425            qPos.add(repeating);
1426
1427            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, calEvent);
1428
1429            CalEvent[] array = new CalEventImpl[3];
1430
1431            array[0] = (CalEvent)objArray[0];
1432            array[1] = (CalEvent)objArray[1];
1433            array[2] = (CalEvent)objArray[2];
1434
1435            return array;
1436        }
1437        catch (Exception e) {
1438            throw processException(e);
1439        }
1440        finally {
1441            closeSession(session);
1442        }
1443    }
1444
1445    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1446        throws SystemException {
1447        Session session = null;
1448
1449        try {
1450            session = openSession();
1451
1452            dynamicQuery.compile(session);
1453
1454            return dynamicQuery.list();
1455        }
1456        catch (Exception e) {
1457            throw processException(e);
1458        }
1459        finally {
1460            closeSession(session);
1461        }
1462    }
1463
1464    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1465        int start, int end) throws SystemException {
1466        Session session = null;
1467
1468        try {
1469            session = openSession();
1470
1471            dynamicQuery.setLimit(start, end);
1472
1473            dynamicQuery.compile(session);
1474
1475            return dynamicQuery.list();
1476        }
1477        catch (Exception e) {
1478            throw processException(e);
1479        }
1480        finally {
1481            closeSession(session);
1482        }
1483    }
1484
1485    public List<CalEvent> findAll() throws SystemException {
1486        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1487    }
1488
1489    public List<CalEvent> findAll(int start, int end) throws SystemException {
1490        return findAll(start, end, null);
1491    }
1492
1493    public List<CalEvent> findAll(int start, int end, OrderByComparator obc)
1494        throws SystemException {
1495        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1496        String finderClassName = CalEvent.class.getName();
1497        String finderMethodName = "findAll";
1498        String[] finderParams = new String[] {
1499                "java.lang.Integer", "java.lang.Integer",
1500                "com.liferay.portal.kernel.util.OrderByComparator"
1501            };
1502        Object[] finderArgs = new Object[] {
1503                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1504            };
1505
1506        Object result = null;
1507
1508        if (finderClassNameCacheEnabled) {
1509            result = FinderCacheUtil.getResult(finderClassName,
1510                    finderMethodName, finderParams, finderArgs, this);
1511        }
1512
1513        if (result == null) {
1514            Session session = null;
1515
1516            try {
1517                session = openSession();
1518
1519                StringBuilder query = new StringBuilder();
1520
1521                query.append(
1522                    "FROM com.liferay.portlet.calendar.model.CalEvent ");
1523
1524                if (obc != null) {
1525                    query.append("ORDER BY ");
1526                    query.append(obc.getOrderBy());
1527                }
1528
1529                else {
1530                    query.append("ORDER BY ");
1531
1532                    query.append("startDate ASC, ");
1533                    query.append("title ASC");
1534                }
1535
1536                Query q = session.createQuery(query.toString());
1537
1538                List<CalEvent> list = null;
1539
1540                if (obc == null) {
1541                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
1542                            start, end, false);
1543
1544                    Collections.sort(list);
1545                }
1546                else {
1547                    list = (List<CalEvent>)QueryUtil.list(q, getDialect(),
1548                            start, end);
1549                }
1550
1551                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1552                    finderClassName, finderMethodName, finderParams,
1553                    finderArgs, list);
1554
1555                return list;
1556            }
1557            catch (Exception e) {
1558                throw processException(e);
1559            }
1560            finally {
1561                closeSession(session);
1562            }
1563        }
1564        else {
1565            return (List<CalEvent>)result;
1566        }
1567    }
1568
1569    public void removeByUuid(String uuid) throws SystemException {
1570        for (CalEvent calEvent : findByUuid(uuid)) {
1571            remove(calEvent);
1572        }
1573    }
1574
1575    public void removeByUUID_G(String uuid, long groupId)
1576        throws NoSuchEventException, SystemException {
1577        CalEvent calEvent = findByUUID_G(uuid, groupId);
1578
1579        remove(calEvent);
1580    }
1581
1582    public void removeByGroupId(long groupId) throws SystemException {
1583        for (CalEvent calEvent : findByGroupId(groupId)) {
1584            remove(calEvent);
1585        }
1586    }
1587
1588    public void removeByG_T(long groupId, String type)
1589        throws SystemException {
1590        for (CalEvent calEvent : findByG_T(groupId, type)) {
1591            remove(calEvent);
1592        }
1593    }
1594
1595    public void removeByG_R(long groupId, boolean repeating)
1596        throws SystemException {
1597        for (CalEvent calEvent : findByG_R(groupId, repeating)) {
1598            remove(calEvent);
1599        }
1600    }
1601
1602    public void removeAll() throws SystemException {
1603        for (CalEvent calEvent : findAll()) {
1604            remove(calEvent);
1605        }
1606    }
1607
1608    public int countByUuid(String uuid) throws SystemException {
1609        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1610        String finderClassName = CalEvent.class.getName();
1611        String finderMethodName = "countByUuid";
1612        String[] finderParams = new String[] { String.class.getName() };
1613        Object[] finderArgs = new Object[] { uuid };
1614
1615        Object result = null;
1616
1617        if (finderClassNameCacheEnabled) {
1618            result = FinderCacheUtil.getResult(finderClassName,
1619                    finderMethodName, finderParams, finderArgs, this);
1620        }
1621
1622        if (result == null) {
1623            Session session = null;
1624
1625            try {
1626                session = openSession();
1627
1628                StringBuilder query = new StringBuilder();
1629
1630                query.append("SELECT COUNT(*) ");
1631                query.append(
1632                    "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1633
1634                if (uuid == null) {
1635                    query.append("uuid_ IS NULL");
1636                }
1637                else {
1638                    query.append("uuid_ = ?");
1639                }
1640
1641                query.append(" ");
1642
1643                Query q = session.createQuery(query.toString());
1644
1645                QueryPos qPos = QueryPos.getInstance(q);
1646
1647                if (uuid != null) {
1648                    qPos.add(uuid);
1649                }
1650
1651                Long count = null;
1652
1653                Iterator<Long> itr = q.list().iterator();
1654
1655                if (itr.hasNext()) {
1656                    count = itr.next();
1657                }
1658
1659                if (count == null) {
1660                    count = new Long(0);
1661                }
1662
1663                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1664                    finderClassName, finderMethodName, finderParams,
1665                    finderArgs, count);
1666
1667                return count.intValue();
1668            }
1669            catch (Exception e) {
1670                throw processException(e);
1671            }
1672            finally {
1673                closeSession(session);
1674            }
1675        }
1676        else {
1677            return ((Long)result).intValue();
1678        }
1679    }
1680
1681    public int countByUUID_G(String uuid, long groupId)
1682        throws SystemException {
1683        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1684        String finderClassName = CalEvent.class.getName();
1685        String finderMethodName = "countByUUID_G";
1686        String[] finderParams = new String[] {
1687                String.class.getName(), Long.class.getName()
1688            };
1689        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1690
1691        Object result = null;
1692
1693        if (finderClassNameCacheEnabled) {
1694            result = FinderCacheUtil.getResult(finderClassName,
1695                    finderMethodName, finderParams, finderArgs, this);
1696        }
1697
1698        if (result == null) {
1699            Session session = null;
1700
1701            try {
1702                session = openSession();
1703
1704                StringBuilder query = new StringBuilder();
1705
1706                query.append("SELECT COUNT(*) ");
1707                query.append(
1708                    "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1709
1710                if (uuid == null) {
1711                    query.append("uuid_ IS NULL");
1712                }
1713                else {
1714                    query.append("uuid_ = ?");
1715                }
1716
1717                query.append(" AND ");
1718
1719                query.append("groupId = ?");
1720
1721                query.append(" ");
1722
1723                Query q = session.createQuery(query.toString());
1724
1725                QueryPos qPos = QueryPos.getInstance(q);
1726
1727                if (uuid != null) {
1728                    qPos.add(uuid);
1729                }
1730
1731                qPos.add(groupId);
1732
1733                Long count = null;
1734
1735                Iterator<Long> itr = q.list().iterator();
1736
1737                if (itr.hasNext()) {
1738                    count = itr.next();
1739                }
1740
1741                if (count == null) {
1742                    count = new Long(0);
1743                }
1744
1745                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1746                    finderClassName, finderMethodName, finderParams,
1747                    finderArgs, count);
1748
1749                return count.intValue();
1750            }
1751            catch (Exception e) {
1752                throw processException(e);
1753            }
1754            finally {
1755                closeSession(session);
1756            }
1757        }
1758        else {
1759            return ((Long)result).intValue();
1760        }
1761    }
1762
1763    public int countByGroupId(long groupId) throws SystemException {
1764        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1765        String finderClassName = CalEvent.class.getName();
1766        String finderMethodName = "countByGroupId";
1767        String[] finderParams = new String[] { Long.class.getName() };
1768        Object[] finderArgs = new Object[] { new Long(groupId) };
1769
1770        Object result = null;
1771
1772        if (finderClassNameCacheEnabled) {
1773            result = FinderCacheUtil.getResult(finderClassName,
1774                    finderMethodName, finderParams, finderArgs, this);
1775        }
1776
1777        if (result == null) {
1778            Session session = null;
1779
1780            try {
1781                session = openSession();
1782
1783                StringBuilder query = new StringBuilder();
1784
1785                query.append("SELECT COUNT(*) ");
1786                query.append(
1787                    "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1788
1789                query.append("groupId = ?");
1790
1791                query.append(" ");
1792
1793                Query q = session.createQuery(query.toString());
1794
1795                QueryPos qPos = QueryPos.getInstance(q);
1796
1797                qPos.add(groupId);
1798
1799                Long count = null;
1800
1801                Iterator<Long> itr = q.list().iterator();
1802
1803                if (itr.hasNext()) {
1804                    count = itr.next();
1805                }
1806
1807                if (count == null) {
1808                    count = new Long(0);
1809                }
1810
1811                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1812                    finderClassName, finderMethodName, finderParams,
1813                    finderArgs, count);
1814
1815                return count.intValue();
1816            }
1817            catch (Exception e) {
1818                throw processException(e);
1819            }
1820            finally {
1821                closeSession(session);
1822            }
1823        }
1824        else {
1825            return ((Long)result).intValue();
1826        }
1827    }
1828
1829    public int countByG_T(long groupId, String type) throws SystemException {
1830        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1831        String finderClassName = CalEvent.class.getName();
1832        String finderMethodName = "countByG_T";
1833        String[] finderParams = new String[] {
1834                Long.class.getName(), String.class.getName()
1835            };
1836        Object[] finderArgs = new Object[] { new Long(groupId), type };
1837
1838        Object result = null;
1839
1840        if (finderClassNameCacheEnabled) {
1841            result = FinderCacheUtil.getResult(finderClassName,
1842                    finderMethodName, finderParams, finderArgs, this);
1843        }
1844
1845        if (result == null) {
1846            Session session = null;
1847
1848            try {
1849                session = openSession();
1850
1851                StringBuilder query = new StringBuilder();
1852
1853                query.append("SELECT COUNT(*) ");
1854                query.append(
1855                    "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1856
1857                query.append("groupId = ?");
1858
1859                query.append(" AND ");
1860
1861                if (type == null) {
1862                    query.append("type_ IS NULL");
1863                }
1864                else {
1865                    query.append("type_ = ?");
1866                }
1867
1868                query.append(" ");
1869
1870                Query q = session.createQuery(query.toString());
1871
1872                QueryPos qPos = QueryPos.getInstance(q);
1873
1874                qPos.add(groupId);
1875
1876                if (type != null) {
1877                    qPos.add(type);
1878                }
1879
1880                Long count = null;
1881
1882                Iterator<Long> itr = q.list().iterator();
1883
1884                if (itr.hasNext()) {
1885                    count = itr.next();
1886                }
1887
1888                if (count == null) {
1889                    count = new Long(0);
1890                }
1891
1892                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1893                    finderClassName, finderMethodName, finderParams,
1894                    finderArgs, count);
1895
1896                return count.intValue();
1897            }
1898            catch (Exception e) {
1899                throw processException(e);
1900            }
1901            finally {
1902                closeSession(session);
1903            }
1904        }
1905        else {
1906            return ((Long)result).intValue();
1907        }
1908    }
1909
1910    public int countByG_R(long groupId, boolean repeating)
1911        throws SystemException {
1912        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1913        String finderClassName = CalEvent.class.getName();
1914        String finderMethodName = "countByG_R";
1915        String[] finderParams = new String[] {
1916                Long.class.getName(), Boolean.class.getName()
1917            };
1918        Object[] finderArgs = new Object[] {
1919                new Long(groupId), Boolean.valueOf(repeating)
1920            };
1921
1922        Object result = null;
1923
1924        if (finderClassNameCacheEnabled) {
1925            result = FinderCacheUtil.getResult(finderClassName,
1926                    finderMethodName, finderParams, finderArgs, this);
1927        }
1928
1929        if (result == null) {
1930            Session session = null;
1931
1932            try {
1933                session = openSession();
1934
1935                StringBuilder query = new StringBuilder();
1936
1937                query.append("SELECT COUNT(*) ");
1938                query.append(
1939                    "FROM com.liferay.portlet.calendar.model.CalEvent WHERE ");
1940
1941                query.append("groupId = ?");
1942
1943                query.append(" AND ");
1944
1945                query.append("repeating = ?");
1946
1947                query.append(" ");
1948
1949                Query q = session.createQuery(query.toString());
1950
1951                QueryPos qPos = QueryPos.getInstance(q);
1952
1953                qPos.add(groupId);
1954
1955                qPos.add(repeating);
1956
1957                Long count = null;
1958
1959                Iterator<Long> itr = q.list().iterator();
1960
1961                if (itr.hasNext()) {
1962                    count = itr.next();
1963                }
1964
1965                if (count == null) {
1966                    count = new Long(0);
1967                }
1968
1969                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1970                    finderClassName, finderMethodName, finderParams,
1971                    finderArgs, count);
1972
1973                return count.intValue();
1974            }
1975            catch (Exception e) {
1976                throw processException(e);
1977            }
1978            finally {
1979                closeSession(session);
1980            }
1981        }
1982        else {
1983            return ((Long)result).intValue();
1984        }
1985    }
1986
1987    public int countAll() throws SystemException {
1988        boolean finderClassNameCacheEnabled = CalEventModelImpl.CACHE_ENABLED;
1989        String finderClassName = CalEvent.class.getName();
1990        String finderMethodName = "countAll";
1991        String[] finderParams = new String[] {  };
1992        Object[] finderArgs = new Object[] {  };
1993
1994        Object result = null;
1995
1996        if (finderClassNameCacheEnabled) {
1997            result = FinderCacheUtil.getResult(finderClassName,
1998                    finderMethodName, finderParams, finderArgs, this);
1999        }
2000
2001        if (result == null) {
2002            Session session = null;
2003
2004            try {
2005                session = openSession();
2006
2007                Query q = session.createQuery(
2008                        "SELECT COUNT(*) FROM com.liferay.portlet.calendar.model.CalEvent");
2009
2010                Long count = null;
2011
2012                Iterator<Long> itr = q.list().iterator();
2013
2014                if (itr.hasNext()) {
2015                    count = itr.next();
2016                }
2017
2018                if (count == null) {
2019                    count = new Long(0);
2020                }
2021
2022                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2023                    finderClassName, finderMethodName, finderParams,
2024                    finderArgs, count);
2025
2026                return count.intValue();
2027            }
2028            catch (Exception e) {
2029                throw processException(e);
2030            }
2031            finally {
2032                closeSession(session);
2033            }
2034        }
2035        else {
2036            return ((Long)result).intValue();
2037        }
2038    }
2039
2040    public void afterPropertiesSet() {
2041        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2042                    com.liferay.portal.util.PropsUtil.get(
2043                        "value.object.listener.com.liferay.portlet.calendar.model.CalEvent")));
2044
2045        if (listenerClassNames.length > 0) {
2046            try {
2047                List<ModelListener> listenersList = new ArrayList<ModelListener>();
2048
2049                for (String listenerClassName : listenerClassNames) {
2050                    listenersList.add((ModelListener)Class.forName(
2051                            listenerClassName).newInstance());
2052                }
2053
2054                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2055            }
2056            catch (Exception e) {
2057                _log.error(e);
2058            }
2059        }
2060    }
2061
2062    private static Log _log = LogFactoryUtil.getLog(CalEventPersistenceImpl.class);
2063}