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