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