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