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