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