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.portal.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="RegionUtil.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class RegionUtil {
40      public static com.liferay.portal.model.Region create(long regionId) {
41          return getPersistence().create(regionId);
42      }
43  
44      public static com.liferay.portal.model.Region remove(long regionId)
45          throws com.liferay.portal.SystemException, 
46              com.liferay.portal.NoSuchRegionException {
47          ModelListener listener = _getListener();
48  
49          if (listener != null) {
50              listener.onBeforeRemove(findByPrimaryKey(regionId));
51          }
52  
53          com.liferay.portal.model.Region region = getPersistence().remove(regionId);
54  
55          if (listener != null) {
56              listener.onAfterRemove(region);
57          }
58  
59          return region;
60      }
61  
62      public static com.liferay.portal.model.Region remove(
63          com.liferay.portal.model.Region region)
64          throws com.liferay.portal.SystemException {
65          ModelListener listener = _getListener();
66  
67          if (listener != null) {
68              listener.onBeforeRemove(region);
69          }
70  
71          region = getPersistence().remove(region);
72  
73          if (listener != null) {
74              listener.onAfterRemove(region);
75          }
76  
77          return region;
78      }
79  
80      public static com.liferay.portal.model.Region update(
81          com.liferay.portal.model.Region region)
82          throws com.liferay.portal.SystemException {
83          ModelListener listener = _getListener();
84          boolean isNew = region.isNew();
85  
86          if (listener != null) {
87              if (isNew) {
88                  listener.onBeforeCreate(region);
89              }
90              else {
91                  listener.onBeforeUpdate(region);
92              }
93          }
94  
95          region = getPersistence().update(region);
96  
97          if (listener != null) {
98              if (isNew) {
99                  listener.onAfterCreate(region);
100             }
101             else {
102                 listener.onAfterUpdate(region);
103             }
104         }
105 
106         return region;
107     }
108 
109     public static com.liferay.portal.model.Region update(
110         com.liferay.portal.model.Region region, boolean merge)
111         throws com.liferay.portal.SystemException {
112         ModelListener listener = _getListener();
113         boolean isNew = region.isNew();
114 
115         if (listener != null) {
116             if (isNew) {
117                 listener.onBeforeCreate(region);
118             }
119             else {
120                 listener.onBeforeUpdate(region);
121             }
122         }
123 
124         region = getPersistence().update(region, merge);
125 
126         if (listener != null) {
127             if (isNew) {
128                 listener.onAfterCreate(region);
129             }
130             else {
131                 listener.onAfterUpdate(region);
132             }
133         }
134 
135         return region;
136     }
137 
138     public static com.liferay.portal.model.Region findByPrimaryKey(
139         long regionId)
140         throws com.liferay.portal.SystemException, 
141             com.liferay.portal.NoSuchRegionException {
142         return getPersistence().findByPrimaryKey(regionId);
143     }
144 
145     public static com.liferay.portal.model.Region fetchByPrimaryKey(
146         long regionId) throws com.liferay.portal.SystemException {
147         return getPersistence().fetchByPrimaryKey(regionId);
148     }
149 
150     public static java.util.List findByCountryId(long countryId)
151         throws com.liferay.portal.SystemException {
152         return getPersistence().findByCountryId(countryId);
153     }
154 
155     public static java.util.List findByCountryId(long countryId, int begin,
156         int end) throws com.liferay.portal.SystemException {
157         return getPersistence().findByCountryId(countryId, begin, end);
158     }
159 
160     public static java.util.List findByCountryId(long countryId, int begin,
161         int end, com.liferay.portal.kernel.util.OrderByComparator obc)
162         throws com.liferay.portal.SystemException {
163         return getPersistence().findByCountryId(countryId, begin, end, obc);
164     }
165 
166     public static com.liferay.portal.model.Region findByCountryId_First(
167         long countryId, com.liferay.portal.kernel.util.OrderByComparator obc)
168         throws com.liferay.portal.SystemException, 
169             com.liferay.portal.NoSuchRegionException {
170         return getPersistence().findByCountryId_First(countryId, obc);
171     }
172 
173     public static com.liferay.portal.model.Region findByCountryId_Last(
174         long countryId, com.liferay.portal.kernel.util.OrderByComparator obc)
175         throws com.liferay.portal.SystemException, 
176             com.liferay.portal.NoSuchRegionException {
177         return getPersistence().findByCountryId_Last(countryId, obc);
178     }
179 
180     public static com.liferay.portal.model.Region[] findByCountryId_PrevAndNext(
181         long regionId, long countryId,
182         com.liferay.portal.kernel.util.OrderByComparator obc)
183         throws com.liferay.portal.SystemException, 
184             com.liferay.portal.NoSuchRegionException {
185         return getPersistence().findByCountryId_PrevAndNext(regionId,
186             countryId, obc);
187     }
188 
189     public static java.util.List findByActive(boolean active)
190         throws com.liferay.portal.SystemException {
191         return getPersistence().findByActive(active);
192     }
193 
194     public static java.util.List findByActive(boolean active, int begin, int end)
195         throws com.liferay.portal.SystemException {
196         return getPersistence().findByActive(active, begin, end);
197     }
198 
199     public static java.util.List findByActive(boolean active, int begin,
200         int end, com.liferay.portal.kernel.util.OrderByComparator obc)
201         throws com.liferay.portal.SystemException {
202         return getPersistence().findByActive(active, begin, end, obc);
203     }
204 
205     public static com.liferay.portal.model.Region findByActive_First(
206         boolean active, com.liferay.portal.kernel.util.OrderByComparator obc)
207         throws com.liferay.portal.SystemException, 
208             com.liferay.portal.NoSuchRegionException {
209         return getPersistence().findByActive_First(active, obc);
210     }
211 
212     public static com.liferay.portal.model.Region findByActive_Last(
213         boolean active, com.liferay.portal.kernel.util.OrderByComparator obc)
214         throws com.liferay.portal.SystemException, 
215             com.liferay.portal.NoSuchRegionException {
216         return getPersistence().findByActive_Last(active, obc);
217     }
218 
219     public static com.liferay.portal.model.Region[] findByActive_PrevAndNext(
220         long regionId, boolean active,
221         com.liferay.portal.kernel.util.OrderByComparator obc)
222         throws com.liferay.portal.SystemException, 
223             com.liferay.portal.NoSuchRegionException {
224         return getPersistence().findByActive_PrevAndNext(regionId, active, obc);
225     }
226 
227     public static java.util.List findByC_A(long countryId, boolean active)
228         throws com.liferay.portal.SystemException {
229         return getPersistence().findByC_A(countryId, active);
230     }
231 
232     public static java.util.List findByC_A(long countryId, boolean active,
233         int begin, int end) throws com.liferay.portal.SystemException {
234         return getPersistence().findByC_A(countryId, active, begin, end);
235     }
236 
237     public static java.util.List findByC_A(long countryId, boolean active,
238         int begin, int end, com.liferay.portal.kernel.util.OrderByComparator obc)
239         throws com.liferay.portal.SystemException {
240         return getPersistence().findByC_A(countryId, active, begin, end, obc);
241     }
242 
243     public static com.liferay.portal.model.Region findByC_A_First(
244         long countryId, boolean active,
245         com.liferay.portal.kernel.util.OrderByComparator obc)
246         throws com.liferay.portal.SystemException, 
247             com.liferay.portal.NoSuchRegionException {
248         return getPersistence().findByC_A_First(countryId, active, obc);
249     }
250 
251     public static com.liferay.portal.model.Region findByC_A_Last(
252         long countryId, boolean active,
253         com.liferay.portal.kernel.util.OrderByComparator obc)
254         throws com.liferay.portal.SystemException, 
255             com.liferay.portal.NoSuchRegionException {
256         return getPersistence().findByC_A_Last(countryId, active, obc);
257     }
258 
259     public static com.liferay.portal.model.Region[] findByC_A_PrevAndNext(
260         long regionId, long countryId, boolean active,
261         com.liferay.portal.kernel.util.OrderByComparator obc)
262         throws com.liferay.portal.SystemException, 
263             com.liferay.portal.NoSuchRegionException {
264         return getPersistence().findByC_A_PrevAndNext(regionId, countryId,
265             active, obc);
266     }
267 
268     public static java.util.List findWithDynamicQuery(
269         com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer)
270         throws com.liferay.portal.SystemException {
271         return getPersistence().findWithDynamicQuery(queryInitializer);
272     }
273 
274     public static java.util.List findWithDynamicQuery(
275         com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer,
276         int begin, int end) throws com.liferay.portal.SystemException {
277         return getPersistence().findWithDynamicQuery(queryInitializer, begin,
278             end);
279     }
280 
281     public static java.util.List findAll()
282         throws com.liferay.portal.SystemException {
283         return getPersistence().findAll();
284     }
285 
286     public static java.util.List findAll(int begin, int end)
287         throws com.liferay.portal.SystemException {
288         return getPersistence().findAll(begin, end);
289     }
290 
291     public static java.util.List findAll(int begin, int end,
292         com.liferay.portal.kernel.util.OrderByComparator obc)
293         throws com.liferay.portal.SystemException {
294         return getPersistence().findAll(begin, end, obc);
295     }
296 
297     public static void removeByCountryId(long countryId)
298         throws com.liferay.portal.SystemException {
299         getPersistence().removeByCountryId(countryId);
300     }
301 
302     public static void removeByActive(boolean active)
303         throws com.liferay.portal.SystemException {
304         getPersistence().removeByActive(active);
305     }
306 
307     public static void removeByC_A(long countryId, boolean active)
308         throws com.liferay.portal.SystemException {
309         getPersistence().removeByC_A(countryId, active);
310     }
311 
312     public static void removeAll() throws com.liferay.portal.SystemException {
313         getPersistence().removeAll();
314     }
315 
316     public static int countByCountryId(long countryId)
317         throws com.liferay.portal.SystemException {
318         return getPersistence().countByCountryId(countryId);
319     }
320 
321     public static int countByActive(boolean active)
322         throws com.liferay.portal.SystemException {
323         return getPersistence().countByActive(active);
324     }
325 
326     public static int countByC_A(long countryId, boolean active)
327         throws com.liferay.portal.SystemException {
328         return getPersistence().countByC_A(countryId, active);
329     }
330 
331     public static int countAll() throws com.liferay.portal.SystemException {
332         return getPersistence().countAll();
333     }
334 
335     public static RegionPersistence getPersistence() {
336         return _getUtil()._persistence;
337     }
338 
339     public void setPersistence(RegionPersistence persistence) {
340         _persistence = persistence;
341     }
342 
343     private static RegionUtil _getUtil() {
344         if (_util == null) {
345             _util = (RegionUtil)com.liferay.portal.kernel.bean.BeanLocatorUtil.locate(_UTIL);
346         }
347 
348         return _util;
349     }
350 
351     private static ModelListener _getListener() {
352         if (Validator.isNotNull(_LISTENER)) {
353             try {
354                 return (ModelListener)Class.forName(_LISTENER).newInstance();
355             }
356             catch (Exception e) {
357                 _log.error(e);
358             }
359         }
360 
361         return null;
362     }
363 
364     private static final String _UTIL = RegionUtil.class.getName();
365     private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
366                 "value.object.listener.com.liferay.portal.model.Region"));
367     private static Log _log = LogFactory.getLog(RegionUtil.class);
368     private static RegionUtil _util;
369     private RegionPersistence _persistence;
370 }