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