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