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="BookmarksEntryUtil.java.html"><b><i>View Source</i></b></a>
39   *
40   * @author  Brian Wing Shun Chan
41   *
42   */
43  public class BookmarksEntryUtil {
44      public static final String CLASS_NAME = BookmarksEntryUtil.class.getName();
45      public static final String LISTENER = GetterUtil.getString(PropsUtil.get(
46                  "value.object.listener.com.liferay.portlet.bookmarks.model.BookmarksEntry"));
47  
48      public static com.liferay.portlet.bookmarks.model.BookmarksEntry create(
49          java.lang.String entryId) {
50          return getPersistence().create(entryId);
51      }
52  
53      public static com.liferay.portlet.bookmarks.model.BookmarksEntry remove(
54          java.lang.String entryId)
55          throws com.liferay.portlet.bookmarks.NoSuchEntryException, 
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(entryId));
70          }
71  
72          com.liferay.portlet.bookmarks.model.BookmarksEntry bookmarksEntry = getPersistence()
73                                                                                  .remove(entryId);
74  
75          if (listener != null) {
76              listener.onAfterRemove(bookmarksEntry);
77          }
78  
79          return bookmarksEntry;
80      }
81  
82      public static com.liferay.portlet.bookmarks.model.BookmarksEntry remove(
83          com.liferay.portlet.bookmarks.model.BookmarksEntry bookmarksEntry)
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(bookmarksEntry);
98          }
99  
100         bookmarksEntry = getPersistence().remove(bookmarksEntry);
101 
102         if (listener != null) {
103             listener.onAfterRemove(bookmarksEntry);
104         }
105 
106         return bookmarksEntry;
107     }
108 
109     public static com.liferay.portlet.bookmarks.model.BookmarksEntry update(
110         com.liferay.portlet.bookmarks.model.BookmarksEntry bookmarksEntry)
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 = bookmarksEntry.isNew();
124 
125         if (listener != null) {
126             if (isNew) {
127                 listener.onBeforeCreate(bookmarksEntry);
128             }
129             else {
130                 listener.onBeforeUpdate(bookmarksEntry);
131             }
132         }
133 
134         bookmarksEntry = getPersistence().update(bookmarksEntry);
135 
136         if (listener != null) {
137             if (isNew) {
138                 listener.onAfterCreate(bookmarksEntry);
139             }
140             else {
141                 listener.onAfterUpdate(bookmarksEntry);
142             }
143         }
144 
145         return bookmarksEntry;
146     }
147 
148     public static com.liferay.portlet.bookmarks.model.BookmarksEntry findByPrimaryKey(
149         java.lang.String entryId)
150         throws com.liferay.portlet.bookmarks.NoSuchEntryException, 
151             com.liferay.portal.SystemException {
152         return getPersistence().findByPrimaryKey(entryId);
153     }
154 
155     public static com.liferay.portlet.bookmarks.model.BookmarksEntry fetchByPrimaryKey(
156         java.lang.String entryId) throws com.liferay.portal.SystemException {
157         return getPersistence().fetchByPrimaryKey(entryId);
158     }
159 
160     public static java.util.List findByFolderId(java.lang.String folderId)
161         throws com.liferay.portal.SystemException {
162         return getPersistence().findByFolderId(folderId);
163     }
164 
165     public static java.util.List findByFolderId(java.lang.String folderId,
166         int begin, int end) throws com.liferay.portal.SystemException {
167         return getPersistence().findByFolderId(folderId, begin, end);
168     }
169 
170     public static java.util.List findByFolderId(java.lang.String folderId,
171         int begin, int end, com.liferay.util.dao.hibernate.OrderByComparator obc)
172         throws com.liferay.portal.SystemException {
173         return getPersistence().findByFolderId(folderId, begin, end, obc);
174     }
175 
176     public static com.liferay.portlet.bookmarks.model.BookmarksEntry findByFolderId_First(
177         java.lang.String folderId,
178         com.liferay.util.dao.hibernate.OrderByComparator obc)
179         throws com.liferay.portlet.bookmarks.NoSuchEntryException, 
180             com.liferay.portal.SystemException {
181         return getPersistence().findByFolderId_First(folderId, obc);
182     }
183 
184     public static com.liferay.portlet.bookmarks.model.BookmarksEntry findByFolderId_Last(
185         java.lang.String folderId,
186         com.liferay.util.dao.hibernate.OrderByComparator obc)
187         throws com.liferay.portlet.bookmarks.NoSuchEntryException, 
188             com.liferay.portal.SystemException {
189         return getPersistence().findByFolderId_Last(folderId, obc);
190     }
191 
192     public static com.liferay.portlet.bookmarks.model.BookmarksEntry[] findByFolderId_PrevAndNext(
193         java.lang.String entryId, java.lang.String folderId,
194         com.liferay.util.dao.hibernate.OrderByComparator obc)
195         throws com.liferay.portlet.bookmarks.NoSuchEntryException, 
196             com.liferay.portal.SystemException {
197         return getPersistence().findByFolderId_PrevAndNext(entryId, folderId,
198             obc);
199     }
200 
201     public static java.util.List findAll()
202         throws com.liferay.portal.SystemException {
203         return getPersistence().findAll();
204     }
205 
206     public static void removeByFolderId(java.lang.String folderId)
207         throws com.liferay.portal.SystemException {
208         getPersistence().removeByFolderId(folderId);
209     }
210 
211     public static int countByFolderId(java.lang.String folderId)
212         throws com.liferay.portal.SystemException {
213         return getPersistence().countByFolderId(folderId);
214     }
215 
216     public static void initDao() {
217         getPersistence().initDao();
218     }
219 
220     public static BookmarksEntryPersistence getPersistence() {
221         ApplicationContext ctx = SpringUtil.getContext();
222         BookmarksEntryUtil util = (BookmarksEntryUtil)ctx.getBean(CLASS_NAME);
223 
224         return util._persistence;
225     }
226 
227     public void setPersistence(BookmarksEntryPersistence persistence) {
228         _persistence = persistence;
229     }
230 
231     private static Log _log = LogFactory.getLog(BookmarksEntryUtil.class);
232     private BookmarksEntryPersistence _persistence;
233 }