1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.calendar.service.persistence;
24  
25  import com.liferay.portal.kernel.util.GetterUtil;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.model.ModelListener;
28  import com.liferay.portal.util.PropsUtil;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  
33  /**
34   * <a href="CalEventUtil.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class CalEventUtil {
40      public static com.liferay.portlet.calendar.model.CalEvent create(
41          long eventId) {
42          return getPersistence().create(eventId);
43      }
44  
45      public static com.liferay.portlet.calendar.model.CalEvent remove(
46          long eventId)
47          throws com.liferay.portal.SystemException, 
48              com.liferay.portlet.calendar.NoSuchEventException {
49          ModelListener listener = _getListener();
50  
51          if (listener != null) {
52              listener.onBeforeRemove(findByPrimaryKey(eventId));
53          }
54  
55          com.liferay.portlet.calendar.model.CalEvent calEvent = getPersistence()
56                                                                     .remove(eventId);
57  
58          if (listener != null) {
59              listener.onAfterRemove(calEvent);
60          }
61  
62          return calEvent;
63      }
64  
65      public static com.liferay.portlet.calendar.model.CalEvent remove(
66          com.liferay.portlet.calendar.model.CalEvent calEvent)
67          throws com.liferay.portal.SystemException {
68          ModelListener listener = _getListener();
69  
70          if (listener != null) {
71              listener.onBeforeRemove(calEvent);
72          }
73  
74          calEvent = getPersistence().remove(calEvent);
75  
76          if (listener != null) {
77              listener.onAfterRemove(calEvent);
78          }
79  
80          return calEvent;
81      }
82  
83      public static com.liferay.portlet.calendar.model.CalEvent update(
84          com.liferay.portlet.calendar.model.CalEvent calEvent)
85          throws com.liferay.portal.SystemException {
86          ModelListener listener = _getListener();
87          boolean isNew = calEvent.isNew();
88  
89          if (listener != null) {
90              if (isNew) {
91                  listener.onBeforeCreate(calEvent);
92              }
93              else {
94                  listener.onBeforeUpdate(calEvent);
95              }
96          }
97  
98          calEvent = getPersistence().update(calEvent);
99  
100         if (listener != null) {
101             if (isNew) {
102                 listener.onAfterCreate(calEvent);
103             }
104             else {
105                 listener.onAfterUpdate(calEvent);
106             }
107         }
108 
109         return calEvent;
110     }
111 
112     public static com.liferay.portlet.calendar.model.CalEvent update(
113         com.liferay.portlet.calendar.model.CalEvent calEvent, boolean merge)
114         throws com.liferay.portal.SystemException {
115         ModelListener listener = _getListener();
116         boolean isNew = calEvent.isNew();
117 
118         if (listener != null) {
119             if (isNew) {
120                 listener.onBeforeCreate(calEvent);
121             }
122             else {
123                 listener.onBeforeUpdate(calEvent);
124             }
125         }
126 
127         calEvent = getPersistence().update(calEvent, merge);
128 
129         if (listener != null) {
130             if (isNew) {
131                 listener.onAfterCreate(calEvent);
132             }
133             else {
134                 listener.onAfterUpdate(calEvent);
135             }
136         }
137 
138         return calEvent;
139     }
140 
141     public static com.liferay.portlet.calendar.model.CalEvent findByPrimaryKey(
142         long eventId)
143         throws com.liferay.portal.SystemException, 
144             com.liferay.portlet.calendar.NoSuchEventException {
145         return getPersistence().findByPrimaryKey(eventId);
146     }
147 
148     public static com.liferay.portlet.calendar.model.CalEvent fetchByPrimaryKey(
149         long eventId) throws com.liferay.portal.SystemException {
150         return getPersistence().fetchByPrimaryKey(eventId);
151     }
152 
153     public static java.util.List findByGroupId(long groupId)
154         throws com.liferay.portal.SystemException {
155         return getPersistence().findByGroupId(groupId);
156     }
157 
158     public static java.util.List findByGroupId(long groupId, int begin, int end)
159         throws com.liferay.portal.SystemException {
160         return getPersistence().findByGroupId(groupId, begin, end);
161     }
162 
163     public static java.util.List findByGroupId(long groupId, int begin,
164         int end, com.liferay.portal.kernel.util.OrderByComparator obc)
165         throws com.liferay.portal.SystemException {
166         return getPersistence().findByGroupId(groupId, begin, end, obc);
167     }
168 
169     public static com.liferay.portlet.calendar.model.CalEvent findByGroupId_First(
170         long groupId, com.liferay.portal.kernel.util.OrderByComparator obc)
171         throws com.liferay.portal.SystemException, 
172             com.liferay.portlet.calendar.NoSuchEventException {
173         return getPersistence().findByGroupId_First(groupId, obc);
174     }
175 
176     public static com.liferay.portlet.calendar.model.CalEvent findByGroupId_Last(
177         long groupId, com.liferay.portal.kernel.util.OrderByComparator obc)
178         throws com.liferay.portal.SystemException, 
179             com.liferay.portlet.calendar.NoSuchEventException {
180         return getPersistence().findByGroupId_Last(groupId, obc);
181     }
182 
183     public static com.liferay.portlet.calendar.model.CalEvent[] findByGroupId_PrevAndNext(
184         long eventId, long groupId,
185         com.liferay.portal.kernel.util.OrderByComparator obc)
186         throws com.liferay.portal.SystemException, 
187             com.liferay.portlet.calendar.NoSuchEventException {
188         return getPersistence().findByGroupId_PrevAndNext(eventId, groupId, obc);
189     }
190 
191     public static java.util.List findByG_T(long groupId, java.lang.String type)
192         throws com.liferay.portal.SystemException {
193         return getPersistence().findByG_T(groupId, type);
194     }
195 
196     public static java.util.List findByG_T(long groupId, java.lang.String type,
197         int begin, int end) throws com.liferay.portal.SystemException {
198         return getPersistence().findByG_T(groupId, type, begin, end);
199     }
200 
201     public static java.util.List findByG_T(long groupId, java.lang.String type,
202         int begin, int end, com.liferay.portal.kernel.util.OrderByComparator obc)
203         throws com.liferay.portal.SystemException {
204         return getPersistence().findByG_T(groupId, type, begin, end, obc);
205     }
206 
207     public static com.liferay.portlet.calendar.model.CalEvent findByG_T_First(
208         long groupId, java.lang.String type,
209         com.liferay.portal.kernel.util.OrderByComparator obc)
210         throws com.liferay.portal.SystemException, 
211             com.liferay.portlet.calendar.NoSuchEventException {
212         return getPersistence().findByG_T_First(groupId, type, obc);
213     }
214 
215     public static com.liferay.portlet.calendar.model.CalEvent findByG_T_Last(
216         long groupId, java.lang.String type,
217         com.liferay.portal.kernel.util.OrderByComparator obc)
218         throws com.liferay.portal.SystemException, 
219             com.liferay.portlet.calendar.NoSuchEventException {
220         return getPersistence().findByG_T_Last(groupId, type, obc);
221     }
222 
223     public static com.liferay.portlet.calendar.model.CalEvent[] findByG_T_PrevAndNext(
224         long eventId, long groupId, java.lang.String type,
225         com.liferay.portal.kernel.util.OrderByComparator obc)
226         throws com.liferay.portal.SystemException, 
227             com.liferay.portlet.calendar.NoSuchEventException {
228         return getPersistence().findByG_T_PrevAndNext(eventId, groupId, type,
229             obc);
230     }
231 
232     public static java.util.List findByG_R(long groupId, boolean repeating)
233         throws com.liferay.portal.SystemException {
234         return getPersistence().findByG_R(groupId, repeating);
235     }
236 
237     public static java.util.List findByG_R(long groupId, boolean repeating,
238         int begin, int end) throws com.liferay.portal.SystemException {
239         return getPersistence().findByG_R(groupId, repeating, begin, end);
240     }
241 
242     public static java.util.List findByG_R(long groupId, boolean repeating,
243         int begin, int end, com.liferay.portal.kernel.util.OrderByComparator obc)
244         throws com.liferay.portal.SystemException {
245         return getPersistence().findByG_R(groupId, repeating, begin, end, obc);
246     }
247 
248     public static com.liferay.portlet.calendar.model.CalEvent findByG_R_First(
249         long groupId, boolean repeating,
250         com.liferay.portal.kernel.util.OrderByComparator obc)
251         throws com.liferay.portal.SystemException, 
252             com.liferay.portlet.calendar.NoSuchEventException {
253         return getPersistence().findByG_R_First(groupId, repeating, obc);
254     }
255 
256     public static com.liferay.portlet.calendar.model.CalEvent findByG_R_Last(
257         long groupId, boolean repeating,
258         com.liferay.portal.kernel.util.OrderByComparator obc)
259         throws com.liferay.portal.SystemException, 
260             com.liferay.portlet.calendar.NoSuchEventException {
261         return getPersistence().findByG_R_Last(groupId, repeating, obc);
262     }
263 
264     public static com.liferay.portlet.calendar.model.CalEvent[] findByG_R_PrevAndNext(
265         long eventId, long groupId, boolean repeating,
266         com.liferay.portal.kernel.util.OrderByComparator obc)
267         throws com.liferay.portal.SystemException, 
268             com.liferay.portlet.calendar.NoSuchEventException {
269         return getPersistence().findByG_R_PrevAndNext(eventId, groupId,
270             repeating, obc);
271     }
272 
273     public static java.util.List findWithDynamicQuery(
274         com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer)
275         throws com.liferay.portal.SystemException {
276         return getPersistence().findWithDynamicQuery(queryInitializer);
277     }
278 
279     public static java.util.List findWithDynamicQuery(
280         com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer,
281         int begin, int end) throws com.liferay.portal.SystemException {
282         return getPersistence().findWithDynamicQuery(queryInitializer, begin,
283             end);
284     }
285 
286     public static java.util.List findAll()
287         throws com.liferay.portal.SystemException {
288         return getPersistence().findAll();
289     }
290 
291     public static java.util.List findAll(int begin, int end)
292         throws com.liferay.portal.SystemException {
293         return getPersistence().findAll(begin, end);
294     }
295 
296     public static java.util.List findAll(int begin, int end,
297         com.liferay.portal.kernel.util.OrderByComparator obc)
298         throws com.liferay.portal.SystemException {
299         return getPersistence().findAll(begin, end, obc);
300     }
301 
302     public static void removeByGroupId(long groupId)
303         throws com.liferay.portal.SystemException {
304         getPersistence().removeByGroupId(groupId);
305     }
306 
307     public static void removeByG_T(long groupId, java.lang.String type)
308         throws com.liferay.portal.SystemException {
309         getPersistence().removeByG_T(groupId, type);
310     }
311 
312     public static void removeByG_R(long groupId, boolean repeating)
313         throws com.liferay.portal.SystemException {
314         getPersistence().removeByG_R(groupId, repeating);
315     }
316 
317     public static void removeAll() throws com.liferay.portal.SystemException {
318         getPersistence().removeAll();
319     }
320 
321     public static int countByGroupId(long groupId)
322         throws com.liferay.portal.SystemException {
323         return getPersistence().countByGroupId(groupId);
324     }
325 
326     public static int countByG_T(long groupId, java.lang.String type)
327         throws com.liferay.portal.SystemException {
328         return getPersistence().countByG_T(groupId, type);
329     }
330 
331     public static int countByG_R(long groupId, boolean repeating)
332         throws com.liferay.portal.SystemException {
333         return getPersistence().countByG_R(groupId, repeating);
334     }
335 
336     public static int countAll() throws com.liferay.portal.SystemException {
337         return getPersistence().countAll();
338     }
339 
340     public static CalEventPersistence getPersistence() {
341         return _getUtil()._persistence;
342     }
343 
344     public void setPersistence(CalEventPersistence persistence) {
345         _persistence = persistence;
346     }
347 
348     private static CalEventUtil _getUtil() {
349         if (_util == null) {
350             _util = (CalEventUtil)com.liferay.portal.kernel.bean.BeanLocatorUtil.locate(_UTIL);
351         }
352 
353         return _util;
354     }
355 
356     private static ModelListener _getListener() {
357         if (Validator.isNotNull(_LISTENER)) {
358             try {
359                 return (ModelListener)Class.forName(_LISTENER).newInstance();
360             }
361             catch (Exception e) {
362                 _log.error(e);
363             }
364         }
365 
366         return null;
367     }
368 
369     private static final String _UTIL = CalEventUtil.class.getName();
370     private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
371                 "value.object.listener.com.liferay.portlet.calendar.model.CalEvent"));
372     private static Log _log = LogFactory.getLog(CalEventUtil.class);
373     private static CalEventUtil _util;
374     private CalEventPersistence _persistence;
375 }