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