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="UserGroupUtil.java.html"><b><i>View Source</i></b></a>
35   *
36   * @author Brian Wing Shun Chan
37   *
38   */
39  public class UserGroupUtil {
40      public static com.liferay.portal.model.UserGroup create(long userGroupId) {
41          return getPersistence().create(userGroupId);
42      }
43  
44      public static com.liferay.portal.model.UserGroup remove(long userGroupId)
45          throws com.liferay.portal.SystemException, 
46              com.liferay.portal.NoSuchUserGroupException {
47          ModelListener listener = _getListener();
48  
49          if (listener != null) {
50              listener.onBeforeRemove(findByPrimaryKey(userGroupId));
51          }
52  
53          com.liferay.portal.model.UserGroup userGroup = getPersistence().remove(userGroupId);
54  
55          if (listener != null) {
56              listener.onAfterRemove(userGroup);
57          }
58  
59          return userGroup;
60      }
61  
62      public static com.liferay.portal.model.UserGroup remove(
63          com.liferay.portal.model.UserGroup userGroup)
64          throws com.liferay.portal.SystemException {
65          ModelListener listener = _getListener();
66  
67          if (listener != null) {
68              listener.onBeforeRemove(userGroup);
69          }
70  
71          userGroup = getPersistence().remove(userGroup);
72  
73          if (listener != null) {
74              listener.onAfterRemove(userGroup);
75          }
76  
77          return userGroup;
78      }
79  
80      public static com.liferay.portal.model.UserGroup update(
81          com.liferay.portal.model.UserGroup userGroup)
82          throws com.liferay.portal.SystemException {
83          ModelListener listener = _getListener();
84          boolean isNew = userGroup.isNew();
85  
86          if (listener != null) {
87              if (isNew) {
88                  listener.onBeforeCreate(userGroup);
89              }
90              else {
91                  listener.onBeforeUpdate(userGroup);
92              }
93          }
94  
95          userGroup = getPersistence().update(userGroup);
96  
97          if (listener != null) {
98              if (isNew) {
99                  listener.onAfterCreate(userGroup);
100             }
101             else {
102                 listener.onAfterUpdate(userGroup);
103             }
104         }
105 
106         return userGroup;
107     }
108 
109     public static com.liferay.portal.model.UserGroup update(
110         com.liferay.portal.model.UserGroup userGroup, boolean merge)
111         throws com.liferay.portal.SystemException {
112         ModelListener listener = _getListener();
113         boolean isNew = userGroup.isNew();
114 
115         if (listener != null) {
116             if (isNew) {
117                 listener.onBeforeCreate(userGroup);
118             }
119             else {
120                 listener.onBeforeUpdate(userGroup);
121             }
122         }
123 
124         userGroup = getPersistence().update(userGroup, merge);
125 
126         if (listener != null) {
127             if (isNew) {
128                 listener.onAfterCreate(userGroup);
129             }
130             else {
131                 listener.onAfterUpdate(userGroup);
132             }
133         }
134 
135         return userGroup;
136     }
137 
138     public static com.liferay.portal.model.UserGroup findByPrimaryKey(
139         long userGroupId)
140         throws com.liferay.portal.SystemException, 
141             com.liferay.portal.NoSuchUserGroupException {
142         return getPersistence().findByPrimaryKey(userGroupId);
143     }
144 
145     public static com.liferay.portal.model.UserGroup fetchByPrimaryKey(
146         long userGroupId) throws com.liferay.portal.SystemException {
147         return getPersistence().fetchByPrimaryKey(userGroupId);
148     }
149 
150     public static java.util.List findByCompanyId(long companyId)
151         throws com.liferay.portal.SystemException {
152         return getPersistence().findByCompanyId(companyId);
153     }
154 
155     public static java.util.List findByCompanyId(long companyId, int begin,
156         int end) throws com.liferay.portal.SystemException {
157         return getPersistence().findByCompanyId(companyId, begin, end);
158     }
159 
160     public static java.util.List findByCompanyId(long companyId, int begin,
161         int end, com.liferay.portal.kernel.util.OrderByComparator obc)
162         throws com.liferay.portal.SystemException {
163         return getPersistence().findByCompanyId(companyId, begin, end, obc);
164     }
165 
166     public static com.liferay.portal.model.UserGroup findByCompanyId_First(
167         long companyId, com.liferay.portal.kernel.util.OrderByComparator obc)
168         throws com.liferay.portal.SystemException, 
169             com.liferay.portal.NoSuchUserGroupException {
170         return getPersistence().findByCompanyId_First(companyId, obc);
171     }
172 
173     public static com.liferay.portal.model.UserGroup findByCompanyId_Last(
174         long companyId, com.liferay.portal.kernel.util.OrderByComparator obc)
175         throws com.liferay.portal.SystemException, 
176             com.liferay.portal.NoSuchUserGroupException {
177         return getPersistence().findByCompanyId_Last(companyId, obc);
178     }
179 
180     public static com.liferay.portal.model.UserGroup[] findByCompanyId_PrevAndNext(
181         long userGroupId, long companyId,
182         com.liferay.portal.kernel.util.OrderByComparator obc)
183         throws com.liferay.portal.SystemException, 
184             com.liferay.portal.NoSuchUserGroupException {
185         return getPersistence().findByCompanyId_PrevAndNext(userGroupId,
186             companyId, obc);
187     }
188 
189     public static java.util.List findByC_P(long companyId,
190         long parentUserGroupId) throws com.liferay.portal.SystemException {
191         return getPersistence().findByC_P(companyId, parentUserGroupId);
192     }
193 
194     public static java.util.List findByC_P(long companyId,
195         long parentUserGroupId, int begin, int end)
196         throws com.liferay.portal.SystemException {
197         return getPersistence().findByC_P(companyId, parentUserGroupId, begin,
198             end);
199     }
200 
201     public static java.util.List findByC_P(long companyId,
202         long parentUserGroupId, int begin, int end,
203         com.liferay.portal.kernel.util.OrderByComparator obc)
204         throws com.liferay.portal.SystemException {
205         return getPersistence().findByC_P(companyId, parentUserGroupId, begin,
206             end, obc);
207     }
208 
209     public static com.liferay.portal.model.UserGroup findByC_P_First(
210         long companyId, long parentUserGroupId,
211         com.liferay.portal.kernel.util.OrderByComparator obc)
212         throws com.liferay.portal.SystemException, 
213             com.liferay.portal.NoSuchUserGroupException {
214         return getPersistence().findByC_P_First(companyId, parentUserGroupId,
215             obc);
216     }
217 
218     public static com.liferay.portal.model.UserGroup findByC_P_Last(
219         long companyId, long parentUserGroupId,
220         com.liferay.portal.kernel.util.OrderByComparator obc)
221         throws com.liferay.portal.SystemException, 
222             com.liferay.portal.NoSuchUserGroupException {
223         return getPersistence().findByC_P_Last(companyId, parentUserGroupId, obc);
224     }
225 
226     public static com.liferay.portal.model.UserGroup[] findByC_P_PrevAndNext(
227         long userGroupId, long companyId, long parentUserGroupId,
228         com.liferay.portal.kernel.util.OrderByComparator obc)
229         throws com.liferay.portal.SystemException, 
230             com.liferay.portal.NoSuchUserGroupException {
231         return getPersistence().findByC_P_PrevAndNext(userGroupId, companyId,
232             parentUserGroupId, obc);
233     }
234 
235     public static com.liferay.portal.model.UserGroup findByC_N(long companyId,
236         java.lang.String name)
237         throws com.liferay.portal.SystemException, 
238             com.liferay.portal.NoSuchUserGroupException {
239         return getPersistence().findByC_N(companyId, name);
240     }
241 
242     public static com.liferay.portal.model.UserGroup fetchByC_N(
243         long companyId, java.lang.String name)
244         throws com.liferay.portal.SystemException {
245         return getPersistence().fetchByC_N(companyId, name);
246     }
247 
248     public static java.util.List findWithDynamicQuery(
249         com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer)
250         throws com.liferay.portal.SystemException {
251         return getPersistence().findWithDynamicQuery(queryInitializer);
252     }
253 
254     public static java.util.List findWithDynamicQuery(
255         com.liferay.portal.kernel.dao.DynamicQueryInitializer queryInitializer,
256         int begin, int end) throws com.liferay.portal.SystemException {
257         return getPersistence().findWithDynamicQuery(queryInitializer, begin,
258             end);
259     }
260 
261     public static java.util.List findAll()
262         throws com.liferay.portal.SystemException {
263         return getPersistence().findAll();
264     }
265 
266     public static java.util.List findAll(int begin, int end)
267         throws com.liferay.portal.SystemException {
268         return getPersistence().findAll(begin, end);
269     }
270 
271     public static java.util.List findAll(int begin, int end,
272         com.liferay.portal.kernel.util.OrderByComparator obc)
273         throws com.liferay.portal.SystemException {
274         return getPersistence().findAll(begin, end, obc);
275     }
276 
277     public static void removeByCompanyId(long companyId)
278         throws com.liferay.portal.SystemException {
279         getPersistence().removeByCompanyId(companyId);
280     }
281 
282     public static void removeByC_P(long companyId, long parentUserGroupId)
283         throws com.liferay.portal.SystemException {
284         getPersistence().removeByC_P(companyId, parentUserGroupId);
285     }
286 
287     public static void removeByC_N(long companyId, java.lang.String name)
288         throws com.liferay.portal.SystemException, 
289             com.liferay.portal.NoSuchUserGroupException {
290         getPersistence().removeByC_N(companyId, name);
291     }
292 
293     public static void removeAll() throws com.liferay.portal.SystemException {
294         getPersistence().removeAll();
295     }
296 
297     public static int countByCompanyId(long companyId)
298         throws com.liferay.portal.SystemException {
299         return getPersistence().countByCompanyId(companyId);
300     }
301 
302     public static int countByC_P(long companyId, long parentUserGroupId)
303         throws com.liferay.portal.SystemException {
304         return getPersistence().countByC_P(companyId, parentUserGroupId);
305     }
306 
307     public static int countByC_N(long companyId, java.lang.String name)
308         throws com.liferay.portal.SystemException {
309         return getPersistence().countByC_N(companyId, name);
310     }
311 
312     public static int countAll() throws com.liferay.portal.SystemException {
313         return getPersistence().countAll();
314     }
315 
316     public static java.util.List getUsers(long pk)
317         throws com.liferay.portal.SystemException, 
318             com.liferay.portal.NoSuchUserGroupException {
319         return getPersistence().getUsers(pk);
320     }
321 
322     public static java.util.List getUsers(long pk, int begin, int end)
323         throws com.liferay.portal.SystemException, 
324             com.liferay.portal.NoSuchUserGroupException {
325         return getPersistence().getUsers(pk, begin, end);
326     }
327 
328     public static java.util.List getUsers(long pk, int begin, int end,
329         com.liferay.portal.kernel.util.OrderByComparator obc)
330         throws com.liferay.portal.SystemException, 
331             com.liferay.portal.NoSuchUserGroupException {
332         return getPersistence().getUsers(pk, begin, end, obc);
333     }
334 
335     public static int getUsersSize(long pk)
336         throws com.liferay.portal.SystemException {
337         return getPersistence().getUsersSize(pk);
338     }
339 
340     public static boolean containsUser(long pk, long userPK)
341         throws com.liferay.portal.SystemException {
342         return getPersistence().containsUser(pk, userPK);
343     }
344 
345     public static boolean containsUsers(long pk)
346         throws com.liferay.portal.SystemException {
347         return getPersistence().containsUsers(pk);
348     }
349 
350     public static void addUser(long pk, long userPK)
351         throws com.liferay.portal.SystemException, 
352             com.liferay.portal.NoSuchUserGroupException, 
353             com.liferay.portal.NoSuchUserException {
354         getPersistence().addUser(pk, userPK);
355     }
356 
357     public static void addUser(long pk, com.liferay.portal.model.User user)
358         throws com.liferay.portal.SystemException, 
359             com.liferay.portal.NoSuchUserGroupException, 
360             com.liferay.portal.NoSuchUserException {
361         getPersistence().addUser(pk, user);
362     }
363 
364     public static void addUsers(long pk, long[] userPKs)
365         throws com.liferay.portal.SystemException, 
366             com.liferay.portal.NoSuchUserGroupException, 
367             com.liferay.portal.NoSuchUserException {
368         getPersistence().addUsers(pk, userPKs);
369     }
370 
371     public static void addUsers(long pk, java.util.List users)
372         throws com.liferay.portal.SystemException, 
373             com.liferay.portal.NoSuchUserGroupException, 
374             com.liferay.portal.NoSuchUserException {
375         getPersistence().addUsers(pk, users);
376     }
377 
378     public static void clearUsers(long pk)
379         throws com.liferay.portal.SystemException, 
380             com.liferay.portal.NoSuchUserGroupException {
381         getPersistence().clearUsers(pk);
382     }
383 
384     public static void removeUser(long pk, long userPK)
385         throws com.liferay.portal.SystemException, 
386             com.liferay.portal.NoSuchUserGroupException, 
387             com.liferay.portal.NoSuchUserException {
388         getPersistence().removeUser(pk, userPK);
389     }
390 
391     public static void removeUser(long pk, com.liferay.portal.model.User user)
392         throws com.liferay.portal.SystemException, 
393             com.liferay.portal.NoSuchUserGroupException, 
394             com.liferay.portal.NoSuchUserException {
395         getPersistence().removeUser(pk, user);
396     }
397 
398     public static void removeUsers(long pk, long[] userPKs)
399         throws com.liferay.portal.SystemException, 
400             com.liferay.portal.NoSuchUserGroupException, 
401             com.liferay.portal.NoSuchUserException {
402         getPersistence().removeUsers(pk, userPKs);
403     }
404 
405     public static void removeUsers(long pk, java.util.List users)
406         throws com.liferay.portal.SystemException, 
407             com.liferay.portal.NoSuchUserGroupException, 
408             com.liferay.portal.NoSuchUserException {
409         getPersistence().removeUsers(pk, users);
410     }
411 
412     public static void setUsers(long pk, long[] userPKs)
413         throws com.liferay.portal.SystemException, 
414             com.liferay.portal.NoSuchUserGroupException, 
415             com.liferay.portal.NoSuchUserException {
416         getPersistence().setUsers(pk, userPKs);
417     }
418 
419     public static void setUsers(long pk, java.util.List users)
420         throws com.liferay.portal.SystemException, 
421             com.liferay.portal.NoSuchUserGroupException, 
422             com.liferay.portal.NoSuchUserException {
423         getPersistence().setUsers(pk, users);
424     }
425 
426     public static UserGroupPersistence getPersistence() {
427         return _getUtil()._persistence;
428     }
429 
430     public void setPersistence(UserGroupPersistence persistence) {
431         _persistence = persistence;
432     }
433 
434     private static UserGroupUtil _getUtil() {
435         if (_util == null) {
436             _util = (UserGroupUtil)com.liferay.portal.kernel.bean.BeanLocatorUtil.locate(_UTIL);
437         }
438 
439         return _util;
440     }
441 
442     private static ModelListener _getListener() {
443         if (Validator.isNotNull(_LISTENER)) {
444             try {
445                 return (ModelListener)Class.forName(_LISTENER).newInstance();
446             }
447             catch (Exception e) {
448                 _log.error(e);
449             }
450         }
451 
452         return null;
453     }
454 
455     private static final String _UTIL = UserGroupUtil.class.getName();
456     private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
457                 "value.object.listener.com.liferay.portal.model.UserGroup"));
458     private static Log _log = LogFactory.getLog(UserGroupUtil.class);
459     private static UserGroupUtil _util;
460     private UserGroupPersistence _persistence;
461 }