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