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