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