1   /**
2    * Copyright (c) 2000-2007 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchUserException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.dao.DynamicQuery;
28  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
29  import com.liferay.portal.kernel.util.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.model.User;
33  import com.liferay.portal.model.impl.UserImpl;
34  import com.liferay.portal.service.persistence.BasePersistence;
35  import com.liferay.portal.spring.hibernate.FinderCache;
36  import com.liferay.portal.spring.hibernate.HibernateUtil;
37  
38  import com.liferay.util.dao.hibernate.QueryPos;
39  import com.liferay.util.dao.hibernate.QueryUtil;
40  
41  import org.apache.commons.logging.Log;
42  import org.apache.commons.logging.LogFactory;
43  
44  import org.hibernate.Hibernate;
45  import org.hibernate.Query;
46  import org.hibernate.SQLQuery;
47  import org.hibernate.Session;
48  
49  import org.springframework.dao.DataAccessException;
50  
51  import org.springframework.jdbc.core.SqlParameter;
52  import org.springframework.jdbc.object.MappingSqlQuery;
53  import org.springframework.jdbc.object.SqlUpdate;
54  
55  import java.sql.ResultSet;
56  import java.sql.SQLException;
57  import java.sql.Types;
58  
59  import java.util.Collections;
60  import java.util.Iterator;
61  import java.util.List;
62  
63  /**
64   * <a href="UserPersistenceImpl.java.html"><b><i>View Source</i></b></a>
65   *
66   * @author Brian Wing Shun Chan
67   *
68   */
69  public class UserPersistenceImpl extends BasePersistence
70      implements UserPersistence {
71      public User create(long userId) {
72          User user = new UserImpl();
73          user.setNew(true);
74          user.setPrimaryKey(userId);
75  
76          return user;
77      }
78  
79      public User remove(long userId) throws NoSuchUserException, SystemException {
80          Session session = null;
81  
82          try {
83              session = openSession();
84  
85              User user = (User)session.get(UserImpl.class, new Long(userId));
86  
87              if (user == null) {
88                  if (_log.isWarnEnabled()) {
89                      _log.warn("No User exists with the primary key " + userId);
90                  }
91  
92                  throw new NoSuchUserException(
93                      "No User exists with the primary key " + userId);
94              }
95  
96              return remove(user);
97          }
98          catch (NoSuchUserException nsee) {
99              throw nsee;
100         }
101         catch (Exception e) {
102             throw HibernateUtil.processException(e);
103         }
104         finally {
105             closeSession(session);
106         }
107     }
108 
109     public User remove(User user) throws SystemException {
110         try {
111             clearGroups.clear(user.getPrimaryKey());
112         }
113         catch (Exception e) {
114             throw HibernateUtil.processException(e);
115         }
116         finally {
117             FinderCache.clearCache("Users_Groups");
118         }
119 
120         try {
121             clearOrganizations.clear(user.getPrimaryKey());
122         }
123         catch (Exception e) {
124             throw HibernateUtil.processException(e);
125         }
126         finally {
127             FinderCache.clearCache("Users_Orgs");
128         }
129 
130         try {
131             clearPermissions.clear(user.getPrimaryKey());
132         }
133         catch (Exception e) {
134             throw HibernateUtil.processException(e);
135         }
136         finally {
137             FinderCache.clearCache("Users_Permissions");
138         }
139 
140         try {
141             clearRoles.clear(user.getPrimaryKey());
142         }
143         catch (Exception e) {
144             throw HibernateUtil.processException(e);
145         }
146         finally {
147             FinderCache.clearCache("Users_Roles");
148         }
149 
150         try {
151             clearUserGroups.clear(user.getPrimaryKey());
152         }
153         catch (Exception e) {
154             throw HibernateUtil.processException(e);
155         }
156         finally {
157             FinderCache.clearCache("Users_UserGroups");
158         }
159 
160         Session session = null;
161 
162         try {
163             session = openSession();
164             session.delete(user);
165             session.flush();
166 
167             return user;
168         }
169         catch (Exception e) {
170             throw HibernateUtil.processException(e);
171         }
172         finally {
173             closeSession(session);
174             FinderCache.clearCache(User.class.getName());
175         }
176     }
177 
178     public User update(com.liferay.portal.model.User user)
179         throws SystemException {
180         return update(user, false);
181     }
182 
183     public User update(com.liferay.portal.model.User user, boolean merge)
184         throws SystemException {
185         FinderCache.clearCache("Users_Groups");
186         FinderCache.clearCache("Users_Orgs");
187         FinderCache.clearCache("Users_Permissions");
188         FinderCache.clearCache("Users_Roles");
189         FinderCache.clearCache("Users_UserGroups");
190 
191         Session session = null;
192 
193         try {
194             session = openSession();
195 
196             if (merge) {
197                 session.merge(user);
198             }
199             else {
200                 if (user.isNew()) {
201                     session.save(user);
202                 }
203             }
204 
205             session.flush();
206             user.setNew(false);
207 
208             return user;
209         }
210         catch (Exception e) {
211             throw HibernateUtil.processException(e);
212         }
213         finally {
214             closeSession(session);
215             FinderCache.clearCache(User.class.getName());
216         }
217     }
218 
219     public User findByPrimaryKey(long userId)
220         throws NoSuchUserException, SystemException {
221         User user = fetchByPrimaryKey(userId);
222 
223         if (user == null) {
224             if (_log.isWarnEnabled()) {
225                 _log.warn("No User exists with the primary key " + userId);
226             }
227 
228             throw new NoSuchUserException(
229                 "No User exists with the primary key " + userId);
230         }
231 
232         return user;
233     }
234 
235     public User fetchByPrimaryKey(long userId) throws SystemException {
236         Session session = null;
237 
238         try {
239             session = openSession();
240 
241             return (User)session.get(UserImpl.class, new Long(userId));
242         }
243         catch (Exception e) {
244             throw HibernateUtil.processException(e);
245         }
246         finally {
247             closeSession(session);
248         }
249     }
250 
251     public List findByCompanyId(long companyId) throws SystemException {
252         String finderClassName = User.class.getName();
253         String finderMethodName = "findByCompanyId";
254         String[] finderParams = new String[] { Long.class.getName() };
255         Object[] finderArgs = new Object[] { new Long(companyId) };
256         Object result = FinderCache.getResult(finderClassName,
257                 finderMethodName, finderParams, finderArgs, getSessionFactory());
258 
259         if (result == null) {
260             Session session = null;
261 
262             try {
263                 session = openSession();
264 
265                 StringMaker query = new StringMaker();
266                 query.append("FROM com.liferay.portal.model.User WHERE ");
267                 query.append("companyId = ?");
268                 query.append(" ");
269 
270                 Query q = session.createQuery(query.toString());
271                 int queryPos = 0;
272                 q.setLong(queryPos++, companyId);
273 
274                 List list = q.list();
275                 FinderCache.putResult(finderClassName, finderMethodName,
276                     finderParams, finderArgs, list);
277 
278                 return list;
279             }
280             catch (Exception e) {
281                 throw HibernateUtil.processException(e);
282             }
283             finally {
284                 closeSession(session);
285             }
286         }
287         else {
288             return (List)result;
289         }
290     }
291 
292     public List findByCompanyId(long companyId, int begin, int end)
293         throws SystemException {
294         return findByCompanyId(companyId, begin, end, null);
295     }
296 
297     public List findByCompanyId(long companyId, int begin, int end,
298         OrderByComparator obc) throws SystemException {
299         String finderClassName = User.class.getName();
300         String finderMethodName = "findByCompanyId";
301         String[] finderParams = new String[] {
302                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
303                 "com.liferay.portal.kernel.util.OrderByComparator"
304             };
305         Object[] finderArgs = new Object[] {
306                 new Long(companyId), String.valueOf(begin), String.valueOf(end),
307                 String.valueOf(obc)
308             };
309         Object result = FinderCache.getResult(finderClassName,
310                 finderMethodName, finderParams, finderArgs, getSessionFactory());
311 
312         if (result == null) {
313             Session session = null;
314 
315             try {
316                 session = openSession();
317 
318                 StringMaker query = new StringMaker();
319                 query.append("FROM com.liferay.portal.model.User WHERE ");
320                 query.append("companyId = ?");
321                 query.append(" ");
322 
323                 if (obc != null) {
324                     query.append("ORDER BY ");
325                     query.append(obc.getOrderBy());
326                 }
327 
328                 Query q = session.createQuery(query.toString());
329                 int queryPos = 0;
330                 q.setLong(queryPos++, companyId);
331 
332                 List list = QueryUtil.list(q, getDialect(), begin, end);
333                 FinderCache.putResult(finderClassName, finderMethodName,
334                     finderParams, finderArgs, list);
335 
336                 return list;
337             }
338             catch (Exception e) {
339                 throw HibernateUtil.processException(e);
340             }
341             finally {
342                 closeSession(session);
343             }
344         }
345         else {
346             return (List)result;
347         }
348     }
349 
350     public User findByCompanyId_First(long companyId, OrderByComparator obc)
351         throws NoSuchUserException, SystemException {
352         List list = findByCompanyId(companyId, 0, 1, obc);
353 
354         if (list.size() == 0) {
355             StringMaker msg = new StringMaker();
356             msg.append("No User exists with the key ");
357             msg.append(StringPool.OPEN_CURLY_BRACE);
358             msg.append("companyId=");
359             msg.append(companyId);
360             msg.append(StringPool.CLOSE_CURLY_BRACE);
361             throw new NoSuchUserException(msg.toString());
362         }
363         else {
364             return (User)list.get(0);
365         }
366     }
367 
368     public User findByCompanyId_Last(long companyId, OrderByComparator obc)
369         throws NoSuchUserException, SystemException {
370         int count = countByCompanyId(companyId);
371         List list = findByCompanyId(companyId, count - 1, count, obc);
372 
373         if (list.size() == 0) {
374             StringMaker msg = new StringMaker();
375             msg.append("No User exists with the key ");
376             msg.append(StringPool.OPEN_CURLY_BRACE);
377             msg.append("companyId=");
378             msg.append(companyId);
379             msg.append(StringPool.CLOSE_CURLY_BRACE);
380             throw new NoSuchUserException(msg.toString());
381         }
382         else {
383             return (User)list.get(0);
384         }
385     }
386 
387     public User[] findByCompanyId_PrevAndNext(long userId, long companyId,
388         OrderByComparator obc) throws NoSuchUserException, SystemException {
389         User user = findByPrimaryKey(userId);
390         int count = countByCompanyId(companyId);
391         Session session = null;
392 
393         try {
394             session = openSession();
395 
396             StringMaker query = new StringMaker();
397             query.append("FROM com.liferay.portal.model.User WHERE ");
398             query.append("companyId = ?");
399             query.append(" ");
400 
401             if (obc != null) {
402                 query.append("ORDER BY ");
403                 query.append(obc.getOrderBy());
404             }
405 
406             Query q = session.createQuery(query.toString());
407             int queryPos = 0;
408             q.setLong(queryPos++, companyId);
409 
410             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, user);
411             User[] array = new UserImpl[3];
412             array[0] = (User)objArray[0];
413             array[1] = (User)objArray[1];
414             array[2] = (User)objArray[2];
415 
416             return array;
417         }
418         catch (Exception e) {
419             throw HibernateUtil.processException(e);
420         }
421         finally {
422             closeSession(session);
423         }
424     }
425 
426     public User findByContactId(long contactId)
427         throws NoSuchUserException, SystemException {
428         User user = fetchByContactId(contactId);
429 
430         if (user == null) {
431             StringMaker msg = new StringMaker();
432             msg.append("No User exists with the key ");
433             msg.append(StringPool.OPEN_CURLY_BRACE);
434             msg.append("contactId=");
435             msg.append(contactId);
436             msg.append(StringPool.CLOSE_CURLY_BRACE);
437 
438             if (_log.isWarnEnabled()) {
439                 _log.warn(msg.toString());
440             }
441 
442             throw new NoSuchUserException(msg.toString());
443         }
444 
445         return user;
446     }
447 
448     public User fetchByContactId(long contactId) throws SystemException {
449         String finderClassName = User.class.getName();
450         String finderMethodName = "fetchByContactId";
451         String[] finderParams = new String[] { Long.class.getName() };
452         Object[] finderArgs = new Object[] { new Long(contactId) };
453         Object result = FinderCache.getResult(finderClassName,
454                 finderMethodName, finderParams, finderArgs, getSessionFactory());
455 
456         if (result == null) {
457             Session session = null;
458 
459             try {
460                 session = openSession();
461 
462                 StringMaker query = new StringMaker();
463                 query.append("FROM com.liferay.portal.model.User WHERE ");
464                 query.append("contactId = ?");
465                 query.append(" ");
466 
467                 Query q = session.createQuery(query.toString());
468                 int queryPos = 0;
469                 q.setLong(queryPos++, contactId);
470 
471                 List list = q.list();
472                 FinderCache.putResult(finderClassName, finderMethodName,
473                     finderParams, finderArgs, list);
474 
475                 if (list.size() == 0) {
476                     return null;
477                 }
478                 else {
479                     return (User)list.get(0);
480                 }
481             }
482             catch (Exception e) {
483                 throw HibernateUtil.processException(e);
484             }
485             finally {
486                 closeSession(session);
487             }
488         }
489         else {
490             List list = (List)result;
491 
492             if (list.size() == 0) {
493                 return null;
494             }
495             else {
496                 return (User)list.get(0);
497             }
498         }
499     }
500 
501     public User findByPortraitId(long portraitId)
502         throws NoSuchUserException, SystemException {
503         User user = fetchByPortraitId(portraitId);
504 
505         if (user == null) {
506             StringMaker msg = new StringMaker();
507             msg.append("No User exists with the key ");
508             msg.append(StringPool.OPEN_CURLY_BRACE);
509             msg.append("portraitId=");
510             msg.append(portraitId);
511             msg.append(StringPool.CLOSE_CURLY_BRACE);
512 
513             if (_log.isWarnEnabled()) {
514                 _log.warn(msg.toString());
515             }
516 
517             throw new NoSuchUserException(msg.toString());
518         }
519 
520         return user;
521     }
522 
523     public User fetchByPortraitId(long portraitId) throws SystemException {
524         String finderClassName = User.class.getName();
525         String finderMethodName = "fetchByPortraitId";
526         String[] finderParams = new String[] { Long.class.getName() };
527         Object[] finderArgs = new Object[] { new Long(portraitId) };
528         Object result = FinderCache.getResult(finderClassName,
529                 finderMethodName, finderParams, finderArgs, getSessionFactory());
530 
531         if (result == null) {
532             Session session = null;
533 
534             try {
535                 session = openSession();
536 
537                 StringMaker query = new StringMaker();
538                 query.append("FROM com.liferay.portal.model.User WHERE ");
539                 query.append("portraitId = ?");
540                 query.append(" ");
541 
542                 Query q = session.createQuery(query.toString());
543                 int queryPos = 0;
544                 q.setLong(queryPos++, portraitId);
545 
546                 List list = q.list();
547                 FinderCache.putResult(finderClassName, finderMethodName,
548                     finderParams, finderArgs, list);
549 
550                 if (list.size() == 0) {
551                     return null;
552                 }
553                 else {
554                     return (User)list.get(0);
555                 }
556             }
557             catch (Exception e) {
558                 throw HibernateUtil.processException(e);
559             }
560             finally {
561                 closeSession(session);
562             }
563         }
564         else {
565             List list = (List)result;
566 
567             if (list.size() == 0) {
568                 return null;
569             }
570             else {
571                 return (User)list.get(0);
572             }
573         }
574     }
575 
576     public User findByC_U(long companyId, long userId)
577         throws NoSuchUserException, SystemException {
578         User user = fetchByC_U(companyId, userId);
579 
580         if (user == null) {
581             StringMaker msg = new StringMaker();
582             msg.append("No User exists with the key ");
583             msg.append(StringPool.OPEN_CURLY_BRACE);
584             msg.append("companyId=");
585             msg.append(companyId);
586             msg.append(", ");
587             msg.append("userId=");
588             msg.append(userId);
589             msg.append(StringPool.CLOSE_CURLY_BRACE);
590 
591             if (_log.isWarnEnabled()) {
592                 _log.warn(msg.toString());
593             }
594 
595             throw new NoSuchUserException(msg.toString());
596         }
597 
598         return user;
599     }
600 
601     public User fetchByC_U(long companyId, long userId)
602         throws SystemException {
603         String finderClassName = User.class.getName();
604         String finderMethodName = "fetchByC_U";
605         String[] finderParams = new String[] {
606                 Long.class.getName(), Long.class.getName()
607             };
608         Object[] finderArgs = new Object[] { new Long(companyId), new Long(userId) };
609         Object result = FinderCache.getResult(finderClassName,
610                 finderMethodName, finderParams, finderArgs, getSessionFactory());
611 
612         if (result == null) {
613             Session session = null;
614 
615             try {
616                 session = openSession();
617 
618                 StringMaker query = new StringMaker();
619                 query.append("FROM com.liferay.portal.model.User WHERE ");
620                 query.append("companyId = ?");
621                 query.append(" AND ");
622                 query.append("userId = ?");
623                 query.append(" ");
624 
625                 Query q = session.createQuery(query.toString());
626                 int queryPos = 0;
627                 q.setLong(queryPos++, companyId);
628                 q.setLong(queryPos++, userId);
629 
630                 List list = q.list();
631                 FinderCache.putResult(finderClassName, finderMethodName,
632                     finderParams, finderArgs, list);
633 
634                 if (list.size() == 0) {
635                     return null;
636                 }
637                 else {
638                     return (User)list.get(0);
639                 }
640             }
641             catch (Exception e) {
642                 throw HibernateUtil.processException(e);
643             }
644             finally {
645                 closeSession(session);
646             }
647         }
648         else {
649             List list = (List)result;
650 
651             if (list.size() == 0) {
652                 return null;
653             }
654             else {
655                 return (User)list.get(0);
656             }
657         }
658     }
659 
660     public User findByC_DU(long companyId, boolean defaultUser)
661         throws NoSuchUserException, SystemException {
662         User user = fetchByC_DU(companyId, defaultUser);
663 
664         if (user == null) {
665             StringMaker msg = new StringMaker();
666             msg.append("No User exists with the key ");
667             msg.append(StringPool.OPEN_CURLY_BRACE);
668             msg.append("companyId=");
669             msg.append(companyId);
670             msg.append(", ");
671             msg.append("defaultUser=");
672             msg.append(defaultUser);
673             msg.append(StringPool.CLOSE_CURLY_BRACE);
674 
675             if (_log.isWarnEnabled()) {
676                 _log.warn(msg.toString());
677             }
678 
679             throw new NoSuchUserException(msg.toString());
680         }
681 
682         return user;
683     }
684 
685     public User fetchByC_DU(long companyId, boolean defaultUser)
686         throws SystemException {
687         String finderClassName = User.class.getName();
688         String finderMethodName = "fetchByC_DU";
689         String[] finderParams = new String[] {
690                 Long.class.getName(), Boolean.class.getName()
691             };
692         Object[] finderArgs = new Object[] {
693                 new Long(companyId), Boolean.valueOf(defaultUser)
694             };
695         Object result = FinderCache.getResult(finderClassName,
696                 finderMethodName, finderParams, finderArgs, getSessionFactory());
697 
698         if (result == null) {
699             Session session = null;
700 
701             try {
702                 session = openSession();
703 
704                 StringMaker query = new StringMaker();
705                 query.append("FROM com.liferay.portal.model.User WHERE ");
706                 query.append("companyId = ?");
707                 query.append(" AND ");
708                 query.append("defaultUser = ?");
709                 query.append(" ");
710 
711                 Query q = session.createQuery(query.toString());
712                 int queryPos = 0;
713                 q.setLong(queryPos++, companyId);
714                 q.setBoolean(queryPos++, defaultUser);
715 
716                 List list = q.list();
717                 FinderCache.putResult(finderClassName, finderMethodName,
718                     finderParams, finderArgs, list);
719 
720                 if (list.size() == 0) {
721                     return null;
722                 }
723                 else {
724                     return (User)list.get(0);
725                 }
726             }
727             catch (Exception e) {
728                 throw HibernateUtil.processException(e);
729             }
730             finally {
731                 closeSession(session);
732             }
733         }
734         else {
735             List list = (List)result;
736 
737             if (list.size() == 0) {
738                 return null;
739             }
740             else {
741                 return (User)list.get(0);
742             }
743         }
744     }
745 
746     public List findByC_P(long companyId, String password)
747         throws SystemException {
748         String finderClassName = User.class.getName();
749         String finderMethodName = "findByC_P";
750         String[] finderParams = new String[] {
751                 Long.class.getName(), String.class.getName()
752             };
753         Object[] finderArgs = new Object[] { new Long(companyId), password };
754         Object result = FinderCache.getResult(finderClassName,
755                 finderMethodName, finderParams, finderArgs, getSessionFactory());
756 
757         if (result == null) {
758             Session session = null;
759 
760             try {
761                 session = openSession();
762 
763                 StringMaker query = new StringMaker();
764                 query.append("FROM com.liferay.portal.model.User WHERE ");
765                 query.append("companyId = ?");
766                 query.append(" AND ");
767 
768                 if (password == null) {
769                     query.append("password_ IS NULL");
770                 }
771                 else {
772                     query.append("password_ = ?");
773                 }
774 
775                 query.append(" ");
776 
777                 Query q = session.createQuery(query.toString());
778                 int queryPos = 0;
779                 q.setLong(queryPos++, companyId);
780 
781                 if (password != null) {
782                     q.setString(queryPos++, password);
783                 }
784 
785                 List list = q.list();
786                 FinderCache.putResult(finderClassName, finderMethodName,
787                     finderParams, finderArgs, list);
788 
789                 return list;
790             }
791             catch (Exception e) {
792                 throw HibernateUtil.processException(e);
793             }
794             finally {
795                 closeSession(session);
796             }
797         }
798         else {
799             return (List)result;
800         }
801     }
802 
803     public List findByC_P(long companyId, String password, int begin, int end)
804         throws SystemException {
805         return findByC_P(companyId, password, begin, end, null);
806     }
807 
808     public List findByC_P(long companyId, String password, int begin, int end,
809         OrderByComparator obc) throws SystemException {
810         String finderClassName = User.class.getName();
811         String finderMethodName = "findByC_P";
812         String[] finderParams = new String[] {
813                 Long.class.getName(), String.class.getName(),
814                 "java.lang.Integer", "java.lang.Integer",
815                 "com.liferay.portal.kernel.util.OrderByComparator"
816             };
817         Object[] finderArgs = new Object[] {
818                 new Long(companyId), password, String.valueOf(begin),
819                 String.valueOf(end), String.valueOf(obc)
820             };
821         Object result = FinderCache.getResult(finderClassName,
822                 finderMethodName, finderParams, finderArgs, getSessionFactory());
823 
824         if (result == null) {
825             Session session = null;
826 
827             try {
828                 session = openSession();
829 
830                 StringMaker query = new StringMaker();
831                 query.append("FROM com.liferay.portal.model.User WHERE ");
832                 query.append("companyId = ?");
833                 query.append(" AND ");
834 
835                 if (password == null) {
836                     query.append("password_ IS NULL");
837                 }
838                 else {
839                     query.append("password_ = ?");
840                 }
841 
842                 query.append(" ");
843 
844                 if (obc != null) {
845                     query.append("ORDER BY ");
846                     query.append(obc.getOrderBy());
847                 }
848 
849                 Query q = session.createQuery(query.toString());
850                 int queryPos = 0;
851                 q.setLong(queryPos++, companyId);
852 
853                 if (password != null) {
854                     q.setString(queryPos++, password);
855                 }
856 
857                 List list = QueryUtil.list(q, getDialect(), begin, end);
858                 FinderCache.putResult(finderClassName, finderMethodName,
859                     finderParams, finderArgs, list);
860 
861                 return list;
862             }
863             catch (Exception e) {
864                 throw HibernateUtil.processException(e);
865             }
866             finally {
867                 closeSession(session);
868             }
869         }
870         else {
871             return (List)result;
872         }
873     }
874 
875     public User findByC_P_First(long companyId, String password,
876         OrderByComparator obc) throws NoSuchUserException, SystemException {
877         List list = findByC_P(companyId, password, 0, 1, obc);
878 
879         if (list.size() == 0) {
880             StringMaker msg = new StringMaker();
881             msg.append("No User exists with the key ");
882             msg.append(StringPool.OPEN_CURLY_BRACE);
883             msg.append("companyId=");
884             msg.append(companyId);
885             msg.append(", ");
886             msg.append("password=");
887             msg.append(password);
888             msg.append(StringPool.CLOSE_CURLY_BRACE);
889             throw new NoSuchUserException(msg.toString());
890         }
891         else {
892             return (User)list.get(0);
893         }
894     }
895 
896     public User findByC_P_Last(long companyId, String password,
897         OrderByComparator obc) throws NoSuchUserException, SystemException {
898         int count = countByC_P(companyId, password);
899         List list = findByC_P(companyId, password, count - 1, count, obc);
900 
901         if (list.size() == 0) {
902             StringMaker msg = new StringMaker();
903             msg.append("No User exists with the key ");
904             msg.append(StringPool.OPEN_CURLY_BRACE);
905             msg.append("companyId=");
906             msg.append(companyId);
907             msg.append(", ");
908             msg.append("password=");
909             msg.append(password);
910             msg.append(StringPool.CLOSE_CURLY_BRACE);
911             throw new NoSuchUserException(msg.toString());
912         }
913         else {
914             return (User)list.get(0);
915         }
916     }
917 
918     public User[] findByC_P_PrevAndNext(long userId, long companyId,
919         String password, OrderByComparator obc)
920         throws NoSuchUserException, SystemException {
921         User user = findByPrimaryKey(userId);
922         int count = countByC_P(companyId, password);
923         Session session = null;
924 
925         try {
926             session = openSession();
927 
928             StringMaker query = new StringMaker();
929             query.append("FROM com.liferay.portal.model.User WHERE ");
930             query.append("companyId = ?");
931             query.append(" AND ");
932 
933             if (password == null) {
934                 query.append("password_ IS NULL");
935             }
936             else {
937                 query.append("password_ = ?");
938             }
939 
940             query.append(" ");
941 
942             if (obc != null) {
943                 query.append("ORDER BY ");
944                 query.append(obc.getOrderBy());
945             }
946 
947             Query q = session.createQuery(query.toString());
948             int queryPos = 0;
949             q.setLong(queryPos++, companyId);
950 
951             if (password != null) {
952                 q.setString(queryPos++, password);
953             }
954 
955             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, user);
956             User[] array = new UserImpl[3];
957             array[0] = (User)objArray[0];
958             array[1] = (User)objArray[1];
959             array[2] = (User)objArray[2];
960 
961             return array;
962         }
963         catch (Exception e) {
964             throw HibernateUtil.processException(e);
965         }
966         finally {
967             closeSession(session);
968         }
969     }
970 
971     public User findByC_SN(long companyId, String screenName)
972         throws NoSuchUserException, SystemException {
973         User user = fetchByC_SN(companyId, screenName);
974 
975         if (user == null) {
976             StringMaker msg = new StringMaker();
977             msg.append("No User exists with the key ");
978             msg.append(StringPool.OPEN_CURLY_BRACE);
979             msg.append("companyId=");
980             msg.append(companyId);
981             msg.append(", ");
982             msg.append("screenName=");
983             msg.append(screenName);
984             msg.append(StringPool.CLOSE_CURLY_BRACE);
985 
986             if (_log.isWarnEnabled()) {
987                 _log.warn(msg.toString());
988             }
989 
990             throw new NoSuchUserException(msg.toString());
991         }
992 
993         return user;
994     }
995 
996     public User fetchByC_SN(long companyId, String screenName)
997         throws SystemException {
998         String finderClassName = User.class.getName();
999         String finderMethodName = "fetchByC_SN";
1000        String[] finderParams = new String[] {
1001                Long.class.getName(), String.class.getName()
1002            };
1003        Object[] finderArgs = new Object[] { new Long(companyId), screenName };
1004        Object result = FinderCache.getResult(finderClassName,
1005                finderMethodName, finderParams, finderArgs, getSessionFactory());
1006
1007        if (result == null) {
1008            Session session = null;
1009
1010            try {
1011                session = openSession();
1012
1013                StringMaker query = new StringMaker();
1014                query.append("FROM com.liferay.portal.model.User WHERE ");
1015                query.append("companyId = ?");
1016                query.append(" AND ");
1017
1018                if (screenName == null) {
1019                    query.append("screenName IS NULL");
1020                }
1021                else {
1022                    query.append("screenName = ?");
1023                }
1024
1025                query.append(" ");
1026
1027                Query q = session.createQuery(query.toString());
1028                int queryPos = 0;
1029                q.setLong(queryPos++, companyId);
1030
1031                if (screenName != null) {
1032                    q.setString(queryPos++, screenName);
1033                }
1034
1035                List list = q.list();
1036                FinderCache.putResult(finderClassName, finderMethodName,
1037                    finderParams, finderArgs, list);
1038
1039                if (list.size() == 0) {
1040                    return null;
1041                }
1042                else {
1043                    return (User)list.get(0);
1044                }
1045            }
1046            catch (Exception e) {
1047                throw HibernateUtil.processException(e);
1048            }
1049            finally {
1050                closeSession(session);
1051            }
1052        }
1053        else {
1054            List list = (List)result;
1055
1056            if (list.size() == 0) {
1057                return null;
1058            }
1059            else {
1060                return (User)list.get(0);
1061            }
1062        }
1063    }
1064
1065    public User findByC_EA(long companyId, String emailAddress)
1066        throws NoSuchUserException, SystemException {
1067        User user = fetchByC_EA(companyId, emailAddress);
1068
1069        if (user == null) {
1070            StringMaker msg = new StringMaker();
1071            msg.append("No User exists with the key ");
1072            msg.append(StringPool.OPEN_CURLY_BRACE);
1073            msg.append("companyId=");
1074            msg.append(companyId);
1075            msg.append(", ");
1076            msg.append("emailAddress=");
1077            msg.append(emailAddress);
1078            msg.append(StringPool.CLOSE_CURLY_BRACE);
1079
1080            if (_log.isWarnEnabled()) {
1081                _log.warn(msg.toString());
1082            }
1083
1084            throw new NoSuchUserException(msg.toString());
1085        }
1086
1087        return user;
1088    }
1089
1090    public User fetchByC_EA(long companyId, String emailAddress)
1091        throws SystemException {
1092        String finderClassName = User.class.getName();
1093        String finderMethodName = "fetchByC_EA";
1094        String[] finderParams = new String[] {
1095                Long.class.getName(), String.class.getName()
1096            };
1097        Object[] finderArgs = new Object[] { new Long(companyId), emailAddress };
1098        Object result = FinderCache.getResult(finderClassName,
1099                finderMethodName, finderParams, finderArgs, getSessionFactory());
1100
1101        if (result == null) {
1102            Session session = null;
1103
1104            try {
1105                session = openSession();
1106
1107                StringMaker query = new StringMaker();
1108                query.append("FROM com.liferay.portal.model.User WHERE ");
1109                query.append("companyId = ?");
1110                query.append(" AND ");
1111
1112                if (emailAddress == null) {
1113                    query.append("emailAddress IS NULL");
1114                }
1115                else {
1116                    query.append("emailAddress = ?");
1117                }
1118
1119                query.append(" ");
1120
1121                Query q = session.createQuery(query.toString());
1122                int queryPos = 0;
1123                q.setLong(queryPos++, companyId);
1124
1125                if (emailAddress != null) {
1126                    q.setString(queryPos++, emailAddress);
1127                }
1128
1129                List list = q.list();
1130                FinderCache.putResult(finderClassName, finderMethodName,
1131                    finderParams, finderArgs, list);
1132
1133                if (list.size() == 0) {
1134                    return null;
1135                }
1136                else {
1137                    return (User)list.get(0);
1138                }
1139            }
1140            catch (Exception e) {
1141                throw HibernateUtil.processException(e);
1142            }
1143            finally {
1144                closeSession(session);
1145            }
1146        }
1147        else {
1148            List list = (List)result;
1149
1150            if (list.size() == 0) {
1151                return null;
1152            }
1153            else {
1154                return (User)list.get(0);
1155            }
1156        }
1157    }
1158
1159    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1160        throws SystemException {
1161        Session session = null;
1162
1163        try {
1164            session = openSession();
1165
1166            DynamicQuery query = queryInitializer.initialize(session);
1167
1168            return query.list();
1169        }
1170        catch (Exception e) {
1171            throw HibernateUtil.processException(e);
1172        }
1173        finally {
1174            closeSession(session);
1175        }
1176    }
1177
1178    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1179        int begin, int end) throws SystemException {
1180        Session session = null;
1181
1182        try {
1183            session = openSession();
1184
1185            DynamicQuery query = queryInitializer.initialize(session);
1186            query.setLimit(begin, end);
1187
1188            return query.list();
1189        }
1190        catch (Exception e) {
1191            throw HibernateUtil.processException(e);
1192        }
1193        finally {
1194            closeSession(session);
1195        }
1196    }
1197
1198    public List findAll() throws SystemException {
1199        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1200    }
1201
1202    public List findAll(int begin, int end) throws SystemException {
1203        return findAll(begin, end, null);
1204    }
1205
1206    public List findAll(int begin, int end, OrderByComparator obc)
1207        throws SystemException {
1208        String finderClassName = User.class.getName();
1209        String finderMethodName = "findAll";
1210        String[] finderParams = new String[] {
1211                "java.lang.Integer", "java.lang.Integer",
1212                "com.liferay.portal.kernel.util.OrderByComparator"
1213            };
1214        Object[] finderArgs = new Object[] {
1215                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1216            };
1217        Object result = FinderCache.getResult(finderClassName,
1218                finderMethodName, finderParams, finderArgs, getSessionFactory());
1219
1220        if (result == null) {
1221            Session session = null;
1222
1223            try {
1224                session = openSession();
1225
1226                StringMaker query = new StringMaker();
1227                query.append("FROM com.liferay.portal.model.User ");
1228
1229                if (obc != null) {
1230                    query.append("ORDER BY ");
1231                    query.append(obc.getOrderBy());
1232                }
1233
1234                Query q = session.createQuery(query.toString());
1235                List list = QueryUtil.list(q, getDialect(), begin, end);
1236
1237                if (obc == null) {
1238                    Collections.sort(list);
1239                }
1240
1241                FinderCache.putResult(finderClassName, finderMethodName,
1242                    finderParams, finderArgs, list);
1243
1244                return list;
1245            }
1246            catch (Exception e) {
1247                throw HibernateUtil.processException(e);
1248            }
1249            finally {
1250                closeSession(session);
1251            }
1252        }
1253        else {
1254            return (List)result;
1255        }
1256    }
1257
1258    public void removeByCompanyId(long companyId) throws SystemException {
1259        Iterator itr = findByCompanyId(companyId).iterator();
1260
1261        while (itr.hasNext()) {
1262            User user = (User)itr.next();
1263            remove(user);
1264        }
1265    }
1266
1267    public void removeByContactId(long contactId)
1268        throws NoSuchUserException, SystemException {
1269        User user = findByContactId(contactId);
1270        remove(user);
1271    }
1272
1273    public void removeByPortraitId(long portraitId)
1274        throws NoSuchUserException, SystemException {
1275        User user = findByPortraitId(portraitId);
1276        remove(user);
1277    }
1278
1279    public void removeByC_U(long companyId, long userId)
1280        throws NoSuchUserException, SystemException {
1281        User user = findByC_U(companyId, userId);
1282        remove(user);
1283    }
1284
1285    public void removeByC_DU(long companyId, boolean defaultUser)
1286        throws NoSuchUserException, SystemException {
1287        User user = findByC_DU(companyId, defaultUser);
1288        remove(user);
1289    }
1290
1291    public void removeByC_P(long companyId, String password)
1292        throws SystemException {
1293        Iterator itr = findByC_P(companyId, password).iterator();
1294
1295        while (itr.hasNext()) {
1296            User user = (User)itr.next();
1297            remove(user);
1298        }
1299    }
1300
1301    public void removeByC_SN(long companyId, String screenName)
1302        throws NoSuchUserException, SystemException {
1303        User user = findByC_SN(companyId, screenName);
1304        remove(user);
1305    }
1306
1307    public void removeByC_EA(long companyId, String emailAddress)
1308        throws NoSuchUserException, SystemException {
1309        User user = findByC_EA(companyId, emailAddress);
1310        remove(user);
1311    }
1312
1313    public void removeAll() throws SystemException {
1314        Iterator itr = findAll().iterator();
1315
1316        while (itr.hasNext()) {
1317            remove((User)itr.next());
1318        }
1319    }
1320
1321    public int countByCompanyId(long companyId) throws SystemException {
1322        String finderClassName = User.class.getName();
1323        String finderMethodName = "countByCompanyId";
1324        String[] finderParams = new String[] { Long.class.getName() };
1325        Object[] finderArgs = new Object[] { new Long(companyId) };
1326        Object result = FinderCache.getResult(finderClassName,
1327                finderMethodName, finderParams, finderArgs, getSessionFactory());
1328
1329        if (result == null) {
1330            Session session = null;
1331
1332            try {
1333                session = openSession();
1334
1335                StringMaker query = new StringMaker();
1336                query.append("SELECT COUNT(*) ");
1337                query.append("FROM com.liferay.portal.model.User WHERE ");
1338                query.append("companyId = ?");
1339                query.append(" ");
1340
1341                Query q = session.createQuery(query.toString());
1342                int queryPos = 0;
1343                q.setLong(queryPos++, companyId);
1344
1345                Long count = null;
1346                Iterator itr = q.list().iterator();
1347
1348                if (itr.hasNext()) {
1349                    count = (Long)itr.next();
1350                }
1351
1352                if (count == null) {
1353                    count = new Long(0);
1354                }
1355
1356                FinderCache.putResult(finderClassName, finderMethodName,
1357                    finderParams, finderArgs, count);
1358
1359                return count.intValue();
1360            }
1361            catch (Exception e) {
1362                throw HibernateUtil.processException(e);
1363            }
1364            finally {
1365                closeSession(session);
1366            }
1367        }
1368        else {
1369            return ((Long)result).intValue();
1370        }
1371    }
1372
1373    public int countByContactId(long contactId) throws SystemException {
1374        String finderClassName = User.class.getName();
1375        String finderMethodName = "countByContactId";
1376        String[] finderParams = new String[] { Long.class.getName() };
1377        Object[] finderArgs = new Object[] { new Long(contactId) };
1378        Object result = FinderCache.getResult(finderClassName,
1379                finderMethodName, finderParams, finderArgs, getSessionFactory());
1380
1381        if (result == null) {
1382            Session session = null;
1383
1384            try {
1385                session = openSession();
1386
1387                StringMaker query = new StringMaker();
1388                query.append("SELECT COUNT(*) ");
1389                query.append("FROM com.liferay.portal.model.User WHERE ");
1390                query.append("contactId = ?");
1391                query.append(" ");
1392
1393                Query q = session.createQuery(query.toString());
1394                int queryPos = 0;
1395                q.setLong(queryPos++, contactId);
1396
1397                Long count = null;
1398                Iterator itr = q.list().iterator();
1399
1400                if (itr.hasNext()) {
1401                    count = (Long)itr.next();
1402                }
1403
1404                if (count == null) {
1405                    count = new Long(0);
1406                }
1407
1408                FinderCache.putResult(finderClassName, finderMethodName,
1409                    finderParams, finderArgs, count);
1410
1411                return count.intValue();
1412            }
1413            catch (Exception e) {
1414                throw HibernateUtil.processException(e);
1415            }
1416            finally {
1417                closeSession(session);
1418            }
1419        }
1420        else {
1421            return ((Long)result).intValue();
1422        }
1423    }
1424
1425    public int countByPortraitId(long portraitId) throws SystemException {
1426        String finderClassName = User.class.getName();
1427        String finderMethodName = "countByPortraitId";
1428        String[] finderParams = new String[] { Long.class.getName() };
1429        Object[] finderArgs = new Object[] { new Long(portraitId) };
1430        Object result = FinderCache.getResult(finderClassName,
1431                finderMethodName, finderParams, finderArgs, getSessionFactory());
1432
1433        if (result == null) {
1434            Session session = null;
1435
1436            try {
1437                session = openSession();
1438
1439                StringMaker query = new StringMaker();
1440                query.append("SELECT COUNT(*) ");
1441                query.append("FROM com.liferay.portal.model.User WHERE ");
1442                query.append("portraitId = ?");
1443                query.append(" ");
1444
1445                Query q = session.createQuery(query.toString());
1446                int queryPos = 0;
1447                q.setLong(queryPos++, portraitId);
1448
1449                Long count = null;
1450                Iterator itr = q.list().iterator();
1451
1452                if (itr.hasNext()) {
1453                    count = (Long)itr.next();
1454                }
1455
1456                if (count == null) {
1457                    count = new Long(0);
1458                }
1459
1460                FinderCache.putResult(finderClassName, finderMethodName,
1461                    finderParams, finderArgs, count);
1462
1463                return count.intValue();
1464            }
1465            catch (Exception e) {
1466                throw HibernateUtil.processException(e);
1467            }
1468            finally {
1469                closeSession(session);
1470            }
1471        }
1472        else {
1473            return ((Long)result).intValue();
1474        }
1475    }
1476
1477    public int countByC_U(long companyId, long userId)
1478        throws SystemException {
1479        String finderClassName = User.class.getName();
1480        String finderMethodName = "countByC_U";
1481        String[] finderParams = new String[] {
1482                Long.class.getName(), Long.class.getName()
1483            };
1484        Object[] finderArgs = new Object[] { new Long(companyId), new Long(userId) };
1485        Object result = FinderCache.getResult(finderClassName,
1486                finderMethodName, finderParams, finderArgs, getSessionFactory());
1487
1488        if (result == null) {
1489            Session session = null;
1490
1491            try {
1492                session = openSession();
1493
1494                StringMaker query = new StringMaker();
1495                query.append("SELECT COUNT(*) ");
1496                query.append("FROM com.liferay.portal.model.User WHERE ");
1497                query.append("companyId = ?");
1498                query.append(" AND ");
1499                query.append("userId = ?");
1500                query.append(" ");
1501
1502                Query q = session.createQuery(query.toString());
1503                int queryPos = 0;
1504                q.setLong(queryPos++, companyId);
1505                q.setLong(queryPos++, userId);
1506
1507                Long count = null;
1508                Iterator itr = q.list().iterator();
1509
1510                if (itr.hasNext()) {
1511                    count = (Long)itr.next();
1512                }
1513
1514                if (count == null) {
1515                    count = new Long(0);
1516                }
1517
1518                FinderCache.putResult(finderClassName, finderMethodName,
1519                    finderParams, finderArgs, count);
1520
1521                return count.intValue();
1522            }
1523            catch (Exception e) {
1524                throw HibernateUtil.processException(e);
1525            }
1526            finally {
1527                closeSession(session);
1528            }
1529        }
1530        else {
1531            return ((Long)result).intValue();
1532        }
1533    }
1534
1535    public int countByC_DU(long companyId, boolean defaultUser)
1536        throws SystemException {
1537        String finderClassName = User.class.getName();
1538        String finderMethodName = "countByC_DU";
1539        String[] finderParams = new String[] {
1540                Long.class.getName(), Boolean.class.getName()
1541            };
1542        Object[] finderArgs = new Object[] {
1543                new Long(companyId), Boolean.valueOf(defaultUser)
1544            };
1545        Object result = FinderCache.getResult(finderClassName,
1546                finderMethodName, finderParams, finderArgs, getSessionFactory());
1547
1548        if (result == null) {
1549            Session session = null;
1550
1551            try {
1552                session = openSession();
1553
1554                StringMaker query = new StringMaker();
1555                query.append("SELECT COUNT(*) ");
1556                query.append("FROM com.liferay.portal.model.User WHERE ");
1557                query.append("companyId = ?");
1558                query.append(" AND ");
1559                query.append("defaultUser = ?");
1560                query.append(" ");
1561
1562                Query q = session.createQuery(query.toString());
1563                int queryPos = 0;
1564                q.setLong(queryPos++, companyId);
1565                q.setBoolean(queryPos++, defaultUser);
1566
1567                Long count = null;
1568                Iterator itr = q.list().iterator();
1569
1570                if (itr.hasNext()) {
1571                    count = (Long)itr.next();
1572                }
1573
1574                if (count == null) {
1575                    count = new Long(0);
1576                }
1577
1578                FinderCache.putResult(finderClassName, finderMethodName,
1579                    finderParams, finderArgs, count);
1580
1581                return count.intValue();
1582            }
1583            catch (Exception e) {
1584                throw HibernateUtil.processException(e);
1585            }
1586            finally {
1587                closeSession(session);
1588            }
1589        }
1590        else {
1591            return ((Long)result).intValue();
1592        }
1593    }
1594
1595    public int countByC_P(long companyId, String password)
1596        throws SystemException {
1597        String finderClassName = User.class.getName();
1598        String finderMethodName = "countByC_P";
1599        String[] finderParams = new String[] {
1600                Long.class.getName(), String.class.getName()
1601            };
1602        Object[] finderArgs = new Object[] { new Long(companyId), password };
1603        Object result = FinderCache.getResult(finderClassName,
1604                finderMethodName, finderParams, finderArgs, getSessionFactory());
1605
1606        if (result == null) {
1607            Session session = null;
1608
1609            try {
1610                session = openSession();
1611
1612                StringMaker query = new StringMaker();
1613                query.append("SELECT COUNT(*) ");
1614                query.append("FROM com.liferay.portal.model.User WHERE ");
1615                query.append("companyId = ?");
1616                query.append(" AND ");
1617
1618                if (password == null) {
1619                    query.append("password_ IS NULL");
1620                }
1621                else {
1622                    query.append("password_ = ?");
1623                }
1624
1625                query.append(" ");
1626
1627                Query q = session.createQuery(query.toString());
1628                int queryPos = 0;
1629                q.setLong(queryPos++, companyId);
1630
1631                if (password != null) {
1632                    q.setString(queryPos++, password);
1633                }
1634
1635                Long count = null;
1636                Iterator itr = q.list().iterator();
1637
1638                if (itr.hasNext()) {
1639                    count = (Long)itr.next();
1640                }
1641
1642                if (count == null) {
1643                    count = new Long(0);
1644                }
1645
1646                FinderCache.putResult(finderClassName, finderMethodName,
1647                    finderParams, finderArgs, count);
1648
1649                return count.intValue();
1650            }
1651            catch (Exception e) {
1652                throw HibernateUtil.processException(e);
1653            }
1654            finally {
1655                closeSession(session);
1656            }
1657        }
1658        else {
1659            return ((Long)result).intValue();
1660        }
1661    }
1662
1663    public int countByC_SN(long companyId, String screenName)
1664        throws SystemException {
1665        String finderClassName = User.class.getName();
1666        String finderMethodName = "countByC_SN";
1667        String[] finderParams = new String[] {
1668                Long.class.getName(), String.class.getName()
1669            };
1670        Object[] finderArgs = new Object[] { new Long(companyId), screenName };
1671        Object result = FinderCache.getResult(finderClassName,
1672                finderMethodName, finderParams, finderArgs, getSessionFactory());
1673
1674        if (result == null) {
1675            Session session = null;
1676
1677            try {
1678                session = openSession();
1679
1680                StringMaker query = new StringMaker();
1681                query.append("SELECT COUNT(*) ");
1682                query.append("FROM com.liferay.portal.model.User WHERE ");
1683                query.append("companyId = ?");
1684                query.append(" AND ");
1685
1686                if (screenName == null) {
1687                    query.append("screenName IS NULL");
1688                }
1689                else {
1690                    query.append("screenName = ?");
1691                }
1692
1693                query.append(" ");
1694
1695                Query q = session.createQuery(query.toString());
1696                int queryPos = 0;
1697                q.setLong(queryPos++, companyId);
1698
1699                if (screenName != null) {
1700                    q.setString(queryPos++, screenName);
1701                }
1702
1703                Long count = null;
1704                Iterator itr = q.list().iterator();
1705
1706                if (itr.hasNext()) {
1707                    count = (Long)itr.next();
1708                }
1709
1710                if (count == null) {
1711                    count = new Long(0);
1712                }
1713
1714                FinderCache.putResult(finderClassName, finderMethodName,
1715                    finderParams, finderArgs, count);
1716
1717                return count.intValue();
1718            }
1719            catch (Exception e) {
1720                throw HibernateUtil.processException(e);
1721            }
1722            finally {
1723                closeSession(session);
1724            }
1725        }
1726        else {
1727            return ((Long)result).intValue();
1728        }
1729    }
1730
1731    public int countByC_EA(long companyId, String emailAddress)
1732        throws SystemException {
1733        String finderClassName = User.class.getName();
1734        String finderMethodName = "countByC_EA";
1735        String[] finderParams = new String[] {
1736                Long.class.getName(), String.class.getName()
1737            };
1738        Object[] finderArgs = new Object[] { new Long(companyId), emailAddress };
1739        Object result = FinderCache.getResult(finderClassName,
1740                finderMethodName, finderParams, finderArgs, getSessionFactory());
1741
1742        if (result == null) {
1743            Session session = null;
1744
1745            try {
1746                session = openSession();
1747
1748                StringMaker query = new StringMaker();
1749                query.append("SELECT COUNT(*) ");
1750                query.append("FROM com.liferay.portal.model.User WHERE ");
1751                query.append("companyId = ?");
1752                query.append(" AND ");
1753
1754                if (emailAddress == null) {
1755                    query.append("emailAddress IS NULL");
1756                }
1757                else {
1758                    query.append("emailAddress = ?");
1759                }
1760
1761                query.append(" ");
1762
1763                Query q = session.createQuery(query.toString());
1764                int queryPos = 0;
1765                q.setLong(queryPos++, companyId);
1766
1767                if (emailAddress != null) {
1768                    q.setString(queryPos++, emailAddress);
1769                }
1770
1771                Long count = null;
1772                Iterator itr = q.list().iterator();
1773
1774                if (itr.hasNext()) {
1775                    count = (Long)itr.next();
1776                }
1777
1778                if (count == null) {
1779                    count = new Long(0);
1780                }
1781
1782                FinderCache.putResult(finderClassName, finderMethodName,
1783                    finderParams, finderArgs, count);
1784
1785                return count.intValue();
1786            }
1787            catch (Exception e) {
1788                throw HibernateUtil.processException(e);
1789            }
1790            finally {
1791                closeSession(session);
1792            }
1793        }
1794        else {
1795            return ((Long)result).intValue();
1796        }
1797    }
1798
1799    public int countAll() throws SystemException {
1800        String finderClassName = User.class.getName();
1801        String finderMethodName = "countAll";
1802        String[] finderParams = new String[] {  };
1803        Object[] finderArgs = new Object[] {  };
1804        Object result = FinderCache.getResult(finderClassName,
1805                finderMethodName, finderParams, finderArgs, getSessionFactory());
1806
1807        if (result == null) {
1808            Session session = null;
1809
1810            try {
1811                session = openSession();
1812
1813                StringMaker query = new StringMaker();
1814                query.append("SELECT COUNT(*) ");
1815                query.append("FROM com.liferay.portal.model.User");
1816
1817                Query q = session.createQuery(query.toString());
1818                Long count = null;
1819                Iterator itr = q.list().iterator();
1820
1821                if (itr.hasNext()) {
1822                    count = (Long)itr.next();
1823                }
1824
1825                if (count == null) {
1826                    count = new Long(0);
1827                }
1828
1829                FinderCache.putResult(finderClassName, finderMethodName,
1830                    finderParams, finderArgs, count);
1831
1832                return count.intValue();
1833            }
1834            catch (Exception e) {
1835                throw HibernateUtil.processException(e);
1836            }
1837            finally {
1838                closeSession(session);
1839            }
1840        }
1841        else {
1842            return ((Long)result).intValue();
1843        }
1844    }
1845
1846    public List getGroups(long pk) throws NoSuchUserException, SystemException {
1847        return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1848    }
1849
1850    public List getGroups(long pk, int begin, int end)
1851        throws NoSuchUserException, SystemException {
1852        return getGroups(pk, begin, end, null);
1853    }
1854
1855    public List getGroups(long pk, int begin, int end, OrderByComparator obc)
1856        throws NoSuchUserException, SystemException {
1857        String finderClassName = "Users_Groups";
1858        String finderMethodName = "getGroups";
1859        String[] finderParams = new String[] {
1860                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1861                "com.liferay.portal.kernel.util.OrderByComparator"
1862            };
1863        Object[] finderArgs = new Object[] {
1864                new Long(pk), String.valueOf(begin), String.valueOf(end),
1865                String.valueOf(obc)
1866            };
1867        Object result = FinderCache.getResult(finderClassName,
1868                finderMethodName, finderParams, finderArgs, getSessionFactory());
1869
1870        if (result == null) {
1871            Session session = null;
1872
1873            try {
1874                session = HibernateUtil.openSession();
1875
1876                StringMaker sm = new StringMaker();
1877                sm.append(_SQL_GETGROUPS);
1878
1879                if (obc != null) {
1880                    sm.append("ORDER BY ");
1881                    sm.append(obc.getOrderBy());
1882                }
1883                else {
1884                    sm.append("ORDER BY ");
1885                    sm.append("Group_.name ASC");
1886                }
1887
1888                String sql = sm.toString();
1889                SQLQuery q = session.createSQLQuery(sql);
1890                q.addEntity("Group_",
1891                    com.liferay.portal.model.impl.GroupImpl.class);
1892
1893                QueryPos qPos = QueryPos.getInstance(q);
1894                qPos.add(pk);
1895
1896                List list = QueryUtil.list(q, getDialect(), begin, end);
1897                FinderCache.putResult(finderClassName, finderMethodName,
1898                    finderParams, finderArgs, list);
1899
1900                return list;
1901            }
1902            catch (Exception e) {
1903                throw new SystemException(e);
1904            }
1905            finally {
1906                closeSession(session);
1907            }
1908        }
1909        else {
1910            return (List)result;
1911        }
1912    }
1913
1914    public int getGroupsSize(long pk) throws SystemException {
1915        String finderClassName = "Users_Groups";
1916        String finderMethodName = "getGroupsSize";
1917        String[] finderParams = new String[] { Long.class.getName() };
1918        Object[] finderArgs = new Object[] { new Long(pk) };
1919        Object result = FinderCache.getResult(finderClassName,
1920                finderMethodName, finderParams, finderArgs, getSessionFactory());
1921
1922        if (result == null) {
1923            Session session = null;
1924
1925            try {
1926                session = openSession();
1927
1928                SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1929                q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
1930
1931                QueryPos qPos = QueryPos.getInstance(q);
1932                qPos.add(pk);
1933
1934                Long count = null;
1935                Iterator itr = q.list().iterator();
1936
1937                if (itr.hasNext()) {
1938                    count = (Long)itr.next();
1939                }
1940
1941                if (count == null) {
1942                    count = new Long(0);
1943                }
1944
1945                FinderCache.putResult(finderClassName, finderMethodName,
1946                    finderParams, finderArgs, count);
1947
1948                return count.intValue();
1949            }
1950            catch (Exception e) {
1951                throw HibernateUtil.processException(e);
1952            }
1953            finally {
1954                closeSession(session);
1955            }
1956        }
1957        else {
1958            return ((Long)result).intValue();
1959        }
1960    }
1961
1962    public boolean containsGroup(long pk, long groupPK)
1963        throws SystemException {
1964        String finderClassName = "Users_Groups";
1965        String finderMethodName = "containsGroups";
1966        String[] finderParams = new String[] {
1967                Long.class.getName(), Long.class.getName()
1968            };
1969        Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
1970        Object result = FinderCache.getResult(finderClassName,
1971                finderMethodName, finderParams, finderArgs, getSessionFactory());
1972
1973        if (result == null) {
1974            try {
1975                Boolean value = Boolean.valueOf(containsGroup.contains(pk,
1976                            groupPK));
1977                FinderCache.putResult(finderClassName, finderMethodName,
1978                    finderParams, finderArgs, value);
1979
1980                return value.booleanValue();
1981            }
1982            catch (DataAccessException dae) {
1983                throw new SystemException(dae);
1984            }
1985        }
1986        else {
1987            return ((Boolean)result).booleanValue();
1988        }
1989    }
1990
1991    public boolean containsGroups(long pk) throws SystemException {
1992        if (getGroupsSize(pk) > 0) {
1993            return true;
1994        }
1995        else {
1996            return false;
1997        }
1998    }
1999
2000    public void addGroup(long pk, long groupPK)
2001        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2002            SystemException {
2003        try {
2004            addGroup.add(pk, groupPK);
2005        }
2006        catch (DataAccessException dae) {
2007            throw new SystemException(dae);
2008        }
2009        finally {
2010            FinderCache.clearCache("Users_Groups");
2011        }
2012    }
2013
2014    public void addGroup(long pk, com.liferay.portal.model.Group group)
2015        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2016            SystemException {
2017        try {
2018            addGroup.add(pk, group.getPrimaryKey());
2019        }
2020        catch (DataAccessException dae) {
2021            throw new SystemException(dae);
2022        }
2023        finally {
2024            FinderCache.clearCache("Users_Groups");
2025        }
2026    }
2027
2028    public void addGroups(long pk, long[] groupPKs)
2029        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2030            SystemException {
2031        try {
2032            for (int i = 0; i < groupPKs.length; i++) {
2033                addGroup.add(pk, groupPKs[i]);
2034            }
2035        }
2036        catch (DataAccessException dae) {
2037            throw new SystemException(dae);
2038        }
2039        finally {
2040            FinderCache.clearCache("Users_Groups");
2041        }
2042    }
2043
2044    public void addGroups(long pk, List groups)
2045        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2046            SystemException {
2047        try {
2048            for (int i = 0; i < groups.size(); i++) {
2049                com.liferay.portal.model.Group group = (com.liferay.portal.model.Group)groups.get(i);
2050                addGroup.add(pk, group.getPrimaryKey());
2051            }
2052        }
2053        catch (DataAccessException dae) {
2054            throw new SystemException(dae);
2055        }
2056        finally {
2057            FinderCache.clearCache("Users_Groups");
2058        }
2059    }
2060
2061    public void clearGroups(long pk)
2062        throws NoSuchUserException, SystemException {
2063        try {
2064            clearGroups.clear(pk);
2065        }
2066        catch (DataAccessException dae) {
2067            throw new SystemException(dae);
2068        }
2069        finally {
2070            FinderCache.clearCache("Users_Groups");
2071        }
2072    }
2073
2074    public void removeGroup(long pk, long groupPK)
2075        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2076            SystemException {
2077        try {
2078            removeGroup.remove(pk, groupPK);
2079        }
2080        catch (DataAccessException dae) {
2081            throw new SystemException(dae);
2082        }
2083        finally {
2084            FinderCache.clearCache("Users_Groups");
2085        }
2086    }
2087
2088    public void removeGroup(long pk, com.liferay.portal.model.Group group)
2089        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2090            SystemException {
2091        try {
2092            removeGroup.remove(pk, group.getPrimaryKey());
2093        }
2094        catch (DataAccessException dae) {
2095            throw new SystemException(dae);
2096        }
2097        finally {
2098            FinderCache.clearCache("Users_Groups");
2099        }
2100    }
2101
2102    public void removeGroups(long pk, long[] groupPKs)
2103        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2104            SystemException {
2105        try {
2106            for (int i = 0; i < groupPKs.length; i++) {
2107                removeGroup.remove(pk, groupPKs[i]);
2108            }
2109        }
2110        catch (DataAccessException dae) {
2111            throw new SystemException(dae);
2112        }
2113        finally {
2114            FinderCache.clearCache("Users_Groups");
2115        }
2116    }
2117
2118    public void removeGroups(long pk, List groups)
2119        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2120            SystemException {
2121        try {
2122            for (int i = 0; i < groups.size(); i++) {
2123                com.liferay.portal.model.Group group = (com.liferay.portal.model.Group)groups.get(i);
2124                removeGroup.remove(pk, group.getPrimaryKey());
2125            }
2126        }
2127        catch (DataAccessException dae) {
2128            throw new SystemException(dae);
2129        }
2130        finally {
2131            FinderCache.clearCache("Users_Groups");
2132        }
2133    }
2134
2135    public void setGroups(long pk, long[] groupPKs)
2136        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2137            SystemException {
2138        try {
2139            clearGroups.clear(pk);
2140
2141            for (int i = 0; i < groupPKs.length; i++) {
2142                addGroup.add(pk, groupPKs[i]);
2143            }
2144        }
2145        catch (DataAccessException dae) {
2146            throw new SystemException(dae);
2147        }
2148        finally {
2149            FinderCache.clearCache("Users_Groups");
2150        }
2151    }
2152
2153    public void setGroups(long pk, List groups)
2154        throws NoSuchUserException, com.liferay.portal.NoSuchGroupException, 
2155            SystemException {
2156        try {
2157            clearGroups.clear(pk);
2158
2159            for (int i = 0; i < groups.size(); i++) {
2160                com.liferay.portal.model.Group group = (com.liferay.portal.model.Group)groups.get(i);
2161                addGroup.add(pk, group.getPrimaryKey());
2162            }
2163        }
2164        catch (DataAccessException dae) {
2165            throw new SystemException(dae);
2166        }
2167        finally {
2168            FinderCache.clearCache("Users_Groups");
2169        }
2170    }
2171
2172    public List getOrganizations(long pk)
2173        throws NoSuchUserException, SystemException {
2174        return getOrganizations(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2175    }
2176
2177    public List getOrganizations(long pk, int begin, int end)
2178        throws NoSuchUserException, SystemException {
2179        return getOrganizations(pk, begin, end, null);
2180    }
2181
2182    public List getOrganizations(long pk, int begin, int end,
2183        OrderByComparator obc) throws NoSuchUserException, SystemException {
2184        String finderClassName = "Users_Orgs";
2185        String finderMethodName = "getOrganizations";
2186        String[] finderParams = new String[] {
2187                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2188                "com.liferay.portal.kernel.util.OrderByComparator"
2189            };
2190        Object[] finderArgs = new Object[] {
2191                new Long(pk), String.valueOf(begin), String.valueOf(end),
2192                String.valueOf(obc)
2193            };
2194        Object result = FinderCache.getResult(finderClassName,
2195                finderMethodName, finderParams, finderArgs, getSessionFactory());
2196
2197        if (result == null) {
2198            Session session = null;
2199
2200            try {
2201                session = HibernateUtil.openSession();
2202
2203                StringMaker sm = new StringMaker();
2204                sm.append(_SQL_GETORGANIZATIONS);
2205
2206                if (obc != null) {
2207                    sm.append("ORDER BY ");
2208                    sm.append(obc.getOrderBy());
2209                }
2210                else {
2211                    sm.append("ORDER BY ");
2212                    sm.append("Organization_.name ASC");
2213                }
2214
2215                String sql = sm.toString();
2216                SQLQuery q = session.createSQLQuery(sql);
2217                q.addEntity("Organization_",
2218                    com.liferay.portal.model.impl.OrganizationImpl.class);
2219
2220                QueryPos qPos = QueryPos.getInstance(q);
2221                qPos.add(pk);
2222
2223                List list = QueryUtil.list(q, getDialect(), begin, end);
2224                FinderCache.putResult(finderClassName, finderMethodName,
2225                    finderParams, finderArgs, list);
2226
2227                return list;
2228            }
2229            catch (Exception e) {
2230                throw new SystemException(e);
2231            }
2232            finally {
2233                closeSession(session);
2234            }
2235        }
2236        else {
2237            return (List)result;
2238        }
2239    }
2240
2241    public int getOrganizationsSize(long pk) throws SystemException {
2242        String finderClassName = "Users_Orgs";
2243        String finderMethodName = "getOrganizationsSize";
2244        String[] finderParams = new String[] { Long.class.getName() };
2245        Object[] finderArgs = new Object[] { new Long(pk) };
2246        Object result = FinderCache.getResult(finderClassName,
2247                finderMethodName, finderParams, finderArgs, getSessionFactory());
2248
2249        if (result == null) {
2250            Session session = null;
2251
2252            try {
2253                session = openSession();
2254
2255                SQLQuery q = session.createSQLQuery(_SQL_GETORGANIZATIONSSIZE);
2256                q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
2257
2258                QueryPos qPos = QueryPos.getInstance(q);
2259                qPos.add(pk);
2260
2261                Long count = null;
2262                Iterator itr = q.list().iterator();
2263
2264                if (itr.hasNext()) {
2265                    count = (Long)itr.next();
2266                }
2267
2268                if (count == null) {
2269                    count = new Long(0);
2270                }
2271
2272                FinderCache.putResult(finderClassName, finderMethodName,
2273                    finderParams, finderArgs, count);
2274
2275                return count.intValue();
2276            }
2277            catch (Exception e) {
2278                throw HibernateUtil.processException(e);
2279            }
2280            finally {
2281                closeSession(session);
2282            }
2283        }
2284        else {
2285            return ((Long)result).intValue();
2286        }
2287    }
2288
2289    public boolean containsOrganization(long pk, long organizationPK)
2290        throws SystemException {
2291        String finderClassName = "Users_Orgs";
2292        String finderMethodName = "containsOrganizations";
2293        String[] finderParams = new String[] {
2294                Long.class.getName(), Long.class.getName()
2295            };
2296        Object[] finderArgs = new Object[] {
2297                new Long(pk), new Long(organizationPK)
2298            };
2299        Object result = FinderCache.getResult(finderClassName,
2300                finderMethodName, finderParams, finderArgs, getSessionFactory());
2301
2302        if (result == null) {
2303            try {
2304                Boolean value = Boolean.valueOf(containsOrganization.contains(
2305                            pk, organizationPK));
2306                FinderCache.putResult(finderClassName, finderMethodName,
2307                    finderParams, finderArgs, value);
2308
2309                return value.booleanValue();
2310            }
2311            catch (DataAccessException dae) {
2312                throw new SystemException(dae);
2313            }
2314        }
2315        else {
2316            return ((Boolean)result).booleanValue();
2317        }
2318    }
2319
2320    public boolean containsOrganizations(long pk) throws SystemException {
2321        if (getOrganizationsSize(pk) > 0) {
2322            return true;
2323        }
2324        else {
2325            return false;
2326        }
2327    }
2328
2329    public void addOrganization(long pk, long organizationPK)
2330        throws NoSuchUserException, 
2331            com.liferay.portal.NoSuchOrganizationException, SystemException {
2332        try {
2333            addOrganization.add(pk, organizationPK);
2334        }
2335        catch (DataAccessException dae) {
2336            throw new SystemException(dae);
2337        }
2338        finally {
2339            FinderCache.clearCache("Users_Orgs");
2340        }
2341    }
2342
2343    public void addOrganization(long pk,
2344        com.liferay.portal.model.Organization organization)
2345        throws NoSuchUserException, 
2346            com.liferay.portal.NoSuchOrganizationException, SystemException {
2347        try {
2348            addOrganization.add(pk, organization.getPrimaryKey());
2349        }
2350        catch (DataAccessException dae) {
2351            throw new SystemException(dae);
2352        }
2353        finally {
2354            FinderCache.clearCache("Users_Orgs");
2355        }
2356    }
2357
2358    public void addOrganizations(long pk, long[] organizationPKs)
2359        throws NoSuchUserException, 
2360            com.liferay.portal.NoSuchOrganizationException, SystemException {
2361        try {
2362            for (int i = 0; i < organizationPKs.length; i++) {
2363                addOrganization.add(pk, organizationPKs[i]);
2364            }
2365        }
2366        catch (DataAccessException dae) {
2367            throw new SystemException(dae);
2368        }
2369        finally {
2370            FinderCache.clearCache("Users_Orgs");
2371        }
2372    }
2373
2374    public void addOrganizations(long pk, List organizations)
2375        throws NoSuchUserException, 
2376            com.liferay.portal.NoSuchOrganizationException, SystemException {
2377        try {
2378            for (int i = 0; i < organizations.size(); i++) {
2379                com.liferay.portal.model.Organization organization = (com.liferay.portal.model.Organization)organizations.get(i);
2380                addOrganization.add(pk, organization.getPrimaryKey());
2381            }
2382        }
2383        catch (DataAccessException dae) {
2384            throw new SystemException(dae);
2385        }
2386        finally {
2387            FinderCache.clearCache("Users_Orgs");
2388        }
2389    }
2390
2391    public void clearOrganizations(long pk)
2392        throws NoSuchUserException, SystemException {
2393        try {
2394            clearOrganizations.clear(pk);
2395        }
2396        catch (DataAccessException dae) {
2397            throw new SystemException(dae);
2398        }
2399        finally {
2400            FinderCache.clearCache("Users_Orgs");
2401        }
2402    }
2403
2404    public void removeOrganization(long pk, long organizationPK)
2405        throws NoSuchUserException, 
2406            com.liferay.portal.NoSuchOrganizationException, SystemException {
2407        try {
2408            removeOrganization.remove(pk, organizationPK);
2409        }
2410        catch (DataAccessException dae) {
2411            throw new SystemException(dae);
2412        }
2413        finally {
2414            FinderCache.clearCache("Users_Orgs");
2415        }
2416    }
2417
2418    public void removeOrganization(long pk,
2419        com.liferay.portal.model.Organization organization)
2420        throws NoSuchUserException, 
2421            com.liferay.portal.NoSuchOrganizationException, SystemException {
2422        try {
2423            removeOrganization.remove(pk, organization.getPrimaryKey());
2424        }
2425        catch (DataAccessException dae) {
2426            throw new SystemException(dae);
2427        }
2428        finally {
2429            FinderCache.clearCache("Users_Orgs");
2430        }
2431    }
2432
2433    public void removeOrganizations(long pk, long[] organizationPKs)
2434        throws NoSuchUserException, 
2435            com.liferay.portal.NoSuchOrganizationException, SystemException {
2436        try {
2437            for (int i = 0; i < organizationPKs.length; i++) {
2438                removeOrganization.remove(pk, organizationPKs[i]);
2439            }
2440        }
2441        catch (DataAccessException dae) {
2442            throw new SystemException(dae);
2443        }
2444        finally {
2445            FinderCache.clearCache("Users_Orgs");
2446        }
2447    }
2448
2449    public void removeOrganizations(long pk, List organizations)
2450        throws NoSuchUserException, 
2451            com.liferay.portal.NoSuchOrganizationException, SystemException {
2452        try {
2453            for (int i = 0; i < organizations.size(); i++) {
2454                com.liferay.portal.model.Organization organization = (com.liferay.portal.model.Organization)organizations.get(i);
2455                removeOrganization.remove(pk, organization.getPrimaryKey());
2456            }
2457        }
2458        catch (DataAccessException dae) {
2459            throw new SystemException(dae);
2460        }
2461        finally {
2462            FinderCache.clearCache("Users_Orgs");
2463        }
2464    }
2465
2466    public void setOrganizations(long pk, long[] organizationPKs)
2467        throws NoSuchUserException, 
2468            com.liferay.portal.NoSuchOrganizationException, SystemException {
2469        try {
2470            clearOrganizations.clear(pk);
2471
2472            for (int i = 0; i < organizationPKs.length; i++) {
2473                addOrganization.add(pk, organizationPKs[i]);
2474            }
2475        }
2476        catch (DataAccessException dae) {
2477            throw new SystemException(dae);
2478        }
2479        finally {
2480            FinderCache.clearCache("Users_Orgs");
2481        }
2482    }
2483
2484    public void setOrganizations(long pk, List organizations)
2485        throws NoSuchUserException, 
2486            com.liferay.portal.NoSuchOrganizationException, SystemException {
2487        try {
2488            clearOrganizations.clear(pk);
2489
2490            for (int i = 0; i < organizations.size(); i++) {
2491                com.liferay.portal.model.Organization organization = (com.liferay.portal.model.Organization)organizations.get(i);
2492                addOrganization.add(pk, organization.getPrimaryKey());
2493            }
2494        }
2495        catch (DataAccessException dae) {
2496            throw new SystemException(dae);
2497        }
2498        finally {
2499            FinderCache.clearCache("Users_Orgs");
2500        }
2501    }
2502
2503    public List getPermissions(long pk)
2504        throws NoSuchUserException, SystemException {
2505        return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2506    }
2507
2508    public List getPermissions(long pk, int begin, int end)
2509        throws NoSuchUserException, SystemException {
2510        return getPermissions(pk, begin, end, null);
2511    }
2512
2513    public List getPermissions(long pk, int begin, int end,
2514        OrderByComparator obc) throws NoSuchUserException, SystemException {
2515        String finderClassName = "Users_Permissions";
2516        String finderMethodName = "getPermissions";
2517        String[] finderParams = new String[] {
2518                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2519                "com.liferay.portal.kernel.util.OrderByComparator"
2520            };
2521        Object[] finderArgs = new Object[] {
2522                new Long(pk), String.valueOf(begin), String.valueOf(end),
2523                String.valueOf(obc)
2524            };
2525        Object result = FinderCache.getResult(finderClassName,
2526                finderMethodName, finderParams, finderArgs, getSessionFactory());
2527
2528        if (result == null) {
2529            Session session = null;
2530
2531            try {
2532                session = HibernateUtil.openSession();
2533
2534                StringMaker sm = new StringMaker();
2535                sm.append(_SQL_GETPERMISSIONS);
2536
2537                if (obc != null) {
2538                    sm.append("ORDER BY ");
2539                    sm.append(obc.getOrderBy());
2540                }
2541
2542                String sql = sm.toString();
2543                SQLQuery q = session.createSQLQuery(sql);
2544                q.addEntity("Permission_",
2545                    com.liferay.portal.model.impl.PermissionImpl.class);
2546
2547                QueryPos qPos = QueryPos.getInstance(q);
2548                qPos.add(pk);
2549
2550                List list = QueryUtil.list(q, getDialect(), begin, end);
2551                FinderCache.putResult(finderClassName, finderMethodName,
2552                    finderParams, finderArgs, list);
2553
2554                return list;
2555            }
2556            catch (Exception e) {
2557                throw new SystemException(e);
2558            }
2559            finally {
2560                closeSession(session);
2561            }
2562        }
2563        else {
2564            return (List)result;
2565        }
2566    }
2567
2568    public int getPermissionsSize(long pk) throws SystemException {
2569        String finderClassName = "Users_Permissions";
2570        String finderMethodName = "getPermissionsSize";
2571        String[] finderParams = new String[] { Long.class.getName() };
2572        Object[] finderArgs = new Object[] { new Long(pk) };
2573        Object result = FinderCache.getResult(finderClassName,
2574                finderMethodName, finderParams, finderArgs, getSessionFactory());
2575
2576        if (result == null) {
2577            Session session = null;
2578
2579            try {
2580                session = openSession();
2581
2582                SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
2583                q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
2584
2585                QueryPos qPos = QueryPos.getInstance(q);
2586                qPos.add(pk);
2587
2588                Long count = null;
2589                Iterator itr = q.list().iterator();
2590
2591                if (itr.hasNext()) {
2592                    count = (Long)itr.next();
2593                }
2594
2595                if (count == null) {
2596                    count = new Long(0);
2597                }
2598
2599                FinderCache.putResult(finderClassName, finderMethodName,
2600                    finderParams, finderArgs, count);
2601
2602                return count.intValue();
2603            }
2604            catch (Exception e) {
2605                throw HibernateUtil.processException(e);
2606            }
2607            finally {
2608                closeSession(session);
2609            }
2610        }
2611        else {
2612            return ((Long)result).intValue();
2613        }
2614    }
2615
2616    public boolean containsPermission(long pk, long permissionPK)
2617        throws SystemException {
2618        String finderClassName = "Users_Permissions";
2619        String finderMethodName = "containsPermissions";
2620        String[] finderParams = new String[] {
2621                Long.class.getName(), Long.class.getName()
2622            };
2623        Object[] finderArgs = new Object[] { new Long(pk), new Long(permissionPK) };
2624        Object result = FinderCache.getResult(finderClassName,
2625                finderMethodName, finderParams, finderArgs, getSessionFactory());
2626
2627        if (result == null) {
2628            try {
2629                Boolean value = Boolean.valueOf(containsPermission.contains(
2630                            pk, permissionPK));
2631                FinderCache.putResult(finderClassName, finderMethodName,
2632                    finderParams, finderArgs, value);
2633
2634                return value.booleanValue();
2635            }
2636            catch (DataAccessException dae) {
2637                throw new SystemException(dae);
2638            }
2639        }
2640        else {
2641            return ((Boolean)result).booleanValue();
2642        }
2643    }
2644
2645    public boolean containsPermissions(long pk) throws SystemException {
2646        if (getPermissionsSize(pk) > 0) {
2647            return true;
2648        }
2649        else {
2650            return false;
2651        }
2652    }
2653
2654    public void addPermission(long pk, long permissionPK)
2655        throws NoSuchUserException, 
2656            com.liferay.portal.NoSuchPermissionException, SystemException {
2657        try {
2658            addPermission.add(pk, permissionPK);
2659        }
2660        catch (DataAccessException dae) {
2661            throw new SystemException(dae);
2662        }
2663        finally {
2664            FinderCache.clearCache("Users_Permissions");
2665        }
2666    }
2667
2668    public void addPermission(long pk,
2669        com.liferay.portal.model.Permission permission)
2670        throws NoSuchUserException, 
2671            com.liferay.portal.NoSuchPermissionException, SystemException {
2672        try {
2673            addPermission.add(pk, permission.getPrimaryKey());
2674        }
2675        catch (DataAccessException dae) {
2676            throw new SystemException(dae);
2677        }
2678        finally {
2679            FinderCache.clearCache("Users_Permissions");
2680        }
2681    }
2682
2683    public void addPermissions(long pk, long[] permissionPKs)
2684        throws NoSuchUserException, 
2685            com.liferay.portal.NoSuchPermissionException, SystemException {
2686        try {
2687            for (int i = 0; i < permissionPKs.length; i++) {
2688                addPermission.add(pk, permissionPKs[i]);
2689            }
2690        }
2691        catch (DataAccessException dae) {
2692            throw new SystemException(dae);
2693        }
2694        finally {
2695            FinderCache.clearCache("Users_Permissions");
2696        }
2697    }
2698
2699    public void addPermissions(long pk, List permissions)
2700        throws NoSuchUserException, 
2701            com.liferay.portal.NoSuchPermissionException, SystemException {
2702        try {
2703            for (int i = 0; i < permissions.size(); i++) {
2704                com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission)permissions.get(i);
2705                addPermission.add(pk, permission.getPrimaryKey());
2706            }
2707        }
2708        catch (DataAccessException dae) {
2709            throw new SystemException(dae);
2710        }
2711        finally {
2712            FinderCache.clearCache("Users_Permissions");
2713        }
2714    }
2715
2716    public void clearPermissions(long pk)
2717        throws NoSuchUserException, SystemException {
2718        try {
2719            clearPermissions.clear(pk);
2720        }
2721        catch (DataAccessException dae) {
2722            throw new SystemException(dae);
2723        }
2724        finally {
2725            FinderCache.clearCache("Users_Permissions");
2726        }
2727    }
2728
2729    public void removePermission(long pk, long permissionPK)
2730        throws NoSuchUserException, 
2731            com.liferay.portal.NoSuchPermissionException, SystemException {
2732        try {
2733            removePermission.remove(pk, permissionPK);
2734        }
2735        catch (DataAccessException dae) {
2736            throw new SystemException(dae);
2737        }
2738        finally {
2739            FinderCache.clearCache("Users_Permissions");
2740        }
2741    }
2742
2743    public void removePermission(long pk,
2744        com.liferay.portal.model.Permission permission)
2745        throws NoSuchUserException, 
2746            com.liferay.portal.NoSuchPermissionException, SystemException {
2747        try {
2748            removePermission.remove(pk, permission.getPrimaryKey());
2749        }
2750        catch (DataAccessException dae) {
2751            throw new SystemException(dae);
2752        }
2753        finally {
2754            FinderCache.clearCache("Users_Permissions");
2755        }
2756    }
2757
2758    public void removePermissions(long pk, long[] permissionPKs)
2759        throws NoSuchUserException, 
2760            com.liferay.portal.NoSuchPermissionException, SystemException {
2761        try {
2762            for (int i = 0; i < permissionPKs.length; i++) {
2763                removePermission.remove(pk, permissionPKs[i]);
2764            }
2765        }
2766        catch (DataAccessException dae) {
2767            throw new SystemException(dae);
2768        }
2769        finally {
2770            FinderCache.clearCache("Users_Permissions");
2771        }
2772    }
2773
2774    public void removePermissions(long pk, List permissions)
2775        throws NoSuchUserException, 
2776            com.liferay.portal.NoSuchPermissionException, SystemException {
2777        try {
2778            for (int i = 0; i < permissions.size(); i++) {
2779                com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission)permissions.get(i);
2780                removePermission.remove(pk, permission.getPrimaryKey());
2781            }
2782        }
2783        catch (DataAccessException dae) {
2784            throw new SystemException(dae);
2785        }
2786        finally {
2787            FinderCache.clearCache("Users_Permissions");
2788        }
2789    }
2790
2791    public void setPermissions(long pk, long[] permissionPKs)
2792        throws NoSuchUserException, 
2793            com.liferay.portal.NoSuchPermissionException, SystemException {
2794        try {
2795            clearPermissions.clear(pk);
2796
2797            for (int i = 0; i < permissionPKs.length; i++) {
2798                addPermission.add(pk, permissionPKs[i]);
2799            }
2800        }
2801        catch (DataAccessException dae) {
2802            throw new SystemException(dae);
2803        }
2804        finally {
2805            FinderCache.clearCache("Users_Permissions");
2806        }
2807    }
2808
2809    public void setPermissions(long pk, List permissions)
2810        throws NoSuchUserException, 
2811            com.liferay.portal.NoSuchPermissionException, SystemException {
2812        try {
2813            clearPermissions.clear(pk);
2814
2815            for (int i = 0; i < permissions.size(); i++) {
2816                com.liferay.portal.model.Permission permission = (com.liferay.portal.model.Permission)permissions.get(i);
2817                addPermission.add(pk, permission.getPrimaryKey());
2818            }
2819        }
2820        catch (DataAccessException dae) {
2821            throw new SystemException(dae);
2822        }
2823        finally {
2824            FinderCache.clearCache("Users_Permissions");
2825        }
2826    }
2827
2828    public List getRoles(long pk) throws NoSuchUserException, SystemException {
2829        return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2830    }
2831
2832    public List getRoles(long pk, int begin, int end)
2833        throws NoSuchUserException, SystemException {
2834        return getRoles(pk, begin, end, null);
2835    }
2836
2837    public List getRoles(long pk, int begin, int end, OrderByComparator obc)
2838        throws NoSuchUserException, SystemException {
2839        String finderClassName = "Users_Roles";
2840        String finderMethodName = "getRoles";
2841        String[] finderParams = new String[] {
2842                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2843                "com.liferay.portal.kernel.util.OrderByComparator"
2844            };
2845        Object[] finderArgs = new Object[] {
2846                new Long(pk), String.valueOf(begin), String.valueOf(end),
2847                String.valueOf(obc)
2848            };
2849        Object result = FinderCache.getResult(finderClassName,
2850                finderMethodName, finderParams, finderArgs, getSessionFactory());
2851
2852        if (result == null) {
2853            Session session = null;
2854
2855            try {
2856                session = HibernateUtil.openSession();
2857
2858                StringMaker sm = new StringMaker();
2859                sm.append(_SQL_GETROLES);
2860
2861                if (obc != null) {
2862                    sm.append("ORDER BY ");
2863                    sm.append(obc.getOrderBy());
2864                }
2865                else {
2866                    sm.append("ORDER BY ");
2867                    sm.append("Role_.name ASC");
2868                }
2869
2870                String sql = sm.toString();
2871                SQLQuery q = session.createSQLQuery(sql);
2872                q.addEntity("Role_",
2873                    com.liferay.portal.model.impl.RoleImpl.class);
2874
2875                QueryPos qPos = QueryPos.getInstance(q);
2876                qPos.add(pk);
2877
2878                List list = QueryUtil.list(q, getDialect(), begin, end);
2879                FinderCache.putResult(finderClassName, finderMethodName,
2880                    finderParams, finderArgs, list);
2881
2882                return list;
2883            }
2884            catch (Exception e) {
2885                throw new SystemException(e);
2886            }
2887            finally {
2888                closeSession(session);
2889            }
2890        }
2891        else {
2892            return (List)result;
2893        }
2894    }
2895
2896    public int getRolesSize(long pk) throws SystemException {
2897        String finderClassName = "Users_Roles";
2898        String finderMethodName = "getRolesSize";
2899        String[] finderParams = new String[] { Long.class.getName() };
2900        Object[] finderArgs = new Object[] { new Long(pk) };
2901        Object result = FinderCache.getResult(finderClassName,
2902                finderMethodName, finderParams, finderArgs, getSessionFactory());
2903
2904        if (result == null) {
2905            Session session = null;
2906
2907            try {
2908                session = openSession();
2909
2910                SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
2911                q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
2912
2913                QueryPos qPos = QueryPos.getInstance(q);
2914                qPos.add(pk);
2915
2916                Long count = null;
2917                Iterator itr = q.list().iterator();
2918
2919                if (itr.hasNext()) {
2920                    count = (Long)itr.next();
2921                }
2922
2923                if (count == null) {
2924                    count = new Long(0);
2925                }
2926
2927                FinderCache.putResult(finderClassName, finderMethodName,
2928                    finderParams, finderArgs, count);
2929
2930                return count.intValue();
2931            }
2932            catch (Exception e) {
2933                throw HibernateUtil.processException(e);
2934            }
2935            finally {
2936                closeSession(session);
2937            }
2938        }
2939        else {
2940            return ((Long)result).intValue();
2941        }
2942    }
2943
2944    public boolean containsRole(long pk, long rolePK) throws SystemException {
2945        String finderClassName = "Users_Roles";
2946        String finderMethodName = "containsRoles";
2947        String[] finderParams = new String[] {
2948                Long.class.getName(), Long.class.getName()
2949            };
2950        Object[] finderArgs = new Object[] { new Long(pk), new Long(rolePK) };
2951        Object result = FinderCache.getResult(finderClassName,
2952                finderMethodName, finderParams, finderArgs, getSessionFactory());
2953
2954        if (result == null) {
2955            try {
2956                Boolean value = Boolean.valueOf(containsRole.contains(pk, rolePK));
2957                FinderCache.putResult(finderClassName, finderMethodName,
2958                    finderParams, finderArgs, value);
2959
2960                return value.booleanValue();
2961            }
2962            catch (DataAccessException dae) {
2963                throw new SystemException(dae);
2964            }
2965        }
2966        else {
2967            return ((Boolean)result).booleanValue();
2968        }
2969    }
2970
2971    public boolean containsRoles(long pk) throws SystemException {
2972        if (getRolesSize(pk) > 0) {
2973            return true;
2974        }
2975        else {
2976            return false;
2977        }
2978    }
2979
2980    public void addRole(long pk, long rolePK)
2981        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
2982            SystemException {
2983        try {
2984            addRole.add(pk, rolePK);
2985        }
2986        catch (DataAccessException dae) {
2987            throw new SystemException(dae);
2988        }
2989        finally {
2990            FinderCache.clearCache("Users_Roles");
2991        }
2992    }
2993
2994    public void addRole(long pk, com.liferay.portal.model.Role role)
2995        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
2996            SystemException {
2997        try {
2998            addRole.add(pk, role.getPrimaryKey());
2999        }
3000        catch (DataAccessException dae) {
3001            throw new SystemException(dae);
3002        }
3003        finally {
3004            FinderCache.clearCache("Users_Roles");
3005        }
3006    }
3007
3008    public void addRoles(long pk, long[] rolePKs)
3009        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
3010            SystemException {
3011        try {
3012            for (int i = 0; i < rolePKs.length; i++) {
3013                addRole.add(pk, rolePKs[i]);
3014            }
3015        }
3016        catch (DataAccessException dae) {
3017            throw new SystemException(dae);
3018        }
3019        finally {
3020            FinderCache.clearCache("Users_Roles");
3021        }
3022    }
3023
3024    public void addRoles(long pk, List roles)
3025        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
3026            SystemException {
3027        try {
3028            for (int i = 0; i < roles.size(); i++) {
3029                com.liferay.portal.model.Role role = (com.liferay.portal.model.Role)roles.get(i);
3030                addRole.add(pk, role.getPrimaryKey());
3031            }
3032        }
3033        catch (DataAccessException dae) {
3034            throw new SystemException(dae);
3035        }
3036        finally {
3037            FinderCache.clearCache("Users_Roles");
3038        }
3039    }
3040
3041    public void clearRoles(long pk) throws NoSuchUserException, SystemException {
3042        try {
3043            clearRoles.clear(pk);
3044        }
3045        catch (DataAccessException dae) {
3046            throw new SystemException(dae);
3047        }
3048        finally {
3049            FinderCache.clearCache("Users_Roles");
3050        }
3051    }
3052
3053    public void removeRole(long pk, long rolePK)
3054        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
3055            SystemException {
3056        try {
3057            removeRole.remove(pk, rolePK);
3058        }
3059        catch (DataAccessException dae) {
3060            throw new SystemException(dae);
3061        }
3062        finally {
3063            FinderCache.clearCache("Users_Roles");
3064        }
3065    }
3066
3067    public void removeRole(long pk, com.liferay.portal.model.Role role)
3068        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
3069            SystemException {
3070        try {
3071            removeRole.remove(pk, role.getPrimaryKey());
3072        }
3073        catch (DataAccessException dae) {
3074            throw new SystemException(dae);
3075        }
3076        finally {
3077            FinderCache.clearCache("Users_Roles");
3078        }
3079    }
3080
3081    public void removeRoles(long pk, long[] rolePKs)
3082        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
3083            SystemException {
3084        try {
3085            for (int i = 0; i < rolePKs.length; i++) {
3086                removeRole.remove(pk, rolePKs[i]);
3087            }
3088        }
3089        catch (DataAccessException dae) {
3090            throw new SystemException(dae);
3091        }
3092        finally {
3093            FinderCache.clearCache("Users_Roles");
3094        }
3095    }
3096
3097    public void removeRoles(long pk, List roles)
3098        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
3099            SystemException {
3100        try {
3101            for (int i = 0; i < roles.size(); i++) {
3102                com.liferay.portal.model.Role role = (com.liferay.portal.model.Role)roles.get(i);
3103                removeRole.remove(pk, role.getPrimaryKey());
3104            }
3105        }
3106        catch (DataAccessException dae) {
3107            throw new SystemException(dae);
3108        }
3109        finally {
3110            FinderCache.clearCache("Users_Roles");
3111        }
3112    }
3113
3114    public void setRoles(long pk, long[] rolePKs)
3115        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
3116            SystemException {
3117        try {
3118            clearRoles.clear(pk);
3119
3120            for (int i = 0; i < rolePKs.length; i++) {
3121                addRole.add(pk, rolePKs[i]);
3122            }
3123        }
3124        catch (DataAccessException dae) {
3125            throw new SystemException(dae);
3126        }
3127        finally {
3128            FinderCache.clearCache("Users_Roles");
3129        }
3130    }
3131
3132    public void setRoles(long pk, List roles)
3133        throws NoSuchUserException, com.liferay.portal.NoSuchRoleException, 
3134            SystemException {
3135        try {
3136            clearRoles.clear(pk);
3137
3138            for (int i = 0; i < roles.size(); i++) {
3139                com.liferay.portal.model.Role role = (com.liferay.portal.model.Role)roles.get(i);
3140                addRole.add(pk, role.getPrimaryKey());
3141            }
3142        }
3143        catch (DataAccessException dae) {
3144            throw new SystemException(dae);
3145        }
3146        finally {
3147            FinderCache.clearCache("Users_Roles");
3148        }
3149    }
3150
3151    public List getUserGroups(long pk)
3152        throws NoSuchUserException, SystemException {
3153        return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3154    }
3155
3156    public List getUserGroups(long pk, int begin, int end)
3157        throws NoSuchUserException, SystemException {
3158        return getUserGroups(pk, begin, end, null);
3159    }
3160
3161    public List getUserGroups(long pk, int begin, int end, OrderByComparator obc)
3162        throws NoSuchUserException, SystemException {
3163        String finderClassName = "Users_UserGroups";
3164        String finderMethodName = "getUserGroups";
3165        String[] finderParams = new String[] {
3166                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3167                "com.liferay.portal.kernel.util.OrderByComparator"
3168            };
3169        Object[] finderArgs = new Object[] {
3170                new Long(pk), String.valueOf(begin), String.valueOf(end),
3171                String.valueOf(obc)
3172            };
3173        Object result = FinderCache.getResult(finderClassName,
3174                finderMethodName, finderParams, finderArgs, getSessionFactory());
3175
3176        if (result == null) {
3177            Session session = null;
3178
3179            try {
3180                session = HibernateUtil.openSession();
3181
3182                StringMaker sm = new StringMaker();
3183                sm.append(_SQL_GETUSERGROUPS);
3184
3185                if (obc != null) {
3186                    sm.append("ORDER BY ");
3187                    sm.append(obc.getOrderBy());
3188                }
3189                else {
3190                    sm.append("ORDER BY ");
3191                    sm.append("UserGroup.name ASC");
3192                }
3193
3194                String sql = sm.toString();
3195                SQLQuery q = session.createSQLQuery(sql);
3196                q.addEntity("UserGroup",
3197                    com.liferay.portal.model.impl.UserGroupImpl.class);
3198
3199                QueryPos qPos = QueryPos.getInstance(q);
3200                qPos.add(pk);
3201
3202                List list = QueryUtil.list(q, getDialect(), begin, end);
3203                FinderCache.putResult(finderClassName, finderMethodName,
3204                    finderParams, finderArgs, list);
3205
3206                return list;
3207            }
3208            catch (Exception e) {
3209                throw new SystemException(e);
3210            }
3211            finally {
3212                closeSession(session);
3213            }
3214        }
3215        else {
3216            return (List)result;
3217        }
3218    }
3219
3220    public int getUserGroupsSize(long pk) throws SystemException {
3221        String finderClassName = "Users_UserGroups";
3222        String finderMethodName = "getUserGroupsSize";
3223        String[] finderParams = new String[] { Long.class.getName() };
3224        Object[] finderArgs = new Object[] { new Long(pk) };
3225        Object result = FinderCache.getResult(finderClassName,
3226                finderMethodName, finderParams, finderArgs, getSessionFactory());
3227
3228        if (result == null) {
3229            Session session = null;
3230
3231            try {
3232                session = openSession();
3233
3234                SQLQuery q = session.createSQLQuery(_SQL_GETUSERGROUPSSIZE);
3235                q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
3236
3237                QueryPos qPos = QueryPos.getInstance(q);
3238                qPos.add(pk);
3239
3240                Long count = null;
3241                Iterator itr = q.list().iterator();
3242
3243                if (itr.hasNext()) {
3244                    count = (Long)itr.next();
3245                }
3246
3247                if (count == null) {
3248                    count = new Long(0);
3249                }
3250
3251                FinderCache.putResult(finderClassName, finderMethodName,
3252                    finderParams, finderArgs, count);
3253
3254                return count.intValue();
3255            }
3256            catch (Exception e) {
3257                throw HibernateUtil.processException(e);
3258            }
3259            finally {
3260                closeSession(session);
3261            }
3262        }
3263        else {
3264            return ((Long)result).intValue();
3265        }
3266    }
3267
3268    public boolean containsUserGroup(long pk, long userGroupPK)
3269        throws SystemException {
3270        String finderClassName = "Users_UserGroups";
3271        String finderMethodName = "containsUserGroups";
3272        String[] finderParams = new String[] {
3273                Long.class.getName(), Long.class.getName()
3274            };
3275        Object[] finderArgs = new Object[] { new Long(pk), new Long(userGroupPK) };
3276        Object result = FinderCache.getResult(finderClassName,
3277                finderMethodName, finderParams, finderArgs, getSessionFactory());
3278
3279        if (result == null) {
3280            try {
3281                Boolean value = Boolean.valueOf(containsUserGroup.contains(pk,
3282                            userGroupPK));
3283                FinderCache.putResult(finderClassName, finderMethodName,
3284                    finderParams, finderArgs, value);
3285
3286                return value.booleanValue();
3287            }
3288            catch (DataAccessException dae) {
3289                throw new SystemException(dae);
3290            }
3291        }
3292        else {
3293            return ((Boolean)result).booleanValue();
3294        }
3295    }
3296
3297    public boolean containsUserGroups(long pk) throws SystemException {
3298        if (getUserGroupsSize(pk) > 0) {
3299            return true;
3300        }
3301        else {
3302            return false;
3303        }
3304    }
3305
3306    public void addUserGroup(long pk, long userGroupPK)
3307        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3308            SystemException {
3309        try {
3310            addUserGroup.add(pk, userGroupPK);
3311        }
3312        catch (DataAccessException dae) {
3313            throw new SystemException(dae);
3314        }
3315        finally {
3316            FinderCache.clearCache("Users_UserGroups");
3317        }
3318    }
3319
3320    public void addUserGroup(long pk,
3321        com.liferay.portal.model.UserGroup userGroup)
3322        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3323            SystemException {
3324        try {
3325            addUserGroup.add(pk, userGroup.getPrimaryKey());
3326        }
3327        catch (DataAccessException dae) {
3328            throw new SystemException(dae);
3329        }
3330        finally {
3331            FinderCache.clearCache("Users_UserGroups");
3332        }
3333    }
3334
3335    public void addUserGroups(long pk, long[] userGroupPKs)
3336        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3337            SystemException {
3338        try {
3339            for (int i = 0; i < userGroupPKs.length; i++) {
3340                addUserGroup.add(pk, userGroupPKs[i]);
3341            }
3342        }
3343        catch (DataAccessException dae) {
3344            throw new SystemException(dae);
3345        }
3346        finally {
3347            FinderCache.clearCache("Users_UserGroups");
3348        }
3349    }
3350
3351    public void addUserGroups(long pk, List userGroups)
3352        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3353            SystemException {
3354        try {
3355            for (int i = 0; i < userGroups.size(); i++) {
3356                com.liferay.portal.model.UserGroup userGroup = (com.liferay.portal.model.UserGroup)userGroups.get(i);
3357                addUserGroup.add(pk, userGroup.getPrimaryKey());
3358            }
3359        }
3360        catch (DataAccessException dae) {
3361            throw new SystemException(dae);
3362        }
3363        finally {
3364            FinderCache.clearCache("Users_UserGroups");
3365        }
3366    }
3367
3368    public void clearUserGroups(long pk)
3369        throws NoSuchUserException, SystemException {
3370        try {
3371            clearUserGroups.clear(pk);
3372        }
3373        catch (DataAccessException dae) {
3374            throw new SystemException(dae);
3375        }
3376        finally {
3377            FinderCache.clearCache("Users_UserGroups");
3378        }
3379    }
3380
3381    public void removeUserGroup(long pk, long userGroupPK)
3382        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3383            SystemException {
3384        try {
3385            removeUserGroup.remove(pk, userGroupPK);
3386        }
3387        catch (DataAccessException dae) {
3388            throw new SystemException(dae);
3389        }
3390        finally {
3391            FinderCache.clearCache("Users_UserGroups");
3392        }
3393    }
3394
3395    public void removeUserGroup(long pk,
3396        com.liferay.portal.model.UserGroup userGroup)
3397        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3398            SystemException {
3399        try {
3400            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
3401        }
3402        catch (DataAccessException dae) {
3403            throw new SystemException(dae);
3404        }
3405        finally {
3406            FinderCache.clearCache("Users_UserGroups");
3407        }
3408    }
3409
3410    public void removeUserGroups(long pk, long[] userGroupPKs)
3411        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3412            SystemException {
3413        try {
3414            for (int i = 0; i < userGroupPKs.length; i++) {
3415                removeUserGroup.remove(pk, userGroupPKs[i]);
3416            }
3417        }
3418        catch (DataAccessException dae) {
3419            throw new SystemException(dae);
3420        }
3421        finally {
3422            FinderCache.clearCache("Users_UserGroups");
3423        }
3424    }
3425
3426    public void removeUserGroups(long pk, List userGroups)
3427        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3428            SystemException {
3429        try {
3430            for (int i = 0; i < userGroups.size(); i++) {
3431                com.liferay.portal.model.UserGroup userGroup = (com.liferay.portal.model.UserGroup)userGroups.get(i);
3432                removeUserGroup.remove(pk, userGroup.getPrimaryKey());
3433            }
3434        }
3435        catch (DataAccessException dae) {
3436            throw new SystemException(dae);
3437        }
3438        finally {
3439            FinderCache.clearCache("Users_UserGroups");
3440        }
3441    }
3442
3443    public void setUserGroups(long pk, long[] userGroupPKs)
3444        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3445            SystemException {
3446        try {
3447            clearUserGroups.clear(pk);
3448
3449            for (int i = 0; i < userGroupPKs.length; i++) {
3450                addUserGroup.add(pk, userGroupPKs[i]);
3451            }
3452        }
3453        catch (DataAccessException dae) {
3454            throw new SystemException(dae);
3455        }
3456        finally {
3457            FinderCache.clearCache("Users_UserGroups");
3458        }
3459    }
3460
3461    public void setUserGroups(long pk, List userGroups)
3462        throws NoSuchUserException, com.liferay.portal.NoSuchUserGroupException, 
3463            SystemException {
3464        try {
3465            clearUserGroups.clear(pk);
3466
3467            for (int i = 0; i < userGroups.size(); i++) {
3468                com.liferay.portal.model.UserGroup userGroup = (com.liferay.portal.model.UserGroup)userGroups.get(i);
3469                addUserGroup.add(pk, userGroup.getPrimaryKey());
3470            }
3471        }
3472        catch (DataAccessException dae) {
3473            throw new SystemException(dae);
3474        }
3475        finally {
3476            FinderCache.clearCache("Users_UserGroups");
3477        }
3478    }
3479
3480    protected void initDao() {
3481        containsGroup = new ContainsGroup(this);
3482        addGroup = new AddGroup(this);
3483        clearGroups = new ClearGroups(this);
3484        removeGroup = new RemoveGroup(this);
3485        containsOrganization = new ContainsOrganization(this);
3486        addOrganization = new AddOrganization(this);
3487        clearOrganizations = new ClearOrganizations(this);
3488        removeOrganization = new RemoveOrganization(this);
3489        containsPermission = new ContainsPermission(this);
3490        addPermission = new AddPermission(this);
3491        clearPermissions = new ClearPermissions(this);
3492        removePermission = new RemovePermission(this);
3493        containsRole = new ContainsRole(this);
3494        addRole = new AddRole(this);
3495        clearRoles = new ClearRoles(this);
3496        removeRole = new RemoveRole(this);
3497        containsUserGroup = new ContainsUserGroup(this);
3498        addUserGroup = new AddUserGroup(this);
3499        clearUserGroups = new ClearUserGroups(this);
3500        removeUserGroup = new RemoveUserGroup(this);
3501    }
3502
3503    protected ContainsGroup containsGroup;
3504    protected AddGroup addGroup;
3505    protected ClearGroups clearGroups;
3506    protected RemoveGroup removeGroup;
3507    protected ContainsOrganization containsOrganization;
3508    protected AddOrganization addOrganization;
3509    protected ClearOrganizations clearOrganizations;
3510    protected RemoveOrganization removeOrganization;
3511    protected ContainsPermission containsPermission;
3512    protected AddPermission addPermission;
3513    protected ClearPermissions clearPermissions;
3514    protected RemovePermission removePermission;
3515    protected ContainsRole containsRole;
3516    protected AddRole addRole;
3517    protected ClearRoles clearRoles;
3518    protected RemoveRole removeRole;
3519    protected ContainsUserGroup containsUserGroup;
3520    protected AddUserGroup addUserGroup;
3521    protected ClearUserGroups clearUserGroups;
3522    protected RemoveUserGroup removeUserGroup;
3523
3524    protected class ContainsGroup extends MappingSqlQuery {
3525        protected ContainsGroup(UserPersistenceImpl persistenceImpl) {
3526            super(persistenceImpl.getDataSource(), _SQL_CONTAINSGROUP);
3527            declareParameter(new SqlParameter(Types.BIGINT));
3528            declareParameter(new SqlParameter(Types.BIGINT));
3529            compile();
3530        }
3531
3532        protected Object mapRow(ResultSet rs, int rowNumber)
3533            throws SQLException {
3534            return new Integer(rs.getInt("COUNT_VALUE"));
3535        }
3536
3537        protected boolean contains(long userId, long groupId) {
3538            List results = execute(new Object[] {
3539                        new Long(userId), new Long(groupId)
3540                    });
3541
3542            if (results.size() > 0) {
3543                Integer count = (Integer)results.get(0);
3544
3545                if (count.intValue() > 0) {
3546                    return true;
3547                }
3548            }
3549
3550            return false;
3551        }
3552    }
3553
3554    protected class AddGroup extends SqlUpdate {
3555        protected AddGroup(UserPersistenceImpl persistenceImpl) {
3556            super(persistenceImpl.getDataSource(),
3557                "INSERT INTO Users_Groups (userId, groupId) VALUES (?, ?)");
3558            _persistenceImpl = persistenceImpl;
3559            declareParameter(new SqlParameter(Types.BIGINT));
3560            declareParameter(new SqlParameter(Types.BIGINT));
3561            compile();
3562        }
3563
3564        protected void add(long userId, long groupId) {
3565            if (!_persistenceImpl.containsGroup.contains(userId, groupId)) {
3566                update(new Object[] { new Long(userId), new Long(groupId) });
3567            }
3568        }
3569
3570        private UserPersistenceImpl _persistenceImpl;
3571    }
3572
3573    protected class ClearGroups extends SqlUpdate {
3574        protected ClearGroups(UserPersistenceImpl persistenceImpl) {
3575            super(persistenceImpl.getDataSource(),
3576                "DELETE FROM Users_Groups WHERE userId = ?");
3577            declareParameter(new SqlParameter(Types.BIGINT));
3578            compile();
3579        }
3580
3581        protected void clear(long userId) {
3582            update(new Object[] { new Long(userId) });
3583        }
3584    }
3585
3586    protected class RemoveGroup extends SqlUpdate {
3587        protected RemoveGroup(UserPersistenceImpl persistenceImpl) {
3588            super(persistenceImpl.getDataSource(),
3589                "DELETE FROM Users_Groups WHERE userId = ? AND groupId = ?");
3590            declareParameter(new SqlParameter(Types.BIGINT));
3591            declareParameter(new SqlParameter(Types.BIGINT));
3592            compile();
3593        }
3594
3595        protected void remove(long userId, long groupId) {
3596            update(new Object[] { new Long(userId), new Long(groupId) });
3597        }
3598    }
3599
3600    protected class ContainsOrganization extends MappingSqlQuery {
3601        protected ContainsOrganization(UserPersistenceImpl persistenceImpl) {
3602            super(persistenceImpl.getDataSource(), _SQL_CONTAINSORGANIZATION);
3603            declareParameter(new SqlParameter(Types.BIGINT));
3604            declareParameter(new SqlParameter(Types.BIGINT));
3605            compile();
3606        }
3607
3608        protected Object mapRow(ResultSet rs, int rowNumber)
3609            throws SQLException {
3610            return new Integer(rs.getInt("COUNT_VALUE"));
3611        }
3612
3613        protected boolean contains(long userId, long organizationId) {
3614            List results = execute(new Object[] {
3615                        new Long(userId), new Long(organizationId)
3616                    });
3617
3618            if (results.size() > 0) {
3619                Integer count = (Integer)results.get(0);
3620
3621                if (count.intValue() > 0) {
3622                    return true;
3623                }
3624            }
3625
3626            return false;
3627        }
3628    }
3629
3630    protected class AddOrganization extends SqlUpdate {
3631        protected AddOrganization(UserPersistenceImpl persistenceImpl) {
3632            super(persistenceImpl.getDataSource(),
3633                "INSERT INTO Users_Orgs (userId, organizationId) VALUES (?, ?)");
3634            _persistenceImpl = persistenceImpl;
3635            declareParameter(new SqlParameter(Types.BIGINT));
3636            declareParameter(new SqlParameter(Types.BIGINT));
3637            compile();
3638        }
3639
3640        protected void add(long userId, long organizationId) {
3641            if (!_persistenceImpl.containsOrganization.contains(userId,
3642                        organizationId)) {
3643                update(new Object[] { new Long(userId), new Long(organizationId) });
3644            }
3645        }
3646
3647        private UserPersistenceImpl _persistenceImpl;
3648    }
3649
3650    protected class ClearOrganizations extends SqlUpdate {
3651        protected ClearOrganizations(UserPersistenceImpl persistenceImpl) {
3652            super(persistenceImpl.getDataSource(),
3653                "DELETE FROM Users_Orgs WHERE userId = ?");
3654            declareParameter(new SqlParameter(Types.BIGINT));
3655            compile();
3656        }
3657
3658        protected void clear(long userId) {
3659            update(new Object[] { new Long(userId) });
3660        }
3661    }
3662
3663    protected class RemoveOrganization extends SqlUpdate {
3664        protected RemoveOrganization(UserPersistenceImpl persistenceImpl) {
3665            super(persistenceImpl.getDataSource(),
3666                "DELETE FROM Users_Orgs WHERE userId = ? AND organizationId = ?");
3667            declareParameter(new SqlParameter(Types.BIGINT));
3668            declareParameter(new SqlParameter(Types.BIGINT));
3669            compile();
3670        }
3671
3672        protected void remove(long userId, long organizationId) {
3673            update(new Object[] { new Long(userId), new Long(organizationId) });
3674        }
3675    }
3676
3677    protected class ContainsPermission extends MappingSqlQuery {
3678        protected ContainsPermission(UserPersistenceImpl persistenceImpl) {
3679            super(persistenceImpl.getDataSource(), _SQL_CONTAINSPERMISSION);
3680            declareParameter(new SqlParameter(Types.BIGINT));
3681            declareParameter(new SqlParameter(Types.BIGINT));
3682            compile();
3683        }
3684
3685        protected Object mapRow(ResultSet rs, int rowNumber)
3686            throws SQLException {
3687            return new Integer(rs.getInt("COUNT_VALUE"));
3688        }
3689
3690        protected boolean contains(long userId, long permissionId) {
3691            List results = execute(new Object[] {
3692                        new Long(userId), new Long(permissionId)
3693                    });
3694
3695            if (results.size() > 0) {
3696                Integer count = (Integer)results.get(0);
3697
3698                if (count.intValue() > 0) {
3699                    return true;
3700                }
3701            }
3702
3703            return false;
3704        }
3705    }
3706
3707    protected class AddPermission extends SqlUpdate {
3708        protected AddPermission(UserPersistenceImpl persistenceImpl) {
3709            super(persistenceImpl.getDataSource(),
3710                "INSERT INTO Users_Permissions (userId, permissionId) VALUES (?, ?)");
3711            _persistenceImpl = persistenceImpl;
3712            declareParameter(new SqlParameter(Types.BIGINT));
3713            declareParameter(new SqlParameter(Types.BIGINT));
3714            compile();
3715        }
3716
3717        protected void add(long userId, long permissionId) {
3718            if (!_persistenceImpl.containsPermission.contains(userId,
3719                        permissionId)) {
3720                update(new Object[] { new Long(userId), new Long(permissionId) });
3721            }
3722        }
3723
3724        private UserPersistenceImpl _persistenceImpl;
3725    }
3726
3727    protected class ClearPermissions extends SqlUpdate {
3728        protected ClearPermissions(UserPersistenceImpl persistenceImpl) {
3729            super(persistenceImpl.getDataSource(),
3730                "DELETE FROM Users_Permissions WHERE userId = ?");
3731            declareParameter(new SqlParameter(Types.BIGINT));
3732            compile();
3733        }
3734
3735        protected void clear(long userId) {
3736            update(new Object[] { new Long(userId) });
3737        }
3738    }
3739
3740    protected class RemovePermission extends SqlUpdate {
3741        protected RemovePermission(UserPersistenceImpl persistenceImpl) {
3742            super(persistenceImpl.getDataSource(),
3743                "DELETE FROM Users_Permissions WHERE userId = ? AND permissionId = ?");
3744            declareParameter(new SqlParameter(Types.BIGINT));
3745            declareParameter(new SqlParameter(Types.BIGINT));
3746            compile();
3747        }
3748
3749        protected void remove(long userId, long permissionId) {
3750            update(new Object[] { new Long(userId), new Long(permissionId) });
3751        }
3752    }
3753
3754    protected class ContainsRole extends MappingSqlQuery {
3755        protected ContainsRole(UserPersistenceImpl persistenceImpl) {
3756            super(persistenceImpl.getDataSource(), _SQL_CONTAINSROLE);
3757            declareParameter(new SqlParameter(Types.BIGINT));
3758            declareParameter(new SqlParameter(Types.BIGINT));
3759            compile();
3760        }
3761
3762        protected Object mapRow(ResultSet rs, int rowNumber)
3763            throws SQLException {
3764            return new Integer(rs.getInt("COUNT_VALUE"));
3765        }
3766
3767        protected boolean contains(long userId, long roleId) {
3768            List results = execute(new Object[] {
3769                        new Long(userId), new Long(roleId)
3770                    });
3771
3772            if (results.size() > 0) {
3773                Integer count = (Integer)results.get(0);
3774
3775                if (count.intValue() > 0) {
3776                    return true;
3777                }
3778            }
3779
3780            return false;
3781        }
3782    }
3783
3784    protected class AddRole extends SqlUpdate {
3785        protected AddRole(UserPersistenceImpl persistenceImpl) {
3786            super(persistenceImpl.getDataSource(),
3787                "INSERT INTO Users_Roles (userId, roleId) VALUES (?, ?)");
3788            _persistenceImpl = persistenceImpl;
3789            declareParameter(new SqlParameter(Types.BIGINT));
3790            declareParameter(new SqlParameter(Types.BIGINT));
3791            compile();
3792        }
3793
3794        protected void add(long userId, long roleId) {
3795            if (!_persistenceImpl.containsRole.contains(userId, roleId)) {
3796                update(new Object[] { new Long(userId), new Long(roleId) });
3797            }
3798        }
3799
3800        private UserPersistenceImpl _persistenceImpl;
3801    }
3802
3803    protected class ClearRoles extends SqlUpdate {
3804        protected ClearRoles(UserPersistenceImpl persistenceImpl) {
3805            super(persistenceImpl.getDataSource(),
3806                "DELETE FROM Users_Roles WHERE userId = ?");
3807            declareParameter(new SqlParameter(Types.BIGINT));
3808            compile();
3809        }
3810
3811        protected void clear(long userId) {
3812            update(new Object[] { new Long(userId) });
3813        }
3814    }
3815
3816    protected class RemoveRole extends SqlUpdate {
3817        protected RemoveRole(UserPersistenceImpl persistenceImpl) {
3818            super(persistenceImpl.getDataSource(),
3819                "DELETE FROM Users_Roles WHERE userId = ? AND roleId = ?");
3820            declareParameter(new SqlParameter(Types.BIGINT));
3821            declareParameter(new SqlParameter(Types.BIGINT));
3822            compile();
3823        }
3824
3825        protected void remove(long userId, long roleId) {
3826            update(new Object[] { new Long(userId), new Long(roleId) });
3827        }
3828    }
3829
3830    protected class ContainsUserGroup extends MappingSqlQuery {
3831        protected ContainsUserGroup(UserPersistenceImpl persistenceImpl) {
3832            super(persistenceImpl.getDataSource(), _SQL_CONTAINSUSERGROUP);
3833            declareParameter(new SqlParameter(Types.BIGINT));
3834            declareParameter(new SqlParameter(Types.BIGINT));
3835            compile();
3836        }
3837
3838        protected Object mapRow(ResultSet rs, int rowNumber)
3839            throws SQLException {
3840            return new Integer(rs.getInt("COUNT_VALUE"));
3841        }
3842
3843        protected boolean contains(long userId, long userGroupId) {
3844            List results = execute(new Object[] {
3845                        new Long(userId), new Long(userGroupId)
3846                    });
3847
3848            if (results.size() > 0) {
3849                Integer count = (Integer)results.get(0);
3850
3851                if (count.intValue() > 0) {
3852                    return true;
3853                }
3854            }
3855
3856            return false;
3857        }
3858    }
3859
3860    protected class AddUserGroup extends SqlUpdate {
3861        protected AddUserGroup(UserPersistenceImpl persistenceImpl) {
3862            super(persistenceImpl.getDataSource(),
3863                "INSERT INTO Users_UserGroups (userId, userGroupId) VALUES (?, ?)");
3864            _persistenceImpl = persistenceImpl;
3865            declareParameter(new SqlParameter(Types.BIGINT));
3866            declareParameter(new SqlParameter(Types.BIGINT));
3867            compile();
3868        }
3869
3870        protected void add(long userId, long userGroupId) {
3871            if (!_persistenceImpl.containsUserGroup.contains(userId, userGroupId)) {
3872                update(new Object[] { new Long(userId), new Long(userGroupId) });
3873            }
3874        }
3875
3876        private UserPersistenceImpl _persistenceImpl;
3877    }
3878
3879    protected class ClearUserGroups extends SqlUpdate {
3880        protected ClearUserGroups(UserPersistenceImpl persistenceImpl) {
3881            super(persistenceImpl.getDataSource(),
3882                "DELETE FROM Users_UserGroups WHERE userId = ?");
3883            declareParameter(new SqlParameter(Types.BIGINT));
3884            compile();
3885        }
3886
3887        protected void clear(long userId) {
3888            update(new Object[] { new Long(userId) });
3889        }
3890    }
3891
3892    protected class RemoveUserGroup extends SqlUpdate {
3893        protected RemoveUserGroup(UserPersistenceImpl persistenceImpl) {
3894            super(persistenceImpl.getDataSource(),
3895                "DELETE FROM Users_UserGroups WHERE userId = ? AND userGroupId = ?");
3896            declareParameter(new SqlParameter(Types.BIGINT));
3897            declareParameter(new SqlParameter(Types.BIGINT));
3898            compile();
3899        }
3900
3901        protected void remove(long userId, long userGroupId) {
3902            update(new Object[] { new Long(userId), new Long(userGroupId) });
3903        }
3904    }
3905
3906    private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Users_Groups ON (Users_Groups.groupId = Group_.groupId) WHERE (Users_Groups.userId = ?)";
3907    private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE userId = ?";
3908    private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE userId = ? AND groupId = ?";
3909    private static final String _SQL_GETORGANIZATIONS = "SELECT {Organization_.*} FROM Organization_ INNER JOIN Users_Orgs ON (Users_Orgs.organizationId = Organization_.organizationId) WHERE (Users_Orgs.userId = ?)";
3910    private static final String _SQL_GETORGANIZATIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE userId = ?";
3911    private static final String _SQL_CONTAINSORGANIZATION = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE userId = ? AND organizationId = ?";
3912    private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Users_Permissions ON (Users_Permissions.permissionId = Permission_.permissionId) WHERE (Users_Permissions.userId = ?)";
3913    private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE userId = ?";
3914    private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE userId = ? AND permissionId = ?";
3915    private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Users_Roles ON (Users_Roles.roleId = Role_.roleId) WHERE (Users_Roles.userId = ?)";
3916    private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE userId = ?";
3917    private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE userId = ? AND roleId = ?";
3918    private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN Users_UserGroups ON (Users_UserGroups.userGroupId = UserGroup.userGroupId) WHERE (Users_UserGroups.userId = ?)";
3919    private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userId = ?";
3920    private static final String _SQL_CONTAINSUSERGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userId = ? AND userGroupId = ?";
3921    private static Log _log = LogFactory.getLog(UserPersistenceImpl.class);
3922}