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             if (BatchSessionUtil.isEnabled()) {
189                 Object staleObject = session.get(UserImpl.class,
190                         user.getPrimaryKeyObj());
191 
192                 if (staleObject != null) {
193                     session.evict(staleObject);
194                 }
195             }
196 
197             session.delete(user);
198 
199             session.flush();
200 
201             return user;
202         }
203         catch (Exception e) {
204             throw processException(e);
205         }
206         finally {
207             closeSession(session);
208 
209             FinderCacheUtil.clearCache(User.class.getName());
210         }
211     }
212 
213     /**
214      * @deprecated Use <code>update(User user, boolean merge)</code>.
215      */
216     public User update(User user) throws SystemException {
217         if (_log.isWarnEnabled()) {
218             _log.warn(
219                 "Using the deprecated update(User user) method. Use update(User user, boolean merge) instead.");
220         }
221 
222         return update(user, false);
223     }
224 
225     /**
226      * Add, update, or merge, the entity. This method also calls the model
227      * listeners to trigger the proper events associated with adding, deleting,
228      * or updating an entity.
229      *
230      * @param        user the entity to add, update, or merge
231      * @param        merge boolean value for whether to merge the entity. The
232      *                default value is false. Setting merge to true is more
233      *                expensive and should only be true when user is
234      *                transient. See LEP-5473 for a detailed discussion of this
235      *                method.
236      * @return        true if the portlet can be displayed via Ajax
237      */
238     public User update(User user, boolean merge) throws SystemException {
239         boolean isNew = user.isNew();
240 
241         if (_listeners.length > 0) {
242             for (ModelListener listener : _listeners) {
243                 if (isNew) {
244                     listener.onBeforeCreate(user);
245                 }
246                 else {
247                     listener.onBeforeUpdate(user);
248                 }
249             }
250         }
251 
252         user = updateImpl(user, merge);
253 
254         if (_listeners.length > 0) {
255             for (ModelListener listener : _listeners) {
256                 if (isNew) {
257                     listener.onAfterCreate(user);
258                 }
259                 else {
260                     listener.onAfterUpdate(user);
261                 }
262             }
263         }
264 
265         return user;
266     }
267 
268     public User updateImpl(com.liferay.portal.model.User user, boolean merge)
269         throws SystemException {
270         FinderCacheUtil.clearCache("Users_Groups");
271         FinderCacheUtil.clearCache("Users_Orgs");
272         FinderCacheUtil.clearCache("Users_Permissions");
273         FinderCacheUtil.clearCache("Users_Roles");
274         FinderCacheUtil.clearCache("Users_UserGroups");
275 
276         if (Validator.isNull(user.getUuid())) {
277             String uuid = PortalUUIDUtil.generate();
278 
279             user.setUuid(uuid);
280         }
281 
282         Session session = null;
283 
284         try {
285             session = openSession();
286 
287             BatchSessionUtil.update(session, user, merge);
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 = null;
2086
2087                if (obc == null) {
2088                    list = (List<User>)QueryUtil.list(q, getDialect(), start,
2089                            end, false);
2090
2091                    Collections.sort(list);
2092                }
2093                else {
2094                    list = (List<User>)QueryUtil.list(q, getDialect(), start,
2095                            end);
2096                }
2097
2098                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2099                    finderClassName, finderMethodName, finderParams,
2100                    finderArgs, list);
2101
2102                return list;
2103            }
2104            catch (Exception e) {
2105                throw processException(e);
2106            }
2107            finally {
2108                closeSession(session);
2109            }
2110        }
2111        else {
2112            return (List<User>)result;
2113        }
2114    }
2115
2116    public void removeByUuid(String uuid) throws SystemException {
2117        for (User user : findByUuid(uuid)) {
2118            remove(user);
2119        }
2120    }
2121
2122    public void removeByCompanyId(long companyId) throws SystemException {
2123        for (User user : findByCompanyId(companyId)) {
2124            remove(user);
2125        }
2126    }
2127
2128    public void removeByContactId(long contactId)
2129        throws NoSuchUserException, SystemException {
2130        User user = findByContactId(contactId);
2131
2132        remove(user);
2133    }
2134
2135    public void removeByEmailAddress(String emailAddress)
2136        throws SystemException {
2137        for (User user : findByEmailAddress(emailAddress)) {
2138            remove(user);
2139        }
2140    }
2141
2142    public void removeByOpenId(String openId)
2143        throws NoSuchUserException, SystemException {
2144        User user = findByOpenId(openId);
2145
2146        remove(user);
2147    }
2148
2149    public void removeByPortraitId(long portraitId)
2150        throws NoSuchUserException, SystemException {
2151        User user = findByPortraitId(portraitId);
2152
2153        remove(user);
2154    }
2155
2156    public void removeByC_U(long companyId, long userId)
2157        throws NoSuchUserException, SystemException {
2158        User user = findByC_U(companyId, userId);
2159
2160        remove(user);
2161    }
2162
2163    public void removeByC_DU(long companyId, boolean defaultUser)
2164        throws NoSuchUserException, SystemException {
2165        User user = findByC_DU(companyId, defaultUser);
2166
2167        remove(user);
2168    }
2169
2170    public void removeByC_P(long companyId, String password)
2171        throws SystemException {
2172        for (User user : findByC_P(companyId, password)) {
2173            remove(user);
2174        }
2175    }
2176
2177    public void removeByC_SN(long companyId, String screenName)
2178        throws NoSuchUserException, SystemException {
2179        User user = findByC_SN(companyId, screenName);
2180
2181        remove(user);
2182    }
2183
2184    public void removeByC_EA(long companyId, String emailAddress)
2185        throws NoSuchUserException, SystemException {
2186        User user = findByC_EA(companyId, emailAddress);
2187
2188        remove(user);
2189    }
2190
2191    public void removeAll() throws SystemException {
2192        for (User user : findAll()) {
2193            remove(user);
2194        }
2195    }
2196
2197    public int countByUuid(String uuid) throws SystemException {
2198        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2199        String finderClassName = User.class.getName();
2200        String finderMethodName = "countByUuid";
2201        String[] finderParams = new String[] { String.class.getName() };
2202        Object[] finderArgs = new Object[] { uuid };
2203
2204        Object result = null;
2205
2206        if (finderClassNameCacheEnabled) {
2207            result = FinderCacheUtil.getResult(finderClassName,
2208                    finderMethodName, finderParams, finderArgs, this);
2209        }
2210
2211        if (result == null) {
2212            Session session = null;
2213
2214            try {
2215                session = openSession();
2216
2217                StringBuilder query = new StringBuilder();
2218
2219                query.append("SELECT COUNT(*) ");
2220                query.append("FROM com.liferay.portal.model.User WHERE ");
2221
2222                if (uuid == null) {
2223                    query.append("uuid_ IS NULL");
2224                }
2225                else {
2226                    query.append("uuid_ = ?");
2227                }
2228
2229                query.append(" ");
2230
2231                Query q = session.createQuery(query.toString());
2232
2233                QueryPos qPos = QueryPos.getInstance(q);
2234
2235                if (uuid != null) {
2236                    qPos.add(uuid);
2237                }
2238
2239                Long count = null;
2240
2241                Iterator<Long> itr = q.list().iterator();
2242
2243                if (itr.hasNext()) {
2244                    count = itr.next();
2245                }
2246
2247                if (count == null) {
2248                    count = new Long(0);
2249                }
2250
2251                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2252                    finderClassName, finderMethodName, finderParams,
2253                    finderArgs, count);
2254
2255                return count.intValue();
2256            }
2257            catch (Exception e) {
2258                throw processException(e);
2259            }
2260            finally {
2261                closeSession(session);
2262            }
2263        }
2264        else {
2265            return ((Long)result).intValue();
2266        }
2267    }
2268
2269    public int countByCompanyId(long companyId) throws SystemException {
2270        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2271        String finderClassName = User.class.getName();
2272        String finderMethodName = "countByCompanyId";
2273        String[] finderParams = new String[] { Long.class.getName() };
2274        Object[] finderArgs = new Object[] { new Long(companyId) };
2275
2276        Object result = null;
2277
2278        if (finderClassNameCacheEnabled) {
2279            result = FinderCacheUtil.getResult(finderClassName,
2280                    finderMethodName, finderParams, finderArgs, this);
2281        }
2282
2283        if (result == null) {
2284            Session session = null;
2285
2286            try {
2287                session = openSession();
2288
2289                StringBuilder query = new StringBuilder();
2290
2291                query.append("SELECT COUNT(*) ");
2292                query.append("FROM com.liferay.portal.model.User WHERE ");
2293
2294                query.append("companyId = ?");
2295
2296                query.append(" ");
2297
2298                Query q = session.createQuery(query.toString());
2299
2300                QueryPos qPos = QueryPos.getInstance(q);
2301
2302                qPos.add(companyId);
2303
2304                Long count = null;
2305
2306                Iterator<Long> itr = q.list().iterator();
2307
2308                if (itr.hasNext()) {
2309                    count = itr.next();
2310                }
2311
2312                if (count == null) {
2313                    count = new Long(0);
2314                }
2315
2316                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2317                    finderClassName, finderMethodName, finderParams,
2318                    finderArgs, count);
2319
2320                return count.intValue();
2321            }
2322            catch (Exception e) {
2323                throw processException(e);
2324            }
2325            finally {
2326                closeSession(session);
2327            }
2328        }
2329        else {
2330            return ((Long)result).intValue();
2331        }
2332    }
2333
2334    public int countByContactId(long contactId) throws SystemException {
2335        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2336        String finderClassName = User.class.getName();
2337        String finderMethodName = "countByContactId";
2338        String[] finderParams = new String[] { Long.class.getName() };
2339        Object[] finderArgs = new Object[] { new Long(contactId) };
2340
2341        Object result = null;
2342
2343        if (finderClassNameCacheEnabled) {
2344            result = FinderCacheUtil.getResult(finderClassName,
2345                    finderMethodName, finderParams, finderArgs, this);
2346        }
2347
2348        if (result == null) {
2349            Session session = null;
2350
2351            try {
2352                session = openSession();
2353
2354                StringBuilder query = new StringBuilder();
2355
2356                query.append("SELECT COUNT(*) ");
2357                query.append("FROM com.liferay.portal.model.User WHERE ");
2358
2359                query.append("contactId = ?");
2360
2361                query.append(" ");
2362
2363                Query q = session.createQuery(query.toString());
2364
2365                QueryPos qPos = QueryPos.getInstance(q);
2366
2367                qPos.add(contactId);
2368
2369                Long count = null;
2370
2371                Iterator<Long> itr = q.list().iterator();
2372
2373                if (itr.hasNext()) {
2374                    count = itr.next();
2375                }
2376
2377                if (count == null) {
2378                    count = new Long(0);
2379                }
2380
2381                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2382                    finderClassName, finderMethodName, finderParams,
2383                    finderArgs, count);
2384
2385                return count.intValue();
2386            }
2387            catch (Exception e) {
2388                throw processException(e);
2389            }
2390            finally {
2391                closeSession(session);
2392            }
2393        }
2394        else {
2395            return ((Long)result).intValue();
2396        }
2397    }
2398
2399    public int countByEmailAddress(String emailAddress)
2400        throws SystemException {
2401        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2402        String finderClassName = User.class.getName();
2403        String finderMethodName = "countByEmailAddress";
2404        String[] finderParams = new String[] { String.class.getName() };
2405        Object[] finderArgs = new Object[] { emailAddress };
2406
2407        Object result = null;
2408
2409        if (finderClassNameCacheEnabled) {
2410            result = FinderCacheUtil.getResult(finderClassName,
2411                    finderMethodName, finderParams, finderArgs, this);
2412        }
2413
2414        if (result == null) {
2415            Session session = null;
2416
2417            try {
2418                session = openSession();
2419
2420                StringBuilder query = new StringBuilder();
2421
2422                query.append("SELECT COUNT(*) ");
2423                query.append("FROM com.liferay.portal.model.User WHERE ");
2424
2425                if (emailAddress == null) {
2426                    query.append("emailAddress IS NULL");
2427                }
2428                else {
2429                    query.append("emailAddress = ?");
2430                }
2431
2432                query.append(" ");
2433
2434                Query q = session.createQuery(query.toString());
2435
2436                QueryPos qPos = QueryPos.getInstance(q);
2437
2438                if (emailAddress != null) {
2439                    qPos.add(emailAddress);
2440                }
2441
2442                Long count = null;
2443
2444                Iterator<Long> itr = q.list().iterator();
2445
2446                if (itr.hasNext()) {
2447                    count = itr.next();
2448                }
2449
2450                if (count == null) {
2451                    count = new Long(0);
2452                }
2453
2454                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2455                    finderClassName, finderMethodName, finderParams,
2456                    finderArgs, count);
2457
2458                return count.intValue();
2459            }
2460            catch (Exception e) {
2461                throw processException(e);
2462            }
2463            finally {
2464                closeSession(session);
2465            }
2466        }
2467        else {
2468            return ((Long)result).intValue();
2469        }
2470    }
2471
2472    public int countByOpenId(String openId) throws SystemException {
2473        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2474        String finderClassName = User.class.getName();
2475        String finderMethodName = "countByOpenId";
2476        String[] finderParams = new String[] { String.class.getName() };
2477        Object[] finderArgs = new Object[] { openId };
2478
2479        Object result = null;
2480
2481        if (finderClassNameCacheEnabled) {
2482            result = FinderCacheUtil.getResult(finderClassName,
2483                    finderMethodName, finderParams, finderArgs, this);
2484        }
2485
2486        if (result == null) {
2487            Session session = null;
2488
2489            try {
2490                session = openSession();
2491
2492                StringBuilder query = new StringBuilder();
2493
2494                query.append("SELECT COUNT(*) ");
2495                query.append("FROM com.liferay.portal.model.User WHERE ");
2496
2497                if (openId == null) {
2498                    query.append("openId IS NULL");
2499                }
2500                else {
2501                    query.append("openId = ?");
2502                }
2503
2504                query.append(" ");
2505
2506                Query q = session.createQuery(query.toString());
2507
2508                QueryPos qPos = QueryPos.getInstance(q);
2509
2510                if (openId != null) {
2511                    qPos.add(openId);
2512                }
2513
2514                Long count = null;
2515
2516                Iterator<Long> itr = q.list().iterator();
2517
2518                if (itr.hasNext()) {
2519                    count = itr.next();
2520                }
2521
2522                if (count == null) {
2523                    count = new Long(0);
2524                }
2525
2526                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2527                    finderClassName, finderMethodName, finderParams,
2528                    finderArgs, count);
2529
2530                return count.intValue();
2531            }
2532            catch (Exception e) {
2533                throw processException(e);
2534            }
2535            finally {
2536                closeSession(session);
2537            }
2538        }
2539        else {
2540            return ((Long)result).intValue();
2541        }
2542    }
2543
2544    public int countByPortraitId(long portraitId) throws SystemException {
2545        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2546        String finderClassName = User.class.getName();
2547        String finderMethodName = "countByPortraitId";
2548        String[] finderParams = new String[] { Long.class.getName() };
2549        Object[] finderArgs = new Object[] { new Long(portraitId) };
2550
2551        Object result = null;
2552
2553        if (finderClassNameCacheEnabled) {
2554            result = FinderCacheUtil.getResult(finderClassName,
2555                    finderMethodName, finderParams, finderArgs, this);
2556        }
2557
2558        if (result == null) {
2559            Session session = null;
2560
2561            try {
2562                session = openSession();
2563
2564                StringBuilder query = new StringBuilder();
2565
2566                query.append("SELECT COUNT(*) ");
2567                query.append("FROM com.liferay.portal.model.User WHERE ");
2568
2569                query.append("portraitId = ?");
2570
2571                query.append(" ");
2572
2573                Query q = session.createQuery(query.toString());
2574
2575                QueryPos qPos = QueryPos.getInstance(q);
2576
2577                qPos.add(portraitId);
2578
2579                Long count = null;
2580
2581                Iterator<Long> itr = q.list().iterator();
2582
2583                if (itr.hasNext()) {
2584                    count = itr.next();
2585                }
2586
2587                if (count == null) {
2588                    count = new Long(0);
2589                }
2590
2591                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2592                    finderClassName, finderMethodName, finderParams,
2593                    finderArgs, count);
2594
2595                return count.intValue();
2596            }
2597            catch (Exception e) {
2598                throw processException(e);
2599            }
2600            finally {
2601                closeSession(session);
2602            }
2603        }
2604        else {
2605            return ((Long)result).intValue();
2606        }
2607    }
2608
2609    public int countByC_U(long companyId, long userId)
2610        throws SystemException {
2611        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2612        String finderClassName = User.class.getName();
2613        String finderMethodName = "countByC_U";
2614        String[] finderParams = new String[] {
2615                Long.class.getName(), Long.class.getName()
2616            };
2617        Object[] finderArgs = new Object[] { new Long(companyId), new Long(userId) };
2618
2619        Object result = null;
2620
2621        if (finderClassNameCacheEnabled) {
2622            result = FinderCacheUtil.getResult(finderClassName,
2623                    finderMethodName, finderParams, finderArgs, this);
2624        }
2625
2626        if (result == null) {
2627            Session session = null;
2628
2629            try {
2630                session = openSession();
2631
2632                StringBuilder query = new StringBuilder();
2633
2634                query.append("SELECT COUNT(*) ");
2635                query.append("FROM com.liferay.portal.model.User WHERE ");
2636
2637                query.append("companyId = ?");
2638
2639                query.append(" AND ");
2640
2641                query.append("userId = ?");
2642
2643                query.append(" ");
2644
2645                Query q = session.createQuery(query.toString());
2646
2647                QueryPos qPos = QueryPos.getInstance(q);
2648
2649                qPos.add(companyId);
2650
2651                qPos.add(userId);
2652
2653                Long count = null;
2654
2655                Iterator<Long> itr = q.list().iterator();
2656
2657                if (itr.hasNext()) {
2658                    count = itr.next();
2659                }
2660
2661                if (count == null) {
2662                    count = new Long(0);
2663                }
2664
2665                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2666                    finderClassName, finderMethodName, finderParams,
2667                    finderArgs, count);
2668
2669                return count.intValue();
2670            }
2671            catch (Exception e) {
2672                throw processException(e);
2673            }
2674            finally {
2675                closeSession(session);
2676            }
2677        }
2678        else {
2679            return ((Long)result).intValue();
2680        }
2681    }
2682
2683    public int countByC_DU(long companyId, boolean defaultUser)
2684        throws SystemException {
2685        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2686        String finderClassName = User.class.getName();
2687        String finderMethodName = "countByC_DU";
2688        String[] finderParams = new String[] {
2689                Long.class.getName(), Boolean.class.getName()
2690            };
2691        Object[] finderArgs = new Object[] {
2692                new Long(companyId), Boolean.valueOf(defaultUser)
2693            };
2694
2695        Object result = null;
2696
2697        if (finderClassNameCacheEnabled) {
2698            result = FinderCacheUtil.getResult(finderClassName,
2699                    finderMethodName, finderParams, finderArgs, this);
2700        }
2701
2702        if (result == null) {
2703            Session session = null;
2704
2705            try {
2706                session = openSession();
2707
2708                StringBuilder query = new StringBuilder();
2709
2710                query.append("SELECT COUNT(*) ");
2711                query.append("FROM com.liferay.portal.model.User WHERE ");
2712
2713                query.append("companyId = ?");
2714
2715                query.append(" AND ");
2716
2717                query.append("defaultUser = ?");
2718
2719                query.append(" ");
2720
2721                Query q = session.createQuery(query.toString());
2722
2723                QueryPos qPos = QueryPos.getInstance(q);
2724
2725                qPos.add(companyId);
2726
2727                qPos.add(defaultUser);
2728
2729                Long count = null;
2730
2731                Iterator<Long> itr = q.list().iterator();
2732
2733                if (itr.hasNext()) {
2734                    count = itr.next();
2735                }
2736
2737                if (count == null) {
2738                    count = new Long(0);
2739                }
2740
2741                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2742                    finderClassName, finderMethodName, finderParams,
2743                    finderArgs, count);
2744
2745                return count.intValue();
2746            }
2747            catch (Exception e) {
2748                throw processException(e);
2749            }
2750            finally {
2751                closeSession(session);
2752            }
2753        }
2754        else {
2755            return ((Long)result).intValue();
2756        }
2757    }
2758
2759    public int countByC_P(long companyId, String password)
2760        throws SystemException {
2761        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2762        String finderClassName = User.class.getName();
2763        String finderMethodName = "countByC_P";
2764        String[] finderParams = new String[] {
2765                Long.class.getName(), String.class.getName()
2766            };
2767        Object[] finderArgs = new Object[] { new Long(companyId), password };
2768
2769        Object result = null;
2770
2771        if (finderClassNameCacheEnabled) {
2772            result = FinderCacheUtil.getResult(finderClassName,
2773                    finderMethodName, finderParams, finderArgs, this);
2774        }
2775
2776        if (result == null) {
2777            Session session = null;
2778
2779            try {
2780                session = openSession();
2781
2782                StringBuilder query = new StringBuilder();
2783
2784                query.append("SELECT COUNT(*) ");
2785                query.append("FROM com.liferay.portal.model.User WHERE ");
2786
2787                query.append("companyId = ?");
2788
2789                query.append(" AND ");
2790
2791                if (password == null) {
2792                    query.append("password_ IS NULL");
2793                }
2794                else {
2795                    query.append("password_ = ?");
2796                }
2797
2798                query.append(" ");
2799
2800                Query q = session.createQuery(query.toString());
2801
2802                QueryPos qPos = QueryPos.getInstance(q);
2803
2804                qPos.add(companyId);
2805
2806                if (password != null) {
2807                    qPos.add(password);
2808                }
2809
2810                Long count = null;
2811
2812                Iterator<Long> itr = q.list().iterator();
2813
2814                if (itr.hasNext()) {
2815                    count = itr.next();
2816                }
2817
2818                if (count == null) {
2819                    count = new Long(0);
2820                }
2821
2822                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2823                    finderClassName, finderMethodName, finderParams,
2824                    finderArgs, count);
2825
2826                return count.intValue();
2827            }
2828            catch (Exception e) {
2829                throw processException(e);
2830            }
2831            finally {
2832                closeSession(session);
2833            }
2834        }
2835        else {
2836            return ((Long)result).intValue();
2837        }
2838    }
2839
2840    public int countByC_SN(long companyId, String screenName)
2841        throws SystemException {
2842        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2843        String finderClassName = User.class.getName();
2844        String finderMethodName = "countByC_SN";
2845        String[] finderParams = new String[] {
2846                Long.class.getName(), String.class.getName()
2847            };
2848        Object[] finderArgs = new Object[] { new Long(companyId), screenName };
2849
2850        Object result = null;
2851
2852        if (finderClassNameCacheEnabled) {
2853            result = FinderCacheUtil.getResult(finderClassName,
2854                    finderMethodName, finderParams, finderArgs, this);
2855        }
2856
2857        if (result == null) {
2858            Session session = null;
2859
2860            try {
2861                session = openSession();
2862
2863                StringBuilder query = new StringBuilder();
2864
2865                query.append("SELECT COUNT(*) ");
2866                query.append("FROM com.liferay.portal.model.User WHERE ");
2867
2868                query.append("companyId = ?");
2869
2870                query.append(" AND ");
2871
2872                if (screenName == null) {
2873                    query.append("screenName IS NULL");
2874                }
2875                else {
2876                    query.append("screenName = ?");
2877                }
2878
2879                query.append(" ");
2880
2881                Query q = session.createQuery(query.toString());
2882
2883                QueryPos qPos = QueryPos.getInstance(q);
2884
2885                qPos.add(companyId);
2886
2887                if (screenName != null) {
2888                    qPos.add(screenName);
2889                }
2890
2891                Long count = null;
2892
2893                Iterator<Long> itr = q.list().iterator();
2894
2895                if (itr.hasNext()) {
2896                    count = itr.next();
2897                }
2898
2899                if (count == null) {
2900                    count = new Long(0);
2901                }
2902
2903                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2904                    finderClassName, finderMethodName, finderParams,
2905                    finderArgs, count);
2906
2907                return count.intValue();
2908            }
2909            catch (Exception e) {
2910                throw processException(e);
2911            }
2912            finally {
2913                closeSession(session);
2914            }
2915        }
2916        else {
2917            return ((Long)result).intValue();
2918        }
2919    }
2920
2921    public int countByC_EA(long companyId, String emailAddress)
2922        throws SystemException {
2923        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
2924        String finderClassName = User.class.getName();
2925        String finderMethodName = "countByC_EA";
2926        String[] finderParams = new String[] {
2927                Long.class.getName(), String.class.getName()
2928            };
2929        Object[] finderArgs = new Object[] { new Long(companyId), emailAddress };
2930
2931        Object result = null;
2932
2933        if (finderClassNameCacheEnabled) {
2934            result = FinderCacheUtil.getResult(finderClassName,
2935                    finderMethodName, finderParams, finderArgs, this);
2936        }
2937
2938        if (result == null) {
2939            Session session = null;
2940
2941            try {
2942                session = openSession();
2943
2944                StringBuilder query = new StringBuilder();
2945
2946                query.append("SELECT COUNT(*) ");
2947                query.append("FROM com.liferay.portal.model.User WHERE ");
2948
2949                query.append("companyId = ?");
2950
2951                query.append(" AND ");
2952
2953                if (emailAddress == null) {
2954                    query.append("emailAddress IS NULL");
2955                }
2956                else {
2957                    query.append("emailAddress = ?");
2958                }
2959
2960                query.append(" ");
2961
2962                Query q = session.createQuery(query.toString());
2963
2964                QueryPos qPos = QueryPos.getInstance(q);
2965
2966                qPos.add(companyId);
2967
2968                if (emailAddress != null) {
2969                    qPos.add(emailAddress);
2970                }
2971
2972                Long count = null;
2973
2974                Iterator<Long> itr = q.list().iterator();
2975
2976                if (itr.hasNext()) {
2977                    count = itr.next();
2978                }
2979
2980                if (count == null) {
2981                    count = new Long(0);
2982                }
2983
2984                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2985                    finderClassName, finderMethodName, finderParams,
2986                    finderArgs, count);
2987
2988                return count.intValue();
2989            }
2990            catch (Exception e) {
2991                throw processException(e);
2992            }
2993            finally {
2994                closeSession(session);
2995            }
2996        }
2997        else {
2998            return ((Long)result).intValue();
2999        }
3000    }
3001
3002    public int countAll() throws SystemException {
3003        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED;
3004        String finderClassName = User.class.getName();
3005        String finderMethodName = "countAll";
3006        String[] finderParams = new String[] {  };
3007        Object[] finderArgs = new Object[] {  };
3008
3009        Object result = null;
3010
3011        if (finderClassNameCacheEnabled) {
3012            result = FinderCacheUtil.getResult(finderClassName,
3013                    finderMethodName, finderParams, finderArgs, this);
3014        }
3015
3016        if (result == null) {
3017            Session session = null;
3018
3019            try {
3020                session = openSession();
3021
3022                Query q = session.createQuery(
3023                        "SELECT COUNT(*) FROM com.liferay.portal.model.User");
3024
3025                Long count = null;
3026
3027                Iterator<Long> itr = q.list().iterator();
3028
3029                if (itr.hasNext()) {
3030                    count = itr.next();
3031                }
3032
3033                if (count == null) {
3034                    count = new Long(0);
3035                }
3036
3037                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3038                    finderClassName, finderMethodName, finderParams,
3039                    finderArgs, count);
3040
3041                return count.intValue();
3042            }
3043            catch (Exception e) {
3044                throw processException(e);
3045            }
3046            finally {
3047                closeSession(session);
3048            }
3049        }
3050        else {
3051            return ((Long)result).intValue();
3052        }
3053    }
3054
3055    public List<com.liferay.portal.model.Group> getGroups(long pk)
3056        throws SystemException {
3057        return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3058    }
3059
3060    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
3061        int end) throws SystemException {
3062        return getGroups(pk, start, end, null);
3063    }
3064
3065    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
3066        int end, OrderByComparator obc) throws SystemException {
3067        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_GROUPS;
3068
3069        String finderClassName = "Users_Groups";
3070
3071        String finderMethodName = "getGroups";
3072        String[] finderParams = new String[] {
3073                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3074                "com.liferay.portal.kernel.util.OrderByComparator"
3075            };
3076        Object[] finderArgs = new Object[] {
3077                new Long(pk), String.valueOf(start), String.valueOf(end),
3078                String.valueOf(obc)
3079            };
3080
3081        Object result = null;
3082
3083        if (finderClassNameCacheEnabled) {
3084            result = FinderCacheUtil.getResult(finderClassName,
3085                    finderMethodName, finderParams, finderArgs, this);
3086        }
3087
3088        if (result == null) {
3089            Session session = null;
3090
3091            try {
3092                session = openSession();
3093
3094                StringBuilder sb = new StringBuilder();
3095
3096                sb.append(_SQL_GETGROUPS);
3097
3098                if (obc != null) {
3099                    sb.append("ORDER BY ");
3100                    sb.append(obc.getOrderBy());
3101                }
3102
3103                else {
3104                    sb.append("ORDER BY ");
3105
3106                    sb.append("Group_.name ASC");
3107                }
3108
3109                String sql = sb.toString();
3110
3111                SQLQuery q = session.createSQLQuery(sql);
3112
3113                q.addEntity("Group_",
3114                    com.liferay.portal.model.impl.GroupImpl.class);
3115
3116                QueryPos qPos = QueryPos.getInstance(q);
3117
3118                qPos.add(pk);
3119
3120                List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
3121                        getDialect(), start, end);
3122
3123                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3124                    finderClassName, finderMethodName, finderParams,
3125                    finderArgs, list);
3126
3127                return list;
3128            }
3129            catch (Exception e) {
3130                throw processException(e);
3131            }
3132            finally {
3133                closeSession(session);
3134            }
3135        }
3136        else {
3137            return (List<com.liferay.portal.model.Group>)result;
3138        }
3139    }
3140
3141    public int getGroupsSize(long pk) throws SystemException {
3142        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_GROUPS;
3143
3144        String finderClassName = "Users_Groups";
3145
3146        String finderMethodName = "getGroupsSize";
3147        String[] finderParams = new String[] { Long.class.getName() };
3148        Object[] finderArgs = new Object[] { new Long(pk) };
3149
3150        Object result = null;
3151
3152        if (finderClassNameCacheEnabled) {
3153            result = FinderCacheUtil.getResult(finderClassName,
3154                    finderMethodName, finderParams, finderArgs, this);
3155        }
3156
3157        if (result == null) {
3158            Session session = null;
3159
3160            try {
3161                session = openSession();
3162
3163                SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
3164
3165                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3166
3167                QueryPos qPos = QueryPos.getInstance(q);
3168
3169                qPos.add(pk);
3170
3171                Long count = null;
3172
3173                Iterator<Long> itr = q.list().iterator();
3174
3175                if (itr.hasNext()) {
3176                    count = itr.next();
3177                }
3178
3179                if (count == null) {
3180                    count = new Long(0);
3181                }
3182
3183                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3184                    finderClassName, finderMethodName, finderParams,
3185                    finderArgs, count);
3186
3187                return count.intValue();
3188            }
3189            catch (Exception e) {
3190                throw processException(e);
3191            }
3192            finally {
3193                closeSession(session);
3194            }
3195        }
3196        else {
3197            return ((Long)result).intValue();
3198        }
3199    }
3200
3201    public boolean containsGroup(long pk, long groupPK)
3202        throws SystemException {
3203        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_GROUPS;
3204
3205        String finderClassName = "Users_Groups";
3206
3207        String finderMethodName = "containsGroups";
3208        String[] finderParams = new String[] {
3209                Long.class.getName(),
3210                
3211                Long.class.getName()
3212            };
3213        Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
3214
3215        Object result = null;
3216
3217        if (finderClassNameCacheEnabled) {
3218            result = FinderCacheUtil.getResult(finderClassName,
3219                    finderMethodName, finderParams, finderArgs, this);
3220        }
3221
3222        if (result == null) {
3223            try {
3224                Boolean value = Boolean.valueOf(containsGroup.contains(pk,
3225                            groupPK));
3226
3227                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3228                    finderClassName, finderMethodName, finderParams,
3229                    finderArgs, value);
3230
3231                return value.booleanValue();
3232            }
3233            catch (Exception e) {
3234                throw processException(e);
3235            }
3236        }
3237        else {
3238            return ((Boolean)result).booleanValue();
3239        }
3240    }
3241
3242    public boolean containsGroups(long pk) throws SystemException {
3243        if (getGroupsSize(pk) > 0) {
3244            return true;
3245        }
3246        else {
3247            return false;
3248        }
3249    }
3250
3251    public void addGroup(long pk, long groupPK) throws SystemException {
3252        try {
3253            addGroup.add(pk, groupPK);
3254        }
3255        catch (Exception e) {
3256            throw processException(e);
3257        }
3258        finally {
3259            FinderCacheUtil.clearCache("Users_Groups");
3260        }
3261    }
3262
3263    public void addGroup(long pk, com.liferay.portal.model.Group group)
3264        throws SystemException {
3265        try {
3266            addGroup.add(pk, group.getPrimaryKey());
3267        }
3268        catch (Exception e) {
3269            throw processException(e);
3270        }
3271        finally {
3272            FinderCacheUtil.clearCache("Users_Groups");
3273        }
3274    }
3275
3276    public void addGroups(long pk, long[] groupPKs) throws SystemException {
3277        try {
3278            for (long groupPK : groupPKs) {
3279                addGroup.add(pk, groupPK);
3280            }
3281        }
3282        catch (Exception e) {
3283            throw processException(e);
3284        }
3285        finally {
3286            FinderCacheUtil.clearCache("Users_Groups");
3287        }
3288    }
3289
3290    public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
3291        throws SystemException {
3292        try {
3293            for (com.liferay.portal.model.Group group : groups) {
3294                addGroup.add(pk, group.getPrimaryKey());
3295            }
3296        }
3297        catch (Exception e) {
3298            throw processException(e);
3299        }
3300        finally {
3301            FinderCacheUtil.clearCache("Users_Groups");
3302        }
3303    }
3304
3305    public void clearGroups(long pk) throws SystemException {
3306        try {
3307            clearGroups.clear(pk);
3308        }
3309        catch (Exception e) {
3310            throw processException(e);
3311        }
3312        finally {
3313            FinderCacheUtil.clearCache("Users_Groups");
3314        }
3315    }
3316
3317    public void removeGroup(long pk, long groupPK) throws SystemException {
3318        try {
3319            removeGroup.remove(pk, groupPK);
3320        }
3321        catch (Exception e) {
3322            throw processException(e);
3323        }
3324        finally {
3325            FinderCacheUtil.clearCache("Users_Groups");
3326        }
3327    }
3328
3329    public void removeGroup(long pk, com.liferay.portal.model.Group group)
3330        throws SystemException {
3331        try {
3332            removeGroup.remove(pk, group.getPrimaryKey());
3333        }
3334        catch (Exception e) {
3335            throw processException(e);
3336        }
3337        finally {
3338            FinderCacheUtil.clearCache("Users_Groups");
3339        }
3340    }
3341
3342    public void removeGroups(long pk, long[] groupPKs)
3343        throws SystemException {
3344        try {
3345            for (long groupPK : groupPKs) {
3346                removeGroup.remove(pk, groupPK);
3347            }
3348        }
3349        catch (Exception e) {
3350            throw processException(e);
3351        }
3352        finally {
3353            FinderCacheUtil.clearCache("Users_Groups");
3354        }
3355    }
3356
3357    public void removeGroups(long pk,
3358        List<com.liferay.portal.model.Group> groups) throws SystemException {
3359        try {
3360            for (com.liferay.portal.model.Group group : groups) {
3361                removeGroup.remove(pk, group.getPrimaryKey());
3362            }
3363        }
3364        catch (Exception e) {
3365            throw processException(e);
3366        }
3367        finally {
3368            FinderCacheUtil.clearCache("Users_Groups");
3369        }
3370    }
3371
3372    public void setGroups(long pk, long[] groupPKs) throws SystemException {
3373        try {
3374            clearGroups.clear(pk);
3375
3376            for (long groupPK : groupPKs) {
3377                addGroup.add(pk, groupPK);
3378            }
3379        }
3380        catch (Exception e) {
3381            throw processException(e);
3382        }
3383        finally {
3384            FinderCacheUtil.clearCache("Users_Groups");
3385        }
3386    }
3387
3388    public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
3389        throws SystemException {
3390        try {
3391            clearGroups.clear(pk);
3392
3393            for (com.liferay.portal.model.Group group : groups) {
3394                addGroup.add(pk, group.getPrimaryKey());
3395            }
3396        }
3397        catch (Exception e) {
3398            throw processException(e);
3399        }
3400        finally {
3401            FinderCacheUtil.clearCache("Users_Groups");
3402        }
3403    }
3404
3405    public List<com.liferay.portal.model.Organization> getOrganizations(long pk)
3406        throws SystemException {
3407        return getOrganizations(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3408    }
3409
3410    public List<com.liferay.portal.model.Organization> getOrganizations(
3411        long pk, int start, int end) throws SystemException {
3412        return getOrganizations(pk, start, end, null);
3413    }
3414
3415    public List<com.liferay.portal.model.Organization> getOrganizations(
3416        long pk, int start, int end, OrderByComparator obc)
3417        throws SystemException {
3418        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_ORGS;
3419
3420        String finderClassName = "Users_Orgs";
3421
3422        String finderMethodName = "getOrganizations";
3423        String[] finderParams = new String[] {
3424                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3425                "com.liferay.portal.kernel.util.OrderByComparator"
3426            };
3427        Object[] finderArgs = new Object[] {
3428                new Long(pk), String.valueOf(start), String.valueOf(end),
3429                String.valueOf(obc)
3430            };
3431
3432        Object result = null;
3433
3434        if (finderClassNameCacheEnabled) {
3435            result = FinderCacheUtil.getResult(finderClassName,
3436                    finderMethodName, finderParams, finderArgs, this);
3437        }
3438
3439        if (result == null) {
3440            Session session = null;
3441
3442            try {
3443                session = openSession();
3444
3445                StringBuilder sb = new StringBuilder();
3446
3447                sb.append(_SQL_GETORGANIZATIONS);
3448
3449                if (obc != null) {
3450                    sb.append("ORDER BY ");
3451                    sb.append(obc.getOrderBy());
3452                }
3453
3454                else {
3455                    sb.append("ORDER BY ");
3456
3457                    sb.append("Organization_.name ASC");
3458                }
3459
3460                String sql = sb.toString();
3461
3462                SQLQuery q = session.createSQLQuery(sql);
3463
3464                q.addEntity("Organization_",
3465                    com.liferay.portal.model.impl.OrganizationImpl.class);
3466
3467                QueryPos qPos = QueryPos.getInstance(q);
3468
3469                qPos.add(pk);
3470
3471                List<com.liferay.portal.model.Organization> list = (List<com.liferay.portal.model.Organization>)QueryUtil.list(q,
3472                        getDialect(), start, end);
3473
3474                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3475                    finderClassName, finderMethodName, finderParams,
3476                    finderArgs, list);
3477
3478                return list;
3479            }
3480            catch (Exception e) {
3481                throw processException(e);
3482            }
3483            finally {
3484                closeSession(session);
3485            }
3486        }
3487        else {
3488            return (List<com.liferay.portal.model.Organization>)result;
3489        }
3490    }
3491
3492    public int getOrganizationsSize(long pk) throws SystemException {
3493        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_ORGS;
3494
3495        String finderClassName = "Users_Orgs";
3496
3497        String finderMethodName = "getOrganizationsSize";
3498        String[] finderParams = new String[] { Long.class.getName() };
3499        Object[] finderArgs = new Object[] { new Long(pk) };
3500
3501        Object result = null;
3502
3503        if (finderClassNameCacheEnabled) {
3504            result = FinderCacheUtil.getResult(finderClassName,
3505                    finderMethodName, finderParams, finderArgs, this);
3506        }
3507
3508        if (result == null) {
3509            Session session = null;
3510
3511            try {
3512                session = openSession();
3513
3514                SQLQuery q = session.createSQLQuery(_SQL_GETORGANIZATIONSSIZE);
3515
3516                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3517
3518                QueryPos qPos = QueryPos.getInstance(q);
3519
3520                qPos.add(pk);
3521
3522                Long count = null;
3523
3524                Iterator<Long> itr = q.list().iterator();
3525
3526                if (itr.hasNext()) {
3527                    count = itr.next();
3528                }
3529
3530                if (count == null) {
3531                    count = new Long(0);
3532                }
3533
3534                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3535                    finderClassName, finderMethodName, finderParams,
3536                    finderArgs, count);
3537
3538                return count.intValue();
3539            }
3540            catch (Exception e) {
3541                throw processException(e);
3542            }
3543            finally {
3544                closeSession(session);
3545            }
3546        }
3547        else {
3548            return ((Long)result).intValue();
3549        }
3550    }
3551
3552    public boolean containsOrganization(long pk, long organizationPK)
3553        throws SystemException {
3554        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_ORGS;
3555
3556        String finderClassName = "Users_Orgs";
3557
3558        String finderMethodName = "containsOrganizations";
3559        String[] finderParams = new String[] {
3560                Long.class.getName(),
3561                
3562                Long.class.getName()
3563            };
3564        Object[] finderArgs = new Object[] {
3565                new Long(pk),
3566                
3567                new Long(organizationPK)
3568            };
3569
3570        Object result = null;
3571
3572        if (finderClassNameCacheEnabled) {
3573            result = FinderCacheUtil.getResult(finderClassName,
3574                    finderMethodName, finderParams, finderArgs, this);
3575        }
3576
3577        if (result == null) {
3578            try {
3579                Boolean value = Boolean.valueOf(containsOrganization.contains(
3580                            pk, organizationPK));
3581
3582                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3583                    finderClassName, finderMethodName, finderParams,
3584                    finderArgs, value);
3585
3586                return value.booleanValue();
3587            }
3588            catch (Exception e) {
3589                throw processException(e);
3590            }
3591        }
3592        else {
3593            return ((Boolean)result).booleanValue();
3594        }
3595    }
3596
3597    public boolean containsOrganizations(long pk) throws SystemException {
3598        if (getOrganizationsSize(pk) > 0) {
3599            return true;
3600        }
3601        else {
3602            return false;
3603        }
3604    }
3605
3606    public void addOrganization(long pk, long organizationPK)
3607        throws SystemException {
3608        try {
3609            addOrganization.add(pk, organizationPK);
3610        }
3611        catch (Exception e) {
3612            throw processException(e);
3613        }
3614        finally {
3615            FinderCacheUtil.clearCache("Users_Orgs");
3616        }
3617    }
3618
3619    public void addOrganization(long pk,
3620        com.liferay.portal.model.Organization organization)
3621        throws SystemException {
3622        try {
3623            addOrganization.add(pk, organization.getPrimaryKey());
3624        }
3625        catch (Exception e) {
3626            throw processException(e);
3627        }
3628        finally {
3629            FinderCacheUtil.clearCache("Users_Orgs");
3630        }
3631    }
3632
3633    public void addOrganizations(long pk, long[] organizationPKs)
3634        throws SystemException {
3635        try {
3636            for (long organizationPK : organizationPKs) {
3637                addOrganization.add(pk, organizationPK);
3638            }
3639        }
3640        catch (Exception e) {
3641            throw processException(e);
3642        }
3643        finally {
3644            FinderCacheUtil.clearCache("Users_Orgs");
3645        }
3646    }
3647
3648    public void addOrganizations(long pk,
3649        List<com.liferay.portal.model.Organization> organizations)
3650        throws SystemException {
3651        try {
3652            for (com.liferay.portal.model.Organization organization : organizations) {
3653                addOrganization.add(pk, organization.getPrimaryKey());
3654            }
3655        }
3656        catch (Exception e) {
3657            throw processException(e);
3658        }
3659        finally {
3660            FinderCacheUtil.clearCache("Users_Orgs");
3661        }
3662    }
3663
3664    public void clearOrganizations(long pk) throws SystemException {
3665        try {
3666            clearOrganizations.clear(pk);
3667        }
3668        catch (Exception e) {
3669            throw processException(e);
3670        }
3671        finally {
3672            FinderCacheUtil.clearCache("Users_Orgs");
3673        }
3674    }
3675
3676    public void removeOrganization(long pk, long organizationPK)
3677        throws SystemException {
3678        try {
3679            removeOrganization.remove(pk, organizationPK);
3680        }
3681        catch (Exception e) {
3682            throw processException(e);
3683        }
3684        finally {
3685            FinderCacheUtil.clearCache("Users_Orgs");
3686        }
3687    }
3688
3689    public void removeOrganization(long pk,
3690        com.liferay.portal.model.Organization organization)
3691        throws SystemException {
3692        try {
3693            removeOrganization.remove(pk, organization.getPrimaryKey());
3694        }
3695        catch (Exception e) {
3696            throw processException(e);
3697        }
3698        finally {
3699            FinderCacheUtil.clearCache("Users_Orgs");
3700        }
3701    }
3702
3703    public void removeOrganizations(long pk, long[] organizationPKs)
3704        throws SystemException {
3705        try {
3706            for (long organizationPK : organizationPKs) {
3707                removeOrganization.remove(pk, organizationPK);
3708            }
3709        }
3710        catch (Exception e) {
3711            throw processException(e);
3712        }
3713        finally {
3714            FinderCacheUtil.clearCache("Users_Orgs");
3715        }
3716    }
3717
3718    public void removeOrganizations(long pk,
3719        List<com.liferay.portal.model.Organization> organizations)
3720        throws SystemException {
3721        try {
3722            for (com.liferay.portal.model.Organization organization : organizations) {
3723                removeOrganization.remove(pk, organization.getPrimaryKey());
3724            }
3725        }
3726        catch (Exception e) {
3727            throw processException(e);
3728        }
3729        finally {
3730            FinderCacheUtil.clearCache("Users_Orgs");
3731        }
3732    }
3733
3734    public void setOrganizations(long pk, long[] organizationPKs)
3735        throws SystemException {
3736        try {
3737            clearOrganizations.clear(pk);
3738
3739            for (long organizationPK : organizationPKs) {
3740                addOrganization.add(pk, organizationPK);
3741            }
3742        }
3743        catch (Exception e) {
3744            throw processException(e);
3745        }
3746        finally {
3747            FinderCacheUtil.clearCache("Users_Orgs");
3748        }
3749    }
3750
3751    public void setOrganizations(long pk,
3752        List<com.liferay.portal.model.Organization> organizations)
3753        throws SystemException {
3754        try {
3755            clearOrganizations.clear(pk);
3756
3757            for (com.liferay.portal.model.Organization organization : organizations) {
3758                addOrganization.add(pk, organization.getPrimaryKey());
3759            }
3760        }
3761        catch (Exception e) {
3762            throw processException(e);
3763        }
3764        finally {
3765            FinderCacheUtil.clearCache("Users_Orgs");
3766        }
3767    }
3768
3769    public List<com.liferay.portal.model.Permission> getPermissions(long pk)
3770        throws SystemException {
3771        return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3772    }
3773
3774    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
3775        int start, int end) throws SystemException {
3776        return getPermissions(pk, start, end, null);
3777    }
3778
3779    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
3780        int start, int end, OrderByComparator obc) throws SystemException {
3781        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_PERMISSIONS;
3782
3783        String finderClassName = "Users_Permissions";
3784
3785        String finderMethodName = "getPermissions";
3786        String[] finderParams = new String[] {
3787                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3788                "com.liferay.portal.kernel.util.OrderByComparator"
3789            };
3790        Object[] finderArgs = new Object[] {
3791                new Long(pk), String.valueOf(start), String.valueOf(end),
3792                String.valueOf(obc)
3793            };
3794
3795        Object result = null;
3796
3797        if (finderClassNameCacheEnabled) {
3798            result = FinderCacheUtil.getResult(finderClassName,
3799                    finderMethodName, finderParams, finderArgs, this);
3800        }
3801
3802        if (result == null) {
3803            Session session = null;
3804
3805            try {
3806                session = openSession();
3807
3808                StringBuilder sb = new StringBuilder();
3809
3810                sb.append(_SQL_GETPERMISSIONS);
3811
3812                if (obc != null) {
3813                    sb.append("ORDER BY ");
3814                    sb.append(obc.getOrderBy());
3815                }
3816
3817                String sql = sb.toString();
3818
3819                SQLQuery q = session.createSQLQuery(sql);
3820
3821                q.addEntity("Permission_",
3822                    com.liferay.portal.model.impl.PermissionImpl.class);
3823
3824                QueryPos qPos = QueryPos.getInstance(q);
3825
3826                qPos.add(pk);
3827
3828                List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
3829                        getDialect(), start, end);
3830
3831                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3832                    finderClassName, finderMethodName, finderParams,
3833                    finderArgs, list);
3834
3835                return list;
3836            }
3837            catch (Exception e) {
3838                throw processException(e);
3839            }
3840            finally {
3841                closeSession(session);
3842            }
3843        }
3844        else {
3845            return (List<com.liferay.portal.model.Permission>)result;
3846        }
3847    }
3848
3849    public int getPermissionsSize(long pk) throws SystemException {
3850        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_PERMISSIONS;
3851
3852        String finderClassName = "Users_Permissions";
3853
3854        String finderMethodName = "getPermissionsSize";
3855        String[] finderParams = new String[] { Long.class.getName() };
3856        Object[] finderArgs = new Object[] { new Long(pk) };
3857
3858        Object result = null;
3859
3860        if (finderClassNameCacheEnabled) {
3861            result = FinderCacheUtil.getResult(finderClassName,
3862                    finderMethodName, finderParams, finderArgs, this);
3863        }
3864
3865        if (result == null) {
3866            Session session = null;
3867
3868            try {
3869                session = openSession();
3870
3871                SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
3872
3873                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3874
3875                QueryPos qPos = QueryPos.getInstance(q);
3876
3877                qPos.add(pk);
3878
3879                Long count = null;
3880
3881                Iterator<Long> itr = q.list().iterator();
3882
3883                if (itr.hasNext()) {
3884                    count = itr.next();
3885                }
3886
3887                if (count == null) {
3888                    count = new Long(0);
3889                }
3890
3891                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3892                    finderClassName, finderMethodName, finderParams,
3893                    finderArgs, count);
3894
3895                return count.intValue();
3896            }
3897            catch (Exception e) {
3898                throw processException(e);
3899            }
3900            finally {
3901                closeSession(session);
3902            }
3903        }
3904        else {
3905            return ((Long)result).intValue();
3906        }
3907    }
3908
3909    public boolean containsPermission(long pk, long permissionPK)
3910        throws SystemException {
3911        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_PERMISSIONS;
3912
3913        String finderClassName = "Users_Permissions";
3914
3915        String finderMethodName = "containsPermissions";
3916        String[] finderParams = new String[] {
3917                Long.class.getName(),
3918                
3919                Long.class.getName()
3920            };
3921        Object[] finderArgs = new Object[] { new Long(pk), new Long(permissionPK) };
3922
3923        Object result = null;
3924
3925        if (finderClassNameCacheEnabled) {
3926            result = FinderCacheUtil.getResult(finderClassName,
3927                    finderMethodName, finderParams, finderArgs, this);
3928        }
3929
3930        if (result == null) {
3931            try {
3932                Boolean value = Boolean.valueOf(containsPermission.contains(
3933                            pk, permissionPK));
3934
3935                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3936                    finderClassName, finderMethodName, finderParams,
3937                    finderArgs, value);
3938
3939                return value.booleanValue();
3940            }
3941            catch (Exception e) {
3942                throw processException(e);
3943            }
3944        }
3945        else {
3946            return ((Boolean)result).booleanValue();
3947        }
3948    }
3949
3950    public boolean containsPermissions(long pk) throws SystemException {
3951        if (getPermissionsSize(pk) > 0) {
3952            return true;
3953        }
3954        else {
3955            return false;
3956        }
3957    }
3958
3959    public void addPermission(long pk, long permissionPK)
3960        throws SystemException {
3961        try {
3962            addPermission.add(pk, permissionPK);
3963        }
3964        catch (Exception e) {
3965            throw processException(e);
3966        }
3967        finally {
3968            FinderCacheUtil.clearCache("Users_Permissions");
3969        }
3970    }
3971
3972    public void addPermission(long pk,
3973        com.liferay.portal.model.Permission permission)
3974        throws SystemException {
3975        try {
3976            addPermission.add(pk, permission.getPrimaryKey());
3977        }
3978        catch (Exception e) {
3979            throw processException(e);
3980        }
3981        finally {
3982            FinderCacheUtil.clearCache("Users_Permissions");
3983        }
3984    }
3985
3986    public void addPermissions(long pk, long[] permissionPKs)
3987        throws SystemException {
3988        try {
3989            for (long permissionPK : permissionPKs) {
3990                addPermission.add(pk, permissionPK);
3991            }
3992        }
3993        catch (Exception e) {
3994            throw processException(e);
3995        }
3996        finally {
3997            FinderCacheUtil.clearCache("Users_Permissions");
3998        }
3999    }
4000
4001    public void addPermissions(long pk,
4002        List<com.liferay.portal.model.Permission> permissions)
4003        throws SystemException {
4004        try {
4005            for (com.liferay.portal.model.Permission permission : permissions) {
4006                addPermission.add(pk, permission.getPrimaryKey());
4007            }
4008        }
4009        catch (Exception e) {
4010            throw processException(e);
4011        }
4012        finally {
4013            FinderCacheUtil.clearCache("Users_Permissions");
4014        }
4015    }
4016
4017    public void clearPermissions(long pk) throws SystemException {
4018        try {
4019            clearPermissions.clear(pk);
4020        }
4021        catch (Exception e) {
4022            throw processException(e);
4023        }
4024        finally {
4025            FinderCacheUtil.clearCache("Users_Permissions");
4026        }
4027    }
4028
4029    public void removePermission(long pk, long permissionPK)
4030        throws SystemException {
4031        try {
4032            removePermission.remove(pk, permissionPK);
4033        }
4034        catch (Exception e) {
4035            throw processException(e);
4036        }
4037        finally {
4038            FinderCacheUtil.clearCache("Users_Permissions");
4039        }
4040    }
4041
4042    public void removePermission(long pk,
4043        com.liferay.portal.model.Permission permission)
4044        throws SystemException {
4045        try {
4046            removePermission.remove(pk, permission.getPrimaryKey());
4047        }
4048        catch (Exception e) {
4049            throw processException(e);
4050        }
4051        finally {
4052            FinderCacheUtil.clearCache("Users_Permissions");
4053        }
4054    }
4055
4056    public void removePermissions(long pk, long[] permissionPKs)
4057        throws SystemException {
4058        try {
4059            for (long permissionPK : permissionPKs) {
4060                removePermission.remove(pk, permissionPK);
4061            }
4062        }
4063        catch (Exception e) {
4064            throw processException(e);
4065        }
4066        finally {
4067            FinderCacheUtil.clearCache("Users_Permissions");
4068        }
4069    }
4070
4071    public void removePermissions(long pk,
4072        List<com.liferay.portal.model.Permission> permissions)
4073        throws SystemException {
4074        try {
4075            for (com.liferay.portal.model.Permission permission : permissions) {
4076                removePermission.remove(pk, permission.getPrimaryKey());
4077            }
4078        }
4079        catch (Exception e) {
4080            throw processException(e);
4081        }
4082        finally {
4083            FinderCacheUtil.clearCache("Users_Permissions");
4084        }
4085    }
4086
4087    public void setPermissions(long pk, long[] permissionPKs)
4088        throws SystemException {
4089        try {
4090            clearPermissions.clear(pk);
4091
4092            for (long permissionPK : permissionPKs) {
4093                addPermission.add(pk, permissionPK);
4094            }
4095        }
4096        catch (Exception e) {
4097            throw processException(e);
4098        }
4099        finally {
4100            FinderCacheUtil.clearCache("Users_Permissions");
4101        }
4102    }
4103
4104    public void setPermissions(long pk,
4105        List<com.liferay.portal.model.Permission> permissions)
4106        throws SystemException {
4107        try {
4108            clearPermissions.clear(pk);
4109
4110            for (com.liferay.portal.model.Permission permission : permissions) {
4111                addPermission.add(pk, permission.getPrimaryKey());
4112            }
4113        }
4114        catch (Exception e) {
4115            throw processException(e);
4116        }
4117        finally {
4118            FinderCacheUtil.clearCache("Users_Permissions");
4119        }
4120    }
4121
4122    public List<com.liferay.portal.model.Role> getRoles(long pk)
4123        throws SystemException {
4124        return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4125    }
4126
4127    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
4128        int end) throws SystemException {
4129        return getRoles(pk, start, end, null);
4130    }
4131
4132    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
4133        int end, OrderByComparator obc) throws SystemException {
4134        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_ROLES;
4135
4136        String finderClassName = "Users_Roles";
4137
4138        String finderMethodName = "getRoles";
4139        String[] finderParams = new String[] {
4140                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
4141                "com.liferay.portal.kernel.util.OrderByComparator"
4142            };
4143        Object[] finderArgs = new Object[] {
4144                new Long(pk), String.valueOf(start), String.valueOf(end),
4145                String.valueOf(obc)
4146            };
4147
4148        Object result = null;
4149
4150        if (finderClassNameCacheEnabled) {
4151            result = FinderCacheUtil.getResult(finderClassName,
4152                    finderMethodName, finderParams, finderArgs, this);
4153        }
4154
4155        if (result == null) {
4156            Session session = null;
4157
4158            try {
4159                session = openSession();
4160
4161                StringBuilder sb = new StringBuilder();
4162
4163                sb.append(_SQL_GETROLES);
4164
4165                if (obc != null) {
4166                    sb.append("ORDER BY ");
4167                    sb.append(obc.getOrderBy());
4168                }
4169
4170                else {
4171                    sb.append("ORDER BY ");
4172
4173                    sb.append("Role_.name ASC");
4174                }
4175
4176                String sql = sb.toString();
4177
4178                SQLQuery q = session.createSQLQuery(sql);
4179
4180                q.addEntity("Role_",
4181                    com.liferay.portal.model.impl.RoleImpl.class);
4182
4183                QueryPos qPos = QueryPos.getInstance(q);
4184
4185                qPos.add(pk);
4186
4187                List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
4188                        getDialect(), start, end);
4189
4190                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
4191                    finderClassName, finderMethodName, finderParams,
4192                    finderArgs, list);
4193
4194                return list;
4195            }
4196            catch (Exception e) {
4197                throw processException(e);
4198            }
4199            finally {
4200                closeSession(session);
4201            }
4202        }
4203        else {
4204            return (List<com.liferay.portal.model.Role>)result;
4205        }
4206    }
4207
4208    public int getRolesSize(long pk) throws SystemException {
4209        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_ROLES;
4210
4211        String finderClassName = "Users_Roles";
4212
4213        String finderMethodName = "getRolesSize";
4214        String[] finderParams = new String[] { Long.class.getName() };
4215        Object[] finderArgs = new Object[] { new Long(pk) };
4216
4217        Object result = null;
4218
4219        if (finderClassNameCacheEnabled) {
4220            result = FinderCacheUtil.getResult(finderClassName,
4221                    finderMethodName, finderParams, finderArgs, this);
4222        }
4223
4224        if (result == null) {
4225            Session session = null;
4226
4227            try {
4228                session = openSession();
4229
4230                SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
4231
4232                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
4233
4234                QueryPos qPos = QueryPos.getInstance(q);
4235
4236                qPos.add(pk);
4237
4238                Long count = null;
4239
4240                Iterator<Long> itr = q.list().iterator();
4241
4242                if (itr.hasNext()) {
4243                    count = itr.next();
4244                }
4245
4246                if (count == null) {
4247                    count = new Long(0);
4248                }
4249
4250                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
4251                    finderClassName, finderMethodName, finderParams,
4252                    finderArgs, count);
4253
4254                return count.intValue();
4255            }
4256            catch (Exception e) {
4257                throw processException(e);
4258            }
4259            finally {
4260                closeSession(session);
4261            }
4262        }
4263        else {
4264            return ((Long)result).intValue();
4265        }
4266    }
4267
4268    public boolean containsRole(long pk, long rolePK) throws SystemException {
4269        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_ROLES;
4270
4271        String finderClassName = "Users_Roles";
4272
4273        String finderMethodName = "containsRoles";
4274        String[] finderParams = new String[] {
4275                Long.class.getName(),
4276                
4277                Long.class.getName()
4278            };
4279        Object[] finderArgs = new Object[] { new Long(pk), new Long(rolePK) };
4280
4281        Object result = null;
4282
4283        if (finderClassNameCacheEnabled) {
4284            result = FinderCacheUtil.getResult(finderClassName,
4285                    finderMethodName, finderParams, finderArgs, this);
4286        }
4287
4288        if (result == null) {
4289            try {
4290                Boolean value = Boolean.valueOf(containsRole.contains(pk, rolePK));
4291
4292                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
4293                    finderClassName, finderMethodName, finderParams,
4294                    finderArgs, value);
4295
4296                return value.booleanValue();
4297            }
4298            catch (Exception e) {
4299                throw processException(e);
4300            }
4301        }
4302        else {
4303            return ((Boolean)result).booleanValue();
4304        }
4305    }
4306
4307    public boolean containsRoles(long pk) throws SystemException {
4308        if (getRolesSize(pk) > 0) {
4309            return true;
4310        }
4311        else {
4312            return false;
4313        }
4314    }
4315
4316    public void addRole(long pk, long rolePK) throws SystemException {
4317        try {
4318            addRole.add(pk, rolePK);
4319        }
4320        catch (Exception e) {
4321            throw processException(e);
4322        }
4323        finally {
4324            FinderCacheUtil.clearCache("Users_Roles");
4325        }
4326    }
4327
4328    public void addRole(long pk, com.liferay.portal.model.Role role)
4329        throws SystemException {
4330        try {
4331            addRole.add(pk, role.getPrimaryKey());
4332        }
4333        catch (Exception e) {
4334            throw processException(e);
4335        }
4336        finally {
4337            FinderCacheUtil.clearCache("Users_Roles");
4338        }
4339    }
4340
4341    public void addRoles(long pk, long[] rolePKs) throws SystemException {
4342        try {
4343            for (long rolePK : rolePKs) {
4344                addRole.add(pk, rolePK);
4345            }
4346        }
4347        catch (Exception e) {
4348            throw processException(e);
4349        }
4350        finally {
4351            FinderCacheUtil.clearCache("Users_Roles");
4352        }
4353    }
4354
4355    public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
4356        throws SystemException {
4357        try {
4358            for (com.liferay.portal.model.Role role : roles) {
4359                addRole.add(pk, role.getPrimaryKey());
4360            }
4361        }
4362        catch (Exception e) {
4363            throw processException(e);
4364        }
4365        finally {
4366            FinderCacheUtil.clearCache("Users_Roles");
4367        }
4368    }
4369
4370    public void clearRoles(long pk) throws SystemException {
4371        try {
4372            clearRoles.clear(pk);
4373        }
4374        catch (Exception e) {
4375            throw processException(e);
4376        }
4377        finally {
4378            FinderCacheUtil.clearCache("Users_Roles");
4379        }
4380    }
4381
4382    public void removeRole(long pk, long rolePK) throws SystemException {
4383        try {
4384            removeRole.remove(pk, rolePK);
4385        }
4386        catch (Exception e) {
4387            throw processException(e);
4388        }
4389        finally {
4390            FinderCacheUtil.clearCache("Users_Roles");
4391        }
4392    }
4393
4394    public void removeRole(long pk, com.liferay.portal.model.Role role)
4395        throws SystemException {
4396        try {
4397            removeRole.remove(pk, role.getPrimaryKey());
4398        }
4399        catch (Exception e) {
4400            throw processException(e);
4401        }
4402        finally {
4403            FinderCacheUtil.clearCache("Users_Roles");
4404        }
4405    }
4406
4407    public void removeRoles(long pk, long[] rolePKs) throws SystemException {
4408        try {
4409            for (long rolePK : rolePKs) {
4410                removeRole.remove(pk, rolePK);
4411            }
4412        }
4413        catch (Exception e) {
4414            throw processException(e);
4415        }
4416        finally {
4417            FinderCacheUtil.clearCache("Users_Roles");
4418        }
4419    }
4420
4421    public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
4422        throws SystemException {
4423        try {
4424            for (com.liferay.portal.model.Role role : roles) {
4425                removeRole.remove(pk, role.getPrimaryKey());
4426            }
4427        }
4428        catch (Exception e) {
4429            throw processException(e);
4430        }
4431        finally {
4432            FinderCacheUtil.clearCache("Users_Roles");
4433        }
4434    }
4435
4436    public void setRoles(long pk, long[] rolePKs) throws SystemException {
4437        try {
4438            clearRoles.clear(pk);
4439
4440            for (long rolePK : rolePKs) {
4441                addRole.add(pk, rolePK);
4442            }
4443        }
4444        catch (Exception e) {
4445            throw processException(e);
4446        }
4447        finally {
4448            FinderCacheUtil.clearCache("Users_Roles");
4449        }
4450    }
4451
4452    public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
4453        throws SystemException {
4454        try {
4455            clearRoles.clear(pk);
4456
4457            for (com.liferay.portal.model.Role role : roles) {
4458                addRole.add(pk, role.getPrimaryKey());
4459            }
4460        }
4461        catch (Exception e) {
4462            throw processException(e);
4463        }
4464        finally {
4465            FinderCacheUtil.clearCache("Users_Roles");
4466        }
4467    }
4468
4469    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk)
4470        throws SystemException {
4471        return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4472    }
4473
4474    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
4475        int start, int end) throws SystemException {
4476        return getUserGroups(pk, start, end, null);
4477    }
4478
4479    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
4480        int start, int end, OrderByComparator obc) throws SystemException {
4481        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_USERGROUPS;
4482
4483        String finderClassName = "Users_UserGroups";
4484
4485        String finderMethodName = "getUserGroups";
4486        String[] finderParams = new String[] {
4487                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
4488                "com.liferay.portal.kernel.util.OrderByComparator"
4489            };
4490        Object[] finderArgs = new Object[] {
4491                new Long(pk), String.valueOf(start), String.valueOf(end),
4492                String.valueOf(obc)
4493            };
4494
4495        Object result = null;
4496
4497        if (finderClassNameCacheEnabled) {
4498            result = FinderCacheUtil.getResult(finderClassName,
4499                    finderMethodName, finderParams, finderArgs, this);
4500        }
4501
4502        if (result == null) {
4503            Session session = null;
4504
4505            try {
4506                session = openSession();
4507
4508                StringBuilder sb = new StringBuilder();
4509
4510                sb.append(_SQL_GETUSERGROUPS);
4511
4512                if (obc != null) {
4513                    sb.append("ORDER BY ");
4514                    sb.append(obc.getOrderBy());
4515                }
4516
4517                else {
4518                    sb.append("ORDER BY ");
4519
4520                    sb.append("UserGroup.name ASC");
4521                }
4522
4523                String sql = sb.toString();
4524
4525                SQLQuery q = session.createSQLQuery(sql);
4526
4527                q.addEntity("UserGroup",
4528                    com.liferay.portal.model.impl.UserGroupImpl.class);
4529
4530                QueryPos qPos = QueryPos.getInstance(q);
4531
4532                qPos.add(pk);
4533
4534                List<com.liferay.portal.model.UserGroup> list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
4535                        getDialect(), start, end);
4536
4537                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
4538                    finderClassName, finderMethodName, finderParams,
4539                    finderArgs, list);
4540
4541                return list;
4542            }
4543            catch (Exception e) {
4544                throw processException(e);
4545            }
4546            finally {
4547                closeSession(session);
4548            }
4549        }
4550        else {
4551            return (List<com.liferay.portal.model.UserGroup>)result;
4552        }
4553    }
4554
4555    public int getUserGroupsSize(long pk) throws SystemException {
4556        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_USERGROUPS;
4557
4558        String finderClassName = "Users_UserGroups";
4559
4560        String finderMethodName = "getUserGroupsSize";
4561        String[] finderParams = new String[] { Long.class.getName() };
4562        Object[] finderArgs = new Object[] { new Long(pk) };
4563
4564        Object result = null;
4565
4566        if (finderClassNameCacheEnabled) {
4567            result = FinderCacheUtil.getResult(finderClassName,
4568                    finderMethodName, finderParams, finderArgs, this);
4569        }
4570
4571        if (result == null) {
4572            Session session = null;
4573
4574            try {
4575                session = openSession();
4576
4577                SQLQuery q = session.createSQLQuery(_SQL_GETUSERGROUPSSIZE);
4578
4579                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
4580
4581                QueryPos qPos = QueryPos.getInstance(q);
4582
4583                qPos.add(pk);
4584
4585                Long count = null;
4586
4587                Iterator<Long> itr = q.list().iterator();
4588
4589                if (itr.hasNext()) {
4590                    count = itr.next();
4591                }
4592
4593                if (count == null) {
4594                    count = new Long(0);
4595                }
4596
4597                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
4598                    finderClassName, finderMethodName, finderParams,
4599                    finderArgs, count);
4600
4601                return count.intValue();
4602            }
4603            catch (Exception e) {
4604                throw processException(e);
4605            }
4606            finally {
4607                closeSession(session);
4608            }
4609        }
4610        else {
4611            return ((Long)result).intValue();
4612        }
4613    }
4614
4615    public boolean containsUserGroup(long pk, long userGroupPK)
4616        throws SystemException {
4617        boolean finderClassNameCacheEnabled = UserModelImpl.CACHE_ENABLED_USERS_USERGROUPS;
4618
4619        String finderClassName = "Users_UserGroups";
4620
4621        String finderMethodName = "containsUserGroups";
4622        String[] finderParams = new String[] {
4623                Long.class.getName(),
4624                
4625                Long.class.getName()
4626            };
4627        Object[] finderArgs = new Object[] { new Long(pk), new Long(userGroupPK) };
4628
4629        Object result = null;
4630
4631        if (finderClassNameCacheEnabled) {
4632            result = FinderCacheUtil.getResult(finderClassName,
4633                    finderMethodName, finderParams, finderArgs, this);
4634        }
4635
4636        if (result == null) {
4637            try {
4638                Boolean value = Boolean.valueOf(containsUserGroup.contains(pk,
4639                            userGroupPK));
4640
4641                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
4642                    finderClassName, finderMethodName, finderParams,
4643                    finderArgs, value);
4644
4645                return value.booleanValue();
4646            }
4647            catch (Exception e) {
4648                throw processException(e);
4649            }
4650        }
4651        else {
4652            return ((Boolean)result).booleanValue();
4653        }
4654    }
4655
4656    public boolean containsUserGroups(long pk) throws SystemException {
4657        if (getUserGroupsSize(pk) > 0) {
4658            return true;
4659        }
4660        else {
4661            return false;
4662        }
4663    }
4664
4665    public void addUserGroup(long pk, long userGroupPK)
4666        throws SystemException {
4667        try {
4668            addUserGroup.add(pk, userGroupPK);
4669        }
4670        catch (Exception e) {
4671            throw processException(e);
4672        }
4673        finally {
4674            FinderCacheUtil.clearCache("Users_UserGroups");
4675        }
4676    }
4677
4678    public void addUserGroup(long pk,
4679        com.liferay.portal.model.UserGroup userGroup) throws SystemException {
4680        try {
4681            addUserGroup.add(pk, userGroup.getPrimaryKey());
4682        }
4683        catch (Exception e) {
4684            throw processException(e);
4685        }
4686        finally {
4687            FinderCacheUtil.clearCache("Users_UserGroups");
4688        }
4689    }
4690
4691    public void addUserGroups(long pk, long[] userGroupPKs)
4692        throws SystemException {
4693        try {
4694            for (long userGroupPK : userGroupPKs) {
4695                addUserGroup.add(pk, userGroupPK);
4696            }
4697        }
4698        catch (Exception e) {
4699            throw processException(e);
4700        }
4701        finally {
4702            FinderCacheUtil.clearCache("Users_UserGroups");
4703        }
4704    }
4705
4706    public void addUserGroups(long pk,
4707        List<com.liferay.portal.model.UserGroup> userGroups)
4708        throws SystemException {
4709        try {
4710            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
4711                addUserGroup.add(pk, userGroup.getPrimaryKey());
4712            }
4713        }
4714        catch (Exception e) {
4715            throw processException(e);
4716        }
4717        finally {
4718            FinderCacheUtil.clearCache("Users_UserGroups");
4719        }
4720    }
4721
4722    public void clearUserGroups(long pk) throws SystemException {
4723        try {
4724            clearUserGroups.clear(pk);
4725        }
4726        catch (Exception e) {
4727            throw processException(e);
4728        }
4729        finally {
4730            FinderCacheUtil.clearCache("Users_UserGroups");
4731        }
4732    }
4733
4734    public void removeUserGroup(long pk, long userGroupPK)
4735        throws SystemException {
4736        try {
4737            removeUserGroup.remove(pk, userGroupPK);
4738        }
4739        catch (Exception e) {
4740            throw processException(e);
4741        }
4742        finally {
4743            FinderCacheUtil.clearCache("Users_UserGroups");
4744        }
4745    }
4746
4747    public void removeUserGroup(long pk,
4748        com.liferay.portal.model.UserGroup userGroup) throws SystemException {
4749        try {
4750            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
4751        }
4752        catch (Exception e) {
4753            throw processException(e);
4754        }
4755        finally {
4756            FinderCacheUtil.clearCache("Users_UserGroups");
4757        }
4758    }
4759
4760    public void removeUserGroups(long pk, long[] userGroupPKs)
4761        throws SystemException {
4762        try {
4763            for (long userGroupPK : userGroupPKs) {
4764                removeUserGroup.remove(pk, userGroupPK);
4765            }
4766        }
4767        catch (Exception e) {
4768            throw processException(e);
4769        }
4770        finally {
4771            FinderCacheUtil.clearCache("Users_UserGroups");
4772        }
4773    }
4774
4775    public void removeUserGroups(long pk,
4776        List<com.liferay.portal.model.UserGroup> userGroups)
4777        throws SystemException {
4778        try {
4779            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
4780                removeUserGroup.remove(pk, userGroup.getPrimaryKey());
4781            }
4782        }
4783        catch (Exception e) {
4784            throw processException(e);
4785        }
4786        finally {
4787            FinderCacheUtil.clearCache("Users_UserGroups");
4788        }
4789    }
4790
4791    public void setUserGroups(long pk, long[] userGroupPKs)
4792        throws SystemException {
4793        try {
4794            clearUserGroups.clear(pk);
4795
4796            for (long userGroupPK : userGroupPKs) {
4797                addUserGroup.add(pk, userGroupPK);
4798            }
4799        }
4800        catch (Exception e) {
4801            throw processException(e);
4802        }
4803        finally {
4804            FinderCacheUtil.clearCache("Users_UserGroups");
4805        }
4806    }
4807
4808    public void setUserGroups(long pk,
4809        List<com.liferay.portal.model.UserGroup> userGroups)
4810        throws SystemException {
4811        try {
4812            clearUserGroups.clear(pk);
4813
4814            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
4815                addUserGroup.add(pk, userGroup.getPrimaryKey());
4816            }
4817        }
4818        catch (Exception e) {
4819            throw processException(e);
4820        }
4821        finally {
4822            FinderCacheUtil.clearCache("Users_UserGroups");
4823        }
4824    }
4825
4826    public void registerListener(ModelListener listener) {
4827        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
4828
4829        listeners.add(listener);
4830
4831        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
4832    }
4833
4834    public void unregisterListener(ModelListener listener) {
4835        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
4836
4837        listeners.remove(listener);
4838
4839        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
4840    }
4841
4842    public void afterPropertiesSet() {
4843        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4844                    com.liferay.portal.util.PropsUtil.get(
4845                        "value.object.listener.com.liferay.portal.model.User")));
4846
4847        if (listenerClassNames.length > 0) {
4848            try {
4849                List<ModelListener> listeners = new ArrayList<ModelListener>();
4850
4851                for (String listenerClassName : listenerClassNames) {
4852                    listeners.add((ModelListener)Class.forName(
4853                            listenerClassName).newInstance());
4854                }
4855
4856                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
4857            }
4858            catch (Exception e) {
4859                _log.error(e);
4860            }
4861        }
4862
4863        containsGroup = new ContainsGroup(this);
4864
4865        addGroup = new AddGroup(this);
4866        clearGroups = new ClearGroups(this);
4867        removeGroup = new RemoveGroup(this);
4868
4869        containsOrganization = new ContainsOrganization(this);
4870
4871        addOrganization = new AddOrganization(this);
4872        clearOrganizations = new ClearOrganizations(this);
4873        removeOrganization = new RemoveOrganization(this);
4874
4875        containsPermission = new ContainsPermission(this);
4876
4877        addPermission = new AddPermission(this);
4878        clearPermissions = new ClearPermissions(this);
4879        removePermission = new RemovePermission(this);
4880
4881        containsRole = new ContainsRole(this);
4882
4883        addRole = new AddRole(this);
4884        clearRoles = new ClearRoles(this);
4885        removeRole = new RemoveRole(this);
4886
4887        containsUserGroup = new ContainsUserGroup(this);
4888
4889        addUserGroup = new AddUserGroup(this);
4890        clearUserGroups = new ClearUserGroups(this);
4891        removeUserGroup = new RemoveUserGroup(this);
4892    }
4893
4894    protected ContainsGroup containsGroup;
4895    protected AddGroup addGroup;
4896    protected ClearGroups clearGroups;
4897    protected RemoveGroup removeGroup;
4898    protected ContainsOrganization containsOrganization;
4899    protected AddOrganization addOrganization;
4900    protected ClearOrganizations clearOrganizations;
4901    protected RemoveOrganization removeOrganization;
4902    protected ContainsPermission containsPermission;
4903    protected AddPermission addPermission;
4904    protected ClearPermissions clearPermissions;
4905    protected RemovePermission removePermission;
4906    protected ContainsRole containsRole;
4907    protected AddRole addRole;
4908    protected ClearRoles clearRoles;
4909    protected RemoveRole removeRole;
4910    protected ContainsUserGroup containsUserGroup;
4911    protected AddUserGroup addUserGroup;
4912    protected ClearUserGroups clearUserGroups;
4913    protected RemoveUserGroup removeUserGroup;
4914
4915    protected class ContainsGroup {
4916        protected ContainsGroup(UserPersistenceImpl persistenceImpl) {
4917            super();
4918
4919            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4920                    _SQL_CONTAINSGROUP,
4921                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
4922        }
4923
4924        protected boolean contains(long userId, long groupId) {
4925            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4926                        new Long(userId), new Long(groupId)
4927                    });
4928
4929            if (results.size() > 0) {
4930                Integer count = results.get(0);
4931
4932                if (count.intValue() > 0) {
4933                    return true;
4934                }
4935            }
4936
4937            return false;
4938        }
4939
4940        private MappingSqlQuery _mappingSqlQuery;
4941    }
4942
4943    protected class AddGroup {
4944        protected AddGroup(UserPersistenceImpl persistenceImpl) {
4945            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4946                    "INSERT INTO Users_Groups (userId, groupId) VALUES (?, ?)",
4947                    new int[] { Types.BIGINT, Types.BIGINT });
4948            _persistenceImpl = persistenceImpl;
4949        }
4950
4951        protected void add(long userId, long groupId) {
4952            if (!_persistenceImpl.containsGroup.contains(userId, groupId)) {
4953                _sqlUpdate.update(new Object[] {
4954                        new Long(userId), new Long(groupId)
4955                    });
4956            }
4957        }
4958
4959        private SqlUpdate _sqlUpdate;
4960        private UserPersistenceImpl _persistenceImpl;
4961    }
4962
4963    protected class ClearGroups {
4964        protected ClearGroups(UserPersistenceImpl persistenceImpl) {
4965            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4966                    "DELETE FROM Users_Groups WHERE userId = ?",
4967                    new int[] { Types.BIGINT });
4968        }
4969
4970        protected void clear(long userId) {
4971            _sqlUpdate.update(new Object[] { new Long(userId) });
4972        }
4973
4974        private SqlUpdate _sqlUpdate;
4975    }
4976
4977    protected class RemoveGroup {
4978        protected RemoveGroup(UserPersistenceImpl persistenceImpl) {
4979            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4980                    "DELETE FROM Users_Groups WHERE userId = ? AND groupId = ?",
4981                    new int[] { Types.BIGINT, Types.BIGINT });
4982        }
4983
4984        protected void remove(long userId, long groupId) {
4985            _sqlUpdate.update(new Object[] { new Long(userId), new Long(groupId) });
4986        }
4987
4988        private SqlUpdate _sqlUpdate;
4989    }
4990
4991    protected class ContainsOrganization {
4992        protected ContainsOrganization(UserPersistenceImpl persistenceImpl) {
4993            super();
4994
4995            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4996                    _SQL_CONTAINSORGANIZATION,
4997                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
4998        }
4999
5000        protected boolean contains(long userId, long organizationId) {
5001            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5002                        new Long(userId), new Long(organizationId)
5003                    });
5004
5005            if (results.size() > 0) {
5006                Integer count = results.get(0);
5007
5008                if (count.intValue() > 0) {
5009                    return true;
5010                }
5011            }
5012
5013            return false;
5014        }
5015
5016        private MappingSqlQuery _mappingSqlQuery;
5017    }
5018
5019    protected class AddOrganization {
5020        protected AddOrganization(UserPersistenceImpl persistenceImpl) {
5021            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5022                    "INSERT INTO Users_Orgs (userId, organizationId) VALUES (?, ?)",
5023                    new int[] { Types.BIGINT, Types.BIGINT });
5024            _persistenceImpl = persistenceImpl;
5025        }
5026
5027        protected void add(long userId, long organizationId) {
5028            if (!_persistenceImpl.containsOrganization.contains(userId,
5029                        organizationId)) {
5030                _sqlUpdate.update(new Object[] {
5031                        new Long(userId), new Long(organizationId)
5032                    });
5033            }
5034        }
5035
5036        private SqlUpdate _sqlUpdate;
5037        private UserPersistenceImpl _persistenceImpl;
5038    }
5039
5040    protected class ClearOrganizations {
5041        protected ClearOrganizations(UserPersistenceImpl persistenceImpl) {
5042            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5043                    "DELETE FROM Users_Orgs WHERE userId = ?",
5044                    new int[] { Types.BIGINT });
5045        }
5046
5047        protected void clear(long userId) {
5048            _sqlUpdate.update(new Object[] { new Long(userId) });
5049        }
5050
5051        private SqlUpdate _sqlUpdate;
5052    }
5053
5054    protected class RemoveOrganization {
5055        protected RemoveOrganization(UserPersistenceImpl persistenceImpl) {
5056            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5057                    "DELETE FROM Users_Orgs WHERE userId = ? AND organizationId = ?",
5058                    new int[] { Types.BIGINT, Types.BIGINT });
5059        }
5060
5061        protected void remove(long userId, long organizationId) {
5062            _sqlUpdate.update(new Object[] {
5063                    new Long(userId), new Long(organizationId)
5064                });
5065        }
5066
5067        private SqlUpdate _sqlUpdate;
5068    }
5069
5070    protected class ContainsPermission {
5071        protected ContainsPermission(UserPersistenceImpl persistenceImpl) {
5072            super();
5073
5074            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5075                    _SQL_CONTAINSPERMISSION,
5076                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
5077        }
5078
5079        protected boolean contains(long userId, long permissionId) {
5080            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5081                        new Long(userId), new Long(permissionId)
5082                    });
5083
5084            if (results.size() > 0) {
5085                Integer count = results.get(0);
5086
5087                if (count.intValue() > 0) {
5088                    return true;
5089                }
5090            }
5091
5092            return false;
5093        }
5094
5095        private MappingSqlQuery _mappingSqlQuery;
5096    }
5097
5098    protected class AddPermission {
5099        protected AddPermission(UserPersistenceImpl persistenceImpl) {
5100            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5101                    "INSERT INTO Users_Permissions (userId, permissionId) VALUES (?, ?)",
5102                    new int[] { Types.BIGINT, Types.BIGINT });
5103            _persistenceImpl = persistenceImpl;
5104        }
5105
5106        protected void add(long userId, long permissionId) {
5107            if (!_persistenceImpl.containsPermission.contains(userId,
5108                        permissionId)) {
5109                _sqlUpdate.update(new Object[] {
5110                        new Long(userId), new Long(permissionId)
5111                    });
5112            }
5113        }
5114
5115        private SqlUpdate _sqlUpdate;
5116        private UserPersistenceImpl _persistenceImpl;
5117    }
5118
5119    protected class ClearPermissions {
5120        protected ClearPermissions(UserPersistenceImpl persistenceImpl) {
5121            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5122                    "DELETE FROM Users_Permissions WHERE userId = ?",
5123                    new int[] { Types.BIGINT });
5124        }
5125
5126        protected void clear(long userId) {
5127            _sqlUpdate.update(new Object[] { new Long(userId) });
5128        }
5129
5130        private SqlUpdate _sqlUpdate;
5131    }
5132
5133    protected class RemovePermission {
5134        protected RemovePermission(UserPersistenceImpl persistenceImpl) {
5135            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5136                    "DELETE FROM Users_Permissions WHERE userId = ? AND permissionId = ?",
5137                    new int[] { Types.BIGINT, Types.BIGINT });
5138        }
5139
5140        protected void remove(long userId, long permissionId) {
5141            _sqlUpdate.update(new Object[] {
5142                    new Long(userId), new Long(permissionId)
5143                });
5144        }
5145
5146        private SqlUpdate _sqlUpdate;
5147    }
5148
5149    protected class ContainsRole {
5150        protected ContainsRole(UserPersistenceImpl persistenceImpl) {
5151            super();
5152
5153            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5154                    _SQL_CONTAINSROLE,
5155                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
5156        }
5157
5158        protected boolean contains(long userId, long roleId) {
5159            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5160                        new Long(userId), new Long(roleId)
5161                    });
5162
5163            if (results.size() > 0) {
5164                Integer count = results.get(0);
5165
5166                if (count.intValue() > 0) {
5167                    return true;
5168                }
5169            }
5170
5171            return false;
5172        }
5173
5174        private MappingSqlQuery _mappingSqlQuery;
5175    }
5176
5177    protected class AddRole {
5178        protected AddRole(UserPersistenceImpl persistenceImpl) {
5179            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5180                    "INSERT INTO Users_Roles (userId, roleId) VALUES (?, ?)",
5181                    new int[] { Types.BIGINT, Types.BIGINT });
5182            _persistenceImpl = persistenceImpl;
5183        }
5184
5185        protected void add(long userId, long roleId) {
5186            if (!_persistenceImpl.containsRole.contains(userId, roleId)) {
5187                _sqlUpdate.update(new Object[] {
5188                        new Long(userId), new Long(roleId)
5189                    });
5190            }
5191        }
5192
5193        private SqlUpdate _sqlUpdate;
5194        private UserPersistenceImpl _persistenceImpl;
5195    }
5196
5197    protected class ClearRoles {
5198        protected ClearRoles(UserPersistenceImpl persistenceImpl) {
5199            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5200                    "DELETE FROM Users_Roles WHERE userId = ?",
5201                    new int[] { Types.BIGINT });
5202        }
5203
5204        protected void clear(long userId) {
5205            _sqlUpdate.update(new Object[] { new Long(userId) });
5206        }
5207
5208        private SqlUpdate _sqlUpdate;
5209    }
5210
5211    protected class RemoveRole {
5212        protected RemoveRole(UserPersistenceImpl persistenceImpl) {
5213            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5214                    "DELETE FROM Users_Roles WHERE userId = ? AND roleId = ?",
5215                    new int[] { Types.BIGINT, Types.BIGINT });
5216        }
5217
5218        protected void remove(long userId, long roleId) {
5219            _sqlUpdate.update(new Object[] { new Long(userId), new Long(roleId) });
5220        }
5221
5222        private SqlUpdate _sqlUpdate;
5223    }
5224
5225    protected class ContainsUserGroup {
5226        protected ContainsUserGroup(UserPersistenceImpl persistenceImpl) {
5227            super();
5228
5229            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5230                    _SQL_CONTAINSUSERGROUP,
5231                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
5232        }
5233
5234        protected boolean contains(long userId, long userGroupId) {
5235            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5236                        new Long(userId), new Long(userGroupId)
5237                    });
5238
5239            if (results.size() > 0) {
5240                Integer count = results.get(0);
5241
5242                if (count.intValue() > 0) {
5243                    return true;
5244                }
5245            }
5246
5247            return false;
5248        }
5249
5250        private MappingSqlQuery _mappingSqlQuery;
5251    }
5252
5253    protected class AddUserGroup {
5254        protected AddUserGroup(UserPersistenceImpl persistenceImpl) {
5255            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5256                    "INSERT INTO Users_UserGroups (userId, userGroupId) VALUES (?, ?)",
5257                    new int[] { Types.BIGINT, Types.BIGINT });
5258            _persistenceImpl = persistenceImpl;
5259        }
5260
5261        protected void add(long userId, long userGroupId) {
5262            if (!_persistenceImpl.containsUserGroup.contains(userId, userGroupId)) {
5263                _sqlUpdate.update(new Object[] {
5264                        new Long(userId), new Long(userGroupId)
5265                    });
5266            }
5267        }
5268
5269        private SqlUpdate _sqlUpdate;
5270        private UserPersistenceImpl _persistenceImpl;
5271    }
5272
5273    protected class ClearUserGroups {
5274        protected ClearUserGroups(UserPersistenceImpl persistenceImpl) {
5275            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5276                    "DELETE FROM Users_UserGroups WHERE userId = ?",
5277                    new int[] { Types.BIGINT });
5278        }
5279
5280        protected void clear(long userId) {
5281            _sqlUpdate.update(new Object[] { new Long(userId) });
5282        }
5283
5284        private SqlUpdate _sqlUpdate;
5285    }
5286
5287    protected class RemoveUserGroup {
5288        protected RemoveUserGroup(UserPersistenceImpl persistenceImpl) {
5289            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5290                    "DELETE FROM Users_UserGroups WHERE userId = ? AND userGroupId = ?",
5291                    new int[] { Types.BIGINT, Types.BIGINT });
5292        }
5293
5294        protected void remove(long userId, long userGroupId) {
5295            _sqlUpdate.update(new Object[] {
5296                    new Long(userId), new Long(userGroupId)
5297                });
5298        }
5299
5300        private SqlUpdate _sqlUpdate;
5301    }
5302
5303    private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Users_Groups ON (Users_Groups.groupId = Group_.groupId) WHERE (Users_Groups.userId = ?)";
5304    private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE userId = ?";
5305    private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE userId = ? AND groupId = ?";
5306    private static final String _SQL_GETORGANIZATIONS = "SELECT {Organization_.*} FROM Organization_ INNER JOIN Users_Orgs ON (Users_Orgs.organizationId = Organization_.organizationId) WHERE (Users_Orgs.userId = ?)";
5307    private static final String _SQL_GETORGANIZATIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE userId = ?";
5308    private static final String _SQL_CONTAINSORGANIZATION = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE userId = ? AND organizationId = ?";
5309    private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Users_Permissions ON (Users_Permissions.permissionId = Permission_.permissionId) WHERE (Users_Permissions.userId = ?)";
5310    private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE userId = ?";
5311    private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE userId = ? AND permissionId = ?";
5312    private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Users_Roles ON (Users_Roles.roleId = Role_.roleId) WHERE (Users_Roles.userId = ?)";
5313    private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE userId = ?";
5314    private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE userId = ? AND roleId = ?";
5315    private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN Users_UserGroups ON (Users_UserGroups.userGroupId = UserGroup.userGroupId) WHERE (Users_UserGroups.userId = ?)";
5316    private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userId = ?";
5317    private static final String _SQL_CONTAINSUSERGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userId = ? AND userGroupId = ?";
5318    private static Log _log = LogFactory.getLog(UserPersistenceImpl.class);
5319    private ModelListener[] _listeners = new ModelListener[0];
5320}