1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.NoSuchUserException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
22  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
23  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
24  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
25  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
26  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
27  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29  import com.liferay.portal.kernel.dao.orm.FinderPath;
30  import com.liferay.portal.kernel.dao.orm.Query;
31  import com.liferay.portal.kernel.dao.orm.QueryPos;
32  import com.liferay.portal.kernel.dao.orm.QueryUtil;
33  import com.liferay.portal.kernel.dao.orm.SQLQuery;
34  import com.liferay.portal.kernel.dao.orm.Session;
35  import com.liferay.portal.kernel.dao.orm.Type;
36  import com.liferay.portal.kernel.exception.SystemException;
37  import com.liferay.portal.kernel.log.Log;
38  import com.liferay.portal.kernel.log.LogFactoryUtil;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.OrderByComparator;
41  import com.liferay.portal.kernel.util.SetUtil;
42  import com.liferay.portal.kernel.util.StringBundler;
43  import com.liferay.portal.kernel.util.StringPool;
44  import com.liferay.portal.kernel.util.StringUtil;
45  import com.liferay.portal.kernel.util.Validator;
46  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
47  import com.liferay.portal.model.ModelListener;
48  import com.liferay.portal.model.User;
49  import com.liferay.portal.model.impl.UserImpl;
50  import com.liferay.portal.model.impl.UserModelImpl;
51  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
52  
53  import java.io.Serializable;
54  
55  import java.sql.Types;
56  
57  import java.util.ArrayList;
58  import java.util.Collections;
59  import java.util.List;
60  import java.util.Set;
61  
62  /**
63   * <a href="UserPersistenceImpl.java.html"><b><i>View Source</i></b></a>
64   *
65   * <p>
66   * ServiceBuilder generated this class. Modifications in this class will be
67   * overwritten the next time is generated.
68   * </p>
69   *
70   * @author    Brian Wing Shun Chan
71   * @see       UserPersistence
72   * @see       UserUtil
73   * @generated
74   */
75  public class UserPersistenceImpl extends BasePersistenceImpl<User>
76      implements UserPersistence {
77      public static final String FINDER_CLASS_NAME_ENTITY = UserImpl.class.getName();
78      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
79          ".List";
80      public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
81              UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
82              "findByUuid", new String[] { String.class.getName() });
83      public static final FinderPath FINDER_PATH_FIND_BY_OBC_UUID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
84              UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
85              "findByUuid",
86              new String[] {
87                  String.class.getName(),
88                  
89              "java.lang.Integer", "java.lang.Integer",
90                  "com.liferay.portal.kernel.util.OrderByComparator"
91              });
92      public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
93              UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
94              "countByUuid", new String[] { String.class.getName() });
95      public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
96              UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
97              "findByCompanyId", new String[] { Long.class.getName() });
98      public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
99              UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100             "findByCompanyId",
101             new String[] {
102                 Long.class.getName(),
103                 
104             "java.lang.Integer", "java.lang.Integer",
105                 "com.liferay.portal.kernel.util.OrderByComparator"
106             });
107     public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
108             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109             "countByCompanyId", new String[] { Long.class.getName() });
110     public static final FinderPath FINDER_PATH_FETCH_BY_CONTACTID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
111             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
112             "fetchByContactId", new String[] { Long.class.getName() });
113     public static final FinderPath FINDER_PATH_COUNT_BY_CONTACTID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
114             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
115             "countByContactId", new String[] { Long.class.getName() });
116     public static final FinderPath FINDER_PATH_FIND_BY_EMAILADDRESS = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
117             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
118             "findByEmailAddress", new String[] { String.class.getName() });
119     public static final FinderPath FINDER_PATH_FIND_BY_OBC_EMAILADDRESS = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
120             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121             "findByEmailAddress",
122             new String[] {
123                 String.class.getName(),
124                 
125             "java.lang.Integer", "java.lang.Integer",
126                 "com.liferay.portal.kernel.util.OrderByComparator"
127             });
128     public static final FinderPath FINDER_PATH_COUNT_BY_EMAILADDRESS = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
129             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130             "countByEmailAddress", new String[] { String.class.getName() });
131     public static final FinderPath FINDER_PATH_FETCH_BY_OPENID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
132             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
133             "fetchByOpenId", new String[] { String.class.getName() });
134     public static final FinderPath FINDER_PATH_COUNT_BY_OPENID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
135             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
136             "countByOpenId", new String[] { String.class.getName() });
137     public static final FinderPath FINDER_PATH_FETCH_BY_PORTRAITID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
138             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
139             "fetchByPortraitId", new String[] { Long.class.getName() });
140     public static final FinderPath FINDER_PATH_COUNT_BY_PORTRAITID = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
141             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
142             "countByPortraitId", new String[] { Long.class.getName() });
143     public static final FinderPath FINDER_PATH_FETCH_BY_C_U = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
144             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
145             "fetchByC_U",
146             new String[] { Long.class.getName(), Long.class.getName() });
147     public static final FinderPath FINDER_PATH_COUNT_BY_C_U = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
148             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
149             "countByC_U",
150             new String[] { Long.class.getName(), Long.class.getName() });
151     public static final FinderPath FINDER_PATH_FETCH_BY_C_DU = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
152             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
153             "fetchByC_DU",
154             new String[] { Long.class.getName(), Boolean.class.getName() });
155     public static final FinderPath FINDER_PATH_COUNT_BY_C_DU = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
156             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
157             "countByC_DU",
158             new String[] { Long.class.getName(), Boolean.class.getName() });
159     public static final FinderPath FINDER_PATH_FETCH_BY_C_SN = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
160             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
161             "fetchByC_SN",
162             new String[] { Long.class.getName(), String.class.getName() });
163     public static final FinderPath FINDER_PATH_COUNT_BY_C_SN = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
164             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
165             "countByC_SN",
166             new String[] { Long.class.getName(), String.class.getName() });
167     public static final FinderPath FINDER_PATH_FETCH_BY_C_EA = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
168             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
169             "fetchByC_EA",
170             new String[] { Long.class.getName(), String.class.getName() });
171     public static final FinderPath FINDER_PATH_COUNT_BY_C_EA = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
172             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
173             "countByC_EA",
174             new String[] { Long.class.getName(), String.class.getName() });
175     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
176             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
177             "findAll", new String[0]);
178     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserModelImpl.ENTITY_CACHE_ENABLED,
179             UserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
180             "countAll", new String[0]);
181 
182     public void cacheResult(User user) {
183         EntityCacheUtil.putResult(UserModelImpl.ENTITY_CACHE_ENABLED,
184             UserImpl.class, user.getPrimaryKey(), user);
185 
186         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CONTACTID,
187             new Object[] { new Long(user.getContactId()) }, user);
188 
189         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_OPENID,
190             new Object[] { user.getOpenId() }, user);
191 
192         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PORTRAITID,
193             new Object[] { new Long(user.getPortraitId()) }, user);
194 
195         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U,
196             new Object[] {
197                 new Long(user.getCompanyId()), new Long(user.getUserId())
198             }, user);
199 
200         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DU,
201             new Object[] {
202                 new Long(user.getCompanyId()),
203                 Boolean.valueOf(user.getDefaultUser())
204             }, user);
205 
206         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_SN,
207             new Object[] { new Long(user.getCompanyId()), user.getScreenName() },
208             user);
209 
210         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_EA,
211             new Object[] { new Long(user.getCompanyId()), user.getEmailAddress() },
212             user);
213     }
214 
215     public void cacheResult(List<User> users) {
216         for (User user : users) {
217             if (EntityCacheUtil.getResult(UserModelImpl.ENTITY_CACHE_ENABLED,
218                         UserImpl.class, user.getPrimaryKey(), this) == null) {
219                 cacheResult(user);
220             }
221         }
222     }
223 
224     public void clearCache() {
225         CacheRegistry.clear(UserImpl.class.getName());
226         EntityCacheUtil.clearCache(UserImpl.class.getName());
227         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
228         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
229     }
230 
231     public User create(long userId) {
232         User user = new UserImpl();
233 
234         user.setNew(true);
235         user.setPrimaryKey(userId);
236 
237         String uuid = PortalUUIDUtil.generate();
238 
239         user.setUuid(uuid);
240 
241         return user;
242     }
243 
244     public User remove(Serializable primaryKey)
245         throws NoSuchModelException, SystemException {
246         return remove(((Long)primaryKey).longValue());
247     }
248 
249     public User remove(long userId) throws NoSuchUserException, SystemException {
250         Session session = null;
251 
252         try {
253             session = openSession();
254 
255             User user = (User)session.get(UserImpl.class, new Long(userId));
256 
257             if (user == null) {
258                 if (_log.isWarnEnabled()) {
259                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userId);
260                 }
261 
262                 throw new NoSuchUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
263                     userId);
264             }
265 
266             return remove(user);
267         }
268         catch (NoSuchUserException nsee) {
269             throw nsee;
270         }
271         catch (Exception e) {
272             throw processException(e);
273         }
274         finally {
275             closeSession(session);
276         }
277     }
278 
279     public User remove(User user) throws SystemException {
280         for (ModelListener<User> listener : listeners) {
281             listener.onBeforeRemove(user);
282         }
283 
284         user = removeImpl(user);
285 
286         for (ModelListener<User> listener : listeners) {
287             listener.onAfterRemove(user);
288         }
289 
290         return user;
291     }
292 
293     protected User removeImpl(User user) throws SystemException {
294         user = toUnwrappedModel(user);
295 
296         try {
297             clearGroups.clear(user.getPrimaryKey());
298         }
299         catch (Exception e) {
300             throw processException(e);
301         }
302         finally {
303             FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
304         }
305 
306         try {
307             clearOrganizations.clear(user.getPrimaryKey());
308         }
309         catch (Exception e) {
310             throw processException(e);
311         }
312         finally {
313             FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
314         }
315 
316         try {
317             clearPermissions.clear(user.getPrimaryKey());
318         }
319         catch (Exception e) {
320             throw processException(e);
321         }
322         finally {
323             FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
324         }
325 
326         try {
327             clearRoles.clear(user.getPrimaryKey());
328         }
329         catch (Exception e) {
330             throw processException(e);
331         }
332         finally {
333             FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
334         }
335 
336         try {
337             clearUserGroups.clear(user.getPrimaryKey());
338         }
339         catch (Exception e) {
340             throw processException(e);
341         }
342         finally {
343             FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
344         }
345 
346         Session session = null;
347 
348         try {
349             session = openSession();
350 
351             if (user.isCachedModel() || BatchSessionUtil.isEnabled()) {
352                 Object staleObject = session.get(UserImpl.class,
353                         user.getPrimaryKeyObj());
354 
355                 if (staleObject != null) {
356                     session.evict(staleObject);
357                 }
358             }
359 
360             session.delete(user);
361 
362             session.flush();
363         }
364         catch (Exception e) {
365             throw processException(e);
366         }
367         finally {
368             closeSession(session);
369         }
370 
371         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
372 
373         UserModelImpl userModelImpl = (UserModelImpl)user;
374 
375         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CONTACTID,
376             new Object[] { new Long(userModelImpl.getOriginalContactId()) });
377 
378         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_OPENID,
379             new Object[] { userModelImpl.getOriginalOpenId() });
380 
381         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_PORTRAITID,
382             new Object[] { new Long(userModelImpl.getOriginalPortraitId()) });
383 
384         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U,
385             new Object[] {
386                 new Long(userModelImpl.getOriginalCompanyId()),
387                 new Long(userModelImpl.getOriginalUserId())
388             });
389 
390         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DU,
391             new Object[] {
392                 new Long(userModelImpl.getOriginalCompanyId()),
393                 Boolean.valueOf(userModelImpl.getOriginalDefaultUser())
394             });
395 
396         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_SN,
397             new Object[] {
398                 new Long(userModelImpl.getOriginalCompanyId()),
399                 
400             userModelImpl.getOriginalScreenName()
401             });
402 
403         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_EA,
404             new Object[] {
405                 new Long(userModelImpl.getOriginalCompanyId()),
406                 
407             userModelImpl.getOriginalEmailAddress()
408             });
409 
410         EntityCacheUtil.removeResult(UserModelImpl.ENTITY_CACHE_ENABLED,
411             UserImpl.class, user.getPrimaryKey());
412 
413         return user;
414     }
415 
416     public User updateImpl(com.liferay.portal.model.User user, boolean merge)
417         throws SystemException {
418         user = toUnwrappedModel(user);
419 
420         boolean isNew = user.isNew();
421 
422         UserModelImpl userModelImpl = (UserModelImpl)user;
423 
424         if (Validator.isNull(user.getUuid())) {
425             String uuid = PortalUUIDUtil.generate();
426 
427             user.setUuid(uuid);
428         }
429 
430         Session session = null;
431 
432         try {
433             session = openSession();
434 
435             BatchSessionUtil.update(session, user, merge);
436 
437             user.setNew(false);
438         }
439         catch (Exception e) {
440             throw processException(e);
441         }
442         finally {
443             closeSession(session);
444         }
445 
446         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
447 
448         EntityCacheUtil.putResult(UserModelImpl.ENTITY_CACHE_ENABLED,
449             UserImpl.class, user.getPrimaryKey(), user);
450 
451         if (!isNew &&
452                 (user.getContactId() != userModelImpl.getOriginalContactId())) {
453             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_CONTACTID,
454                 new Object[] { new Long(userModelImpl.getOriginalContactId()) });
455         }
456 
457         if (isNew ||
458                 (user.getContactId() != userModelImpl.getOriginalContactId())) {
459             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CONTACTID,
460                 new Object[] { new Long(user.getContactId()) }, user);
461         }
462 
463         if (!isNew &&
464                 (!Validator.equals(user.getOpenId(),
465                     userModelImpl.getOriginalOpenId()))) {
466             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_OPENID,
467                 new Object[] { userModelImpl.getOriginalOpenId() });
468         }
469 
470         if (isNew ||
471                 (!Validator.equals(user.getOpenId(),
472                     userModelImpl.getOriginalOpenId()))) {
473             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_OPENID,
474                 new Object[] { user.getOpenId() }, user);
475         }
476 
477         if (!isNew &&
478                 (user.getPortraitId() != userModelImpl.getOriginalPortraitId())) {
479             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_PORTRAITID,
480                 new Object[] { new Long(userModelImpl.getOriginalPortraitId()) });
481         }
482 
483         if (isNew ||
484                 (user.getPortraitId() != userModelImpl.getOriginalPortraitId())) {
485             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PORTRAITID,
486                 new Object[] { new Long(user.getPortraitId()) }, user);
487         }
488 
489         if (!isNew &&
490                 ((user.getCompanyId() != userModelImpl.getOriginalCompanyId()) ||
491                 (user.getUserId() != userModelImpl.getOriginalUserId()))) {
492             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_U,
493                 new Object[] {
494                     new Long(userModelImpl.getOriginalCompanyId()),
495                     new Long(userModelImpl.getOriginalUserId())
496                 });
497         }
498 
499         if (isNew ||
500                 ((user.getCompanyId() != userModelImpl.getOriginalCompanyId()) ||
501                 (user.getUserId() != userModelImpl.getOriginalUserId()))) {
502             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U,
503                 new Object[] {
504                     new Long(user.getCompanyId()), new Long(user.getUserId())
505                 }, user);
506         }
507 
508         if (!isNew &&
509                 ((user.getCompanyId() != userModelImpl.getOriginalCompanyId()) ||
510                 (user.getDefaultUser() != userModelImpl.getOriginalDefaultUser()))) {
511             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_DU,
512                 new Object[] {
513                     new Long(userModelImpl.getOriginalCompanyId()),
514                     Boolean.valueOf(userModelImpl.getOriginalDefaultUser())
515                 });
516         }
517 
518         if (isNew ||
519                 ((user.getCompanyId() != userModelImpl.getOriginalCompanyId()) ||
520                 (user.getDefaultUser() != userModelImpl.getOriginalDefaultUser()))) {
521             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DU,
522                 new Object[] {
523                     new Long(user.getCompanyId()),
524                     Boolean.valueOf(user.getDefaultUser())
525                 }, user);
526         }
527 
528         if (!isNew &&
529                 ((user.getCompanyId() != userModelImpl.getOriginalCompanyId()) ||
530                 !Validator.equals(user.getScreenName(),
531                     userModelImpl.getOriginalScreenName()))) {
532             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_SN,
533                 new Object[] {
534                     new Long(userModelImpl.getOriginalCompanyId()),
535                     
536                 userModelImpl.getOriginalScreenName()
537                 });
538         }
539 
540         if (isNew ||
541                 ((user.getCompanyId() != userModelImpl.getOriginalCompanyId()) ||
542                 !Validator.equals(user.getScreenName(),
543                     userModelImpl.getOriginalScreenName()))) {
544             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_SN,
545                 new Object[] { new Long(user.getCompanyId()), user.getScreenName() },
546                 user);
547         }
548 
549         if (!isNew &&
550                 ((user.getCompanyId() != userModelImpl.getOriginalCompanyId()) ||
551                 !Validator.equals(user.getEmailAddress(),
552                     userModelImpl.getOriginalEmailAddress()))) {
553             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_EA,
554                 new Object[] {
555                     new Long(userModelImpl.getOriginalCompanyId()),
556                     
557                 userModelImpl.getOriginalEmailAddress()
558                 });
559         }
560 
561         if (isNew ||
562                 ((user.getCompanyId() != userModelImpl.getOriginalCompanyId()) ||
563                 !Validator.equals(user.getEmailAddress(),
564                     userModelImpl.getOriginalEmailAddress()))) {
565             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_EA,
566                 new Object[] {
567                     new Long(user.getCompanyId()),
568                     
569                 user.getEmailAddress()
570                 }, user);
571         }
572 
573         return user;
574     }
575 
576     protected User toUnwrappedModel(User user) {
577         if (user instanceof UserImpl) {
578             return user;
579         }
580 
581         UserImpl userImpl = new UserImpl();
582 
583         userImpl.setNew(user.isNew());
584         userImpl.setPrimaryKey(user.getPrimaryKey());
585 
586         userImpl.setUuid(user.getUuid());
587         userImpl.setUserId(user.getUserId());
588         userImpl.setCompanyId(user.getCompanyId());
589         userImpl.setCreateDate(user.getCreateDate());
590         userImpl.setModifiedDate(user.getModifiedDate());
591         userImpl.setDefaultUser(user.isDefaultUser());
592         userImpl.setContactId(user.getContactId());
593         userImpl.setPassword(user.getPassword());
594         userImpl.setPasswordEncrypted(user.isPasswordEncrypted());
595         userImpl.setPasswordReset(user.isPasswordReset());
596         userImpl.setPasswordModifiedDate(user.getPasswordModifiedDate());
597         userImpl.setReminderQueryQuestion(user.getReminderQueryQuestion());
598         userImpl.setReminderQueryAnswer(user.getReminderQueryAnswer());
599         userImpl.setGraceLoginCount(user.getGraceLoginCount());
600         userImpl.setScreenName(user.getScreenName());
601         userImpl.setEmailAddress(user.getEmailAddress());
602         userImpl.setOpenId(user.getOpenId());
603         userImpl.setPortraitId(user.getPortraitId());
604         userImpl.setLanguageId(user.getLanguageId());
605         userImpl.setTimeZoneId(user.getTimeZoneId());
606         userImpl.setGreeting(user.getGreeting());
607         userImpl.setComments(user.getComments());
608         userImpl.setFirstName(user.getFirstName());
609         userImpl.setMiddleName(user.getMiddleName());
610         userImpl.setLastName(user.getLastName());
611         userImpl.setJobTitle(user.getJobTitle());
612         userImpl.setLoginDate(user.getLoginDate());
613         userImpl.setLoginIP(user.getLoginIP());
614         userImpl.setLastLoginDate(user.getLastLoginDate());
615         userImpl.setLastLoginIP(user.getLastLoginIP());
616         userImpl.setLastFailedLoginDate(user.getLastFailedLoginDate());
617         userImpl.setFailedLoginAttempts(user.getFailedLoginAttempts());
618         userImpl.setLockout(user.isLockout());
619         userImpl.setLockoutDate(user.getLockoutDate());
620         userImpl.setAgreedToTermsOfUse(user.isAgreedToTermsOfUse());
621         userImpl.setActive(user.isActive());
622 
623         return userImpl;
624     }
625 
626     public User findByPrimaryKey(Serializable primaryKey)
627         throws NoSuchModelException, SystemException {
628         return findByPrimaryKey(((Long)primaryKey).longValue());
629     }
630 
631     public User findByPrimaryKey(long userId)
632         throws NoSuchUserException, SystemException {
633         User user = fetchByPrimaryKey(userId);
634 
635         if (user == null) {
636             if (_log.isWarnEnabled()) {
637                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userId);
638             }
639 
640             throw new NoSuchUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
641                 userId);
642         }
643 
644         return user;
645     }
646 
647     public User fetchByPrimaryKey(Serializable primaryKey)
648         throws SystemException {
649         return fetchByPrimaryKey(((Long)primaryKey).longValue());
650     }
651 
652     public User fetchByPrimaryKey(long userId) throws SystemException {
653         User user = (User)EntityCacheUtil.getResult(UserModelImpl.ENTITY_CACHE_ENABLED,
654                 UserImpl.class, userId, this);
655 
656         if (user == null) {
657             Session session = null;
658 
659             try {
660                 session = openSession();
661 
662                 user = (User)session.get(UserImpl.class, new Long(userId));
663             }
664             catch (Exception e) {
665                 throw processException(e);
666             }
667             finally {
668                 if (user != null) {
669                     cacheResult(user);
670                 }
671 
672                 closeSession(session);
673             }
674         }
675 
676         return user;
677     }
678 
679     public List<User> findByUuid(String uuid) throws SystemException {
680         Object[] finderArgs = new Object[] { uuid };
681 
682         List<User> list = (List<User>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
683                 finderArgs, this);
684 
685         if (list == null) {
686             Session session = null;
687 
688             try {
689                 session = openSession();
690 
691                 StringBundler query = new StringBundler(2);
692 
693                 query.append(_SQL_SELECT_USER_WHERE);
694 
695                 if (uuid == null) {
696                     query.append(_FINDER_COLUMN_UUID_UUID_1);
697                 }
698                 else {
699                     if (uuid.equals(StringPool.BLANK)) {
700                         query.append(_FINDER_COLUMN_UUID_UUID_3);
701                     }
702                     else {
703                         query.append(_FINDER_COLUMN_UUID_UUID_2);
704                     }
705                 }
706 
707                 String sql = query.toString();
708 
709                 Query q = session.createQuery(sql);
710 
711                 QueryPos qPos = QueryPos.getInstance(q);
712 
713                 if (uuid != null) {
714                     qPos.add(uuid);
715                 }
716 
717                 list = q.list();
718             }
719             catch (Exception e) {
720                 throw processException(e);
721             }
722             finally {
723                 if (list == null) {
724                     list = new ArrayList<User>();
725                 }
726 
727                 cacheResult(list);
728 
729                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
730                     list);
731 
732                 closeSession(session);
733             }
734         }
735 
736         return list;
737     }
738 
739     public List<User> findByUuid(String uuid, int start, int end)
740         throws SystemException {
741         return findByUuid(uuid, start, end, null);
742     }
743 
744     public List<User> findByUuid(String uuid, int start, int end,
745         OrderByComparator obc) throws SystemException {
746         Object[] finderArgs = new Object[] {
747                 uuid,
748                 
749                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
750             };
751 
752         List<User> list = (List<User>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_UUID,
753                 finderArgs, this);
754 
755         if (list == null) {
756             Session session = null;
757 
758             try {
759                 session = openSession();
760 
761                 StringBundler query = null;
762 
763                 if (obc != null) {
764                     query = new StringBundler(3 +
765                             (obc.getOrderByFields().length * 3));
766                 }
767                 else {
768                     query = new StringBundler(2);
769                 }
770 
771                 query.append(_SQL_SELECT_USER_WHERE);
772 
773                 if (uuid == null) {
774                     query.append(_FINDER_COLUMN_UUID_UUID_1);
775                 }
776                 else {
777                     if (uuid.equals(StringPool.BLANK)) {
778                         query.append(_FINDER_COLUMN_UUID_UUID_3);
779                     }
780                     else {
781                         query.append(_FINDER_COLUMN_UUID_UUID_2);
782                     }
783                 }
784 
785                 if (obc != null) {
786                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
787                 }
788 
789                 String sql = query.toString();
790 
791                 Query q = session.createQuery(sql);
792 
793                 QueryPos qPos = QueryPos.getInstance(q);
794 
795                 if (uuid != null) {
796                     qPos.add(uuid);
797                 }
798 
799                 list = (List<User>)QueryUtil.list(q, getDialect(), start, end);
800             }
801             catch (Exception e) {
802                 throw processException(e);
803             }
804             finally {
805                 if (list == null) {
806                     list = new ArrayList<User>();
807                 }
808 
809                 cacheResult(list);
810 
811                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_UUID,
812                     finderArgs, list);
813 
814                 closeSession(session);
815             }
816         }
817 
818         return list;
819     }
820 
821     public User findByUuid_First(String uuid, OrderByComparator obc)
822         throws NoSuchUserException, SystemException {
823         List<User> list = findByUuid(uuid, 0, 1, obc);
824 
825         if (list.isEmpty()) {
826             StringBundler msg = new StringBundler(4);
827 
828             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
829 
830             msg.append("uuid=");
831             msg.append(uuid);
832 
833             msg.append(StringPool.CLOSE_CURLY_BRACE);
834 
835             throw new NoSuchUserException(msg.toString());
836         }
837         else {
838             return list.get(0);
839         }
840     }
841 
842     public User findByUuid_Last(String uuid, OrderByComparator obc)
843         throws NoSuchUserException, SystemException {
844         int count = countByUuid(uuid);
845 
846         List<User> list = findByUuid(uuid, count - 1, count, obc);
847 
848         if (list.isEmpty()) {
849             StringBundler msg = new StringBundler(4);
850 
851             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
852 
853             msg.append("uuid=");
854             msg.append(uuid);
855 
856             msg.append(StringPool.CLOSE_CURLY_BRACE);
857 
858             throw new NoSuchUserException(msg.toString());
859         }
860         else {
861             return list.get(0);
862         }
863     }
864 
865     public User[] findByUuid_PrevAndNext(long userId, String uuid,
866         OrderByComparator obc) throws NoSuchUserException, SystemException {
867         User user = findByPrimaryKey(userId);
868 
869         int count = countByUuid(uuid);
870 
871         Session session = null;
872 
873         try {
874             session = openSession();
875 
876             StringBundler query = null;
877 
878             if (obc != null) {
879                 query = new StringBundler(3 +
880                         (obc.getOrderByFields().length * 3));
881             }
882             else {
883                 query = new StringBundler(2);
884             }
885 
886             query.append(_SQL_SELECT_USER_WHERE);
887 
888             if (uuid == null) {
889                 query.append(_FINDER_COLUMN_UUID_UUID_1);
890             }
891             else {
892                 if (uuid.equals(StringPool.BLANK)) {
893                     query.append(_FINDER_COLUMN_UUID_UUID_3);
894                 }
895                 else {
896                     query.append(_FINDER_COLUMN_UUID_UUID_2);
897                 }
898             }
899 
900             if (obc != null) {
901                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
902             }
903 
904             String sql = query.toString();
905 
906             Query q = session.createQuery(sql);
907 
908             QueryPos qPos = QueryPos.getInstance(q);
909 
910             if (uuid != null) {
911                 qPos.add(uuid);
912             }
913 
914             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, user);
915 
916             User[] array = new UserImpl[3];
917 
918             array[0] = (User)objArray[0];
919             array[1] = (User)objArray[1];
920             array[2] = (User)objArray[2];
921 
922             return array;
923         }
924         catch (Exception e) {
925             throw processException(e);
926         }
927         finally {
928             closeSession(session);
929         }
930     }
931 
932     public List<User> findByCompanyId(long companyId) throws SystemException {
933         Object[] finderArgs = new Object[] { new Long(companyId) };
934 
935         List<User> list = (List<User>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
936                 finderArgs, this);
937 
938         if (list == null) {
939             Session session = null;
940 
941             try {
942                 session = openSession();
943 
944                 StringBundler query = new StringBundler(2);
945 
946                 query.append(_SQL_SELECT_USER_WHERE);
947 
948                 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
949 
950                 String sql = query.toString();
951 
952                 Query q = session.createQuery(sql);
953 
954                 QueryPos qPos = QueryPos.getInstance(q);
955 
956                 qPos.add(companyId);
957 
958                 list = q.list();
959             }
960             catch (Exception e) {
961                 throw processException(e);
962             }
963             finally {
964                 if (list == null) {
965                     list = new ArrayList<User>();
966                 }
967 
968                 cacheResult(list);
969 
970                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
971                     finderArgs, list);
972 
973                 closeSession(session);
974             }
975         }
976 
977         return list;
978     }
979 
980     public List<User> findByCompanyId(long companyId, int start, int end)
981         throws SystemException {
982         return findByCompanyId(companyId, start, end, null);
983     }
984 
985     public List<User> findByCompanyId(long companyId, int start, int end,
986         OrderByComparator obc) throws SystemException {
987         Object[] finderArgs = new Object[] {
988                 new Long(companyId),
989                 
990                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
991             };
992 
993         List<User> list = (List<User>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
994                 finderArgs, this);
995 
996         if (list == null) {
997             Session session = null;
998 
999             try {
1000                session = openSession();
1001
1002                StringBundler query = null;
1003
1004                if (obc != null) {
1005                    query = new StringBundler(3 +
1006                            (obc.getOrderByFields().length * 3));
1007                }
1008                else {
1009                    query = new StringBundler(2);
1010                }
1011
1012                query.append(_SQL_SELECT_USER_WHERE);
1013
1014                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1015
1016                if (obc != null) {
1017                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1018                }
1019
1020                String sql = query.toString();
1021
1022                Query q = session.createQuery(sql);
1023
1024                QueryPos qPos = QueryPos.getInstance(q);
1025
1026                qPos.add(companyId);
1027
1028                list = (List<User>)QueryUtil.list(q, getDialect(), start, end);
1029            }
1030            catch (Exception e) {
1031                throw processException(e);
1032            }
1033            finally {
1034                if (list == null) {
1035                    list = new ArrayList<User>();
1036                }
1037
1038                cacheResult(list);
1039
1040                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
1041                    finderArgs, list);
1042
1043                closeSession(session);
1044            }
1045        }
1046
1047        return list;
1048    }
1049
1050    public User findByCompanyId_First(long companyId, OrderByComparator obc)
1051        throws NoSuchUserException, SystemException {
1052        List<User> list = findByCompanyId(companyId, 0, 1, obc);
1053
1054        if (list.isEmpty()) {
1055            StringBundler msg = new StringBundler(4);
1056
1057            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1058
1059            msg.append("companyId=");
1060            msg.append(companyId);
1061
1062            msg.append(StringPool.CLOSE_CURLY_BRACE);
1063
1064            throw new NoSuchUserException(msg.toString());
1065        }
1066        else {
1067            return list.get(0);
1068        }
1069    }
1070
1071    public User findByCompanyId_Last(long companyId, OrderByComparator obc)
1072        throws NoSuchUserException, SystemException {
1073        int count = countByCompanyId(companyId);
1074
1075        List<User> list = findByCompanyId(companyId, count - 1, count, obc);
1076
1077        if (list.isEmpty()) {
1078            StringBundler msg = new StringBundler(4);
1079
1080            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1081
1082            msg.append("companyId=");
1083            msg.append(companyId);
1084
1085            msg.append(StringPool.CLOSE_CURLY_BRACE);
1086
1087            throw new NoSuchUserException(msg.toString());
1088        }
1089        else {
1090            return list.get(0);
1091        }
1092    }
1093
1094    public User[] findByCompanyId_PrevAndNext(long userId, long companyId,
1095        OrderByComparator obc) throws NoSuchUserException, SystemException {
1096        User user = findByPrimaryKey(userId);
1097
1098        int count = countByCompanyId(companyId);
1099
1100        Session session = null;
1101
1102        try {
1103            session = openSession();
1104
1105            StringBundler query = null;
1106
1107            if (obc != null) {
1108                query = new StringBundler(3 +
1109                        (obc.getOrderByFields().length * 3));
1110            }
1111            else {
1112                query = new StringBundler(2);
1113            }
1114
1115            query.append(_SQL_SELECT_USER_WHERE);
1116
1117            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1118
1119            if (obc != null) {
1120                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1121            }
1122
1123            String sql = query.toString();
1124
1125            Query q = session.createQuery(sql);
1126
1127            QueryPos qPos = QueryPos.getInstance(q);
1128
1129            qPos.add(companyId);
1130
1131            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, user);
1132
1133            User[] array = new UserImpl[3];
1134
1135            array[0] = (User)objArray[0];
1136            array[1] = (User)objArray[1];
1137            array[2] = (User)objArray[2];
1138
1139            return array;
1140        }
1141        catch (Exception e) {
1142            throw processException(e);
1143        }
1144        finally {
1145            closeSession(session);
1146        }
1147    }
1148
1149    public User findByContactId(long contactId)
1150        throws NoSuchUserException, SystemException {
1151        User user = fetchByContactId(contactId);
1152
1153        if (user == null) {
1154            StringBundler msg = new StringBundler(4);
1155
1156            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1157
1158            msg.append("contactId=");
1159            msg.append(contactId);
1160
1161            msg.append(StringPool.CLOSE_CURLY_BRACE);
1162
1163            if (_log.isWarnEnabled()) {
1164                _log.warn(msg.toString());
1165            }
1166
1167            throw new NoSuchUserException(msg.toString());
1168        }
1169
1170        return user;
1171    }
1172
1173    public User fetchByContactId(long contactId) throws SystemException {
1174        return fetchByContactId(contactId, true);
1175    }
1176
1177    public User fetchByContactId(long contactId, boolean retrieveFromCache)
1178        throws SystemException {
1179        Object[] finderArgs = new Object[] { new Long(contactId) };
1180
1181        Object result = null;
1182
1183        if (retrieveFromCache) {
1184            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_CONTACTID,
1185                    finderArgs, this);
1186        }
1187
1188        if (result == null) {
1189            Session session = null;
1190
1191            try {
1192                session = openSession();
1193
1194                StringBundler query = new StringBundler(2);
1195
1196                query.append(_SQL_SELECT_USER_WHERE);
1197
1198                query.append(_FINDER_COLUMN_CONTACTID_CONTACTID_2);
1199
1200                String sql = query.toString();
1201
1202                Query q = session.createQuery(sql);
1203
1204                QueryPos qPos = QueryPos.getInstance(q);
1205
1206                qPos.add(contactId);
1207
1208                List<User> list = q.list();
1209
1210                result = list;
1211
1212                User user = null;
1213
1214                if (list.isEmpty()) {
1215                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CONTACTID,
1216                        finderArgs, list);
1217                }
1218                else {
1219                    user = list.get(0);
1220
1221                    cacheResult(user);
1222
1223                    if ((user.getContactId() != contactId)) {
1224                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CONTACTID,
1225                            finderArgs, user);
1226                    }
1227                }
1228
1229                return user;
1230            }
1231            catch (Exception e) {
1232                throw processException(e);
1233            }
1234            finally {
1235                if (result == null) {
1236                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_CONTACTID,
1237                        finderArgs, new ArrayList<User>());
1238                }
1239
1240                closeSession(session);
1241            }
1242        }
1243        else {
1244            if (result instanceof List<?>) {
1245                return null;
1246            }
1247            else {
1248                return (User)result;
1249            }
1250        }
1251    }
1252
1253    public List<User> findByEmailAddress(String emailAddress)
1254        throws SystemException {
1255        Object[] finderArgs = new Object[] { emailAddress };
1256
1257        List<User> list = (List<User>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_EMAILADDRESS,
1258                finderArgs, this);
1259
1260        if (list == null) {
1261            Session session = null;
1262
1263            try {
1264                session = openSession();
1265
1266                StringBundler query = new StringBundler(2);
1267
1268                query.append(_SQL_SELECT_USER_WHERE);
1269
1270                if (emailAddress == null) {
1271                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1);
1272                }
1273                else {
1274                    if (emailAddress.equals(StringPool.BLANK)) {
1275                        query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3);
1276                    }
1277                    else {
1278                        query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2);
1279                    }
1280                }
1281
1282                String sql = query.toString();
1283
1284                Query q = session.createQuery(sql);
1285
1286                QueryPos qPos = QueryPos.getInstance(q);
1287
1288                if (emailAddress != null) {
1289                    qPos.add(emailAddress);
1290                }
1291
1292                list = q.list();
1293            }
1294            catch (Exception e) {
1295                throw processException(e);
1296            }
1297            finally {
1298                if (list == null) {
1299                    list = new ArrayList<User>();
1300                }
1301
1302                cacheResult(list);
1303
1304                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_EMAILADDRESS,
1305                    finderArgs, list);
1306
1307                closeSession(session);
1308            }
1309        }
1310
1311        return list;
1312    }
1313
1314    public List<User> findByEmailAddress(String emailAddress, int start, int end)
1315        throws SystemException {
1316        return findByEmailAddress(emailAddress, start, end, null);
1317    }
1318
1319    public List<User> findByEmailAddress(String emailAddress, int start,
1320        int end, OrderByComparator obc) throws SystemException {
1321        Object[] finderArgs = new Object[] {
1322                emailAddress,
1323                
1324                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1325            };
1326
1327        List<User> list = (List<User>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_EMAILADDRESS,
1328                finderArgs, this);
1329
1330        if (list == null) {
1331            Session session = null;
1332
1333            try {
1334                session = openSession();
1335
1336                StringBundler query = null;
1337
1338                if (obc != null) {
1339                    query = new StringBundler(3 +
1340                            (obc.getOrderByFields().length * 3));
1341                }
1342                else {
1343                    query = new StringBundler(2);
1344                }
1345
1346                query.append(_SQL_SELECT_USER_WHERE);
1347
1348                if (emailAddress == null) {
1349                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1);
1350                }
1351                else {
1352                    if (emailAddress.equals(StringPool.BLANK)) {
1353                        query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3);
1354                    }
1355                    else {
1356                        query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2);
1357                    }
1358                }
1359
1360                if (obc != null) {
1361                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1362                }
1363
1364                String sql = query.toString();
1365
1366                Query q = session.createQuery(sql);
1367
1368                QueryPos qPos = QueryPos.getInstance(q);
1369
1370                if (emailAddress != null) {
1371                    qPos.add(emailAddress);
1372                }
1373
1374                list = (List<User>)QueryUtil.list(q, getDialect(), start, end);
1375            }
1376            catch (Exception e) {
1377                throw processException(e);
1378            }
1379            finally {
1380                if (list == null) {
1381                    list = new ArrayList<User>();
1382                }
1383
1384                cacheResult(list);
1385
1386                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_EMAILADDRESS,
1387                    finderArgs, list);
1388
1389                closeSession(session);
1390            }
1391        }
1392
1393        return list;
1394    }
1395
1396    public User findByEmailAddress_First(String emailAddress,
1397        OrderByComparator obc) throws NoSuchUserException, SystemException {
1398        List<User> list = findByEmailAddress(emailAddress, 0, 1, obc);
1399
1400        if (list.isEmpty()) {
1401            StringBundler msg = new StringBundler(4);
1402
1403            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1404
1405            msg.append("emailAddress=");
1406            msg.append(emailAddress);
1407
1408            msg.append(StringPool.CLOSE_CURLY_BRACE);
1409
1410            throw new NoSuchUserException(msg.toString());
1411        }
1412        else {
1413            return list.get(0);
1414        }
1415    }
1416
1417    public User findByEmailAddress_Last(String emailAddress,
1418        OrderByComparator obc) throws NoSuchUserException, SystemException {
1419        int count = countByEmailAddress(emailAddress);
1420
1421        List<User> list = findByEmailAddress(emailAddress, count - 1, count, obc);
1422
1423        if (list.isEmpty()) {
1424            StringBundler msg = new StringBundler(4);
1425
1426            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1427
1428            msg.append("emailAddress=");
1429            msg.append(emailAddress);
1430
1431            msg.append(StringPool.CLOSE_CURLY_BRACE);
1432
1433            throw new NoSuchUserException(msg.toString());
1434        }
1435        else {
1436            return list.get(0);
1437        }
1438    }
1439
1440    public User[] findByEmailAddress_PrevAndNext(long userId,
1441        String emailAddress, OrderByComparator obc)
1442        throws NoSuchUserException, SystemException {
1443        User user = findByPrimaryKey(userId);
1444
1445        int count = countByEmailAddress(emailAddress);
1446
1447        Session session = null;
1448
1449        try {
1450            session = openSession();
1451
1452            StringBundler query = null;
1453
1454            if (obc != null) {
1455                query = new StringBundler(3 +
1456                        (obc.getOrderByFields().length * 3));
1457            }
1458            else {
1459                query = new StringBundler(2);
1460            }
1461
1462            query.append(_SQL_SELECT_USER_WHERE);
1463
1464            if (emailAddress == null) {
1465                query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1);
1466            }
1467            else {
1468                if (emailAddress.equals(StringPool.BLANK)) {
1469                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3);
1470                }
1471                else {
1472                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2);
1473                }
1474            }
1475
1476            if (obc != null) {
1477                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1478            }
1479
1480            String sql = query.toString();
1481
1482            Query q = session.createQuery(sql);
1483
1484            QueryPos qPos = QueryPos.getInstance(q);
1485
1486            if (emailAddress != null) {
1487                qPos.add(emailAddress);
1488            }
1489
1490            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, user);
1491
1492            User[] array = new UserImpl[3];
1493
1494            array[0] = (User)objArray[0];
1495            array[1] = (User)objArray[1];
1496            array[2] = (User)objArray[2];
1497
1498            return array;
1499        }
1500        catch (Exception e) {
1501            throw processException(e);
1502        }
1503        finally {
1504            closeSession(session);
1505        }
1506    }
1507
1508    public User findByOpenId(String openId)
1509        throws NoSuchUserException, SystemException {
1510        User user = fetchByOpenId(openId);
1511
1512        if (user == null) {
1513            StringBundler msg = new StringBundler(4);
1514
1515            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1516
1517            msg.append("openId=");
1518            msg.append(openId);
1519
1520            msg.append(StringPool.CLOSE_CURLY_BRACE);
1521
1522            if (_log.isWarnEnabled()) {
1523                _log.warn(msg.toString());
1524            }
1525
1526            throw new NoSuchUserException(msg.toString());
1527        }
1528
1529        return user;
1530    }
1531
1532    public User fetchByOpenId(String openId) throws SystemException {
1533        return fetchByOpenId(openId, true);
1534    }
1535
1536    public User fetchByOpenId(String openId, boolean retrieveFromCache)
1537        throws SystemException {
1538        Object[] finderArgs = new Object[] { openId };
1539
1540        Object result = null;
1541
1542        if (retrieveFromCache) {
1543            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_OPENID,
1544                    finderArgs, this);
1545        }
1546
1547        if (result == null) {
1548            Session session = null;
1549
1550            try {
1551                session = openSession();
1552
1553                StringBundler query = new StringBundler(2);
1554
1555                query.append(_SQL_SELECT_USER_WHERE);
1556
1557                if (openId == null) {
1558                    query.append(_FINDER_COLUMN_OPENID_OPENID_1);
1559                }
1560                else {
1561                    if (openId.equals(StringPool.BLANK)) {
1562                        query.append(_FINDER_COLUMN_OPENID_OPENID_3);
1563                    }
1564                    else {
1565                        query.append(_FINDER_COLUMN_OPENID_OPENID_2);
1566                    }
1567                }
1568
1569                String sql = query.toString();
1570
1571                Query q = session.createQuery(sql);
1572
1573                QueryPos qPos = QueryPos.getInstance(q);
1574
1575                if (openId != null) {
1576                    qPos.add(openId);
1577                }
1578
1579                List<User> list = q.list();
1580
1581                result = list;
1582
1583                User user = null;
1584
1585                if (list.isEmpty()) {
1586                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_OPENID,
1587                        finderArgs, list);
1588                }
1589                else {
1590                    user = list.get(0);
1591
1592                    cacheResult(user);
1593
1594                    if ((user.getOpenId() == null) ||
1595                            !user.getOpenId().equals(openId)) {
1596                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_OPENID,
1597                            finderArgs, user);
1598                    }
1599                }
1600
1601                return user;
1602            }
1603            catch (Exception e) {
1604                throw processException(e);
1605            }
1606            finally {
1607                if (result == null) {
1608                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_OPENID,
1609                        finderArgs, new ArrayList<User>());
1610                }
1611
1612                closeSession(session);
1613            }
1614        }
1615        else {
1616            if (result instanceof List<?>) {
1617                return null;
1618            }
1619            else {
1620                return (User)result;
1621            }
1622        }
1623    }
1624
1625    public User findByPortraitId(long portraitId)
1626        throws NoSuchUserException, SystemException {
1627        User user = fetchByPortraitId(portraitId);
1628
1629        if (user == null) {
1630            StringBundler msg = new StringBundler(4);
1631
1632            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1633
1634            msg.append("portraitId=");
1635            msg.append(portraitId);
1636
1637            msg.append(StringPool.CLOSE_CURLY_BRACE);
1638
1639            if (_log.isWarnEnabled()) {
1640                _log.warn(msg.toString());
1641            }
1642
1643            throw new NoSuchUserException(msg.toString());
1644        }
1645
1646        return user;
1647    }
1648
1649    public User fetchByPortraitId(long portraitId) throws SystemException {
1650        return fetchByPortraitId(portraitId, true);
1651    }
1652
1653    public User fetchByPortraitId(long portraitId, boolean retrieveFromCache)
1654        throws SystemException {
1655        Object[] finderArgs = new Object[] { new Long(portraitId) };
1656
1657        Object result = null;
1658
1659        if (retrieveFromCache) {
1660            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_PORTRAITID,
1661                    finderArgs, this);
1662        }
1663
1664        if (result == null) {
1665            Session session = null;
1666
1667            try {
1668                session = openSession();
1669
1670                StringBundler query = new StringBundler(2);
1671
1672                query.append(_SQL_SELECT_USER_WHERE);
1673
1674                query.append(_FINDER_COLUMN_PORTRAITID_PORTRAITID_2);
1675
1676                String sql = query.toString();
1677
1678                Query q = session.createQuery(sql);
1679
1680                QueryPos qPos = QueryPos.getInstance(q);
1681
1682                qPos.add(portraitId);
1683
1684                List<User> list = q.list();
1685
1686                result = list;
1687
1688                User user = null;
1689
1690                if (list.isEmpty()) {
1691                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PORTRAITID,
1692                        finderArgs, list);
1693                }
1694                else {
1695                    user = list.get(0);
1696
1697                    cacheResult(user);
1698
1699                    if ((user.getPortraitId() != portraitId)) {
1700                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PORTRAITID,
1701                            finderArgs, user);
1702                    }
1703                }
1704
1705                return user;
1706            }
1707            catch (Exception e) {
1708                throw processException(e);
1709            }
1710            finally {
1711                if (result == null) {
1712                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_PORTRAITID,
1713                        finderArgs, new ArrayList<User>());
1714                }
1715
1716                closeSession(session);
1717            }
1718        }
1719        else {
1720            if (result instanceof List<?>) {
1721                return null;
1722            }
1723            else {
1724                return (User)result;
1725            }
1726        }
1727    }
1728
1729    public User findByC_U(long companyId, long userId)
1730        throws NoSuchUserException, SystemException {
1731        User user = fetchByC_U(companyId, userId);
1732
1733        if (user == null) {
1734            StringBundler msg = new StringBundler(6);
1735
1736            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1737
1738            msg.append("companyId=");
1739            msg.append(companyId);
1740
1741            msg.append(", userId=");
1742            msg.append(userId);
1743
1744            msg.append(StringPool.CLOSE_CURLY_BRACE);
1745
1746            if (_log.isWarnEnabled()) {
1747                _log.warn(msg.toString());
1748            }
1749
1750            throw new NoSuchUserException(msg.toString());
1751        }
1752
1753        return user;
1754    }
1755
1756    public User fetchByC_U(long companyId, long userId)
1757        throws SystemException {
1758        return fetchByC_U(companyId, userId, true);
1759    }
1760
1761    public User fetchByC_U(long companyId, long userId,
1762        boolean retrieveFromCache) throws SystemException {
1763        Object[] finderArgs = new Object[] { new Long(companyId), new Long(userId) };
1764
1765        Object result = null;
1766
1767        if (retrieveFromCache) {
1768            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_U,
1769                    finderArgs, this);
1770        }
1771
1772        if (result == null) {
1773            Session session = null;
1774
1775            try {
1776                session = openSession();
1777
1778                StringBundler query = new StringBundler(3);
1779
1780                query.append(_SQL_SELECT_USER_WHERE);
1781
1782                query.append(_FINDER_COLUMN_C_U_COMPANYID_2);
1783
1784                query.append(_FINDER_COLUMN_C_U_USERID_2);
1785
1786                String sql = query.toString();
1787
1788                Query q = session.createQuery(sql);
1789
1790                QueryPos qPos = QueryPos.getInstance(q);
1791
1792                qPos.add(companyId);
1793
1794                qPos.add(userId);
1795
1796                List<User> list = q.list();
1797
1798                result = list;
1799
1800                User user = null;
1801
1802                if (list.isEmpty()) {
1803                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U,
1804                        finderArgs, list);
1805                }
1806                else {
1807                    user = list.get(0);
1808
1809                    cacheResult(user);
1810
1811                    if ((user.getCompanyId() != companyId) ||
1812                            (user.getUserId() != userId)) {
1813                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U,
1814                            finderArgs, user);
1815                    }
1816                }
1817
1818                return user;
1819            }
1820            catch (Exception e) {
1821                throw processException(e);
1822            }
1823            finally {
1824                if (result == null) {
1825                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_U,
1826                        finderArgs, new ArrayList<User>());
1827                }
1828
1829                closeSession(session);
1830            }
1831        }
1832        else {
1833            if (result instanceof List<?>) {
1834                return null;
1835            }
1836            else {
1837                return (User)result;
1838            }
1839        }
1840    }
1841
1842    public User findByC_DU(long companyId, boolean defaultUser)
1843        throws NoSuchUserException, SystemException {
1844        User user = fetchByC_DU(companyId, defaultUser);
1845
1846        if (user == null) {
1847            StringBundler msg = new StringBundler(6);
1848
1849            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1850
1851            msg.append("companyId=");
1852            msg.append(companyId);
1853
1854            msg.append(", defaultUser=");
1855            msg.append(defaultUser);
1856
1857            msg.append(StringPool.CLOSE_CURLY_BRACE);
1858
1859            if (_log.isWarnEnabled()) {
1860                _log.warn(msg.toString());
1861            }
1862
1863            throw new NoSuchUserException(msg.toString());
1864        }
1865
1866        return user;
1867    }
1868
1869    public User fetchByC_DU(long companyId, boolean defaultUser)
1870        throws SystemException {
1871        return fetchByC_DU(companyId, defaultUser, true);
1872    }
1873
1874    public User fetchByC_DU(long companyId, boolean defaultUser,
1875        boolean retrieveFromCache) throws SystemException {
1876        Object[] finderArgs = new Object[] {
1877                new Long(companyId), Boolean.valueOf(defaultUser)
1878            };
1879
1880        Object result = null;
1881
1882        if (retrieveFromCache) {
1883            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_DU,
1884                    finderArgs, this);
1885        }
1886
1887        if (result == null) {
1888            Session session = null;
1889
1890            try {
1891                session = openSession();
1892
1893                StringBundler query = new StringBundler(3);
1894
1895                query.append(_SQL_SELECT_USER_WHERE);
1896
1897                query.append(_FINDER_COLUMN_C_DU_COMPANYID_2);
1898
1899                query.append(_FINDER_COLUMN_C_DU_DEFAULTUSER_2);
1900
1901                String sql = query.toString();
1902
1903                Query q = session.createQuery(sql);
1904
1905                QueryPos qPos = QueryPos.getInstance(q);
1906
1907                qPos.add(companyId);
1908
1909                qPos.add(defaultUser);
1910
1911                List<User> list = q.list();
1912
1913                result = list;
1914
1915                User user = null;
1916
1917                if (list.isEmpty()) {
1918                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DU,
1919                        finderArgs, list);
1920                }
1921                else {
1922                    user = list.get(0);
1923
1924                    cacheResult(user);
1925
1926                    if ((user.getCompanyId() != companyId) ||
1927                            (user.getDefaultUser() != defaultUser)) {
1928                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DU,
1929                            finderArgs, user);
1930                    }
1931                }
1932
1933                return user;
1934            }
1935            catch (Exception e) {
1936                throw processException(e);
1937            }
1938            finally {
1939                if (result == null) {
1940                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_DU,
1941                        finderArgs, new ArrayList<User>());
1942                }
1943
1944                closeSession(session);
1945            }
1946        }
1947        else {
1948            if (result instanceof List<?>) {
1949                return null;
1950            }
1951            else {
1952                return (User)result;
1953            }
1954        }
1955    }
1956
1957    public User findByC_SN(long companyId, String screenName)
1958        throws NoSuchUserException, SystemException {
1959        User user = fetchByC_SN(companyId, screenName);
1960
1961        if (user == null) {
1962            StringBundler msg = new StringBundler(6);
1963
1964            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1965
1966            msg.append("companyId=");
1967            msg.append(companyId);
1968
1969            msg.append(", screenName=");
1970            msg.append(screenName);
1971
1972            msg.append(StringPool.CLOSE_CURLY_BRACE);
1973
1974            if (_log.isWarnEnabled()) {
1975                _log.warn(msg.toString());
1976            }
1977
1978            throw new NoSuchUserException(msg.toString());
1979        }
1980
1981        return user;
1982    }
1983
1984    public User fetchByC_SN(long companyId, String screenName)
1985        throws SystemException {
1986        return fetchByC_SN(companyId, screenName, true);
1987    }
1988
1989    public User fetchByC_SN(long companyId, String screenName,
1990        boolean retrieveFromCache) throws SystemException {
1991        Object[] finderArgs = new Object[] { new Long(companyId), screenName };
1992
1993        Object result = null;
1994
1995        if (retrieveFromCache) {
1996            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_SN,
1997                    finderArgs, this);
1998        }
1999
2000        if (result == null) {
2001            Session session = null;
2002
2003            try {
2004                session = openSession();
2005
2006                StringBundler query = new StringBundler(3);
2007
2008                query.append(_SQL_SELECT_USER_WHERE);
2009
2010                query.append(_FINDER_COLUMN_C_SN_COMPANYID_2);
2011
2012                if (screenName == null) {
2013                    query.append(_FINDER_COLUMN_C_SN_SCREENNAME_1);
2014                }
2015                else {
2016                    if (screenName.equals(StringPool.BLANK)) {
2017                        query.append(_FINDER_COLUMN_C_SN_SCREENNAME_3);
2018                    }
2019                    else {
2020                        query.append(_FINDER_COLUMN_C_SN_SCREENNAME_2);
2021                    }
2022                }
2023
2024                String sql = query.toString();
2025
2026                Query q = session.createQuery(sql);
2027
2028                QueryPos qPos = QueryPos.getInstance(q);
2029
2030                qPos.add(companyId);
2031
2032                if (screenName != null) {
2033                    qPos.add(screenName);
2034                }
2035
2036                List<User> list = q.list();
2037
2038                result = list;
2039
2040                User user = null;
2041
2042                if (list.isEmpty()) {
2043                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_SN,
2044                        finderArgs, list);
2045                }
2046                else {
2047                    user = list.get(0);
2048
2049                    cacheResult(user);
2050
2051                    if ((user.getCompanyId() != companyId) ||
2052                            (user.getScreenName() == null) ||
2053                            !user.getScreenName().equals(screenName)) {
2054                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_SN,
2055                            finderArgs, user);
2056                    }
2057                }
2058
2059                return user;
2060            }
2061            catch (Exception e) {
2062                throw processException(e);
2063            }
2064            finally {
2065                if (result == null) {
2066                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_SN,
2067                        finderArgs, new ArrayList<User>());
2068                }
2069
2070                closeSession(session);
2071            }
2072        }
2073        else {
2074            if (result instanceof List<?>) {
2075                return null;
2076            }
2077            else {
2078                return (User)result;
2079            }
2080        }
2081    }
2082
2083    public User findByC_EA(long companyId, String emailAddress)
2084        throws NoSuchUserException, SystemException {
2085        User user = fetchByC_EA(companyId, emailAddress);
2086
2087        if (user == null) {
2088            StringBundler msg = new StringBundler(6);
2089
2090            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2091
2092            msg.append("companyId=");
2093            msg.append(companyId);
2094
2095            msg.append(", emailAddress=");
2096            msg.append(emailAddress);
2097
2098            msg.append(StringPool.CLOSE_CURLY_BRACE);
2099
2100            if (_log.isWarnEnabled()) {
2101                _log.warn(msg.toString());
2102            }
2103
2104            throw new NoSuchUserException(msg.toString());
2105        }
2106
2107        return user;
2108    }
2109
2110    public User fetchByC_EA(long companyId, String emailAddress)
2111        throws SystemException {
2112        return fetchByC_EA(companyId, emailAddress, true);
2113    }
2114
2115    public User fetchByC_EA(long companyId, String emailAddress,
2116        boolean retrieveFromCache) throws SystemException {
2117        Object[] finderArgs = new Object[] { new Long(companyId), emailAddress };
2118
2119        Object result = null;
2120
2121        if (retrieveFromCache) {
2122            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_EA,
2123                    finderArgs, this);
2124        }
2125
2126        if (result == null) {
2127            Session session = null;
2128
2129            try {
2130                session = openSession();
2131
2132                StringBundler query = new StringBundler(3);
2133
2134                query.append(_SQL_SELECT_USER_WHERE);
2135
2136                query.append(_FINDER_COLUMN_C_EA_COMPANYID_2);
2137
2138                if (emailAddress == null) {
2139                    query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_1);
2140                }
2141                else {
2142                    if (emailAddress.equals(StringPool.BLANK)) {
2143                        query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_3);
2144                    }
2145                    else {
2146                        query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_2);
2147                    }
2148                }
2149
2150                String sql = query.toString();
2151
2152                Query q = session.createQuery(sql);
2153
2154                QueryPos qPos = QueryPos.getInstance(q);
2155
2156                qPos.add(companyId);
2157
2158                if (emailAddress != null) {
2159                    qPos.add(emailAddress);
2160                }
2161
2162                List<User> list = q.list();
2163
2164                result = list;
2165
2166                User user = null;
2167
2168                if (list.isEmpty()) {
2169                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_EA,
2170                        finderArgs, list);
2171                }
2172                else {
2173                    user = list.get(0);
2174
2175                    cacheResult(user);
2176
2177                    if ((user.getCompanyId() != companyId) ||
2178                            (user.getEmailAddress() == null) ||
2179                            !user.getEmailAddress().equals(emailAddress)) {
2180                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_EA,
2181                            finderArgs, user);
2182                    }
2183                }
2184
2185                return user;
2186            }
2187            catch (Exception e) {
2188                throw processException(e);
2189            }
2190            finally {
2191                if (result == null) {
2192                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_EA,
2193                        finderArgs, new ArrayList<User>());
2194                }
2195
2196                closeSession(session);
2197            }
2198        }
2199        else {
2200            if (result instanceof List<?>) {
2201                return null;
2202            }
2203            else {
2204                return (User)result;
2205            }
2206        }
2207    }
2208
2209    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2210        throws SystemException {
2211        Session session = null;
2212
2213        try {
2214            session = openSession();
2215
2216            dynamicQuery.compile(session);
2217
2218            return dynamicQuery.list();
2219        }
2220        catch (Exception e) {
2221            throw processException(e);
2222        }
2223        finally {
2224            closeSession(session);
2225        }
2226    }
2227
2228    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2229        int start, int end) throws SystemException {
2230        Session session = null;
2231
2232        try {
2233            session = openSession();
2234
2235            dynamicQuery.setLimit(start, end);
2236
2237            dynamicQuery.compile(session);
2238
2239            return dynamicQuery.list();
2240        }
2241        catch (Exception e) {
2242            throw processException(e);
2243        }
2244        finally {
2245            closeSession(session);
2246        }
2247    }
2248
2249    public List<User> findAll() throws SystemException {
2250        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2251    }
2252
2253    public List<User> findAll(int start, int end) throws SystemException {
2254        return findAll(start, end, null);
2255    }
2256
2257    public List<User> findAll(int start, int end, OrderByComparator obc)
2258        throws SystemException {
2259        Object[] finderArgs = new Object[] {
2260                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2261            };
2262
2263        List<User> list = (List<User>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2264                finderArgs, this);
2265
2266        if (list == null) {
2267            Session session = null;
2268
2269            try {
2270                session = openSession();
2271
2272                StringBundler query = null;
2273                String sql = null;
2274
2275                if (obc != null) {
2276                    query = new StringBundler(2 +
2277                            (obc.getOrderByFields().length * 3));
2278
2279                    query.append(_SQL_SELECT_USER);
2280
2281                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
2282
2283                    sql = query.toString();
2284                }
2285
2286                sql = _SQL_SELECT_USER;
2287
2288                Query q = session.createQuery(sql);
2289
2290                if (obc == null) {
2291                    list = (List<User>)QueryUtil.list(q, getDialect(), start,
2292                            end, false);
2293
2294                    Collections.sort(list);
2295                }
2296                else {
2297                    list = (List<User>)QueryUtil.list(q, getDialect(), start,
2298                            end);
2299                }
2300            }
2301            catch (Exception e) {
2302                throw processException(e);
2303            }
2304            finally {
2305                if (list == null) {
2306                    list = new ArrayList<User>();
2307                }
2308
2309                cacheResult(list);
2310
2311                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2312
2313                closeSession(session);
2314            }
2315        }
2316
2317        return list;
2318    }
2319
2320    public void removeByUuid(String uuid) throws SystemException {
2321        for (User user : findByUuid(uuid)) {
2322            remove(user);
2323        }
2324    }
2325
2326    public void removeByCompanyId(long companyId) throws SystemException {
2327        for (User user : findByCompanyId(companyId)) {
2328            remove(user);
2329        }
2330    }
2331
2332    public void removeByContactId(long contactId)
2333        throws NoSuchUserException, SystemException {
2334        User user = findByContactId(contactId);
2335
2336        remove(user);
2337    }
2338
2339    public void removeByEmailAddress(String emailAddress)
2340        throws SystemException {
2341        for (User user : findByEmailAddress(emailAddress)) {
2342            remove(user);
2343        }
2344    }
2345
2346    public void removeByOpenId(String openId)
2347        throws NoSuchUserException, SystemException {
2348        User user = findByOpenId(openId);
2349
2350        remove(user);
2351    }
2352
2353    public void removeByPortraitId(long portraitId)
2354        throws NoSuchUserException, SystemException {
2355        User user = findByPortraitId(portraitId);
2356
2357        remove(user);
2358    }
2359
2360    public void removeByC_U(long companyId, long userId)
2361        throws NoSuchUserException, SystemException {
2362        User user = findByC_U(companyId, userId);
2363
2364        remove(user);
2365    }
2366
2367    public void removeByC_DU(long companyId, boolean defaultUser)
2368        throws NoSuchUserException, SystemException {
2369        User user = findByC_DU(companyId, defaultUser);
2370
2371        remove(user);
2372    }
2373
2374    public void removeByC_SN(long companyId, String screenName)
2375        throws NoSuchUserException, SystemException {
2376        User user = findByC_SN(companyId, screenName);
2377
2378        remove(user);
2379    }
2380
2381    public void removeByC_EA(long companyId, String emailAddress)
2382        throws NoSuchUserException, SystemException {
2383        User user = findByC_EA(companyId, emailAddress);
2384
2385        remove(user);
2386    }
2387
2388    public void removeAll() throws SystemException {
2389        for (User user : findAll()) {
2390            remove(user);
2391        }
2392    }
2393
2394    public int countByUuid(String uuid) throws SystemException {
2395        Object[] finderArgs = new Object[] { uuid };
2396
2397        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2398                finderArgs, this);
2399
2400        if (count == null) {
2401            Session session = null;
2402
2403            try {
2404                session = openSession();
2405
2406                StringBundler query = new StringBundler(2);
2407
2408                query.append(_SQL_COUNT_USER_WHERE);
2409
2410                if (uuid == null) {
2411                    query.append(_FINDER_COLUMN_UUID_UUID_1);
2412                }
2413                else {
2414                    if (uuid.equals(StringPool.BLANK)) {
2415                        query.append(_FINDER_COLUMN_UUID_UUID_3);
2416                    }
2417                    else {
2418                        query.append(_FINDER_COLUMN_UUID_UUID_2);
2419                    }
2420                }
2421
2422                String sql = query.toString();
2423
2424                Query q = session.createQuery(sql);
2425
2426                QueryPos qPos = QueryPos.getInstance(q);
2427
2428                if (uuid != null) {
2429                    qPos.add(uuid);
2430                }
2431
2432                count = (Long)q.uniqueResult();
2433            }
2434            catch (Exception e) {
2435                throw processException(e);
2436            }
2437            finally {
2438                if (count == null) {
2439                    count = Long.valueOf(0);
2440                }
2441
2442                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2443                    finderArgs, count);
2444
2445                closeSession(session);
2446            }
2447        }
2448
2449        return count.intValue();
2450    }
2451
2452    public int countByCompanyId(long companyId) throws SystemException {
2453        Object[] finderArgs = new Object[] { new Long(companyId) };
2454
2455        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2456                finderArgs, this);
2457
2458        if (count == null) {
2459            Session session = null;
2460
2461            try {
2462                session = openSession();
2463
2464                StringBundler query = new StringBundler(2);
2465
2466                query.append(_SQL_COUNT_USER_WHERE);
2467
2468                query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2469
2470                String sql = query.toString();
2471
2472                Query q = session.createQuery(sql);
2473
2474                QueryPos qPos = QueryPos.getInstance(q);
2475
2476                qPos.add(companyId);
2477
2478                count = (Long)q.uniqueResult();
2479            }
2480            catch (Exception e) {
2481                throw processException(e);
2482            }
2483            finally {
2484                if (count == null) {
2485                    count = Long.valueOf(0);
2486                }
2487
2488                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2489                    finderArgs, count);
2490
2491                closeSession(session);
2492            }
2493        }
2494
2495        return count.intValue();
2496    }
2497
2498    public int countByContactId(long contactId) throws SystemException {
2499        Object[] finderArgs = new Object[] { new Long(contactId) };
2500
2501        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CONTACTID,
2502                finderArgs, this);
2503
2504        if (count == null) {
2505            Session session = null;
2506
2507            try {
2508                session = openSession();
2509
2510                StringBundler query = new StringBundler(2);
2511
2512                query.append(_SQL_COUNT_USER_WHERE);
2513
2514                query.append(_FINDER_COLUMN_CONTACTID_CONTACTID_2);
2515
2516                String sql = query.toString();
2517
2518                Query q = session.createQuery(sql);
2519
2520                QueryPos qPos = QueryPos.getInstance(q);
2521
2522                qPos.add(contactId);
2523
2524                count = (Long)q.uniqueResult();
2525            }
2526            catch (Exception e) {
2527                throw processException(e);
2528            }
2529            finally {
2530                if (count == null) {
2531                    count = Long.valueOf(0);
2532                }
2533
2534                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CONTACTID,
2535                    finderArgs, count);
2536
2537                closeSession(session);
2538            }
2539        }
2540
2541        return count.intValue();
2542    }
2543
2544    public int countByEmailAddress(String emailAddress)
2545        throws SystemException {
2546        Object[] finderArgs = new Object[] { emailAddress };
2547
2548        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_EMAILADDRESS,
2549                finderArgs, this);
2550
2551        if (count == null) {
2552            Session session = null;
2553
2554            try {
2555                session = openSession();
2556
2557                StringBundler query = new StringBundler(2);
2558
2559                query.append(_SQL_COUNT_USER_WHERE);
2560
2561                if (emailAddress == null) {
2562                    query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1);
2563                }
2564                else {
2565                    if (emailAddress.equals(StringPool.BLANK)) {
2566                        query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3);
2567                    }
2568                    else {
2569                        query.append(_FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2);
2570                    }
2571                }
2572
2573                String sql = query.toString();
2574
2575                Query q = session.createQuery(sql);
2576
2577                QueryPos qPos = QueryPos.getInstance(q);
2578
2579                if (emailAddress != null) {
2580                    qPos.add(emailAddress);
2581                }
2582
2583                count = (Long)q.uniqueResult();
2584            }
2585            catch (Exception e) {
2586                throw processException(e);
2587            }
2588            finally {
2589                if (count == null) {
2590                    count = Long.valueOf(0);
2591                }
2592
2593                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_EMAILADDRESS,
2594                    finderArgs, count);
2595
2596                closeSession(session);
2597            }
2598        }
2599
2600        return count.intValue();
2601    }
2602
2603    public int countByOpenId(String openId) throws SystemException {
2604        Object[] finderArgs = new Object[] { openId };
2605
2606        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_OPENID,
2607                finderArgs, this);
2608
2609        if (count == null) {
2610            Session session = null;
2611
2612            try {
2613                session = openSession();
2614
2615                StringBundler query = new StringBundler(2);
2616
2617                query.append(_SQL_COUNT_USER_WHERE);
2618
2619                if (openId == null) {
2620                    query.append(_FINDER_COLUMN_OPENID_OPENID_1);
2621                }
2622                else {
2623                    if (openId.equals(StringPool.BLANK)) {
2624                        query.append(_FINDER_COLUMN_OPENID_OPENID_3);
2625                    }
2626                    else {
2627                        query.append(_FINDER_COLUMN_OPENID_OPENID_2);
2628                    }
2629                }
2630
2631                String sql = query.toString();
2632
2633                Query q = session.createQuery(sql);
2634
2635                QueryPos qPos = QueryPos.getInstance(q);
2636
2637                if (openId != null) {
2638                    qPos.add(openId);
2639                }
2640
2641                count = (Long)q.uniqueResult();
2642            }
2643            catch (Exception e) {
2644                throw processException(e);
2645            }
2646            finally {
2647                if (count == null) {
2648                    count = Long.valueOf(0);
2649                }
2650
2651                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_OPENID,
2652                    finderArgs, count);
2653
2654                closeSession(session);
2655            }
2656        }
2657
2658        return count.intValue();
2659    }
2660
2661    public int countByPortraitId(long portraitId) throws SystemException {
2662        Object[] finderArgs = new Object[] { new Long(portraitId) };
2663
2664        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PORTRAITID,
2665                finderArgs, this);
2666
2667        if (count == null) {
2668            Session session = null;
2669
2670            try {
2671                session = openSession();
2672
2673                StringBundler query = new StringBundler(2);
2674
2675                query.append(_SQL_COUNT_USER_WHERE);
2676
2677                query.append(_FINDER_COLUMN_PORTRAITID_PORTRAITID_2);
2678
2679                String sql = query.toString();
2680
2681                Query q = session.createQuery(sql);
2682
2683                QueryPos qPos = QueryPos.getInstance(q);
2684
2685                qPos.add(portraitId);
2686
2687                count = (Long)q.uniqueResult();
2688            }
2689            catch (Exception e) {
2690                throw processException(e);
2691            }
2692            finally {
2693                if (count == null) {
2694                    count = Long.valueOf(0);
2695                }
2696
2697                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PORTRAITID,
2698                    finderArgs, count);
2699
2700                closeSession(session);
2701            }
2702        }
2703
2704        return count.intValue();
2705    }
2706
2707    public int countByC_U(long companyId, long userId)
2708        throws SystemException {
2709        Object[] finderArgs = new Object[] { new Long(companyId), new Long(userId) };
2710
2711        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_U,
2712                finderArgs, this);
2713
2714        if (count == null) {
2715            Session session = null;
2716
2717            try {
2718                session = openSession();
2719
2720                StringBundler query = new StringBundler(3);
2721
2722                query.append(_SQL_COUNT_USER_WHERE);
2723
2724                query.append(_FINDER_COLUMN_C_U_COMPANYID_2);
2725
2726                query.append(_FINDER_COLUMN_C_U_USERID_2);
2727
2728                String sql = query.toString();
2729
2730                Query q = session.createQuery(sql);
2731
2732                QueryPos qPos = QueryPos.getInstance(q);
2733
2734                qPos.add(companyId);
2735
2736                qPos.add(userId);
2737
2738                count = (Long)q.uniqueResult();
2739            }
2740            catch (Exception e) {
2741                throw processException(e);
2742            }
2743            finally {
2744                if (count == null) {
2745                    count = Long.valueOf(0);
2746                }
2747
2748                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_U, finderArgs,
2749                    count);
2750
2751                closeSession(session);
2752            }
2753        }
2754
2755        return count.intValue();
2756    }
2757
2758    public int countByC_DU(long companyId, boolean defaultUser)
2759        throws SystemException {
2760        Object[] finderArgs = new Object[] {
2761                new Long(companyId), Boolean.valueOf(defaultUser)
2762            };
2763
2764        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_DU,
2765                finderArgs, this);
2766
2767        if (count == null) {
2768            Session session = null;
2769
2770            try {
2771                session = openSession();
2772
2773                StringBundler query = new StringBundler(3);
2774
2775                query.append(_SQL_COUNT_USER_WHERE);
2776
2777                query.append(_FINDER_COLUMN_C_DU_COMPANYID_2);
2778
2779                query.append(_FINDER_COLUMN_C_DU_DEFAULTUSER_2);
2780
2781                String sql = query.toString();
2782
2783                Query q = session.createQuery(sql);
2784
2785                QueryPos qPos = QueryPos.getInstance(q);
2786
2787                qPos.add(companyId);
2788
2789                qPos.add(defaultUser);
2790
2791                count = (Long)q.uniqueResult();
2792            }
2793            catch (Exception e) {
2794                throw processException(e);
2795            }
2796            finally {
2797                if (count == null) {
2798                    count = Long.valueOf(0);
2799                }
2800
2801                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_DU,
2802                    finderArgs, count);
2803
2804                closeSession(session);
2805            }
2806        }
2807
2808        return count.intValue();
2809    }
2810
2811    public int countByC_SN(long companyId, String screenName)
2812        throws SystemException {
2813        Object[] finderArgs = new Object[] { new Long(companyId), screenName };
2814
2815        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_SN,
2816                finderArgs, this);
2817
2818        if (count == null) {
2819            Session session = null;
2820
2821            try {
2822                session = openSession();
2823
2824                StringBundler query = new StringBundler(3);
2825
2826                query.append(_SQL_COUNT_USER_WHERE);
2827
2828                query.append(_FINDER_COLUMN_C_SN_COMPANYID_2);
2829
2830                if (screenName == null) {
2831                    query.append(_FINDER_COLUMN_C_SN_SCREENNAME_1);
2832                }
2833                else {
2834                    if (screenName.equals(StringPool.BLANK)) {
2835                        query.append(_FINDER_COLUMN_C_SN_SCREENNAME_3);
2836                    }
2837                    else {
2838                        query.append(_FINDER_COLUMN_C_SN_SCREENNAME_2);
2839                    }
2840                }
2841
2842                String sql = query.toString();
2843
2844                Query q = session.createQuery(sql);
2845
2846                QueryPos qPos = QueryPos.getInstance(q);
2847
2848                qPos.add(companyId);
2849
2850                if (screenName != null) {
2851                    qPos.add(screenName);
2852                }
2853
2854                count = (Long)q.uniqueResult();
2855            }
2856            catch (Exception e) {
2857                throw processException(e);
2858            }
2859            finally {
2860                if (count == null) {
2861                    count = Long.valueOf(0);
2862                }
2863
2864                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_SN,
2865                    finderArgs, count);
2866
2867                closeSession(session);
2868            }
2869        }
2870
2871        return count.intValue();
2872    }
2873
2874    public int countByC_EA(long companyId, String emailAddress)
2875        throws SystemException {
2876        Object[] finderArgs = new Object[] { new Long(companyId), emailAddress };
2877
2878        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_EA,
2879                finderArgs, this);
2880
2881        if (count == null) {
2882            Session session = null;
2883
2884            try {
2885                session = openSession();
2886
2887                StringBundler query = new StringBundler(3);
2888
2889                query.append(_SQL_COUNT_USER_WHERE);
2890
2891                query.append(_FINDER_COLUMN_C_EA_COMPANYID_2);
2892
2893                if (emailAddress == null) {
2894                    query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_1);
2895                }
2896                else {
2897                    if (emailAddress.equals(StringPool.BLANK)) {
2898                        query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_3);
2899                    }
2900                    else {
2901                        query.append(_FINDER_COLUMN_C_EA_EMAILADDRESS_2);
2902                    }
2903                }
2904
2905                String sql = query.toString();
2906
2907                Query q = session.createQuery(sql);
2908
2909                QueryPos qPos = QueryPos.getInstance(q);
2910
2911                qPos.add(companyId);
2912
2913                if (emailAddress != null) {
2914                    qPos.add(emailAddress);
2915                }
2916
2917                count = (Long)q.uniqueResult();
2918            }
2919            catch (Exception e) {
2920                throw processException(e);
2921            }
2922            finally {
2923                if (count == null) {
2924                    count = Long.valueOf(0);
2925                }
2926
2927                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_EA,
2928                    finderArgs, count);
2929
2930                closeSession(session);
2931            }
2932        }
2933
2934        return count.intValue();
2935    }
2936
2937    public int countAll() throws SystemException {
2938        Object[] finderArgs = new Object[0];
2939
2940        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2941                finderArgs, this);
2942
2943        if (count == null) {
2944            Session session = null;
2945
2946            try {
2947                session = openSession();
2948
2949                Query q = session.createQuery(_SQL_COUNT_USER);
2950
2951                count = (Long)q.uniqueResult();
2952            }
2953            catch (Exception e) {
2954                throw processException(e);
2955            }
2956            finally {
2957                if (count == null) {
2958                    count = Long.valueOf(0);
2959                }
2960
2961                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2962                    count);
2963
2964                closeSession(session);
2965            }
2966        }
2967
2968        return count.intValue();
2969    }
2970
2971    public List<com.liferay.portal.model.Group> getGroups(long pk)
2972        throws SystemException {
2973        return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2974    }
2975
2976    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2977        int end) throws SystemException {
2978        return getGroups(pk, start, end, null);
2979    }
2980
2981    public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2982            UserModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS,
2983            UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME, "getGroups",
2984            new String[] {
2985                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2986                "com.liferay.portal.kernel.util.OrderByComparator"
2987            });
2988
2989    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2990        int end, OrderByComparator obc) throws SystemException {
2991        Object[] finderArgs = new Object[] {
2992                new Long(pk), String.valueOf(start), String.valueOf(end),
2993                String.valueOf(obc)
2994            };
2995
2996        List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
2997                finderArgs, this);
2998
2999        if (list == null) {
3000            Session session = null;
3001
3002            try {
3003                session = openSession();
3004
3005                String sql = null;
3006
3007                if (obc != null) {
3008                    sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
3009                                        .concat(obc.getOrderBy());
3010                }
3011
3012                else {
3013                    sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
3014                }
3015
3016                SQLQuery q = session.createSQLQuery(sql);
3017
3018                q.addEntity("Group_",
3019                    com.liferay.portal.model.impl.GroupImpl.class);
3020
3021                QueryPos qPos = QueryPos.getInstance(q);
3022
3023                qPos.add(pk);
3024
3025                list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
3026                        getDialect(), start, end);
3027            }
3028            catch (Exception e) {
3029                throw processException(e);
3030            }
3031            finally {
3032                if (list == null) {
3033                    list = new ArrayList<com.liferay.portal.model.Group>();
3034                }
3035
3036                groupPersistence.cacheResult(list);
3037
3038                FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
3039                    list);
3040
3041                closeSession(session);
3042            }
3043        }
3044
3045        return list;
3046    }
3047
3048    public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3049            UserModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS,
3050            UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME, "getGroupsSize",
3051            new String[] { Long.class.getName() });
3052
3053    public int getGroupsSize(long pk) throws SystemException {
3054        Object[] finderArgs = new Object[] { new Long(pk) };
3055
3056        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
3057                finderArgs, this);
3058
3059        if (count == null) {
3060            Session session = null;
3061
3062            try {
3063                session = openSession();
3064
3065                SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
3066
3067                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3068
3069                QueryPos qPos = QueryPos.getInstance(q);
3070
3071                qPos.add(pk);
3072
3073                count = (Long)q.uniqueResult();
3074            }
3075            catch (Exception e) {
3076                throw processException(e);
3077            }
3078            finally {
3079                if (count == null) {
3080                    count = Long.valueOf(0);
3081                }
3082
3083                FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
3084                    finderArgs, count);
3085
3086                closeSession(session);
3087            }
3088        }
3089
3090        return count.intValue();
3091    }
3092
3093    public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3094            UserModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS,
3095            UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME, "containsGroup",
3096            new String[] { Long.class.getName(), Long.class.getName() });
3097
3098    public boolean containsGroup(long pk, long groupPK)
3099        throws SystemException {
3100        Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
3101
3102        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
3103                finderArgs, this);
3104
3105        if (value == null) {
3106            try {
3107                value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
3108            }
3109            catch (Exception e) {
3110                throw processException(e);
3111            }
3112            finally {
3113                if (value == null) {
3114                    value = Boolean.FALSE;
3115                }
3116
3117                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
3118                    finderArgs, value);
3119            }
3120        }
3121
3122        return value.booleanValue();
3123    }
3124
3125    public boolean containsGroups(long pk) throws SystemException {
3126        if (getGroupsSize(pk) > 0) {
3127            return true;
3128        }
3129        else {
3130            return false;
3131        }
3132    }
3133
3134    public void addGroup(long pk, long groupPK) throws SystemException {
3135        try {
3136            addGroup.add(pk, groupPK);
3137        }
3138        catch (Exception e) {
3139            throw processException(e);
3140        }
3141        finally {
3142            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3143        }
3144    }
3145
3146    public void addGroup(long pk, com.liferay.portal.model.Group group)
3147        throws SystemException {
3148        try {
3149            addGroup.add(pk, group.getPrimaryKey());
3150        }
3151        catch (Exception e) {
3152            throw processException(e);
3153        }
3154        finally {
3155            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3156        }
3157    }
3158
3159    public void addGroups(long pk, long[] groupPKs) throws SystemException {
3160        try {
3161            for (long groupPK : groupPKs) {
3162                addGroup.add(pk, groupPK);
3163            }
3164        }
3165        catch (Exception e) {
3166            throw processException(e);
3167        }
3168        finally {
3169            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3170        }
3171    }
3172
3173    public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
3174        throws SystemException {
3175        try {
3176            for (com.liferay.portal.model.Group group : groups) {
3177                addGroup.add(pk, group.getPrimaryKey());
3178            }
3179        }
3180        catch (Exception e) {
3181            throw processException(e);
3182        }
3183        finally {
3184            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3185        }
3186    }
3187
3188    public void clearGroups(long pk) throws SystemException {
3189        try {
3190            clearGroups.clear(pk);
3191        }
3192        catch (Exception e) {
3193            throw processException(e);
3194        }
3195        finally {
3196            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3197        }
3198    }
3199
3200    public void removeGroup(long pk, long groupPK) throws SystemException {
3201        try {
3202            removeGroup.remove(pk, groupPK);
3203        }
3204        catch (Exception e) {
3205            throw processException(e);
3206        }
3207        finally {
3208            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3209        }
3210    }
3211
3212    public void removeGroup(long pk, com.liferay.portal.model.Group group)
3213        throws SystemException {
3214        try {
3215            removeGroup.remove(pk, group.getPrimaryKey());
3216        }
3217        catch (Exception e) {
3218            throw processException(e);
3219        }
3220        finally {
3221            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3222        }
3223    }
3224
3225    public void removeGroups(long pk, long[] groupPKs)
3226        throws SystemException {
3227        try {
3228            for (long groupPK : groupPKs) {
3229                removeGroup.remove(pk, groupPK);
3230            }
3231        }
3232        catch (Exception e) {
3233            throw processException(e);
3234        }
3235        finally {
3236            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3237        }
3238    }
3239
3240    public void removeGroups(long pk,
3241        List<com.liferay.portal.model.Group> groups) throws SystemException {
3242        try {
3243            for (com.liferay.portal.model.Group group : groups) {
3244                removeGroup.remove(pk, group.getPrimaryKey());
3245            }
3246        }
3247        catch (Exception e) {
3248            throw processException(e);
3249        }
3250        finally {
3251            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3252        }
3253    }
3254
3255    public void setGroups(long pk, long[] groupPKs) throws SystemException {
3256        try {
3257            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
3258
3259            List<com.liferay.portal.model.Group> groups = getGroups(pk);
3260
3261            for (com.liferay.portal.model.Group group : groups) {
3262                if (!groupPKSet.contains(group.getPrimaryKey())) {
3263                    removeGroup.remove(pk, group.getPrimaryKey());
3264                }
3265                else {
3266                    groupPKSet.remove(group.getPrimaryKey());
3267                }
3268            }
3269
3270            for (Long groupPK : groupPKSet) {
3271                addGroup.add(pk, groupPK);
3272            }
3273        }
3274        catch (Exception e) {
3275            throw processException(e);
3276        }
3277        finally {
3278            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3279        }
3280    }
3281
3282    public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
3283        throws SystemException {
3284        try {
3285            long[] groupPKs = new long[groups.size()];
3286
3287            for (int i = 0; i < groups.size(); i++) {
3288                com.liferay.portal.model.Group group = groups.get(i);
3289
3290                groupPKs[i] = group.getPrimaryKey();
3291            }
3292
3293            setGroups(pk, groupPKs);
3294        }
3295        catch (Exception e) {
3296            throw processException(e);
3297        }
3298        finally {
3299            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
3300        }
3301    }
3302
3303    public List<com.liferay.portal.model.Organization> getOrganizations(long pk)
3304        throws SystemException {
3305        return getOrganizations(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3306    }
3307
3308    public List<com.liferay.portal.model.Organization> getOrganizations(
3309        long pk, int start, int end) throws SystemException {
3310        return getOrganizations(pk, start, end, null);
3311    }
3312
3313    public static final FinderPath FINDER_PATH_GET_ORGANIZATIONS = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3314            UserModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
3315            UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME, "getOrganizations",
3316            new String[] {
3317                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3318                "com.liferay.portal.kernel.util.OrderByComparator"
3319            });
3320
3321    public List<com.liferay.portal.model.Organization> getOrganizations(
3322        long pk, int start, int end, OrderByComparator obc)
3323        throws SystemException {
3324        Object[] finderArgs = new Object[] {
3325                new Long(pk), String.valueOf(start), String.valueOf(end),
3326                String.valueOf(obc)
3327            };
3328
3329        List<com.liferay.portal.model.Organization> list = (List<com.liferay.portal.model.Organization>)FinderCacheUtil.getResult(FINDER_PATH_GET_ORGANIZATIONS,
3330                finderArgs, this);
3331
3332        if (list == null) {
3333            Session session = null;
3334
3335            try {
3336                session = openSession();
3337
3338                String sql = null;
3339
3340                if (obc != null) {
3341                    sql = _SQL_GETORGANIZATIONS.concat(ORDER_BY_CLAUSE)
3342                                               .concat(obc.getOrderBy());
3343                }
3344
3345                else {
3346                    sql = _SQL_GETORGANIZATIONS.concat(com.liferay.portal.model.impl.OrganizationModelImpl.ORDER_BY_SQL);
3347                }
3348
3349                SQLQuery q = session.createSQLQuery(sql);
3350
3351                q.addEntity("Organization_",
3352                    com.liferay.portal.model.impl.OrganizationImpl.class);
3353
3354                QueryPos qPos = QueryPos.getInstance(q);
3355
3356                qPos.add(pk);
3357
3358                list = (List<com.liferay.portal.model.Organization>)QueryUtil.list(q,
3359                        getDialect(), start, end);
3360            }
3361            catch (Exception e) {
3362                throw processException(e);
3363            }
3364            finally {
3365                if (list == null) {
3366                    list = new ArrayList<com.liferay.portal.model.Organization>();
3367                }
3368
3369                organizationPersistence.cacheResult(list);
3370
3371                FinderCacheUtil.putResult(FINDER_PATH_GET_ORGANIZATIONS,
3372                    finderArgs, list);
3373
3374                closeSession(session);
3375            }
3376        }
3377
3378        return list;
3379    }
3380
3381    public static final FinderPath FINDER_PATH_GET_ORGANIZATIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3382            UserModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
3383            UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
3384            "getOrganizationsSize", new String[] { Long.class.getName() });
3385
3386    public int getOrganizationsSize(long pk) throws SystemException {
3387        Object[] finderArgs = new Object[] { new Long(pk) };
3388
3389        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ORGANIZATIONS_SIZE,
3390                finderArgs, this);
3391
3392        if (count == null) {
3393            Session session = null;
3394
3395            try {
3396                session = openSession();
3397
3398                SQLQuery q = session.createSQLQuery(_SQL_GETORGANIZATIONSSIZE);
3399
3400                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3401
3402                QueryPos qPos = QueryPos.getInstance(q);
3403
3404                qPos.add(pk);
3405
3406                count = (Long)q.uniqueResult();
3407            }
3408            catch (Exception e) {
3409                throw processException(e);
3410            }
3411            finally {
3412                if (count == null) {
3413                    count = Long.valueOf(0);
3414                }
3415
3416                FinderCacheUtil.putResult(FINDER_PATH_GET_ORGANIZATIONS_SIZE,
3417                    finderArgs, count);
3418
3419                closeSession(session);
3420            }
3421        }
3422
3423        return count.intValue();
3424    }
3425
3426    public static final FinderPath FINDER_PATH_CONTAINS_ORGANIZATION = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
3427            UserModelImpl.FINDER_CACHE_ENABLED_USERS_ORGS,
3428            UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME,
3429            "containsOrganization",
3430            new String[] { Long.class.getName(), Long.class.getName() });
3431
3432    public boolean containsOrganization(long pk, long organizationPK)
3433        throws SystemException {
3434        Object[] finderArgs = new Object[] {
3435                new Long(pk),
3436                
3437                new Long(organizationPK)
3438            };
3439
3440        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ORGANIZATION,
3441                finderArgs, this);
3442
3443        if (value == null) {
3444            try {
3445                value = Boolean.valueOf(containsOrganization.contains(pk,
3446                            organizationPK));
3447            }
3448            catch (Exception e) {
3449                throw processException(e);
3450            }
3451            finally {
3452                if (value == null) {
3453                    value = Boolean.FALSE;
3454                }
3455
3456                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ORGANIZATION,
3457                    finderArgs, value);
3458            }
3459        }
3460
3461        return value.booleanValue();
3462    }
3463
3464    public boolean containsOrganizations(long pk) throws SystemException {
3465        if (getOrganizationsSize(pk) > 0) {
3466            return true;
3467        }
3468        else {
3469            return false;
3470        }
3471    }
3472
3473    public void addOrganization(long pk, long organizationPK)
3474        throws SystemException {
3475        try {
3476            addOrganization.add(pk, organizationPK);
3477        }
3478        catch (Exception e) {
3479            throw processException(e);
3480        }
3481        finally {
3482            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3483        }
3484    }
3485
3486    public void addOrganization(long pk,
3487        com.liferay.portal.model.Organization organization)
3488        throws SystemException {
3489        try {
3490            addOrganization.add(pk, organization.getPrimaryKey());
3491        }
3492        catch (Exception e) {
3493            throw processException(e);
3494        }
3495        finally {
3496            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3497        }
3498    }
3499
3500    public void addOrganizations(long pk, long[] organizationPKs)
3501        throws SystemException {
3502        try {
3503            for (long organizationPK : organizationPKs) {
3504                addOrganization.add(pk, organizationPK);
3505            }
3506        }
3507        catch (Exception e) {
3508            throw processException(e);
3509        }
3510        finally {
3511            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3512        }
3513    }
3514
3515    public void addOrganizations(long pk,
3516        List<com.liferay.portal.model.Organization> organizations)
3517        throws SystemException {
3518        try {
3519            for (com.liferay.portal.model.Organization organization : organizations) {
3520                addOrganization.add(pk, organization.getPrimaryKey());
3521            }
3522        }
3523        catch (Exception e) {
3524            throw processException(e);
3525        }
3526        finally {
3527            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3528        }
3529    }
3530
3531    public void clearOrganizations(long pk) throws SystemException {
3532        try {
3533            clearOrganizations.clear(pk);
3534        }
3535        catch (Exception e) {
3536            throw processException(e);
3537        }
3538        finally {
3539            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3540        }
3541    }
3542
3543    public void removeOrganization(long pk, long organizationPK)
3544        throws SystemException {
3545        try {
3546            removeOrganization.remove(pk, organizationPK);
3547        }
3548        catch (Exception e) {
3549            throw processException(e);
3550        }
3551        finally {
3552            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3553        }
3554    }
3555
3556    public void removeOrganization(long pk,
3557        com.liferay.portal.model.Organization organization)
3558        throws SystemException {
3559        try {
3560            removeOrganization.remove(pk, organization.getPrimaryKey());
3561        }
3562        catch (Exception e) {
3563            throw processException(e);
3564        }
3565        finally {
3566            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3567        }
3568    }
3569
3570    public void removeOrganizations(long pk, long[] organizationPKs)
3571        throws SystemException {
3572        try {
3573            for (long organizationPK : organizationPKs) {
3574                removeOrganization.remove(pk, organizationPK);
3575            }
3576        }
3577        catch (Exception e) {
3578            throw processException(e);
3579        }
3580        finally {
3581            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3582        }
3583    }
3584
3585    public void removeOrganizations(long pk,
3586        List<com.liferay.portal.model.Organization> organizations)
3587        throws SystemException {
3588        try {
3589            for (com.liferay.portal.model.Organization organization : organizations) {
3590                removeOrganization.remove(pk, organization.getPrimaryKey());
3591            }
3592        }
3593        catch (Exception e) {
3594            throw processException(e);
3595        }
3596        finally {
3597            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3598        }
3599    }
3600
3601    public void setOrganizations(long pk, long[] organizationPKs)
3602        throws SystemException {
3603        try {
3604            Set<Long> organizationPKSet = SetUtil.fromArray(organizationPKs);
3605
3606            List<com.liferay.portal.model.Organization> organizations = getOrganizations(pk);
3607
3608            for (com.liferay.portal.model.Organization organization : organizations) {
3609                if (!organizationPKSet.contains(organization.getPrimaryKey())) {
3610                    removeOrganization.remove(pk, organization.getPrimaryKey());
3611                }
3612                else {
3613                    organizationPKSet.remove(organization.getPrimaryKey());
3614                }
3615            }
3616
3617            for (Long organizationPK : organizationPKSet) {
3618                addOrganization.add(pk, organizationPK);
3619            }
3620        }
3621        catch (Exception e) {
3622            throw processException(e);
3623        }
3624        finally {
3625            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3626        }
3627    }
3628
3629    public void setOrganizations(long pk,
3630        List<com.liferay.portal.model.Organization> organizations)
3631        throws SystemException {
3632        try {
3633            long[] organizationPKs = new long[organizations.size()];
3634
3635            for (int i = 0; i < organizations.size(); i++) {
3636                com.liferay.portal.model.Organization organization = organizations.get(i);
3637
3638                organizationPKs[i] = organization.getPrimaryKey();
3639            }
3640
3641            setOrganizations(pk, organizationPKs);
3642        }
3643        catch (Exception e) {
3644            throw processException(e);
3645        }
3646        finally {
3647            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ORGS_NAME);
3648        }
3649    }
3650
3651    public List<com.liferay.portal.model.Permission> getPermissions(long pk)
3652        throws SystemException {
3653        return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3654    }
3655
3656    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
3657        int start, int end) throws SystemException {
3658        return getPermissions(pk, start, end, null);
3659    }
3660
3661    public static final FinderPath FINDER_PATH_GET_PERMISSIONS = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
3662            UserModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
3663            UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
3664            "getPermissions",
3665            new String[] {
3666                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3667                "com.liferay.portal.kernel.util.OrderByComparator"
3668            });
3669
3670    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
3671        int start, int end, OrderByComparator obc) throws SystemException {
3672        Object[] finderArgs = new Object[] {
3673                new Long(pk), String.valueOf(start), String.valueOf(end),
3674                String.valueOf(obc)
3675            };
3676
3677        List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS,
3678                finderArgs, this);
3679
3680        if (list == null) {
3681            Session session = null;
3682
3683            try {
3684                session = openSession();
3685
3686                String sql = null;
3687
3688                if (obc != null) {
3689                    sql = _SQL_GETPERMISSIONS.concat(ORDER_BY_CLAUSE)
3690                                             .concat(obc.getOrderBy());
3691                }
3692
3693                sql = _SQL_GETPERMISSIONS;
3694
3695                SQLQuery q = session.createSQLQuery(sql);
3696
3697                q.addEntity("Permission_",
3698                    com.liferay.portal.model.impl.PermissionImpl.class);
3699
3700                QueryPos qPos = QueryPos.getInstance(q);
3701
3702                qPos.add(pk);
3703
3704                list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
3705                        getDialect(), start, end);
3706            }
3707            catch (Exception e) {
3708                throw processException(e);
3709            }
3710            finally {
3711                if (list == null) {
3712                    list = new ArrayList<com.liferay.portal.model.Permission>();
3713                }
3714
3715                permissionPersistence.cacheResult(list);
3716
3717                FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS,
3718                    finderArgs, list);
3719
3720                closeSession(session);
3721            }
3722        }
3723
3724        return list;
3725    }
3726
3727    public static final FinderPath FINDER_PATH_GET_PERMISSIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
3728            UserModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
3729            UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
3730            "getPermissionsSize", new String[] { Long.class.getName() });
3731
3732    public int getPermissionsSize(long pk) throws SystemException {
3733        Object[] finderArgs = new Object[] { new Long(pk) };
3734
3735        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
3736                finderArgs, this);
3737
3738        if (count == null) {
3739            Session session = null;
3740
3741            try {
3742                session = openSession();
3743
3744                SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
3745
3746                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3747
3748                QueryPos qPos = QueryPos.getInstance(q);
3749
3750                qPos.add(pk);
3751
3752                count = (Long)q.uniqueResult();
3753            }
3754            catch (Exception e) {
3755                throw processException(e);
3756            }
3757            finally {
3758                if (count == null) {
3759                    count = Long.valueOf(0);
3760                }
3761
3762                FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
3763                    finderArgs, count);
3764
3765                closeSession(session);
3766            }
3767        }
3768
3769        return count.intValue();
3770    }
3771
3772    public static final FinderPath FINDER_PATH_CONTAINS_PERMISSION = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
3773            UserModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
3774            UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
3775            "containsPermission",
3776            new String[] { Long.class.getName(), Long.class.getName() });
3777
3778    public boolean containsPermission(long pk, long permissionPK)
3779        throws SystemException {
3780        Object[] finderArgs = new Object[] { new Long(pk), new Long(permissionPK) };
3781
3782        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_PERMISSION,
3783                finderArgs, this);
3784
3785        if (value == null) {
3786            try {
3787                value = Boolean.valueOf(containsPermission.contains(pk,
3788                            permissionPK));
3789            }
3790            catch (Exception e) {
3791                throw processException(e);
3792            }
3793            finally {
3794                if (value == null) {
3795                    value = Boolean.FALSE;
3796                }
3797
3798                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_PERMISSION,
3799                    finderArgs, value);
3800            }
3801        }
3802
3803        return value.booleanValue();
3804    }
3805
3806    public boolean containsPermissions(long pk) throws SystemException {
3807        if (getPermissionsSize(pk) > 0) {
3808            return true;
3809        }
3810        else {
3811            return false;
3812        }
3813    }
3814
3815    public void addPermission(long pk, long permissionPK)
3816        throws SystemException {
3817        try {
3818            addPermission.add(pk, permissionPK);
3819        }
3820        catch (Exception e) {
3821            throw processException(e);
3822        }
3823        finally {
3824            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3825        }
3826    }
3827
3828    public void addPermission(long pk,
3829        com.liferay.portal.model.Permission permission)
3830        throws SystemException {
3831        try {
3832            addPermission.add(pk, permission.getPrimaryKey());
3833        }
3834        catch (Exception e) {
3835            throw processException(e);
3836        }
3837        finally {
3838            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3839        }
3840    }
3841
3842    public void addPermissions(long pk, long[] permissionPKs)
3843        throws SystemException {
3844        try {
3845            for (long permissionPK : permissionPKs) {
3846                addPermission.add(pk, permissionPK);
3847            }
3848        }
3849        catch (Exception e) {
3850            throw processException(e);
3851        }
3852        finally {
3853            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3854        }
3855    }
3856
3857    public void addPermissions(long pk,
3858        List<com.liferay.portal.model.Permission> permissions)
3859        throws SystemException {
3860        try {
3861            for (com.liferay.portal.model.Permission permission : permissions) {
3862                addPermission.add(pk, permission.getPrimaryKey());
3863            }
3864        }
3865        catch (Exception e) {
3866            throw processException(e);
3867        }
3868        finally {
3869            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3870        }
3871    }
3872
3873    public void clearPermissions(long pk) throws SystemException {
3874        try {
3875            clearPermissions.clear(pk);
3876        }
3877        catch (Exception e) {
3878            throw processException(e);
3879        }
3880        finally {
3881            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3882        }
3883    }
3884
3885    public void removePermission(long pk, long permissionPK)
3886        throws SystemException {
3887        try {
3888            removePermission.remove(pk, permissionPK);
3889        }
3890        catch (Exception e) {
3891            throw processException(e);
3892        }
3893        finally {
3894            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3895        }
3896    }
3897
3898    public void removePermission(long pk,
3899        com.liferay.portal.model.Permission permission)
3900        throws SystemException {
3901        try {
3902            removePermission.remove(pk, permission.getPrimaryKey());
3903        }
3904        catch (Exception e) {
3905            throw processException(e);
3906        }
3907        finally {
3908            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3909        }
3910    }
3911
3912    public void removePermissions(long pk, long[] permissionPKs)
3913        throws SystemException {
3914        try {
3915            for (long permissionPK : permissionPKs) {
3916                removePermission.remove(pk, permissionPK);
3917            }
3918        }
3919        catch (Exception e) {
3920            throw processException(e);
3921        }
3922        finally {
3923            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3924        }
3925    }
3926
3927    public void removePermissions(long pk,
3928        List<com.liferay.portal.model.Permission> permissions)
3929        throws SystemException {
3930        try {
3931            for (com.liferay.portal.model.Permission permission : permissions) {
3932                removePermission.remove(pk, permission.getPrimaryKey());
3933            }
3934        }
3935        catch (Exception e) {
3936            throw processException(e);
3937        }
3938        finally {
3939            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3940        }
3941    }
3942
3943    public void setPermissions(long pk, long[] permissionPKs)
3944        throws SystemException {
3945        try {
3946            Set<Long> permissionPKSet = SetUtil.fromArray(permissionPKs);
3947
3948            List<com.liferay.portal.model.Permission> permissions = getPermissions(pk);
3949
3950            for (com.liferay.portal.model.Permission permission : permissions) {
3951                if (!permissionPKSet.contains(permission.getPrimaryKey())) {
3952                    removePermission.remove(pk, permission.getPrimaryKey());
3953                }
3954                else {
3955                    permissionPKSet.remove(permission.getPrimaryKey());
3956                }
3957            }
3958
3959            for (Long permissionPK : permissionPKSet) {
3960                addPermission.add(pk, permissionPK);
3961            }
3962        }
3963        catch (Exception e) {
3964            throw processException(e);
3965        }
3966        finally {
3967            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3968        }
3969    }
3970
3971    public void setPermissions(long pk,
3972        List<com.liferay.portal.model.Permission> permissions)
3973        throws SystemException {
3974        try {
3975            long[] permissionPKs = new long[permissions.size()];
3976
3977            for (int i = 0; i < permissions.size(); i++) {
3978                com.liferay.portal.model.Permission permission = permissions.get(i);
3979
3980                permissionPKs[i] = permission.getPrimaryKey();
3981            }
3982
3983            setPermissions(pk, permissionPKs);
3984        }
3985        catch (Exception e) {
3986            throw processException(e);
3987        }
3988        finally {
3989            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
3990        }
3991    }
3992
3993    public List<com.liferay.portal.model.Role> getRoles(long pk)
3994        throws SystemException {
3995        return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3996    }
3997
3998    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
3999        int end) throws SystemException {
4000        return getRoles(pk, start, end, null);
4001    }
4002
4003    public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
4004            UserModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
4005            UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getRoles",
4006            new String[] {
4007                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
4008                "com.liferay.portal.kernel.util.OrderByComparator"
4009            });
4010
4011    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
4012        int end, OrderByComparator obc) throws SystemException {
4013        Object[] finderArgs = new Object[] {
4014                new Long(pk), String.valueOf(start), String.valueOf(end),
4015                String.valueOf(obc)
4016            };
4017
4018        List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
4019                finderArgs, this);
4020
4021        if (list == null) {
4022            Session session = null;
4023
4024            try {
4025                session = openSession();
4026
4027                String sql = null;
4028
4029                if (obc != null) {
4030                    sql = _SQL_GETROLES.concat(ORDER_BY_CLAUSE)
4031                                       .concat(obc.getOrderBy());
4032                }
4033
4034                else {
4035                    sql = _SQL_GETROLES.concat(com.liferay.portal.model.impl.RoleModelImpl.ORDER_BY_SQL);
4036                }
4037
4038                SQLQuery q = session.createSQLQuery(sql);
4039
4040                q.addEntity("Role_",
4041                    com.liferay.portal.model.impl.RoleImpl.class);
4042
4043                QueryPos qPos = QueryPos.getInstance(q);
4044
4045                qPos.add(pk);
4046
4047                list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
4048                        getDialect(), start, end);
4049            }
4050            catch (Exception e) {
4051                throw processException(e);
4052            }
4053            finally {
4054                if (list == null) {
4055                    list = new ArrayList<com.liferay.portal.model.Role>();
4056                }
4057
4058                rolePersistence.cacheResult(list);
4059
4060                FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES, finderArgs,
4061                    list);
4062
4063                closeSession(session);
4064            }
4065        }
4066
4067        return list;
4068    }
4069
4070    public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
4071            UserModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
4072            UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getRolesSize",
4073            new String[] { Long.class.getName() });
4074
4075    public int getRolesSize(long pk) throws SystemException {
4076        Object[] finderArgs = new Object[] { new Long(pk) };
4077
4078        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
4079                finderArgs, this);
4080
4081        if (count == null) {
4082            Session session = null;
4083
4084            try {
4085                session = openSession();
4086
4087                SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
4088
4089                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
4090
4091                QueryPos qPos = QueryPos.getInstance(q);
4092
4093                qPos.add(pk);
4094
4095                count = (Long)q.uniqueResult();
4096            }
4097            catch (Exception e) {
4098                throw processException(e);
4099            }
4100            finally {
4101                if (count == null) {
4102                    count = Long.valueOf(0);
4103                }
4104
4105                FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
4106                    finderArgs, count);
4107
4108                closeSession(session);
4109            }
4110        }
4111
4112        return count.intValue();
4113    }
4114
4115    public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
4116            UserModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
4117            UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "containsRole",
4118            new String[] { Long.class.getName(), Long.class.getName() });
4119
4120    public boolean containsRole(long pk, long rolePK) throws SystemException {
4121        Object[] finderArgs = new Object[] { new Long(pk), new Long(rolePK) };
4122
4123        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
4124                finderArgs, this);
4125
4126        if (value == null) {
4127            try {
4128                value = Boolean.valueOf(containsRole.contains(pk, rolePK));
4129            }
4130            catch (Exception e) {
4131                throw processException(e);
4132            }
4133            finally {
4134                if (value == null) {
4135                    value = Boolean.FALSE;
4136                }
4137
4138                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
4139                    finderArgs, value);
4140            }
4141        }
4142
4143        return value.booleanValue();
4144    }
4145
4146    public boolean containsRoles(long pk) throws SystemException {
4147        if (getRolesSize(pk) > 0) {
4148            return true;
4149        }
4150        else {
4151            return false;
4152        }
4153    }
4154
4155    public void addRole(long pk, long rolePK) throws SystemException {
4156        try {
4157            addRole.add(pk, rolePK);
4158        }
4159        catch (Exception e) {
4160            throw processException(e);
4161        }
4162        finally {
4163            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4164        }
4165    }
4166
4167    public void addRole(long pk, com.liferay.portal.model.Role role)
4168        throws SystemException {
4169        try {
4170            addRole.add(pk, role.getPrimaryKey());
4171        }
4172        catch (Exception e) {
4173            throw processException(e);
4174        }
4175        finally {
4176            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4177        }
4178    }
4179
4180    public void addRoles(long pk, long[] rolePKs) throws SystemException {
4181        try {
4182            for (long rolePK : rolePKs) {
4183                addRole.add(pk, rolePK);
4184            }
4185        }
4186        catch (Exception e) {
4187            throw processException(e);
4188        }
4189        finally {
4190            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4191        }
4192    }
4193
4194    public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
4195        throws SystemException {
4196        try {
4197            for (com.liferay.portal.model.Role role : roles) {
4198                addRole.add(pk, role.getPrimaryKey());
4199            }
4200        }
4201        catch (Exception e) {
4202            throw processException(e);
4203        }
4204        finally {
4205            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4206        }
4207    }
4208
4209    public void clearRoles(long pk) throws SystemException {
4210        try {
4211            clearRoles.clear(pk);
4212        }
4213        catch (Exception e) {
4214            throw processException(e);
4215        }
4216        finally {
4217            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4218        }
4219    }
4220
4221    public void removeRole(long pk, long rolePK) throws SystemException {
4222        try {
4223            removeRole.remove(pk, rolePK);
4224        }
4225        catch (Exception e) {
4226            throw processException(e);
4227        }
4228        finally {
4229            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4230        }
4231    }
4232
4233    public void removeRole(long pk, com.liferay.portal.model.Role role)
4234        throws SystemException {
4235        try {
4236            removeRole.remove(pk, role.getPrimaryKey());
4237        }
4238        catch (Exception e) {
4239            throw processException(e);
4240        }
4241        finally {
4242            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4243        }
4244    }
4245
4246    public void removeRoles(long pk, long[] rolePKs) throws SystemException {
4247        try {
4248            for (long rolePK : rolePKs) {
4249                removeRole.remove(pk, rolePK);
4250            }
4251        }
4252        catch (Exception e) {
4253            throw processException(e);
4254        }
4255        finally {
4256            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4257        }
4258    }
4259
4260    public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
4261        throws SystemException {
4262        try {
4263            for (com.liferay.portal.model.Role role : roles) {
4264                removeRole.remove(pk, role.getPrimaryKey());
4265            }
4266        }
4267        catch (Exception e) {
4268            throw processException(e);
4269        }
4270        finally {
4271            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4272        }
4273    }
4274
4275    public void setRoles(long pk, long[] rolePKs) throws SystemException {
4276        try {
4277            Set<Long> rolePKSet = SetUtil.fromArray(rolePKs);
4278
4279            List<com.liferay.portal.model.Role> roles = getRoles(pk);
4280
4281            for (com.liferay.portal.model.Role role : roles) {
4282                if (!rolePKSet.contains(role.getPrimaryKey())) {
4283                    removeRole.remove(pk, role.getPrimaryKey());
4284                }
4285                else {
4286                    rolePKSet.remove(role.getPrimaryKey());
4287                }
4288            }
4289
4290            for (Long rolePK : rolePKSet) {
4291                addRole.add(pk, rolePK);
4292            }
4293        }
4294        catch (Exception e) {
4295            throw processException(e);
4296        }
4297        finally {
4298            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4299        }
4300    }
4301
4302    public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
4303        throws SystemException {
4304        try {
4305            long[] rolePKs = new long[roles.size()];
4306
4307            for (int i = 0; i < roles.size(); i++) {
4308                com.liferay.portal.model.Role role = roles.get(i);
4309
4310                rolePKs[i] = role.getPrimaryKey();
4311            }
4312
4313            setRoles(pk, rolePKs);
4314        }
4315        catch (Exception e) {
4316            throw processException(e);
4317        }
4318        finally {
4319            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4320        }
4321    }
4322
4323    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk)
4324        throws SystemException {
4325        return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4326    }
4327
4328    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
4329        int start, int end) throws SystemException {
4330        return getUserGroups(pk, start, end, null);
4331    }
4332
4333    public static final FinderPath FINDER_PATH_GET_USERGROUPS = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4334            UserModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
4335            UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME, "getUserGroups",
4336            new String[] {
4337                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
4338                "com.liferay.portal.kernel.util.OrderByComparator"
4339            });
4340
4341    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
4342        int start, int end, OrderByComparator obc) throws SystemException {
4343        Object[] finderArgs = new Object[] {
4344                new Long(pk), String.valueOf(start), String.valueOf(end),
4345                String.valueOf(obc)
4346            };
4347
4348        List<com.liferay.portal.model.UserGroup> list = (List<com.liferay.portal.model.UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS,
4349                finderArgs, this);
4350
4351        if (list == null) {
4352            Session session = null;
4353
4354            try {
4355                session = openSession();
4356
4357                String sql = null;
4358
4359                if (obc != null) {
4360                    sql = _SQL_GETUSERGROUPS.concat(ORDER_BY_CLAUSE)
4361                                            .concat(obc.getOrderBy());
4362                }
4363
4364                else {
4365                    sql = _SQL_GETUSERGROUPS.concat(com.liferay.portal.model.impl.UserGroupModelImpl.ORDER_BY_SQL);
4366                }
4367
4368                SQLQuery q = session.createSQLQuery(sql);
4369
4370                q.addEntity("UserGroup",
4371                    com.liferay.portal.model.impl.UserGroupImpl.class);
4372
4373                QueryPos qPos = QueryPos.getInstance(q);
4374
4375                qPos.add(pk);
4376
4377                list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
4378                        getDialect(), start, end);
4379            }
4380            catch (Exception e) {
4381                throw processException(e);
4382            }
4383            finally {
4384                if (list == null) {
4385                    list = new ArrayList<com.liferay.portal.model.UserGroup>();
4386                }
4387
4388                userGroupPersistence.cacheResult(list);
4389
4390                FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS,
4391                    finderArgs, list);
4392
4393                closeSession(session);
4394            }
4395        }
4396
4397        return list;
4398    }
4399
4400    public static final FinderPath FINDER_PATH_GET_USERGROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4401            UserModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
4402            UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
4403            "getUserGroupsSize", new String[] { Long.class.getName() });
4404
4405    public int getUserGroupsSize(long pk) throws SystemException {
4406        Object[] finderArgs = new Object[] { new Long(pk) };
4407
4408        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS_SIZE,
4409                finderArgs, this);
4410
4411        if (count == null) {
4412            Session session = null;
4413
4414            try {
4415                session = openSession();
4416
4417                SQLQuery q = session.createSQLQuery(_SQL_GETUSERGROUPSSIZE);
4418
4419                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
4420
4421                QueryPos qPos = QueryPos.getInstance(q);
4422
4423                qPos.add(pk);
4424
4425                count = (Long)q.uniqueResult();
4426            }
4427            catch (Exception e) {
4428                throw processException(e);
4429            }
4430            finally {
4431                if (count == null) {
4432                    count = Long.valueOf(0);
4433                }
4434
4435                FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS_SIZE,
4436                    finderArgs, count);
4437
4438                closeSession(session);
4439            }
4440        }
4441
4442        return count.intValue();
4443    }
4444
4445    public static final FinderPath FINDER_PATH_CONTAINS_USERGROUP = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4446            UserModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
4447            UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
4448            "containsUserGroup",
4449            new String[] { Long.class.getName(), Long.class.getName() });
4450
4451    public boolean containsUserGroup(long pk, long userGroupPK)
4452        throws SystemException {
4453        Object[] finderArgs = new Object[] { new Long(pk), new Long(userGroupPK) };
4454
4455        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USERGROUP,
4456                finderArgs, this);
4457
4458        if (value == null) {
4459            try {
4460                value = Boolean.valueOf(containsUserGroup.contains(pk,
4461                            userGroupPK));
4462            }
4463            catch (Exception e) {
4464                throw processException(e);
4465            }
4466            finally {
4467                if (value == null) {
4468                    value = Boolean.FALSE;
4469                }
4470
4471                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USERGROUP,
4472                    finderArgs, value);
4473            }
4474        }
4475
4476        return value.booleanValue();
4477    }
4478
4479    public boolean containsUserGroups(long pk) throws SystemException {
4480        if (getUserGroupsSize(pk) > 0) {
4481            return true;
4482        }
4483        else {
4484            return false;
4485        }
4486    }
4487
4488    public void addUserGroup(long pk, long userGroupPK)
4489        throws SystemException {
4490        try {
4491            addUserGroup.add(pk, userGroupPK);
4492        }
4493        catch (Exception e) {
4494            throw processException(e);
4495        }
4496        finally {
4497            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4498        }
4499    }
4500
4501    public void addUserGroup(long pk,
4502        com.liferay.portal.model.UserGroup userGroup) throws SystemException {
4503        try {
4504            addUserGroup.add(pk, userGroup.getPrimaryKey());
4505        }
4506        catch (Exception e) {
4507            throw processException(e);
4508        }
4509        finally {
4510            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4511        }
4512    }
4513
4514    public void addUserGroups(long pk, long[] userGroupPKs)
4515        throws SystemException {
4516        try {
4517            for (long userGroupPK : userGroupPKs) {
4518                addUserGroup.add(pk, userGroupPK);
4519            }
4520        }
4521        catch (Exception e) {
4522            throw processException(e);
4523        }
4524        finally {
4525            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4526        }
4527    }
4528
4529    public void addUserGroups(long pk,
4530        List<com.liferay.portal.model.UserGroup> userGroups)
4531        throws SystemException {
4532        try {
4533            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
4534                addUserGroup.add(pk, userGroup.getPrimaryKey());
4535            }
4536        }
4537        catch (Exception e) {
4538            throw processException(e);
4539        }
4540        finally {
4541            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4542        }
4543    }
4544
4545    public void clearUserGroups(long pk) throws SystemException {
4546        try {
4547            clearUserGroups.clear(pk);
4548        }
4549        catch (Exception e) {
4550            throw processException(e);
4551        }
4552        finally {
4553            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4554        }
4555    }
4556
4557    public void removeUserGroup(long pk, long userGroupPK)
4558        throws SystemException {
4559        try {
4560            removeUserGroup.remove(pk, userGroupPK);
4561        }
4562        catch (Exception e) {
4563            throw processException(e);
4564        }
4565        finally {
4566            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4567        }
4568    }
4569
4570    public void removeUserGroup(long pk,
4571        com.liferay.portal.model.UserGroup userGroup) throws SystemException {
4572        try {
4573            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
4574        }
4575        catch (Exception e) {
4576            throw processException(e);
4577        }
4578        finally {
4579            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4580        }
4581    }
4582
4583    public void removeUserGroups(long pk, long[] userGroupPKs)
4584        throws SystemException {
4585        try {
4586            for (long userGroupPK : userGroupPKs) {
4587                removeUserGroup.remove(pk, userGroupPK);
4588            }
4589        }
4590        catch (Exception e) {
4591            throw processException(e);
4592        }
4593        finally {
4594            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4595        }
4596    }
4597
4598    public void removeUserGroups(long pk,
4599        List<com.liferay.portal.model.UserGroup> userGroups)
4600        throws SystemException {
4601        try {
4602            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
4603                removeUserGroup.remove(pk, userGroup.getPrimaryKey());
4604            }
4605        }
4606        catch (Exception e) {
4607            throw processException(e);
4608        }
4609        finally {
4610            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4611        }
4612    }
4613
4614    public void setUserGroups(long pk, long[] userGroupPKs)
4615        throws SystemException {
4616        try {
4617            Set<Long> userGroupPKSet = SetUtil.fromArray(userGroupPKs);
4618
4619            List<com.liferay.portal.model.UserGroup> userGroups = getUserGroups(pk);
4620
4621            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
4622                if (!userGroupPKSet.contains(userGroup.getPrimaryKey())) {
4623                    removeUserGroup.remove(pk, userGroup.getPrimaryKey());
4624                }
4625                else {
4626                    userGroupPKSet.remove(userGroup.getPrimaryKey());
4627                }
4628            }
4629
4630            for (Long userGroupPK : userGroupPKSet) {
4631                addUserGroup.add(pk, userGroupPK);
4632            }
4633        }
4634        catch (Exception e) {
4635            throw processException(e);
4636        }
4637        finally {
4638            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4639        }
4640    }
4641
4642    public void setUserGroups(long pk,
4643        List<com.liferay.portal.model.UserGroup> userGroups)
4644        throws SystemException {
4645        try {
4646            long[] userGroupPKs = new long[userGroups.size()];
4647
4648            for (int i = 0; i < userGroups.size(); i++) {
4649                com.liferay.portal.model.UserGroup userGroup = userGroups.get(i);
4650
4651                userGroupPKs[i] = userGroup.getPrimaryKey();
4652            }
4653
4654            setUserGroups(pk, userGroupPKs);
4655        }
4656        catch (Exception e) {
4657            throw processException(e);
4658        }
4659        finally {
4660            FinderCacheUtil.clearCache(UserModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4661        }
4662    }
4663
4664    public void afterPropertiesSet() {
4665        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4666                    com.liferay.portal.util.PropsUtil.get(
4667                        "value.object.listener.com.liferay.portal.model.User")));
4668
4669        if (listenerClassNames.length > 0) {
4670            try {
4671                List<ModelListener<User>> listenersList = new ArrayList<ModelListener<User>>();
4672
4673                for (String listenerClassName : listenerClassNames) {
4674                    listenersList.add((ModelListener<User>)Class.forName(
4675                            listenerClassName).newInstance());
4676                }
4677
4678                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4679            }
4680            catch (Exception e) {
4681                _log.error(e);
4682            }
4683        }
4684
4685        containsGroup = new ContainsGroup(this);
4686
4687        addGroup = new AddGroup(this);
4688        clearGroups = new ClearGroups(this);
4689        removeGroup = new RemoveGroup(this);
4690
4691        containsOrganization = new ContainsOrganization(this);
4692
4693        addOrganization = new AddOrganization(this);
4694        clearOrganizations = new ClearOrganizations(this);
4695        removeOrganization = new RemoveOrganization(this);
4696
4697        containsPermission = new ContainsPermission(this);
4698
4699        addPermission = new AddPermission(this);
4700        clearPermissions = new ClearPermissions(this);
4701        removePermission = new RemovePermission(this);
4702
4703        containsRole = new ContainsRole(this);
4704
4705        addRole = new AddRole(this);
4706        clearRoles = new ClearRoles(this);
4707        removeRole = new RemoveRole(this);
4708
4709        containsUserGroup = new ContainsUserGroup(this);
4710
4711        addUserGroup = new AddUserGroup(this);
4712        clearUserGroups = new ClearUserGroups(this);
4713        removeUserGroup = new RemoveUserGroup(this);
4714    }
4715
4716    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
4717    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
4718    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
4719    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
4720    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
4721    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
4722    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
4723    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
4724    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
4725    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
4726    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
4727    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
4728    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
4729    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
4730    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
4731    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
4732    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
4733    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
4734    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
4735    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
4736    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
4737    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
4738    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPrototypePersistence")
4739    protected com.liferay.portal.service.persistence.LayoutPrototypePersistence layoutPrototypePersistence;
4740    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
4741    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
4742    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPrototypePersistence")
4743    protected com.liferay.portal.service.persistence.LayoutSetPrototypePersistence layoutSetPrototypePersistence;
4744    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
4745    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
4746    @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
4747    protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
4748    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
4749    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
4750    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
4751    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
4752    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
4753    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
4754    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
4755    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
4756    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
4757    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
4758    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
4759    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
4760    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
4761    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
4762    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
4763    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
4764    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
4765    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
4766    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
4767    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
4768    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
4769    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
4770    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
4771    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
4772    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
4773    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
4774    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
4775    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
4776    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
4777    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
4778    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
4779    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
4780    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
4781    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
4782    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
4783    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
4784    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
4785    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
4786    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
4787    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
4788    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
4789    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
4790    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
4791    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
4792    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
4793    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
4794    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
4795    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
4796    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
4797    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
4798    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
4799    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
4800    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence")
4801    protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
4802    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
4803    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
4804    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
4805    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
4806    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
4807    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
4808    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
4809    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
4810    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
4811    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
4812    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
4813    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
4814    @BeanReference(name = "com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence")
4815    protected com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
4816    @BeanReference(name = "com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence")
4817    protected com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
4818    @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence")
4819    protected com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
4820    @BeanReference(name = "com.liferay.portlet.asset.service.persistence.AssetEntryPersistence")
4821    protected com.liferay.portlet.asset.service.persistence.AssetEntryPersistence assetEntryPersistence;
4822    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence")
4823    protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
4824    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence")
4825    protected com.liferay.portlet.documentlibrary.service.persistence.DLFileRankPersistence dlFileRankPersistence;
4826    @BeanReference(name = "com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence")
4827    protected com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence expandoValuePersistence;
4828    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBBanPersistence")
4829    protected com.liferay.portlet.messageboards.service.persistence.MBBanPersistence mbBanPersistence;
4830    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence")
4831    protected com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence mbMessageFlagPersistence;
4832    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence")
4833    protected com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence mbStatsUserPersistence;
4834    @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence")
4835    protected com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence shoppingCartPersistence;
4836    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence")
4837    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
4838    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialRequestPersistence")
4839    protected com.liferay.portlet.social.service.persistence.SocialRequestPersistence socialRequestPersistence;
4840    protected ContainsGroup containsGroup;
4841    protected AddGroup addGroup;
4842    protected ClearGroups clearGroups;
4843    protected RemoveGroup removeGroup;
4844    protected ContainsOrganization containsOrganization;
4845    protected AddOrganization addOrganization;
4846    protected ClearOrganizations clearOrganizations;
4847    protected RemoveOrganization removeOrganization;
4848    protected ContainsPermission containsPermission;
4849    protected AddPermission addPermission;
4850    protected ClearPermissions clearPermissions;
4851    protected RemovePermission removePermission;
4852    protected ContainsRole containsRole;
4853    protected AddRole addRole;
4854    protected ClearRoles clearRoles;
4855    protected RemoveRole removeRole;
4856    protected ContainsUserGroup containsUserGroup;
4857    protected AddUserGroup addUserGroup;
4858    protected ClearUserGroups clearUserGroups;
4859    protected RemoveUserGroup removeUserGroup;
4860
4861    protected class ContainsGroup {
4862        protected ContainsGroup(UserPersistenceImpl persistenceImpl) {
4863            super();
4864
4865            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4866                    _SQL_CONTAINSGROUP,
4867                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
4868        }
4869
4870        protected boolean contains(long userId, long groupId) {
4871            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4872                        new Long(userId), new Long(groupId)
4873                    });
4874
4875            if (results.size() > 0) {
4876                Integer count = results.get(0);
4877
4878                if (count.intValue() > 0) {
4879                    return true;
4880                }
4881            }
4882
4883            return false;
4884        }
4885
4886        private MappingSqlQuery<Integer> _mappingSqlQuery;
4887    }
4888
4889    protected class AddGroup {
4890        protected AddGroup(UserPersistenceImpl persistenceImpl) {
4891            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4892                    "INSERT INTO Users_Groups (userId, groupId) VALUES (?, ?)",
4893                    new int[] { Types.BIGINT, Types.BIGINT });
4894            _persistenceImpl = persistenceImpl;
4895        }
4896
4897        protected void add(long userId, long groupId) throws SystemException {
4898            if (!_persistenceImpl.containsGroup.contains(userId, groupId)) {
4899                ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4900
4901                for (ModelListener<User> listener : listeners) {
4902                    listener.onBeforeAddAssociation(userId,
4903                        com.liferay.portal.model.Group.class.getName(), groupId);
4904                }
4905
4906                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4907                    listener.onBeforeAddAssociation(groupId,
4908                        User.class.getName(), userId);
4909                }
4910
4911                _sqlUpdate.update(new Object[] {
4912                        new Long(userId), new Long(groupId)
4913                    });
4914
4915                for (ModelListener<User> listener : listeners) {
4916                    listener.onAfterAddAssociation(userId,
4917                        com.liferay.portal.model.Group.class.getName(), groupId);
4918                }
4919
4920                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4921                    listener.onAfterAddAssociation(groupId,
4922                        User.class.getName(), userId);
4923                }
4924            }
4925        }
4926
4927        private SqlUpdate _sqlUpdate;
4928        private UserPersistenceImpl _persistenceImpl;
4929    }
4930
4931    protected class ClearGroups {
4932        protected ClearGroups(UserPersistenceImpl persistenceImpl) {
4933            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4934                    "DELETE FROM Users_Groups WHERE userId = ?",
4935                    new int[] { Types.BIGINT });
4936        }
4937
4938        protected void clear(long userId) throws SystemException {
4939            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4940
4941            List<com.liferay.portal.model.Group> groups = null;
4942
4943            if ((listeners.length > 0) || (groupListeners.length > 0)) {
4944                groups = getGroups(userId);
4945
4946                for (com.liferay.portal.model.Group group : groups) {
4947                    for (ModelListener<User> listener : listeners) {
4948                        listener.onBeforeRemoveAssociation(userId,
4949                            com.liferay.portal.model.Group.class.getName(),
4950                            group.getPrimaryKey());
4951                    }
4952
4953                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4954                        listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
4955                            User.class.getName(), userId);
4956                    }
4957                }
4958            }
4959
4960            _sqlUpdate.update(new Object[] { new Long(userId) });
4961
4962            if ((listeners.length > 0) || (groupListeners.length > 0)) {
4963                for (com.liferay.portal.model.Group group : groups) {
4964                    for (ModelListener<User> listener : listeners) {
4965                        listener.onAfterRemoveAssociation(userId,
4966                            com.liferay.portal.model.Group.class.getName(),
4967                            group.getPrimaryKey());
4968                    }
4969
4970                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4971                        listener.onAfterRemoveAssociation(group.getPrimaryKey(),
4972                            User.class.getName(), userId);
4973                    }
4974                }
4975            }
4976        }
4977
4978        private SqlUpdate _sqlUpdate;
4979    }
4980
4981    protected class RemoveGroup {
4982        protected RemoveGroup(UserPersistenceImpl persistenceImpl) {
4983            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4984                    "DELETE FROM Users_Groups WHERE userId = ? AND groupId = ?",
4985                    new int[] { Types.BIGINT, Types.BIGINT });
4986            _persistenceImpl = persistenceImpl;
4987        }
4988
4989        protected void remove(long userId, long groupId)
4990            throws SystemException {
4991            if (_persistenceImpl.containsGroup.contains(userId, groupId)) {
4992                ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4993
4994                for (ModelListener<User> listener : listeners) {
4995                    listener.onBeforeRemoveAssociation(userId,
4996                        com.liferay.portal.model.Group.class.getName(), groupId);
4997                }
4998
4999                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
5000                    listener.onBeforeRemoveAssociation(groupId,
5001                        User.class.getName(), userId);
5002                }
5003
5004                _sqlUpdate.update(new Object[] {
5005                        new Long(userId), new Long(groupId)
5006                    });
5007
5008                for (ModelListener<User> listener : listeners) {
5009                    listener.onAfterRemoveAssociation(userId,
5010                        com.liferay.portal.model.Group.class.getName(), groupId);
5011                }
5012
5013                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
5014                    listener.onAfterRemoveAssociation(groupId,
5015                        User.class.getName(), userId);
5016                }
5017            }
5018        }
5019
5020        private SqlUpdate _sqlUpdate;
5021        private UserPersistenceImpl _persistenceImpl;
5022    }
5023
5024    protected class ContainsOrganization {
5025        protected ContainsOrganization(UserPersistenceImpl persistenceImpl) {
5026            super();
5027
5028            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5029                    _SQL_CONTAINSORGANIZATION,
5030                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
5031        }
5032
5033        protected boolean contains(long userId, long organizationId) {
5034            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5035                        new Long(userId), new Long(organizationId)
5036                    });
5037
5038            if (results.size() > 0) {
5039                Integer count = results.get(0);
5040
5041                if (count.intValue() > 0) {
5042                    return true;
5043                }
5044            }
5045
5046            return false;
5047        }
5048
5049        private MappingSqlQuery<Integer> _mappingSqlQuery;
5050    }
5051
5052    protected class AddOrganization {
5053        protected AddOrganization(UserPersistenceImpl persistenceImpl) {
5054            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5055                    "INSERT INTO Users_Orgs (userId, organizationId) VALUES (?, ?)",
5056                    new int[] { Types.BIGINT, Types.BIGINT });
5057            _persistenceImpl = persistenceImpl;
5058        }
5059
5060        protected void add(long userId, long organizationId)
5061            throws SystemException {
5062            if (!_persistenceImpl.containsOrganization.contains(userId,
5063                        organizationId)) {
5064                ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
5065                    organizationPersistence.getListeners();
5066
5067                for (ModelListener<User> listener : listeners) {
5068                    listener.onBeforeAddAssociation(userId,
5069                        com.liferay.portal.model.Organization.class.getName(),
5070                        organizationId);
5071                }
5072
5073                for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
5074                    listener.onBeforeAddAssociation(organizationId,
5075                        User.class.getName(), userId);
5076                }
5077
5078                _sqlUpdate.update(new Object[] {
5079                        new Long(userId), new Long(organizationId)
5080                    });
5081
5082                for (ModelListener<User> listener : listeners) {
5083                    listener.onAfterAddAssociation(userId,
5084                        com.liferay.portal.model.Organization.class.getName(),
5085                        organizationId);
5086                }
5087
5088                for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
5089                    listener.onAfterAddAssociation(organizationId,
5090                        User.class.getName(), userId);
5091                }
5092            }
5093        }
5094
5095        private SqlUpdate _sqlUpdate;
5096        private UserPersistenceImpl _persistenceImpl;
5097    }
5098
5099    protected class ClearOrganizations {
5100        protected ClearOrganizations(UserPersistenceImpl persistenceImpl) {
5101            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5102                    "DELETE FROM Users_Orgs WHERE userId = ?",
5103                    new int[] { Types.BIGINT });
5104        }
5105
5106        protected void clear(long userId) throws SystemException {
5107            ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
5108                organizationPersistence.getListeners();
5109
5110            List<com.liferay.portal.model.Organization> organizations = null;
5111
5112            if ((listeners.length > 0) || (organizationListeners.length > 0)) {
5113                organizations = getOrganizations(userId);
5114
5115                for (com.liferay.portal.model.Organization organization : organizations) {
5116                    for (ModelListener<User> listener : listeners) {
5117                        listener.onBeforeRemoveAssociation(userId,
5118                            com.liferay.portal.model.Organization.class.getName(),
5119                            organization.getPrimaryKey());
5120                    }
5121
5122                    for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
5123                        listener.onBeforeRemoveAssociation(organization.getPrimaryKey(),
5124                            User.class.getName(), userId);
5125                    }
5126                }
5127            }
5128
5129            _sqlUpdate.update(new Object[] { new Long(userId) });
5130
5131            if ((listeners.length > 0) || (organizationListeners.length > 0)) {
5132                for (com.liferay.portal.model.Organization organization : organizations) {
5133                    for (ModelListener<User> listener : listeners) {
5134                        listener.onAfterRemoveAssociation(userId,
5135                            com.liferay.portal.model.Organization.class.getName(),
5136                            organization.getPrimaryKey());
5137                    }
5138
5139                    for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
5140                        listener.onAfterRemoveAssociation(organization.getPrimaryKey(),
5141                            User.class.getName(), userId);
5142                    }
5143                }
5144            }
5145        }
5146
5147        private SqlUpdate _sqlUpdate;
5148    }
5149
5150    protected class RemoveOrganization {
5151        protected RemoveOrganization(UserPersistenceImpl persistenceImpl) {
5152            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5153                    "DELETE FROM Users_Orgs WHERE userId = ? AND organizationId = ?",
5154                    new int[] { Types.BIGINT, Types.BIGINT });
5155            _persistenceImpl = persistenceImpl;
5156        }
5157
5158        protected void remove(long userId, long organizationId)
5159            throws SystemException {
5160            if (_persistenceImpl.containsOrganization.contains(userId,
5161                        organizationId)) {
5162                ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
5163                    organizationPersistence.getListeners();
5164
5165                for (ModelListener<User> listener : listeners) {
5166                    listener.onBeforeRemoveAssociation(userId,
5167                        com.liferay.portal.model.Organization.class.getName(),
5168                        organizationId);
5169                }
5170
5171                for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
5172                    listener.onBeforeRemoveAssociation(organizationId,
5173                        User.class.getName(), userId);
5174                }
5175
5176                _sqlUpdate.update(new Object[] {
5177                        new Long(userId), new Long(organizationId)
5178                    });
5179
5180                for (ModelListener<User> listener : listeners) {
5181                    listener.onAfterRemoveAssociation(userId,
5182                        com.liferay.portal.model.Organization.class.getName(),
5183                        organizationId);
5184                }
5185
5186                for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
5187                    listener.onAfterRemoveAssociation(organizationId,
5188                        User.class.getName(), userId);
5189                }
5190            }
5191        }
5192
5193        private SqlUpdate _sqlUpdate;
5194        private UserPersistenceImpl _persistenceImpl;
5195    }
5196
5197    protected class ContainsPermission {
5198        protected ContainsPermission(UserPersistenceImpl persistenceImpl) {
5199            super();
5200
5201            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5202                    _SQL_CONTAINSPERMISSION,
5203                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
5204        }
5205
5206        protected boolean contains(long userId, long permissionId) {
5207            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5208                        new Long(userId), new Long(permissionId)
5209                    });
5210
5211            if (results.size() > 0) {
5212                Integer count = results.get(0);
5213
5214                if (count.intValue() > 0) {
5215                    return true;
5216                }
5217            }
5218
5219            return false;
5220        }
5221
5222        private MappingSqlQuery<Integer> _mappingSqlQuery;
5223    }
5224
5225    protected class AddPermission {
5226        protected AddPermission(UserPersistenceImpl persistenceImpl) {
5227            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5228                    "INSERT INTO Users_Permissions (userId, permissionId) VALUES (?, ?)",
5229                    new int[] { Types.BIGINT, Types.BIGINT });
5230            _persistenceImpl = persistenceImpl;
5231        }
5232
5233        protected void add(long userId, long permissionId)
5234            throws SystemException {
5235            if (!_persistenceImpl.containsPermission.contains(userId,
5236                        permissionId)) {
5237                ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
5238                    permissionPersistence.getListeners();
5239
5240                for (ModelListener<User> listener : listeners) {
5241                    listener.onBeforeAddAssociation(userId,
5242                        com.liferay.portal.model.Permission.class.getName(),
5243                        permissionId);
5244                }
5245
5246                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
5247                    listener.onBeforeAddAssociation(permissionId,
5248                        User.class.getName(), userId);
5249                }
5250
5251                _sqlUpdate.update(new Object[] {
5252                        new Long(userId), new Long(permissionId)
5253                    });
5254
5255                for (ModelListener<User> listener : listeners) {
5256                    listener.onAfterAddAssociation(userId,
5257                        com.liferay.portal.model.Permission.class.getName(),
5258                        permissionId);
5259                }
5260
5261                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
5262                    listener.onAfterAddAssociation(permissionId,
5263                        User.class.getName(), userId);
5264                }
5265            }
5266        }
5267
5268        private SqlUpdate _sqlUpdate;
5269        private UserPersistenceImpl _persistenceImpl;
5270    }
5271
5272    protected class ClearPermissions {
5273        protected ClearPermissions(UserPersistenceImpl persistenceImpl) {
5274            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5275                    "DELETE FROM Users_Permissions WHERE userId = ?",
5276                    new int[] { Types.BIGINT });
5277        }
5278
5279        protected void clear(long userId) throws SystemException {
5280            ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
5281                permissionPersistence.getListeners();
5282
5283            List<com.liferay.portal.model.Permission> permissions = null;
5284
5285            if ((listeners.length > 0) || (permissionListeners.length > 0)) {
5286                permissions = getPermissions(userId);
5287
5288                for (com.liferay.portal.model.Permission permission : permissions) {
5289                    for (ModelListener<User> listener : listeners) {
5290                        listener.onBeforeRemoveAssociation(userId,
5291                            com.liferay.portal.model.Permission.class.getName(),
5292                            permission.getPrimaryKey());
5293                    }
5294
5295                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
5296                        listener.onBeforeRemoveAssociation(permission.getPrimaryKey(),
5297                            User.class.getName(), userId);
5298                    }
5299                }
5300            }
5301
5302            _sqlUpdate.update(new Object[] { new Long(userId) });
5303
5304            if ((listeners.length > 0) || (permissionListeners.length > 0)) {
5305                for (com.liferay.portal.model.Permission permission : permissions) {
5306                    for (ModelListener<User> listener : listeners) {
5307                        listener.onAfterRemoveAssociation(userId,
5308                            com.liferay.portal.model.Permission.class.getName(),
5309                            permission.getPrimaryKey());
5310                    }
5311
5312                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
5313                        listener.onAfterRemoveAssociation(permission.getPrimaryKey(),
5314                            User.class.getName(), userId);
5315                    }
5316                }
5317            }
5318        }
5319
5320        private SqlUpdate _sqlUpdate;
5321    }
5322
5323    protected class RemovePermission {
5324        protected RemovePermission(UserPersistenceImpl persistenceImpl) {
5325            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5326                    "DELETE FROM Users_Permissions WHERE userId = ? AND permissionId = ?",
5327                    new int[] { Types.BIGINT, Types.BIGINT });
5328            _persistenceImpl = persistenceImpl;
5329        }
5330
5331        protected void remove(long userId, long permissionId)
5332            throws SystemException {
5333            if (_persistenceImpl.containsPermission.contains(userId,
5334                        permissionId)) {
5335                ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
5336                    permissionPersistence.getListeners();
5337
5338                for (ModelListener<User> listener : listeners) {
5339                    listener.onBeforeRemoveAssociation(userId,
5340                        com.liferay.portal.model.Permission.class.getName(),
5341                        permissionId);
5342                }
5343
5344                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
5345                    listener.onBeforeRemoveAssociation(permissionId,
5346                        User.class.getName(), userId);
5347                }
5348
5349                _sqlUpdate.update(new Object[] {
5350                        new Long(userId), new Long(permissionId)
5351                    });
5352
5353                for (ModelListener<User> listener : listeners) {
5354                    listener.onAfterRemoveAssociation(userId,
5355                        com.liferay.portal.model.Permission.class.getName(),
5356                        permissionId);
5357                }
5358
5359                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
5360                    listener.onAfterRemoveAssociation(permissionId,
5361                        User.class.getName(), userId);
5362                }
5363            }
5364        }
5365
5366        private SqlUpdate _sqlUpdate;
5367        private UserPersistenceImpl _persistenceImpl;
5368    }
5369
5370    protected class ContainsRole {
5371        protected ContainsRole(UserPersistenceImpl persistenceImpl) {
5372            super();
5373
5374            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5375                    _SQL_CONTAINSROLE,
5376                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
5377        }
5378
5379        protected boolean contains(long userId, long roleId) {
5380            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5381                        new Long(userId), new Long(roleId)
5382                    });
5383
5384            if (results.size() > 0) {
5385                Integer count = results.get(0);
5386
5387                if (count.intValue() > 0) {
5388                    return true;
5389                }
5390            }
5391
5392            return false;
5393        }
5394
5395        private MappingSqlQuery<Integer> _mappingSqlQuery;
5396    }
5397
5398    protected class AddRole {
5399        protected AddRole(UserPersistenceImpl persistenceImpl) {
5400            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5401                    "INSERT INTO Users_Roles (userId, roleId) VALUES (?, ?)",
5402                    new int[] { Types.BIGINT, Types.BIGINT });
5403            _persistenceImpl = persistenceImpl;
5404        }
5405
5406        protected void add(long userId, long roleId) throws SystemException {
5407            if (!_persistenceImpl.containsRole.contains(userId, roleId)) {
5408                ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
5409
5410                for (ModelListener<User> listener : listeners) {
5411                    listener.onBeforeAddAssociation(userId,
5412                        com.liferay.portal.model.Role.class.getName(), roleId);
5413                }
5414
5415                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
5416                    listener.onBeforeAddAssociation(roleId,
5417                        User.class.getName(), userId);
5418                }
5419
5420                _sqlUpdate.update(new Object[] {
5421                        new Long(userId), new Long(roleId)
5422                    });
5423
5424                for (ModelListener<User> listener : listeners) {
5425                    listener.onAfterAddAssociation(userId,
5426                        com.liferay.portal.model.Role.class.getName(), roleId);
5427                }
5428
5429                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
5430                    listener.onAfterAddAssociation(roleId,
5431                        User.class.getName(), userId);
5432                }
5433            }
5434        }
5435
5436        private SqlUpdate _sqlUpdate;
5437        private UserPersistenceImpl _persistenceImpl;
5438    }
5439
5440    protected class ClearRoles {
5441        protected ClearRoles(UserPersistenceImpl persistenceImpl) {
5442            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5443                    "DELETE FROM Users_Roles WHERE userId = ?",
5444                    new int[] { Types.BIGINT });
5445        }
5446
5447        protected void clear(long userId) throws SystemException {
5448            ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
5449
5450            List<com.liferay.portal.model.Role> roles = null;
5451
5452            if ((listeners.length > 0) || (roleListeners.length > 0)) {
5453                roles = getRoles(userId);
5454
5455                for (com.liferay.portal.model.Role role : roles) {
5456                    for (ModelListener<User> listener : listeners) {
5457                        listener.onBeforeRemoveAssociation(userId,
5458                            com.liferay.portal.model.Role.class.getName(),
5459                            role.getPrimaryKey());
5460                    }
5461
5462                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
5463                        listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
5464                            User.class.getName(), userId);
5465                    }
5466                }
5467            }
5468
5469            _sqlUpdate.update(new Object[] { new Long(userId) });
5470
5471            if ((listeners.length > 0) || (roleListeners.length > 0)) {
5472                for (com.liferay.portal.model.Role role : roles) {
5473                    for (ModelListener<User> listener : listeners) {
5474                        listener.onAfterRemoveAssociation(userId,
5475                            com.liferay.portal.model.Role.class.getName(),
5476                            role.getPrimaryKey());
5477                    }
5478
5479                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
5480                        listener.onAfterRemoveAssociation(role.getPrimaryKey(),
5481                            User.class.getName(), userId);
5482                    }
5483                }
5484            }
5485        }
5486
5487        private SqlUpdate _sqlUpdate;
5488    }
5489
5490    protected class RemoveRole {
5491        protected RemoveRole(UserPersistenceImpl persistenceImpl) {
5492            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5493                    "DELETE FROM Users_Roles WHERE userId = ? AND roleId = ?",
5494                    new int[] { Types.BIGINT, Types.BIGINT });
5495            _persistenceImpl = persistenceImpl;
5496        }
5497
5498        protected void remove(long userId, long roleId)
5499            throws SystemException {
5500            if (_persistenceImpl.containsRole.contains(userId, roleId)) {
5501                ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
5502
5503                for (ModelListener<User> listener : listeners) {
5504                    listener.onBeforeRemoveAssociation(userId,
5505                        com.liferay.portal.model.Role.class.getName(), roleId);
5506                }
5507
5508                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
5509                    listener.onBeforeRemoveAssociation(roleId,
5510                        User.class.getName(), userId);
5511                }
5512
5513                _sqlUpdate.update(new Object[] {
5514                        new Long(userId), new Long(roleId)
5515                    });
5516
5517                for (ModelListener<User> listener : listeners) {
5518                    listener.onAfterRemoveAssociation(userId,
5519                        com.liferay.portal.model.Role.class.getName(), roleId);
5520                }
5521
5522                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
5523                    listener.onAfterRemoveAssociation(roleId,
5524                        User.class.getName(), userId);
5525                }
5526            }
5527        }
5528
5529        private SqlUpdate _sqlUpdate;
5530        private UserPersistenceImpl _persistenceImpl;
5531    }
5532
5533    protected class ContainsUserGroup {
5534        protected ContainsUserGroup(UserPersistenceImpl persistenceImpl) {
5535            super();
5536
5537            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5538                    _SQL_CONTAINSUSERGROUP,
5539                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
5540        }
5541
5542        protected boolean contains(long userId, long userGroupId) {
5543            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5544                        new Long(userId), new Long(userGroupId)
5545                    });
5546
5547            if (results.size() > 0) {
5548                Integer count = results.get(0);
5549
5550                if (count.intValue() > 0) {
5551                    return true;
5552                }
5553            }
5554
5555            return false;
5556        }
5557
5558        private MappingSqlQuery<Integer> _mappingSqlQuery;
5559    }
5560
5561    protected class AddUserGroup {
5562        protected AddUserGroup(UserPersistenceImpl persistenceImpl) {
5563            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5564                    "INSERT INTO Users_UserGroups (userId, userGroupId) VALUES (?, ?)",
5565                    new int[] { Types.BIGINT, Types.BIGINT });
5566            _persistenceImpl = persistenceImpl;
5567        }
5568
5569        protected void add(long userId, long userGroupId)
5570            throws SystemException {
5571            if (!_persistenceImpl.containsUserGroup.contains(userId, userGroupId)) {
5572                ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
5573                    userGroupPersistence.getListeners();
5574
5575                for (ModelListener<User> listener : listeners) {
5576                    listener.onBeforeAddAssociation(userId,
5577                        com.liferay.portal.model.UserGroup.class.getName(),
5578                        userGroupId);
5579                }
5580
5581                for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
5582                    listener.onBeforeAddAssociation(userGroupId,
5583                        User.class.getName(), userId);
5584                }
5585
5586                _sqlUpdate.update(new Object[] {
5587                        new Long(userId), new Long(userGroupId)
5588                    });
5589
5590                for (ModelListener<User> listener : listeners) {
5591                    listener.onAfterAddAssociation(userId,
5592                        com.liferay.portal.model.UserGroup.class.getName(),
5593                        userGroupId);
5594                }
5595
5596                for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
5597                    listener.onAfterAddAssociation(userGroupId,
5598                        User.class.getName(), userId);
5599                }
5600            }
5601        }
5602
5603        private SqlUpdate _sqlUpdate;
5604        private UserPersistenceImpl _persistenceImpl;
5605    }
5606
5607    protected class ClearUserGroups {
5608        protected ClearUserGroups(UserPersistenceImpl persistenceImpl) {
5609            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5610                    "DELETE FROM Users_UserGroups WHERE userId = ?",
5611                    new int[] { Types.BIGINT });
5612        }
5613
5614        protected void clear(long userId) throws SystemException {
5615            ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
5616                userGroupPersistence.getListeners();
5617
5618            List<com.liferay.portal.model.UserGroup> userGroups = null;
5619
5620            if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
5621                userGroups = getUserGroups(userId);
5622
5623                for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
5624                    for (ModelListener<User> listener : listeners) {
5625                        listener.onBeforeRemoveAssociation(userId,
5626                            com.liferay.portal.model.UserGroup.class.getName(),
5627                            userGroup.getPrimaryKey());
5628                    }
5629
5630                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
5631                        listener.onBeforeRemoveAssociation(userGroup.getPrimaryKey(),
5632                            User.class.getName(), userId);
5633                    }
5634                }
5635            }
5636
5637            _sqlUpdate.update(new Object[] { new Long(userId) });
5638
5639            if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
5640                for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
5641                    for (ModelListener<User> listener : listeners) {
5642                        listener.onAfterRemoveAssociation(userId,
5643                            com.liferay.portal.model.UserGroup.class.getName(),
5644                            userGroup.getPrimaryKey());
5645                    }
5646
5647                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
5648                        listener.onAfterRemoveAssociation(userGroup.getPrimaryKey(),
5649                            User.class.getName(), userId);
5650                    }
5651                }
5652            }
5653        }
5654
5655        private SqlUpdate _sqlUpdate;
5656    }
5657
5658    protected class RemoveUserGroup {
5659        protected RemoveUserGroup(UserPersistenceImpl persistenceImpl) {
5660            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5661                    "DELETE FROM Users_UserGroups WHERE userId = ? AND userGroupId = ?",
5662                    new int[] { Types.BIGINT, Types.BIGINT });
5663            _persistenceImpl = persistenceImpl;
5664        }
5665
5666        protected void remove(long userId, long userGroupId)
5667            throws SystemException {
5668            if (_persistenceImpl.containsUserGroup.contains(userId, userGroupId)) {
5669                ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
5670                    userGroupPersistence.getListeners();
5671
5672                for (ModelListener<User> listener : listeners) {
5673                    listener.onBeforeRemoveAssociation(userId,
5674                        com.liferay.portal.model.UserGroup.class.getName(),
5675                        userGroupId);
5676                }
5677
5678                for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
5679                    listener.onBeforeRemoveAssociation(userGroupId,
5680                        User.class.getName(), userId);
5681                }
5682
5683                _sqlUpdate.update(new Object[] {
5684                        new Long(userId), new Long(userGroupId)
5685                    });
5686
5687                for (ModelListener<User> listener : listeners) {
5688                    listener.onAfterRemoveAssociation(userId,
5689                        com.liferay.portal.model.UserGroup.class.getName(),
5690                        userGroupId);
5691                }
5692
5693                for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
5694                    listener.onAfterRemoveAssociation(userGroupId,
5695                        User.class.getName(), userId);
5696                }
5697            }
5698        }
5699
5700        private SqlUpdate _sqlUpdate;
5701        private UserPersistenceImpl _persistenceImpl;
5702    }
5703
5704    private static final String _SQL_SELECT_USER = "SELECT user FROM User user";
5705    private static final String _SQL_SELECT_USER_WHERE = "SELECT user FROM User user WHERE ";
5706    private static final String _SQL_COUNT_USER = "SELECT COUNT(user) FROM User user";
5707    private static final String _SQL_COUNT_USER_WHERE = "SELECT COUNT(user) FROM User user WHERE ";
5708    private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Users_Groups ON (Users_Groups.groupId = Group_.groupId) WHERE (Users_Groups.userId = ?)";
5709    private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE userId = ?";
5710    private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE userId = ? AND groupId = ?";
5711    private static final String _SQL_GETORGANIZATIONS = "SELECT {Organization_.*} FROM Organization_ INNER JOIN Users_Orgs ON (Users_Orgs.organizationId = Organization_.organizationId) WHERE (Users_Orgs.userId = ?)";
5712    private static final String _SQL_GETORGANIZATIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE userId = ?";
5713    private static final String _SQL_CONTAINSORGANIZATION = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE userId = ? AND organizationId = ?";
5714    private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Users_Permissions ON (Users_Permissions.permissionId = Permission_.permissionId) WHERE (Users_Permissions.userId = ?)";
5715    private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE userId = ?";
5716    private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE userId = ? AND permissionId = ?";
5717    private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Users_Roles ON (Users_Roles.roleId = Role_.roleId) WHERE (Users_Roles.userId = ?)";
5718    private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE userId = ?";
5719    private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE userId = ? AND roleId = ?";
5720    private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN Users_UserGroups ON (Users_UserGroups.userGroupId = UserGroup.userGroupId) WHERE (Users_UserGroups.userId = ?)";
5721    private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userId = ?";
5722    private static final String _SQL_CONTAINSUSERGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userId = ? AND userGroupId = ?";
5723    private static final String _FINDER_COLUMN_UUID_UUID_1 = "user.uuid IS NULL";
5724    private static final String _FINDER_COLUMN_UUID_UUID_2 = "user.uuid = ?";
5725    private static final String _FINDER_COLUMN_UUID_UUID_3 = "(user.uuid IS NULL OR user.uuid = ?)";
5726    private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "user.companyId = ?";
5727    private static final String _FINDER_COLUMN_CONTACTID_CONTACTID_2 = "user.contactId = ?";
5728    private static final String _FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_1 = "user.emailAddress IS NULL";
5729    private static final String _FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_2 = "user.emailAddress = ?";
5730    private static final String _FINDER_COLUMN_EMAILADDRESS_EMAILADDRESS_3 = "(user.emailAddress IS NULL OR user.emailAddress = ?)";
5731    private static final String _FINDER_COLUMN_OPENID_OPENID_1 = "user.openId IS NULL";
5732    private static final String _FINDER_COLUMN_OPENID_OPENID_2 = "user.openId = ?";
5733    private static final String _FINDER_COLUMN_OPENID_OPENID_3 = "(user.openId IS NULL OR user.openId = ?)";
5734    private static final String _FINDER_COLUMN_PORTRAITID_PORTRAITID_2 = "user.portraitId = ?";
5735    private static final String _FINDER_COLUMN_C_U_COMPANYID_2 = "user.companyId = ? AND ";
5736    private static final String _FINDER_COLUMN_C_U_USERID_2 = "user.userId = ?";
5737    private static final String _FINDER_COLUMN_C_DU_COMPANYID_2 = "user.companyId = ? AND ";
5738    private static final String _FINDER_COLUMN_C_DU_DEFAULTUSER_2 = "user.defaultUser = ?";
5739    private static final String _FINDER_COLUMN_C_SN_COMPANYID_2 = "user.companyId = ? AND ";
5740    private static final String _FINDER_COLUMN_C_SN_SCREENNAME_1 = "user.screenName IS NULL";
5741    private static final String _FINDER_COLUMN_C_SN_SCREENNAME_2 = "user.screenName = ?";
5742    private static final String _FINDER_COLUMN_C_SN_SCREENNAME_3 = "(user.screenName IS NULL OR user.screenName = ?)";
5743    private static final String _FINDER_COLUMN_C_EA_COMPANYID_2 = "user.companyId = ? AND ";
5744    private static final String _FINDER_COLUMN_C_EA_EMAILADDRESS_1 = "user.emailAddress IS NULL";
5745    private static final String _FINDER_COLUMN_C_EA_EMAILADDRESS_2 = "user.emailAddress = ?";
5746    private static final String _FINDER_COLUMN_C_EA_EMAILADDRESS_3 = "(user.emailAddress IS NULL OR user.emailAddress = ?)";
5747    private static final String _ORDER_BY_ENTITY_ALIAS = "user.";
5748    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No User exists with the primary key ";
5749    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No User exists with the key {";
5750    private static Log _log = LogFactoryUtil.getLog(UserPersistenceImpl.class);
5751}