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="CountryUtil.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class CountryUtil {
40      public static com.liferay.portal.model.Country create(long countryId) {
41          return getPersistence().create(countryId);
42      }
43  
44      public static com.liferay.portal.model.Country remove(long countryId)
45          throws com.liferay.portal.SystemException, 
46              com.liferay.portal.NoSuchCountryException {
47          ModelListener listener = _getListener();
48  
49          if (listener != null) {
50              listener.onBeforeRemove(findByPrimaryKey(countryId));
51          }
52  
53          com.liferay.portal.model.Country country = getPersistence().remove(countryId);
54  
55          if (listener != null) {
56              listener.onAfterRemove(country);
57          }
58  
59          return country;
60      }
61  
62      public static com.liferay.portal.model.Country remove(
63          com.liferay.portal.model.Country country)
64          throws com.liferay.portal.SystemException {
65          ModelListener listener = _getListener();
66  
67          if (listener != null) {
68              listener.onBeforeRemove(country);
69          }
70  
71          country = getPersistence().remove(country);
72  
73          if (listener != null) {
74              listener.onAfterRemove(country);
75          }
76  
77          return country;
78      }
79  
80      public static com.liferay.portal.model.Country update(
81          com.liferay.portal.model.Country country)
82          throws com.liferay.portal.SystemException {
83          ModelListener listener = _getListener();
84          boolean isNew = country.isNew();
85  
86          if (listener != null) {
87              if (isNew) {
88                  listener.onBeforeCreate(country);
89              }
90              else {
91                  listener.onBeforeUpdate(country);
92              }
93          }
94  
95          country = getPersistence().update(country);
96  
97          if (listener != null) {
98              if (isNew) {
99                  listener.onAfterCreate(country);
100             }
101             else {
102                 listener.onAfterUpdate(country);
103             }
104         }
105 
106         return country;
107     }
108 
109     public static com.liferay.portal.model.Country update(
110         com.liferay.portal.model.Country country, boolean merge)
111         throws com.liferay.portal.SystemException {
112         ModelListener listener = _getListener();
113         boolean isNew = country.isNew();
114 
115         if (listener != null) {
116             if (isNew) {
117                 listener.onBeforeCreate(country);
118             }
119             else {
120                 listener.onBeforeUpdate(country);
121             }
122         }
123 
124         country = getPersistence().update(country, merge);
125 
126         if (listener != null) {
127             if (isNew) {
128                 listener.onAfterCreate(country);
129             }
130             else {
131                 listener.onAfterUpdate(country);
132             }
133         }
134 
135         return country;
136     }
137 
138     public static com.liferay.portal.model.Country findByPrimaryKey(
139         long countryId)
140         throws com.liferay.portal.SystemException, 
141             com.liferay.portal.NoSuchCountryException {
142         return getPersistence().findByPrimaryKey(countryId);
143     }
144 
145     public static com.liferay.portal.model.Country fetchByPrimaryKey(
146         long countryId) throws com.liferay.portal.SystemException {
147         return getPersistence().fetchByPrimaryKey(countryId);
148     }
149 
150     public static java.util.List findByActive(boolean active)
151         throws com.liferay.portal.SystemException {
152         return getPersistence().findByActive(active);
153     }
154 
155     public static java.util.List findByActive(boolean active, int begin, int end)
156         throws com.liferay.portal.SystemException {
157         return getPersistence().findByActive(active, begin, end);
158     }
159 
160     public static java.util.List findByActive(boolean active, int begin,
161         int end, com.liferay.portal.kernel.util.OrderByComparator obc)
162         throws com.liferay.portal.SystemException {
163         return getPersistence().findByActive(active, begin, end, obc);
164     }
165 
166     public static com.liferay.portal.model.Country findByActive_First(
167         boolean active, com.liferay.portal.kernel.util.OrderByComparator obc)
168         throws com.liferay.portal.SystemException, 
169             com.liferay.portal.NoSuchCountryException {
170         return getPersistence().findByActive_First(active, obc);
171     }
172 
173     public static com.liferay.portal.model.Country findByActive_Last(
174         boolean active, com.liferay.portal.kernel.util.OrderByComparator obc)
175         throws com.liferay.portal.SystemException, 
176             com.liferay.portal.NoSuchCountryException {
177         return getPersistence().findByActive_Last(active, obc);
178     }
179 
180     public static com.liferay.portal.model.Country[] findByActive_PrevAndNext(
181         long countryId, boolean active,
182         com.liferay.portal.kernel.util.OrderByComparator obc)
183         throws com.liferay.portal.SystemException, 
184             com.liferay.portal.NoSuchCountryException {
185         return getPersistence().findByActive_PrevAndNext(countryId, active, obc);
186     }
187 
188     public static java.util.List findWithDynamicQuery(
189         com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer)
190         throws com.liferay.portal.SystemException {
191         return getPersistence().findWithDynamicQuery(queryInitializer);
192     }
193 
194     public static java.util.List findWithDynamicQuery(
195         com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer,
196         int begin, int end) throws com.liferay.portal.SystemException {
197         return getPersistence().findWithDynamicQuery(queryInitializer, begin,
198             end);
199     }
200 
201     public static java.util.List findAll()
202         throws com.liferay.portal.SystemException {
203         return getPersistence().findAll();
204     }
205 
206     public static java.util.List findAll(int begin, int end)
207         throws com.liferay.portal.SystemException {
208         return getPersistence().findAll(begin, end);
209     }
210 
211     public static java.util.List findAll(int begin, int end,
212         com.liferay.portal.kernel.util.OrderByComparator obc)
213         throws com.liferay.portal.SystemException {
214         return getPersistence().findAll(begin, end, obc);
215     }
216 
217     public static void removeByActive(boolean active)
218         throws com.liferay.portal.SystemException {
219         getPersistence().removeByActive(active);
220     }
221 
222     public static void removeAll() throws com.liferay.portal.SystemException {
223         getPersistence().removeAll();
224     }
225 
226     public static int countByActive(boolean active)
227         throws com.liferay.portal.SystemException {
228         return getPersistence().countByActive(active);
229     }
230 
231     public static int countAll() throws com.liferay.portal.SystemException {
232         return getPersistence().countAll();
233     }
234 
235     public static CountryPersistence getPersistence() {
236         return _getUtil()._persistence;
237     }
238 
239     public void setPersistence(CountryPersistence persistence) {
240         _persistence = persistence;
241     }
242 
243     private static CountryUtil _getUtil() {
244         if (_util == null) {
245             _util = (CountryUtil)com.liferay.portal.kernel.bean.BeanLocatorUtil.locate(_UTIL);
246         }
247 
248         return _util;
249     }
250 
251     private static ModelListener _getListener() {
252         if (Validator.isNotNull(_LISTENER)) {
253             try {
254                 return (ModelListener)Class.forName(_LISTENER).newInstance();
255             }
256             catch (Exception e) {
257                 _log.error(e);
258             }
259         }
260 
261         return null;
262     }
263 
264     private static final String _UTIL = CountryUtil.class.getName();
265     private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
266                 "value.object.listener.com.liferay.portal.model.Country"));
267     private static Log _log = LogFactory.getLog(CountryUtil.class);
268     private static CountryUtil _util;
269     private CountryPersistence _persistence;
270 }