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