1   /**
2    * Copyright (c) 2000-2006 Liferay, LLC. 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.bookmarks.service.persistence;
24  
25  import com.liferay.portal.model.ModelListener;
26  import com.liferay.portal.spring.util.SpringUtil;
27  import com.liferay.portal.util.PropsUtil;
28  
29  import com.liferay.util.GetterUtil;
30  import com.liferay.util.Validator;
31  
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  
35  import org.springframework.context.ApplicationContext;
36  
37  /**
38   * <a href="BookmarksFolderUtil.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author  Brian Wing Shun Chan
41   *
42   */
43  public class BookmarksFolderUtil {
44      public static final String CLASS_NAME = BookmarksFolderUtil.class.getName();
45      public static final String LISTENER = GetterUtil.getString(PropsUtil.get(
46                  "value.object.listener.com.liferay.portlet.bookmarks.model.BookmarksFolder"));
47  
48      public static com.liferay.portlet.bookmarks.model.BookmarksFolder create(
49          java.lang.String folderId) {
50          return getPersistence().create(folderId);
51      }
52  
53      public static com.liferay.portlet.bookmarks.model.BookmarksFolder remove(
54          java.lang.String folderId)
55          throws com.liferay.portlet.bookmarks.NoSuchFolderException, 
56              com.liferay.portal.SystemException {
57          ModelListener listener = null;
58  
59          if (Validator.isNotNull(LISTENER)) {
60              try {
61                  listener = (ModelListener)Class.forName(LISTENER).newInstance();
62              }
63              catch (Exception e) {
64                  _log.error(e);
65              }
66          }
67  
68          if (listener != null) {
69              listener.onBeforeRemove(findByPrimaryKey(folderId));
70          }
71  
72          com.liferay.portlet.bookmarks.model.BookmarksFolder bookmarksFolder = getPersistence()
73                                                                                    .remove(folderId);
74  
75          if (listener != null) {
76              listener.onAfterRemove(bookmarksFolder);
77          }
78  
79          return bookmarksFolder;
80      }
81  
82      public static com.liferay.portlet.bookmarks.model.BookmarksFolder remove(
83          com.liferay.portlet.bookmarks.model.BookmarksFolder bookmarksFolder)
84          throws com.liferay.portal.SystemException {
85          ModelListener listener = null;
86  
87          if (Validator.isNotNull(LISTENER)) {
88              try {
89                  listener = (ModelListener)Class.forName(LISTENER).newInstance();
90              }
91              catch (Exception e) {
92                  _log.error(e);
93              }
94          }
95  
96          if (listener != null) {
97              listener.onBeforeRemove(bookmarksFolder);
98          }
99  
100         bookmarksFolder = getPersistence().remove(bookmarksFolder);
101 
102         if (listener != null) {
103             listener.onAfterRemove(bookmarksFolder);
104         }
105 
106         return bookmarksFolder;
107     }
108 
109     public static com.liferay.portlet.bookmarks.model.BookmarksFolder update(
110         com.liferay.portlet.bookmarks.model.BookmarksFolder bookmarksFolder)
111         throws com.liferay.portal.SystemException {
112         ModelListener listener = null;
113 
114         if (Validator.isNotNull(LISTENER)) {
115             try {
116                 listener = (ModelListener)Class.forName(LISTENER).newInstance();
117             }
118             catch (Exception e) {
119                 _log.error(e);
120             }
121         }
122 
123         boolean isNew = bookmarksFolder.isNew();
124 
125         if (listener != null) {
126             if (isNew) {
127                 listener.onBeforeCreate(bookmarksFolder);
128             }
129             else {
130                 listener.onBeforeUpdate(bookmarksFolder);
131             }
132         }
133 
134         bookmarksFolder = getPersistence().update(bookmarksFolder);
135 
136         if (listener != null) {
137             if (isNew) {
138                 listener.onAfterCreate(bookmarksFolder);
139             }
140             else {
141                 listener.onAfterUpdate(bookmarksFolder);
142             }
143         }
144 
145         return bookmarksFolder;
146     }
147 
148     public static com.liferay.portlet.bookmarks.model.BookmarksFolder findByPrimaryKey(
149         java.lang.String folderId)
150         throws com.liferay.portlet.bookmarks.NoSuchFolderException, 
151             com.liferay.portal.SystemException {
152         return getPersistence().findByPrimaryKey(folderId);
153     }
154 
155     public static com.liferay.portlet.bookmarks.model.BookmarksFolder fetchByPrimaryKey(
156         java.lang.String folderId) throws com.liferay.portal.SystemException {
157         return getPersistence().fetchByPrimaryKey(folderId);
158     }
159 
160     public static java.util.List findByGroupId(java.lang.String groupId)
161         throws com.liferay.portal.SystemException {
162         return getPersistence().findByGroupId(groupId);
163     }
164 
165     public static java.util.List findByGroupId(java.lang.String groupId,
166         int begin, int end) throws com.liferay.portal.SystemException {
167         return getPersistence().findByGroupId(groupId, begin, end);
168     }
169 
170     public static java.util.List findByGroupId(java.lang.String groupId,
171         int begin, int end, com.liferay.util.dao.hibernate.OrderByComparator obc)
172         throws com.liferay.portal.SystemException {
173         return getPersistence().findByGroupId(groupId, begin, end, obc);
174     }
175 
176     public static com.liferay.portlet.bookmarks.model.BookmarksFolder findByGroupId_First(
177         java.lang.String groupId,
178         com.liferay.util.dao.hibernate.OrderByComparator obc)
179         throws com.liferay.portlet.bookmarks.NoSuchFolderException, 
180             com.liferay.portal.SystemException {
181         return getPersistence().findByGroupId_First(groupId, obc);
182     }
183 
184     public static com.liferay.portlet.bookmarks.model.BookmarksFolder findByGroupId_Last(
185         java.lang.String groupId,
186         com.liferay.util.dao.hibernate.OrderByComparator obc)
187         throws com.liferay.portlet.bookmarks.NoSuchFolderException, 
188             com.liferay.portal.SystemException {
189         return getPersistence().findByGroupId_Last(groupId, obc);
190     }
191 
192     public static com.liferay.portlet.bookmarks.model.BookmarksFolder[] findByGroupId_PrevAndNext(
193         java.lang.String folderId, java.lang.String groupId,
194         com.liferay.util.dao.hibernate.OrderByComparator obc)
195         throws com.liferay.portlet.bookmarks.NoSuchFolderException, 
196             com.liferay.portal.SystemException {
197         return getPersistence().findByGroupId_PrevAndNext(folderId, groupId, obc);
198     }
199 
200     public static java.util.List findByG_P(java.lang.String groupId,
201         java.lang.String parentFolderId)
202         throws com.liferay.portal.SystemException {
203         return getPersistence().findByG_P(groupId, parentFolderId);
204     }
205 
206     public static java.util.List findByG_P(java.lang.String groupId,
207         java.lang.String parentFolderId, int begin, int end)
208         throws com.liferay.portal.SystemException {
209         return getPersistence().findByG_P(groupId, parentFolderId, begin, end);
210     }
211 
212     public static java.util.List findByG_P(java.lang.String groupId,
213         java.lang.String parentFolderId, int begin, int end,
214         com.liferay.util.dao.hibernate.OrderByComparator obc)
215         throws com.liferay.portal.SystemException {
216         return getPersistence().findByG_P(groupId, parentFolderId, begin, end,
217             obc);
218     }
219 
220     public static com.liferay.portlet.bookmarks.model.BookmarksFolder findByG_P_First(
221         java.lang.String groupId, java.lang.String parentFolderId,
222         com.liferay.util.dao.hibernate.OrderByComparator obc)
223         throws com.liferay.portlet.bookmarks.NoSuchFolderException, 
224             com.liferay.portal.SystemException {
225         return getPersistence().findByG_P_First(groupId, parentFolderId, obc);
226     }
227 
228     public static com.liferay.portlet.bookmarks.model.BookmarksFolder findByG_P_Last(
229         java.lang.String groupId, java.lang.String parentFolderId,
230         com.liferay.util.dao.hibernate.OrderByComparator obc)
231         throws com.liferay.portlet.bookmarks.NoSuchFolderException, 
232             com.liferay.portal.SystemException {
233         return getPersistence().findByG_P_Last(groupId, parentFolderId, obc);
234     }
235 
236     public static com.liferay.portlet.bookmarks.model.BookmarksFolder[] findByG_P_PrevAndNext(
237         java.lang.String folderId, java.lang.String groupId,
238         java.lang.String parentFolderId,
239         com.liferay.util.dao.hibernate.OrderByComparator obc)
240         throws com.liferay.portlet.bookmarks.NoSuchFolderException, 
241             com.liferay.portal.SystemException {
242         return getPersistence().findByG_P_PrevAndNext(folderId, groupId,
243             parentFolderId, obc);
244     }
245 
246     public static java.util.List findAll()
247         throws com.liferay.portal.SystemException {
248         return getPersistence().findAll();
249     }
250 
251     public static void removeByGroupId(java.lang.String groupId)
252         throws com.liferay.portal.SystemException {
253         getPersistence().removeByGroupId(groupId);
254     }
255 
256     public static void removeByG_P(java.lang.String groupId,
257         java.lang.String parentFolderId)
258         throws com.liferay.portal.SystemException {
259         getPersistence().removeByG_P(groupId, parentFolderId);
260     }
261 
262     public static int countByGroupId(java.lang.String groupId)
263         throws com.liferay.portal.SystemException {
264         return getPersistence().countByGroupId(groupId);
265     }
266 
267     public static int countByG_P(java.lang.String groupId,
268         java.lang.String parentFolderId)
269         throws com.liferay.portal.SystemException {
270         return getPersistence().countByG_P(groupId, parentFolderId);
271     }
272 
273     public static void initDao() {
274         getPersistence().initDao();
275     }
276 
277     public static BookmarksFolderPersistence getPersistence() {
278         ApplicationContext ctx = SpringUtil.getContext();
279         BookmarksFolderUtil util = (BookmarksFolderUtil)ctx.getBean(CLASS_NAME);
280 
281         return util._persistence;
282     }
283 
284     public void setPersistence(BookmarksFolderPersistence persistence) {
285         _persistence = persistence;
286     }
287 
288     private static Log _log = LogFactory.getLog(BookmarksFolderUtil.class);
289     private BookmarksFolderPersistence _persistence;
290 }