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