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