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