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