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