1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchOrganizationException;
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.GetterUtil;
30  import com.liferay.portal.kernel.util.OrderByComparator;
31  import com.liferay.portal.kernel.util.StringMaker;
32  import com.liferay.portal.kernel.util.StringPool;
33  import com.liferay.portal.kernel.util.Validator;
34  import com.liferay.portal.model.ModelListener;
35  import com.liferay.portal.model.Organization;
36  import com.liferay.portal.model.impl.OrganizationImpl;
37  import com.liferay.portal.model.impl.OrganizationModelImpl;
38  import com.liferay.portal.spring.hibernate.FinderCache;
39  import com.liferay.portal.spring.hibernate.HibernateUtil;
40  import com.liferay.portal.util.PropsUtil;
41  
42  import com.liferay.util.dao.hibernate.QueryPos;
43  import com.liferay.util.dao.hibernate.QueryUtil;
44  
45  import org.apache.commons.logging.Log;
46  import org.apache.commons.logging.LogFactory;
47  
48  import org.hibernate.Hibernate;
49  import org.hibernate.Query;
50  import org.hibernate.SQLQuery;
51  import org.hibernate.Session;
52  
53  import org.springframework.dao.DataAccessException;
54  
55  import org.springframework.jdbc.core.SqlParameter;
56  import org.springframework.jdbc.object.MappingSqlQuery;
57  import org.springframework.jdbc.object.SqlUpdate;
58  
59  import java.sql.ResultSet;
60  import java.sql.SQLException;
61  import java.sql.Types;
62  
63  import java.util.Collections;
64  import java.util.Iterator;
65  import java.util.List;
66  
67  /**
68   * <a href="OrganizationPersistenceImpl.java.html"><b><i>View Source</i></b></a>
69   *
70   * @author Brian Wing Shun Chan
71   *
72   */
73  public class OrganizationPersistenceImpl extends BasePersistence
74      implements OrganizationPersistence {
75      public Organization create(long organizationId) {
76          Organization organization = new OrganizationImpl();
77  
78          organization.setNew(true);
79          organization.setPrimaryKey(organizationId);
80  
81          return organization;
82      }
83  
84      public Organization remove(long organizationId)
85          throws NoSuchOrganizationException, SystemException {
86          Session session = null;
87  
88          try {
89              session = openSession();
90  
91              Organization organization = (Organization)session.get(OrganizationImpl.class,
92                      new Long(organizationId));
93  
94              if (organization == null) {
95                  if (_log.isWarnEnabled()) {
96                      _log.warn("No Organization exists with the primary key " +
97                          organizationId);
98                  }
99  
100                 throw new NoSuchOrganizationException(
101                     "No Organization exists with the primary key " +
102                     organizationId);
103             }
104 
105             return remove(organization);
106         }
107         catch (NoSuchOrganizationException nsee) {
108             throw nsee;
109         }
110         catch (Exception e) {
111             throw HibernateUtil.processException(e);
112         }
113         finally {
114             closeSession(session);
115         }
116     }
117 
118     public Organization remove(Organization organization)
119         throws SystemException {
120         ModelListener listener = _getListener();
121 
122         if (listener != null) {
123             listener.onBeforeRemove(organization);
124         }
125 
126         organization = removeImpl(organization);
127 
128         if (listener != null) {
129             listener.onAfterRemove(organization);
130         }
131 
132         return organization;
133     }
134 
135     protected Organization removeImpl(Organization organization)
136         throws SystemException {
137         try {
138             clearGroups.clear(organization.getPrimaryKey());
139         }
140         catch (Exception e) {
141             throw HibernateUtil.processException(e);
142         }
143         finally {
144             FinderCache.clearCache("Groups_Orgs");
145         }
146 
147         try {
148             clearUsers.clear(organization.getPrimaryKey());
149         }
150         catch (Exception e) {
151             throw HibernateUtil.processException(e);
152         }
153         finally {
154             FinderCache.clearCache("Users_Orgs");
155         }
156 
157         Session session = null;
158 
159         try {
160             session = openSession();
161 
162             session.delete(organization);
163 
164             session.flush();
165 
166             return organization;
167         }
168         catch (Exception e) {
169             throw HibernateUtil.processException(e);
170         }
171         finally {
172             closeSession(session);
173 
174             FinderCache.clearCache(Organization.class.getName());
175         }
176     }
177 
178     public Organization update(Organization organization)
179         throws SystemException {
180         return update(organization, false);
181     }
182 
183     public Organization update(Organization organization, boolean merge)
184         throws SystemException {
185         ModelListener listener = _getListener();
186 
187         boolean isNew = organization.isNew();
188 
189         if (listener != null) {
190             if (isNew) {
191                 listener.onBeforeCreate(organization);
192             }
193             else {
194                 listener.onBeforeUpdate(organization);
195             }
196         }
197 
198         organization = updateImpl(organization, merge);
199 
200         if (listener != null) {
201             if (isNew) {
202                 listener.onAfterCreate(organization);
203             }
204             else {
205                 listener.onAfterUpdate(organization);
206             }
207         }
208 
209         return organization;
210     }
211 
212     public Organization updateImpl(
213         com.liferay.portal.model.Organization organization, boolean merge)
214         throws SystemException {
215         FinderCache.clearCache("Groups_Orgs");
216         FinderCache.clearCache("Users_Orgs");
217 
218         Session session = null;
219 
220         try {
221             session = openSession();
222 
223             if (merge) {
224                 session.merge(organization);
225             }
226             else {
227                 if (organization.isNew()) {
228                     session.save(organization);
229                 }
230             }
231 
232             session.flush();
233 
234             organization.setNew(false);
235 
236             return organization;
237         }
238         catch (Exception e) {
239             throw HibernateUtil.processException(e);
240         }
241         finally {
242             closeSession(session);
243 
244             FinderCache.clearCache(Organization.class.getName());
245         }
246     }
247 
248     public Organization findByPrimaryKey(long organizationId)
249         throws NoSuchOrganizationException, SystemException {
250         Organization organization = fetchByPrimaryKey(organizationId);
251 
252         if (organization == null) {
253             if (_log.isWarnEnabled()) {
254                 _log.warn("No Organization exists with the primary key " +
255                     organizationId);
256             }
257 
258             throw new NoSuchOrganizationException(
259                 "No Organization exists with the primary key " +
260                 organizationId);
261         }
262 
263         return organization;
264     }
265 
266     public Organization fetchByPrimaryKey(long organizationId)
267         throws SystemException {
268         Session session = null;
269 
270         try {
271             session = openSession();
272 
273             return (Organization)session.get(OrganizationImpl.class,
274                 new Long(organizationId));
275         }
276         catch (Exception e) {
277             throw HibernateUtil.processException(e);
278         }
279         finally {
280             closeSession(session);
281         }
282     }
283 
284     public List findByCompanyId(long companyId) throws SystemException {
285         boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
286         String finderClassName = Organization.class.getName();
287         String finderMethodName = "findByCompanyId";
288         String[] finderParams = new String[] { Long.class.getName() };
289         Object[] finderArgs = new Object[] { new Long(companyId) };
290 
291         Object result = null;
292 
293         if (finderClassNameCacheEnabled) {
294             result = FinderCache.getResult(finderClassName, finderMethodName,
295                     finderParams, finderArgs, getSessionFactory());
296         }
297 
298         if (result == null) {
299             Session session = null;
300 
301             try {
302                 session = openSession();
303 
304                 StringMaker query = new StringMaker();
305 
306                 query.append(
307                     "FROM com.liferay.portal.model.Organization WHERE ");
308 
309                 query.append("companyId = ?");
310 
311                 query.append(" ");
312 
313                 query.append("ORDER BY ");
314 
315                 query.append("name ASC");
316 
317                 Query q = session.createQuery(query.toString());
318 
319                 int queryPos = 0;
320 
321                 q.setLong(queryPos++, companyId);
322 
323                 List list = q.list();
324 
325                 FinderCache.putResult(finderClassNameCacheEnabled,
326                     finderClassName, finderMethodName, finderParams,
327                     finderArgs, list);
328 
329                 return list;
330             }
331             catch (Exception e) {
332                 throw HibernateUtil.processException(e);
333             }
334             finally {
335                 closeSession(session);
336             }
337         }
338         else {
339             return (List)result;
340         }
341     }
342 
343     public List findByCompanyId(long companyId, int begin, int end)
344         throws SystemException {
345         return findByCompanyId(companyId, begin, end, null);
346     }
347 
348     public List findByCompanyId(long companyId, int begin, int end,
349         OrderByComparator obc) throws SystemException {
350         boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
351         String finderClassName = Organization.class.getName();
352         String finderMethodName = "findByCompanyId";
353         String[] finderParams = new String[] {
354                 Long.class.getName(),
355                 
356                 "java.lang.Integer", "java.lang.Integer",
357                 "com.liferay.portal.kernel.util.OrderByComparator"
358             };
359         Object[] finderArgs = new Object[] {
360                 new Long(companyId),
361                 
362                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
363             };
364 
365         Object result = null;
366 
367         if (finderClassNameCacheEnabled) {
368             result = FinderCache.getResult(finderClassName, finderMethodName,
369                     finderParams, finderArgs, getSessionFactory());
370         }
371 
372         if (result == null) {
373             Session session = null;
374 
375             try {
376                 session = openSession();
377 
378                 StringMaker query = new StringMaker();
379 
380                 query.append(
381                     "FROM com.liferay.portal.model.Organization WHERE ");
382 
383                 query.append("companyId = ?");
384 
385                 query.append(" ");
386 
387                 if (obc != null) {
388                     query.append("ORDER BY ");
389                     query.append(obc.getOrderBy());
390                 }
391 
392                 else {
393                     query.append("ORDER BY ");
394 
395                     query.append("name ASC");
396                 }
397 
398                 Query q = session.createQuery(query.toString());
399 
400                 int queryPos = 0;
401 
402                 q.setLong(queryPos++, companyId);
403 
404                 List list = QueryUtil.list(q, getDialect(), begin, end);
405 
406                 FinderCache.putResult(finderClassNameCacheEnabled,
407                     finderClassName, finderMethodName, finderParams,
408                     finderArgs, list);
409 
410                 return list;
411             }
412             catch (Exception e) {
413                 throw HibernateUtil.processException(e);
414             }
415             finally {
416                 closeSession(session);
417             }
418         }
419         else {
420             return (List)result;
421         }
422     }
423 
424     public Organization findByCompanyId_First(long companyId,
425         OrderByComparator obc)
426         throws NoSuchOrganizationException, SystemException {
427         List list = findByCompanyId(companyId, 0, 1, obc);
428 
429         if (list.size() == 0) {
430             StringMaker msg = new StringMaker();
431 
432             msg.append("No Organization exists with the key {");
433 
434             msg.append("companyId=" + companyId);
435 
436             msg.append(StringPool.CLOSE_CURLY_BRACE);
437 
438             throw new NoSuchOrganizationException(msg.toString());
439         }
440         else {
441             return (Organization)list.get(0);
442         }
443     }
444 
445     public Organization findByCompanyId_Last(long companyId,
446         OrderByComparator obc)
447         throws NoSuchOrganizationException, SystemException {
448         int count = countByCompanyId(companyId);
449 
450         List list = findByCompanyId(companyId, count - 1, count, obc);
451 
452         if (list.size() == 0) {
453             StringMaker msg = new StringMaker();
454 
455             msg.append("No Organization exists with the key {");
456 
457             msg.append("companyId=" + companyId);
458 
459             msg.append(StringPool.CLOSE_CURLY_BRACE);
460 
461             throw new NoSuchOrganizationException(msg.toString());
462         }
463         else {
464             return (Organization)list.get(0);
465         }
466     }
467 
468     public Organization[] findByCompanyId_PrevAndNext(long organizationId,
469         long companyId, OrderByComparator obc)
470         throws NoSuchOrganizationException, SystemException {
471         Organization organization = findByPrimaryKey(organizationId);
472 
473         int count = countByCompanyId(companyId);
474 
475         Session session = null;
476 
477         try {
478             session = openSession();
479 
480             StringMaker query = new StringMaker();
481 
482             query.append("FROM com.liferay.portal.model.Organization WHERE ");
483 
484             query.append("companyId = ?");
485 
486             query.append(" ");
487 
488             if (obc != null) {
489                 query.append("ORDER BY ");
490                 query.append(obc.getOrderBy());
491             }
492 
493             else {
494                 query.append("ORDER BY ");
495 
496                 query.append("name ASC");
497             }
498 
499             Query q = session.createQuery(query.toString());
500 
501             int queryPos = 0;
502 
503             q.setLong(queryPos++, companyId);
504 
505             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
506                     organization);
507 
508             Organization[] array = new OrganizationImpl[3];
509 
510             array[0] = (Organization)objArray[0];
511             array[1] = (Organization)objArray[1];
512             array[2] = (Organization)objArray[2];
513 
514             return array;
515         }
516         catch (Exception e) {
517             throw HibernateUtil.processException(e);
518         }
519         finally {
520             closeSession(session);
521         }
522     }
523 
524     public List findByLocations(long companyId) throws SystemException {
525         boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
526         String finderClassName = Organization.class.getName();
527         String finderMethodName = "findByLocations";
528         String[] finderParams = new String[] { Long.class.getName() };
529         Object[] finderArgs = new Object[] { new Long(companyId) };
530 
531         Object result = null;
532 
533         if (finderClassNameCacheEnabled) {
534             result = FinderCache.getResult(finderClassName, finderMethodName,
535                     finderParams, finderArgs, getSessionFactory());
536         }
537 
538         if (result == null) {
539             Session session = null;
540 
541             try {
542                 session = openSession();
543 
544                 StringMaker query = new StringMaker();
545 
546                 query.append(
547                     "FROM com.liferay.portal.model.Organization WHERE ");
548 
549                 query.append("companyId = ?");
550 
551                 query.append(" AND parentOrganizationId != 0 ");
552 
553                 query.append("ORDER BY ");
554 
555                 query.append("name ASC");
556 
557                 Query q = session.createQuery(query.toString());
558 
559                 int queryPos = 0;
560 
561                 q.setLong(queryPos++, companyId);
562 
563                 List list = q.list();
564 
565                 FinderCache.putResult(finderClassNameCacheEnabled,
566                     finderClassName, finderMethodName, finderParams,
567                     finderArgs, list);
568 
569                 return list;
570             }
571             catch (Exception e) {
572                 throw HibernateUtil.processException(e);
573             }
574             finally {
575                 closeSession(session);
576             }
577         }
578         else {
579             return (List)result;
580         }
581     }
582 
583     public List findByLocations(long companyId, int begin, int end)
584         throws SystemException {
585         return findByLocations(companyId, begin, end, null);
586     }
587 
588     public List findByLocations(long companyId, int begin, int end,
589         OrderByComparator obc) throws SystemException {
590         boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
591         String finderClassName = Organization.class.getName();
592         String finderMethodName = "findByLocations";
593         String[] finderParams = new String[] {
594                 Long.class.getName(),
595                 
596                 "java.lang.Integer", "java.lang.Integer",
597                 "com.liferay.portal.kernel.util.OrderByComparator"
598             };
599         Object[] finderArgs = new Object[] {
600                 new Long(companyId),
601                 
602                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
603             };
604 
605         Object result = null;
606 
607         if (finderClassNameCacheEnabled) {
608             result = FinderCache.getResult(finderClassName, finderMethodName,
609                     finderParams, finderArgs, getSessionFactory());
610         }
611 
612         if (result == null) {
613             Session session = null;
614 
615             try {
616                 session = openSession();
617 
618                 StringMaker query = new StringMaker();
619 
620                 query.append(
621                     "FROM com.liferay.portal.model.Organization WHERE ");
622 
623                 query.append("companyId = ?");
624 
625                 query.append(" AND parentOrganizationId != 0 ");
626 
627                 if (obc != null) {
628                     query.append("ORDER BY ");
629                     query.append(obc.getOrderBy());
630                 }
631 
632                 else {
633                     query.append("ORDER BY ");
634 
635                     query.append("name ASC");
636                 }
637 
638                 Query q = session.createQuery(query.toString());
639 
640                 int queryPos = 0;
641 
642                 q.setLong(queryPos++, companyId);
643 
644                 List list = QueryUtil.list(q, getDialect(), begin, end);
645 
646                 FinderCache.putResult(finderClassNameCacheEnabled,
647                     finderClassName, finderMethodName, finderParams,
648                     finderArgs, list);
649 
650                 return list;
651             }
652             catch (Exception e) {
653                 throw HibernateUtil.processException(e);
654             }
655             finally {
656                 closeSession(session);
657             }
658         }
659         else {
660             return (List)result;
661         }
662     }
663 
664     public Organization findByLocations_First(long companyId,
665         OrderByComparator obc)
666         throws NoSuchOrganizationException, SystemException {
667         List list = findByLocations(companyId, 0, 1, obc);
668 
669         if (list.size() == 0) {
670             StringMaker msg = new StringMaker();
671 
672             msg.append("No Organization exists with the key {");
673 
674             msg.append("companyId=" + companyId);
675 
676             msg.append(StringPool.CLOSE_CURLY_BRACE);
677 
678             throw new NoSuchOrganizationException(msg.toString());
679         }
680         else {
681             return (Organization)list.get(0);
682         }
683     }
684 
685     public Organization findByLocations_Last(long companyId,
686         OrderByComparator obc)
687         throws NoSuchOrganizationException, SystemException {
688         int count = countByLocations(companyId);
689 
690         List list = findByLocations(companyId, count - 1, count, obc);
691 
692         if (list.size() == 0) {
693             StringMaker msg = new StringMaker();
694 
695             msg.append("No Organization exists with the key {");
696 
697             msg.append("companyId=" + companyId);
698 
699             msg.append(StringPool.CLOSE_CURLY_BRACE);
700 
701             throw new NoSuchOrganizationException(msg.toString());
702         }
703         else {
704             return (Organization)list.get(0);
705         }
706     }
707 
708     public Organization[] findByLocations_PrevAndNext(long organizationId,
709         long companyId, OrderByComparator obc)
710         throws NoSuchOrganizationException, SystemException {
711         Organization organization = findByPrimaryKey(organizationId);
712 
713         int count = countByLocations(companyId);
714 
715         Session session = null;
716 
717         try {
718             session = openSession();
719 
720             StringMaker query = new StringMaker();
721 
722             query.append("FROM com.liferay.portal.model.Organization WHERE ");
723 
724             query.append("companyId = ?");
725 
726             query.append(" AND parentOrganizationId != 0 ");
727 
728             if (obc != null) {
729                 query.append("ORDER BY ");
730                 query.append(obc.getOrderBy());
731             }
732 
733             else {
734                 query.append("ORDER BY ");
735 
736                 query.append("name ASC");
737             }
738 
739             Query q = session.createQuery(query.toString());
740 
741             int queryPos = 0;
742 
743             q.setLong(queryPos++, companyId);
744 
745             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
746                     organization);
747 
748             Organization[] array = new OrganizationImpl[3];
749 
750             array[0] = (Organization)objArray[0];
751             array[1] = (Organization)objArray[1];
752             array[2] = (Organization)objArray[2];
753 
754             return array;
755         }
756         catch (Exception e) {
757             throw HibernateUtil.processException(e);
758         }
759         finally {
760             closeSession(session);
761         }
762     }
763 
764     public List findByC_P(long companyId, long parentOrganizationId)
765         throws SystemException {
766         boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
767         String finderClassName = Organization.class.getName();
768         String finderMethodName = "findByC_P";
769         String[] finderParams = new String[] {
770                 Long.class.getName(), Long.class.getName()
771             };
772         Object[] finderArgs = new Object[] {
773                 new Long(companyId), new Long(parentOrganizationId)
774             };
775 
776         Object result = null;
777 
778         if (finderClassNameCacheEnabled) {
779             result = FinderCache.getResult(finderClassName, finderMethodName,
780                     finderParams, finderArgs, getSessionFactory());
781         }
782 
783         if (result == null) {
784             Session session = null;
785 
786             try {
787                 session = openSession();
788 
789                 StringMaker query = new StringMaker();
790 
791                 query.append(
792                     "FROM com.liferay.portal.model.Organization WHERE ");
793 
794                 query.append("companyId = ?");
795 
796                 query.append(" AND ");
797 
798                 query.append("parentOrganizationId = ?");
799 
800                 query.append(" ");
801 
802                 query.append("ORDER BY ");
803 
804                 query.append("name ASC");
805 
806                 Query q = session.createQuery(query.toString());
807 
808                 int queryPos = 0;
809 
810                 q.setLong(queryPos++, companyId);
811 
812                 q.setLong(queryPos++, parentOrganizationId);
813 
814                 List list = q.list();
815 
816                 FinderCache.putResult(finderClassNameCacheEnabled,
817                     finderClassName, finderMethodName, finderParams,
818                     finderArgs, list);
819 
820                 return list;
821             }
822             catch (Exception e) {
823                 throw HibernateUtil.processException(e);
824             }
825             finally {
826                 closeSession(session);
827             }
828         }
829         else {
830             return (List)result;
831         }
832     }
833 
834     public List findByC_P(long companyId, long parentOrganizationId, int begin,
835         int end) throws SystemException {
836         return findByC_P(companyId, parentOrganizationId, begin, end, null);
837     }
838 
839     public List findByC_P(long companyId, long parentOrganizationId, int begin,
840         int end, OrderByComparator obc) throws SystemException {
841         boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
842         String finderClassName = Organization.class.getName();
843         String finderMethodName = "findByC_P";
844         String[] finderParams = new String[] {
845                 Long.class.getName(), Long.class.getName(),
846                 
847                 "java.lang.Integer", "java.lang.Integer",
848                 "com.liferay.portal.kernel.util.OrderByComparator"
849             };
850         Object[] finderArgs = new Object[] {
851                 new Long(companyId), new Long(parentOrganizationId),
852                 
853                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
854             };
855 
856         Object result = null;
857 
858         if (finderClassNameCacheEnabled) {
859             result = FinderCache.getResult(finderClassName, finderMethodName,
860                     finderParams, finderArgs, getSessionFactory());
861         }
862 
863         if (result == null) {
864             Session session = null;
865 
866             try {
867                 session = openSession();
868 
869                 StringMaker query = new StringMaker();
870 
871                 query.append(
872                     "FROM com.liferay.portal.model.Organization WHERE ");
873 
874                 query.append("companyId = ?");
875 
876                 query.append(" AND ");
877 
878                 query.append("parentOrganizationId = ?");
879 
880                 query.append(" ");
881 
882                 if (obc != null) {
883                     query.append("ORDER BY ");
884                     query.append(obc.getOrderBy());
885                 }
886 
887                 else {
888                     query.append("ORDER BY ");
889 
890                     query.append("name ASC");
891                 }
892 
893                 Query q = session.createQuery(query.toString());
894 
895                 int queryPos = 0;
896 
897                 q.setLong(queryPos++, companyId);
898 
899                 q.setLong(queryPos++, parentOrganizationId);
900 
901                 List list = QueryUtil.list(q, getDialect(), begin, end);
902 
903                 FinderCache.putResult(finderClassNameCacheEnabled,
904                     finderClassName, finderMethodName, finderParams,
905                     finderArgs, list);
906 
907                 return list;
908             }
909             catch (Exception e) {
910                 throw HibernateUtil.processException(e);
911             }
912             finally {
913                 closeSession(session);
914             }
915         }
916         else {
917             return (List)result;
918         }
919     }
920 
921     public Organization findByC_P_First(long companyId,
922         long parentOrganizationId, OrderByComparator obc)
923         throws NoSuchOrganizationException, SystemException {
924         List list = findByC_P(companyId, parentOrganizationId, 0, 1, obc);
925 
926         if (list.size() == 0) {
927             StringMaker msg = new StringMaker();
928 
929             msg.append("No Organization exists with the key {");
930 
931             msg.append("companyId=" + companyId);
932 
933             msg.append(", ");
934             msg.append("parentOrganizationId=" + parentOrganizationId);
935 
936             msg.append(StringPool.CLOSE_CURLY_BRACE);
937 
938             throw new NoSuchOrganizationException(msg.toString());
939         }
940         else {
941             return (Organization)list.get(0);
942         }
943     }
944 
945     public Organization findByC_P_Last(long companyId,
946         long parentOrganizationId, OrderByComparator obc)
947         throws NoSuchOrganizationException, SystemException {
948         int count = countByC_P(companyId, parentOrganizationId);
949 
950         List list = findByC_P(companyId, parentOrganizationId, count - 1,
951                 count, obc);
952 
953         if (list.size() == 0) {
954             StringMaker msg = new StringMaker();
955 
956             msg.append("No Organization exists with the key {");
957 
958             msg.append("companyId=" + companyId);
959 
960             msg.append(", ");
961             msg.append("parentOrganizationId=" + parentOrganizationId);
962 
963             msg.append(StringPool.CLOSE_CURLY_BRACE);
964 
965             throw new NoSuchOrganizationException(msg.toString());
966         }
967         else {
968             return (Organization)list.get(0);
969         }
970     }
971 
972     public Organization[] findByC_P_PrevAndNext(long organizationId,
973         long companyId, long parentOrganizationId, OrderByComparator obc)
974         throws NoSuchOrganizationException, SystemException {
975         Organization organization = findByPrimaryKey(organizationId);
976 
977         int count = countByC_P(companyId, parentOrganizationId);
978 
979         Session session = null;
980 
981         try {
982             session = openSession();
983 
984             StringMaker query = new StringMaker();
985 
986             query.append("FROM com.liferay.portal.model.Organization WHERE ");
987 
988             query.append("companyId = ?");
989 
990             query.append(" AND ");
991 
992             query.append("parentOrganizationId = ?");
993 
994             query.append(" ");
995 
996             if (obc != null) {
997                 query.append("ORDER BY ");
998                 query.append(obc.getOrderBy());
999             }
1000
1001            else {
1002                query.append("ORDER BY ");
1003
1004                query.append("name ASC");
1005            }
1006
1007            Query q = session.createQuery(query.toString());
1008
1009            int queryPos = 0;
1010
1011            q.setLong(queryPos++, companyId);
1012
1013            q.setLong(queryPos++, parentOrganizationId);
1014
1015            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1016                    organization);
1017
1018            Organization[] array = new OrganizationImpl[3];
1019
1020            array[0] = (Organization)objArray[0];
1021            array[1] = (Organization)objArray[1];
1022            array[2] = (Organization)objArray[2];
1023
1024            return array;
1025        }
1026        catch (Exception e) {
1027            throw HibernateUtil.processException(e);
1028        }
1029        finally {
1030            closeSession(session);
1031        }
1032    }
1033
1034    public Organization findByC_N(long companyId, String name)
1035        throws NoSuchOrganizationException, SystemException {
1036        Organization organization = fetchByC_N(companyId, name);
1037
1038        if (organization == null) {
1039            StringMaker msg = new StringMaker();
1040
1041            msg.append("No Organization exists with the key {");
1042
1043            msg.append("companyId=" + companyId);
1044
1045            msg.append(", ");
1046            msg.append("name=" + name);
1047
1048            msg.append(StringPool.CLOSE_CURLY_BRACE);
1049
1050            if (_log.isWarnEnabled()) {
1051                _log.warn(msg.toString());
1052            }
1053
1054            throw new NoSuchOrganizationException(msg.toString());
1055        }
1056
1057        return organization;
1058    }
1059
1060    public Organization fetchByC_N(long companyId, String name)
1061        throws SystemException {
1062        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1063        String finderClassName = Organization.class.getName();
1064        String finderMethodName = "fetchByC_N";
1065        String[] finderParams = new String[] {
1066                Long.class.getName(), String.class.getName()
1067            };
1068        Object[] finderArgs = new Object[] { new Long(companyId), name };
1069
1070        Object result = null;
1071
1072        if (finderClassNameCacheEnabled) {
1073            result = FinderCache.getResult(finderClassName, finderMethodName,
1074                    finderParams, finderArgs, getSessionFactory());
1075        }
1076
1077        if (result == null) {
1078            Session session = null;
1079
1080            try {
1081                session = openSession();
1082
1083                StringMaker query = new StringMaker();
1084
1085                query.append(
1086                    "FROM com.liferay.portal.model.Organization WHERE ");
1087
1088                query.append("companyId = ?");
1089
1090                query.append(" AND ");
1091
1092                if (name == null) {
1093                    query.append("name IS NULL");
1094                }
1095                else {
1096                    query.append("name = ?");
1097                }
1098
1099                query.append(" ");
1100
1101                query.append("ORDER BY ");
1102
1103                query.append("name ASC");
1104
1105                Query q = session.createQuery(query.toString());
1106
1107                int queryPos = 0;
1108
1109                q.setLong(queryPos++, companyId);
1110
1111                if (name != null) {
1112                    q.setString(queryPos++, name);
1113                }
1114
1115                List list = q.list();
1116
1117                FinderCache.putResult(finderClassNameCacheEnabled,
1118                    finderClassName, finderMethodName, finderParams,
1119                    finderArgs, list);
1120
1121                if (list.size() == 0) {
1122                    return null;
1123                }
1124                else {
1125                    return (Organization)list.get(0);
1126                }
1127            }
1128            catch (Exception e) {
1129                throw HibernateUtil.processException(e);
1130            }
1131            finally {
1132                closeSession(session);
1133            }
1134        }
1135        else {
1136            List list = (List)result;
1137
1138            if (list.size() == 0) {
1139                return null;
1140            }
1141            else {
1142                return (Organization)list.get(0);
1143            }
1144        }
1145    }
1146
1147    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1148        throws SystemException {
1149        Session session = null;
1150
1151        try {
1152            session = openSession();
1153
1154            DynamicQuery query = queryInitializer.initialize(session);
1155
1156            return query.list();
1157        }
1158        catch (Exception e) {
1159            throw HibernateUtil.processException(e);
1160        }
1161        finally {
1162            closeSession(session);
1163        }
1164    }
1165
1166    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1167        int begin, int end) throws SystemException {
1168        Session session = null;
1169
1170        try {
1171            session = openSession();
1172
1173            DynamicQuery query = queryInitializer.initialize(session);
1174
1175            query.setLimit(begin, end);
1176
1177            return query.list();
1178        }
1179        catch (Exception e) {
1180            throw HibernateUtil.processException(e);
1181        }
1182        finally {
1183            closeSession(session);
1184        }
1185    }
1186
1187    public List findAll() throws SystemException {
1188        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1189    }
1190
1191    public List findAll(int begin, int end) throws SystemException {
1192        return findAll(begin, end, null);
1193    }
1194
1195    public List findAll(int begin, int end, OrderByComparator obc)
1196        throws SystemException {
1197        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1198        String finderClassName = Organization.class.getName();
1199        String finderMethodName = "findAll";
1200        String[] finderParams = new String[] {
1201                "java.lang.Integer", "java.lang.Integer",
1202                "com.liferay.portal.kernel.util.OrderByComparator"
1203            };
1204        Object[] finderArgs = new Object[] {
1205                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1206            };
1207
1208        Object result = null;
1209
1210        if (finderClassNameCacheEnabled) {
1211            result = FinderCache.getResult(finderClassName, finderMethodName,
1212                    finderParams, finderArgs, getSessionFactory());
1213        }
1214
1215        if (result == null) {
1216            Session session = null;
1217
1218            try {
1219                session = openSession();
1220
1221                StringMaker query = new StringMaker();
1222
1223                query.append("FROM com.liferay.portal.model.Organization ");
1224
1225                if (obc != null) {
1226                    query.append("ORDER BY ");
1227                    query.append(obc.getOrderBy());
1228                }
1229
1230                else {
1231                    query.append("ORDER BY ");
1232
1233                    query.append("name ASC");
1234                }
1235
1236                Query q = session.createQuery(query.toString());
1237
1238                List list = QueryUtil.list(q, getDialect(), begin, end);
1239
1240                if (obc == null) {
1241                    Collections.sort(list);
1242                }
1243
1244                FinderCache.putResult(finderClassNameCacheEnabled,
1245                    finderClassName, finderMethodName, finderParams,
1246                    finderArgs, list);
1247
1248                return list;
1249            }
1250            catch (Exception e) {
1251                throw HibernateUtil.processException(e);
1252            }
1253            finally {
1254                closeSession(session);
1255            }
1256        }
1257        else {
1258            return (List)result;
1259        }
1260    }
1261
1262    public void removeByCompanyId(long companyId) throws SystemException {
1263        Iterator itr = findByCompanyId(companyId).iterator();
1264
1265        while (itr.hasNext()) {
1266            Organization organization = (Organization)itr.next();
1267
1268            remove(organization);
1269        }
1270    }
1271
1272    public void removeByLocations(long companyId) throws SystemException {
1273        Iterator itr = findByLocations(companyId).iterator();
1274
1275        while (itr.hasNext()) {
1276            Organization organization = (Organization)itr.next();
1277
1278            remove(organization);
1279        }
1280    }
1281
1282    public void removeByC_P(long companyId, long parentOrganizationId)
1283        throws SystemException {
1284        Iterator itr = findByC_P(companyId, parentOrganizationId).iterator();
1285
1286        while (itr.hasNext()) {
1287            Organization organization = (Organization)itr.next();
1288
1289            remove(organization);
1290        }
1291    }
1292
1293    public void removeByC_N(long companyId, String name)
1294        throws NoSuchOrganizationException, SystemException {
1295        Organization organization = findByC_N(companyId, name);
1296
1297        remove(organization);
1298    }
1299
1300    public void removeAll() throws SystemException {
1301        Iterator itr = findAll().iterator();
1302
1303        while (itr.hasNext()) {
1304            remove((Organization)itr.next());
1305        }
1306    }
1307
1308    public int countByCompanyId(long companyId) throws SystemException {
1309        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1310        String finderClassName = Organization.class.getName();
1311        String finderMethodName = "countByCompanyId";
1312        String[] finderParams = new String[] { Long.class.getName() };
1313        Object[] finderArgs = new Object[] { new Long(companyId) };
1314
1315        Object result = null;
1316
1317        if (finderClassNameCacheEnabled) {
1318            result = FinderCache.getResult(finderClassName, finderMethodName,
1319                    finderParams, finderArgs, getSessionFactory());
1320        }
1321
1322        if (result == null) {
1323            Session session = null;
1324
1325            try {
1326                session = openSession();
1327
1328                StringMaker query = new StringMaker();
1329
1330                query.append("SELECT COUNT(*) ");
1331                query.append(
1332                    "FROM com.liferay.portal.model.Organization WHERE ");
1333
1334                query.append("companyId = ?");
1335
1336                query.append(" ");
1337
1338                Query q = session.createQuery(query.toString());
1339
1340                int queryPos = 0;
1341
1342                q.setLong(queryPos++, companyId);
1343
1344                Long count = null;
1345
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(finderClassNameCacheEnabled,
1357                    finderClassName, finderMethodName, finderParams,
1358                    finderArgs, count);
1359
1360                return count.intValue();
1361            }
1362            catch (Exception e) {
1363                throw HibernateUtil.processException(e);
1364            }
1365            finally {
1366                closeSession(session);
1367            }
1368        }
1369        else {
1370            return ((Long)result).intValue();
1371        }
1372    }
1373
1374    public int countByLocations(long companyId) throws SystemException {
1375        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1376        String finderClassName = Organization.class.getName();
1377        String finderMethodName = "countByLocations";
1378        String[] finderParams = new String[] { Long.class.getName() };
1379        Object[] finderArgs = new Object[] { new Long(companyId) };
1380
1381        Object result = null;
1382
1383        if (finderClassNameCacheEnabled) {
1384            result = FinderCache.getResult(finderClassName, finderMethodName,
1385                    finderParams, finderArgs, getSessionFactory());
1386        }
1387
1388        if (result == null) {
1389            Session session = null;
1390
1391            try {
1392                session = openSession();
1393
1394                StringMaker query = new StringMaker();
1395
1396                query.append("SELECT COUNT(*) ");
1397                query.append(
1398                    "FROM com.liferay.portal.model.Organization WHERE ");
1399
1400                query.append("companyId = ?");
1401
1402                query.append(" AND parentOrganizationId != 0 ");
1403
1404                Query q = session.createQuery(query.toString());
1405
1406                int queryPos = 0;
1407
1408                q.setLong(queryPos++, companyId);
1409
1410                Long count = null;
1411
1412                Iterator itr = q.list().iterator();
1413
1414                if (itr.hasNext()) {
1415                    count = (Long)itr.next();
1416                }
1417
1418                if (count == null) {
1419                    count = new Long(0);
1420                }
1421
1422                FinderCache.putResult(finderClassNameCacheEnabled,
1423                    finderClassName, finderMethodName, finderParams,
1424                    finderArgs, count);
1425
1426                return count.intValue();
1427            }
1428            catch (Exception e) {
1429                throw HibernateUtil.processException(e);
1430            }
1431            finally {
1432                closeSession(session);
1433            }
1434        }
1435        else {
1436            return ((Long)result).intValue();
1437        }
1438    }
1439
1440    public int countByC_P(long companyId, long parentOrganizationId)
1441        throws SystemException {
1442        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1443        String finderClassName = Organization.class.getName();
1444        String finderMethodName = "countByC_P";
1445        String[] finderParams = new String[] {
1446                Long.class.getName(), Long.class.getName()
1447            };
1448        Object[] finderArgs = new Object[] {
1449                new Long(companyId), new Long(parentOrganizationId)
1450            };
1451
1452        Object result = null;
1453
1454        if (finderClassNameCacheEnabled) {
1455            result = FinderCache.getResult(finderClassName, finderMethodName,
1456                    finderParams, finderArgs, getSessionFactory());
1457        }
1458
1459        if (result == null) {
1460            Session session = null;
1461
1462            try {
1463                session = openSession();
1464
1465                StringMaker query = new StringMaker();
1466
1467                query.append("SELECT COUNT(*) ");
1468                query.append(
1469                    "FROM com.liferay.portal.model.Organization WHERE ");
1470
1471                query.append("companyId = ?");
1472
1473                query.append(" AND ");
1474
1475                query.append("parentOrganizationId = ?");
1476
1477                query.append(" ");
1478
1479                Query q = session.createQuery(query.toString());
1480
1481                int queryPos = 0;
1482
1483                q.setLong(queryPos++, companyId);
1484
1485                q.setLong(queryPos++, parentOrganizationId);
1486
1487                Long count = null;
1488
1489                Iterator itr = q.list().iterator();
1490
1491                if (itr.hasNext()) {
1492                    count = (Long)itr.next();
1493                }
1494
1495                if (count == null) {
1496                    count = new Long(0);
1497                }
1498
1499                FinderCache.putResult(finderClassNameCacheEnabled,
1500                    finderClassName, finderMethodName, finderParams,
1501                    finderArgs, count);
1502
1503                return count.intValue();
1504            }
1505            catch (Exception e) {
1506                throw HibernateUtil.processException(e);
1507            }
1508            finally {
1509                closeSession(session);
1510            }
1511        }
1512        else {
1513            return ((Long)result).intValue();
1514        }
1515    }
1516
1517    public int countByC_N(long companyId, String name)
1518        throws SystemException {
1519        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1520        String finderClassName = Organization.class.getName();
1521        String finderMethodName = "countByC_N";
1522        String[] finderParams = new String[] {
1523                Long.class.getName(), String.class.getName()
1524            };
1525        Object[] finderArgs = new Object[] { new Long(companyId), name };
1526
1527        Object result = null;
1528
1529        if (finderClassNameCacheEnabled) {
1530            result = FinderCache.getResult(finderClassName, finderMethodName,
1531                    finderParams, finderArgs, getSessionFactory());
1532        }
1533
1534        if (result == null) {
1535            Session session = null;
1536
1537            try {
1538                session = openSession();
1539
1540                StringMaker query = new StringMaker();
1541
1542                query.append("SELECT COUNT(*) ");
1543                query.append(
1544                    "FROM com.liferay.portal.model.Organization WHERE ");
1545
1546                query.append("companyId = ?");
1547
1548                query.append(" AND ");
1549
1550                if (name == null) {
1551                    query.append("name IS NULL");
1552                }
1553                else {
1554                    query.append("name = ?");
1555                }
1556
1557                query.append(" ");
1558
1559                Query q = session.createQuery(query.toString());
1560
1561                int queryPos = 0;
1562
1563                q.setLong(queryPos++, companyId);
1564
1565                if (name != null) {
1566                    q.setString(queryPos++, name);
1567                }
1568
1569                Long count = null;
1570
1571                Iterator itr = q.list().iterator();
1572
1573                if (itr.hasNext()) {
1574                    count = (Long)itr.next();
1575                }
1576
1577                if (count == null) {
1578                    count = new Long(0);
1579                }
1580
1581                FinderCache.putResult(finderClassNameCacheEnabled,
1582                    finderClassName, finderMethodName, finderParams,
1583                    finderArgs, count);
1584
1585                return count.intValue();
1586            }
1587            catch (Exception e) {
1588                throw HibernateUtil.processException(e);
1589            }
1590            finally {
1591                closeSession(session);
1592            }
1593        }
1594        else {
1595            return ((Long)result).intValue();
1596        }
1597    }
1598
1599    public int countAll() throws SystemException {
1600        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1601        String finderClassName = Organization.class.getName();
1602        String finderMethodName = "countAll";
1603        String[] finderParams = new String[] {  };
1604        Object[] finderArgs = new Object[] {  };
1605
1606        Object result = null;
1607
1608        if (finderClassNameCacheEnabled) {
1609            result = FinderCache.getResult(finderClassName, finderMethodName,
1610                    finderParams, finderArgs, getSessionFactory());
1611        }
1612
1613        if (result == null) {
1614            Session session = null;
1615
1616            try {
1617                session = openSession();
1618
1619                Query q = session.createQuery(
1620                        "SELECT COUNT(*) FROM com.liferay.portal.model.Organization");
1621
1622                Long count = null;
1623
1624                Iterator itr = q.list().iterator();
1625
1626                if (itr.hasNext()) {
1627                    count = (Long)itr.next();
1628                }
1629
1630                if (count == null) {
1631                    count = new Long(0);
1632                }
1633
1634                FinderCache.putResult(finderClassNameCacheEnabled,
1635                    finderClassName, finderMethodName, finderParams,
1636                    finderArgs, count);
1637
1638                return count.intValue();
1639            }
1640            catch (Exception e) {
1641                throw HibernateUtil.processException(e);
1642            }
1643            finally {
1644                closeSession(session);
1645            }
1646        }
1647        else {
1648            return ((Long)result).intValue();
1649        }
1650    }
1651
1652    public List getGroups(long pk)
1653        throws NoSuchOrganizationException, SystemException {
1654        return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1655    }
1656
1657    public List getGroups(long pk, int begin, int end)
1658        throws NoSuchOrganizationException, SystemException {
1659        return getGroups(pk, begin, end, null);
1660    }
1661
1662    public List getGroups(long pk, int begin, int end, OrderByComparator obc)
1663        throws NoSuchOrganizationException, SystemException {
1664        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1665        String finderClassName = "Groups_Orgs";
1666        String finderMethodName = "getGroups";
1667        String[] finderParams = new String[] {
1668                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1669                "com.liferay.portal.kernel.util.OrderByComparator"
1670            };
1671        Object[] finderArgs = new Object[] {
1672                new Long(pk), String.valueOf(begin), String.valueOf(end),
1673                String.valueOf(obc)
1674            };
1675
1676        Object result = null;
1677
1678        if (finderClassNameCacheEnabled) {
1679            result = FinderCache.getResult(finderClassName, finderMethodName,
1680                    finderParams, finderArgs, getSessionFactory());
1681        }
1682
1683        if (result == null) {
1684            Session session = null;
1685
1686            try {
1687                session = HibernateUtil.openSession();
1688
1689                StringMaker sm = new StringMaker();
1690
1691                sm.append(_SQL_GETGROUPS);
1692
1693                if (obc != null) {
1694                    sm.append("ORDER BY ");
1695                    sm.append(obc.getOrderBy());
1696                }
1697
1698                else {
1699                    sm.append("ORDER BY ");
1700
1701                    sm.append("Group_.name ASC");
1702                }
1703
1704                String sql = sm.toString();
1705
1706                SQLQuery q = session.createSQLQuery(sql);
1707
1708                q.addEntity("Group_",
1709                    com.liferay.portal.model.impl.GroupImpl.class);
1710
1711                QueryPos qPos = QueryPos.getInstance(q);
1712
1713                qPos.add(pk);
1714
1715                List list = QueryUtil.list(q, getDialect(), begin, end);
1716
1717                FinderCache.putResult(finderClassNameCacheEnabled,
1718                    finderClassName, finderMethodName, finderParams,
1719                    finderArgs, list);
1720
1721                return list;
1722            }
1723            catch (Exception e) {
1724                throw new SystemException(e);
1725            }
1726            finally {
1727                closeSession(session);
1728            }
1729        }
1730        else {
1731            return (List)result;
1732        }
1733    }
1734
1735    public int getGroupsSize(long pk) throws SystemException {
1736        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1737        String finderClassName = "Groups_Orgs";
1738        String finderMethodName = "getGroupsSize";
1739        String[] finderParams = new String[] { Long.class.getName() };
1740        Object[] finderArgs = new Object[] { new Long(pk) };
1741
1742        Object result = null;
1743
1744        if (finderClassNameCacheEnabled) {
1745            result = FinderCache.getResult(finderClassName, finderMethodName,
1746                    finderParams, finderArgs, getSessionFactory());
1747        }
1748
1749        if (result == null) {
1750            Session session = null;
1751
1752            try {
1753                session = openSession();
1754
1755                SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1756
1757                q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
1758
1759                QueryPos qPos = QueryPos.getInstance(q);
1760
1761                qPos.add(pk);
1762
1763                Long count = null;
1764
1765                Iterator itr = q.list().iterator();
1766
1767                if (itr.hasNext()) {
1768                    count = (Long)itr.next();
1769                }
1770
1771                if (count == null) {
1772                    count = new Long(0);
1773                }
1774
1775                FinderCache.putResult(finderClassNameCacheEnabled,
1776                    finderClassName, finderMethodName, finderParams,
1777                    finderArgs, count);
1778
1779                return count.intValue();
1780            }
1781            catch (Exception e) {
1782                throw HibernateUtil.processException(e);
1783            }
1784            finally {
1785                closeSession(session);
1786            }
1787        }
1788        else {
1789            return ((Long)result).intValue();
1790        }
1791    }
1792
1793    public boolean containsGroup(long pk, long groupPK)
1794        throws SystemException {
1795        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1796        String finderClassName = "Groups_Orgs";
1797        String finderMethodName = "containsGroups";
1798        String[] finderParams = new String[] {
1799                Long.class.getName(),
1800                
1801                Long.class.getName()
1802            };
1803        Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
1804
1805        Object result = null;
1806
1807        if (finderClassNameCacheEnabled) {
1808            result = FinderCache.getResult(finderClassName, finderMethodName,
1809                    finderParams, finderArgs, getSessionFactory());
1810        }
1811
1812        if (result == null) {
1813            try {
1814                Boolean value = Boolean.valueOf(containsGroup.contains(pk,
1815                            groupPK));
1816
1817                FinderCache.putResult(finderClassNameCacheEnabled,
1818                    finderClassName, finderMethodName, finderParams,
1819                    finderArgs, value);
1820
1821                return value.booleanValue();
1822            }
1823            catch (DataAccessException dae) {
1824                throw new SystemException(dae);
1825            }
1826        }
1827        else {
1828            return ((Boolean)result).booleanValue();
1829        }
1830    }
1831
1832    public boolean containsGroups(long pk) throws SystemException {
1833        if (getGroupsSize(pk) > 0) {
1834            return true;
1835        }
1836        else {
1837            return false;
1838        }
1839    }
1840
1841    public void addGroup(long pk, long groupPK)
1842        throws NoSuchOrganizationException, 
1843            com.liferay.portal.NoSuchGroupException, SystemException {
1844        try {
1845            addGroup.add(pk, groupPK);
1846        }
1847        catch (DataAccessException dae) {
1848            throw new SystemException(dae);
1849        }
1850        finally {
1851            FinderCache.clearCache("Groups_Orgs");
1852        }
1853    }
1854
1855    public void addGroup(long pk, com.liferay.portal.model.Group group)
1856        throws NoSuchOrganizationException, 
1857            com.liferay.portal.NoSuchGroupException, SystemException {
1858        try {
1859            addGroup.add(pk, group.getPrimaryKey());
1860        }
1861        catch (DataAccessException dae) {
1862            throw new SystemException(dae);
1863        }
1864        finally {
1865            FinderCache.clearCache("Groups_Orgs");
1866        }
1867    }
1868
1869    public void addGroups(long pk, long[] groupPKs)
1870        throws NoSuchOrganizationException, 
1871            com.liferay.portal.NoSuchGroupException, SystemException {
1872        try {
1873            for (int i = 0; i < groupPKs.length; i++) {
1874                addGroup.add(pk, groupPKs[i]);
1875            }
1876        }
1877        catch (DataAccessException dae) {
1878            throw new SystemException(dae);
1879        }
1880        finally {
1881            FinderCache.clearCache("Groups_Orgs");
1882        }
1883    }
1884
1885    public void addGroups(long pk, List groups)
1886        throws NoSuchOrganizationException, 
1887            com.liferay.portal.NoSuchGroupException, SystemException {
1888        try {
1889            for (int i = 0; i < groups.size(); i++) {
1890                com.liferay.portal.model.Group group = (com.liferay.portal.model.Group)groups.get(i);
1891
1892                addGroup.add(pk, group.getPrimaryKey());
1893            }
1894        }
1895        catch (DataAccessException dae) {
1896            throw new SystemException(dae);
1897        }
1898        finally {
1899            FinderCache.clearCache("Groups_Orgs");
1900        }
1901    }
1902
1903    public void clearGroups(long pk)
1904        throws NoSuchOrganizationException, SystemException {
1905        try {
1906            clearGroups.clear(pk);
1907        }
1908        catch (DataAccessException dae) {
1909            throw new SystemException(dae);
1910        }
1911        finally {
1912            FinderCache.clearCache("Groups_Orgs");
1913        }
1914    }
1915
1916    public void removeGroup(long pk, long groupPK)
1917        throws NoSuchOrganizationException, 
1918            com.liferay.portal.NoSuchGroupException, SystemException {
1919        try {
1920            removeGroup.remove(pk, groupPK);
1921        }
1922        catch (DataAccessException dae) {
1923            throw new SystemException(dae);
1924        }
1925        finally {
1926            FinderCache.clearCache("Groups_Orgs");
1927        }
1928    }
1929
1930    public void removeGroup(long pk, com.liferay.portal.model.Group group)
1931        throws NoSuchOrganizationException, 
1932            com.liferay.portal.NoSuchGroupException, SystemException {
1933        try {
1934            removeGroup.remove(pk, group.getPrimaryKey());
1935        }
1936        catch (DataAccessException dae) {
1937            throw new SystemException(dae);
1938        }
1939        finally {
1940            FinderCache.clearCache("Groups_Orgs");
1941        }
1942    }
1943
1944    public void removeGroups(long pk, long[] groupPKs)
1945        throws NoSuchOrganizationException, 
1946            com.liferay.portal.NoSuchGroupException, SystemException {
1947        try {
1948            for (int i = 0; i < groupPKs.length; i++) {
1949                removeGroup.remove(pk, groupPKs[i]);
1950            }
1951        }
1952        catch (DataAccessException dae) {
1953            throw new SystemException(dae);
1954        }
1955        finally {
1956            FinderCache.clearCache("Groups_Orgs");
1957        }
1958    }
1959
1960    public void removeGroups(long pk, List groups)
1961        throws NoSuchOrganizationException, 
1962            com.liferay.portal.NoSuchGroupException, SystemException {
1963        try {
1964            for (int i = 0; i < groups.size(); i++) {
1965                com.liferay.portal.model.Group group = (com.liferay.portal.model.Group)groups.get(i);
1966
1967                removeGroup.remove(pk, group.getPrimaryKey());
1968            }
1969        }
1970        catch (DataAccessException dae) {
1971            throw new SystemException(dae);
1972        }
1973        finally {
1974            FinderCache.clearCache("Groups_Orgs");
1975        }
1976    }
1977
1978    public void setGroups(long pk, long[] groupPKs)
1979        throws NoSuchOrganizationException, 
1980            com.liferay.portal.NoSuchGroupException, SystemException {
1981        try {
1982            clearGroups.clear(pk);
1983
1984            for (int i = 0; i < groupPKs.length; i++) {
1985                addGroup.add(pk, groupPKs[i]);
1986            }
1987        }
1988        catch (DataAccessException dae) {
1989            throw new SystemException(dae);
1990        }
1991        finally {
1992            FinderCache.clearCache("Groups_Orgs");
1993        }
1994    }
1995
1996    public void setGroups(long pk, List groups)
1997        throws NoSuchOrganizationException, 
1998            com.liferay.portal.NoSuchGroupException, SystemException {
1999        try {
2000            clearGroups.clear(pk);
2001
2002            for (int i = 0; i < groups.size(); i++) {
2003                com.liferay.portal.model.Group group = (com.liferay.portal.model.Group)groups.get(i);
2004
2005                addGroup.add(pk, group.getPrimaryKey());
2006            }
2007        }
2008        catch (DataAccessException dae) {
2009            throw new SystemException(dae);
2010        }
2011        finally {
2012            FinderCache.clearCache("Groups_Orgs");
2013        }
2014    }
2015
2016    public List getUsers(long pk)
2017        throws NoSuchOrganizationException, SystemException {
2018        return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2019    }
2020
2021    public List getUsers(long pk, int begin, int end)
2022        throws NoSuchOrganizationException, SystemException {
2023        return getUsers(pk, begin, end, null);
2024    }
2025
2026    public List getUsers(long pk, int begin, int end, OrderByComparator obc)
2027        throws NoSuchOrganizationException, SystemException {
2028        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
2029        String finderClassName = "Users_Orgs";
2030        String finderMethodName = "getUsers";
2031        String[] finderParams = new String[] {
2032                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2033                "com.liferay.portal.kernel.util.OrderByComparator"
2034            };
2035        Object[] finderArgs = new Object[] {
2036                new Long(pk), String.valueOf(begin), String.valueOf(end),
2037                String.valueOf(obc)
2038            };
2039
2040        Object result = null;
2041
2042        if (finderClassNameCacheEnabled) {
2043            result = FinderCache.getResult(finderClassName, finderMethodName,
2044                    finderParams, finderArgs, getSessionFactory());
2045        }
2046
2047        if (result == null) {
2048            Session session = null;
2049
2050            try {
2051                session = HibernateUtil.openSession();
2052
2053                StringMaker sm = new StringMaker();
2054
2055                sm.append(_SQL_GETUSERS);
2056
2057                if (obc != null) {
2058                    sm.append("ORDER BY ");
2059                    sm.append(obc.getOrderBy());
2060                }
2061
2062                String sql = sm.toString();
2063
2064                SQLQuery q = session.createSQLQuery(sql);
2065
2066                q.addEntity("User_",
2067                    com.liferay.portal.model.impl.UserImpl.class);
2068
2069                QueryPos qPos = QueryPos.getInstance(q);
2070
2071                qPos.add(pk);
2072
2073                List list = QueryUtil.list(q, getDialect(), begin, end);
2074
2075                FinderCache.putResult(finderClassNameCacheEnabled,
2076                    finderClassName, finderMethodName, finderParams,
2077                    finderArgs, list);
2078
2079                return list;
2080            }
2081            catch (Exception e) {
2082                throw new SystemException(e);
2083            }
2084            finally {
2085                closeSession(session);
2086            }
2087        }
2088        else {
2089            return (List)result;
2090        }
2091    }
2092
2093    public int getUsersSize(long pk) throws SystemException {
2094        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
2095        String finderClassName = "Users_Orgs";
2096        String finderMethodName = "getUsersSize";
2097        String[] finderParams = new String[] { Long.class.getName() };
2098        Object[] finderArgs = new Object[] { new Long(pk) };
2099
2100        Object result = null;
2101
2102        if (finderClassNameCacheEnabled) {
2103            result = FinderCache.getResult(finderClassName, finderMethodName,
2104                    finderParams, finderArgs, getSessionFactory());
2105        }
2106
2107        if (result == null) {
2108            Session session = null;
2109
2110            try {
2111                session = openSession();
2112
2113                SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2114
2115                q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
2116
2117                QueryPos qPos = QueryPos.getInstance(q);
2118
2119                qPos.add(pk);
2120
2121                Long count = null;
2122
2123                Iterator itr = q.list().iterator();
2124
2125                if (itr.hasNext()) {
2126                    count = (Long)itr.next();
2127                }
2128
2129                if (count == null) {
2130                    count = new Long(0);
2131                }
2132
2133                FinderCache.putResult(finderClassNameCacheEnabled,
2134                    finderClassName, finderMethodName, finderParams,
2135                    finderArgs, count);
2136
2137                return count.intValue();
2138            }
2139            catch (Exception e) {
2140                throw HibernateUtil.processException(e);
2141            }
2142            finally {
2143                closeSession(session);
2144            }
2145        }
2146        else {
2147            return ((Long)result).intValue();
2148        }
2149    }
2150
2151    public boolean containsUser(long pk, long userPK) throws SystemException {
2152        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
2153        String finderClassName = "Users_Orgs";
2154        String finderMethodName = "containsUsers";
2155        String[] finderParams = new String[] {
2156                Long.class.getName(),
2157                
2158                Long.class.getName()
2159            };
2160        Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
2161
2162        Object result = null;
2163
2164        if (finderClassNameCacheEnabled) {
2165            result = FinderCache.getResult(finderClassName, finderMethodName,
2166                    finderParams, finderArgs, getSessionFactory());
2167        }
2168
2169        if (result == null) {
2170            try {
2171                Boolean value = Boolean.valueOf(containsUser.contains(pk, userPK));
2172
2173                FinderCache.putResult(finderClassNameCacheEnabled,
2174                    finderClassName, finderMethodName, finderParams,
2175                    finderArgs, value);
2176
2177                return value.booleanValue();
2178            }
2179            catch (DataAccessException dae) {
2180                throw new SystemException(dae);
2181            }
2182        }
2183        else {
2184            return ((Boolean)result).booleanValue();
2185        }
2186    }
2187
2188    public boolean containsUsers(long pk) throws SystemException {
2189        if (getUsersSize(pk) > 0) {
2190            return true;
2191        }
2192        else {
2193            return false;
2194        }
2195    }
2196
2197    public void addUser(long pk, long userPK)
2198        throws NoSuchOrganizationException, 
2199            com.liferay.portal.NoSuchUserException, SystemException {
2200        try {
2201            addUser.add(pk, userPK);
2202        }
2203        catch (DataAccessException dae) {
2204            throw new SystemException(dae);
2205        }
2206        finally {
2207            FinderCache.clearCache("Users_Orgs");
2208        }
2209    }
2210
2211    public void addUser(long pk, com.liferay.portal.model.User user)
2212        throws NoSuchOrganizationException, 
2213            com.liferay.portal.NoSuchUserException, SystemException {
2214        try {
2215            addUser.add(pk, user.getPrimaryKey());
2216        }
2217        catch (DataAccessException dae) {
2218            throw new SystemException(dae);
2219        }
2220        finally {
2221            FinderCache.clearCache("Users_Orgs");
2222        }
2223    }
2224
2225    public void addUsers(long pk, long[] userPKs)
2226        throws NoSuchOrganizationException, 
2227            com.liferay.portal.NoSuchUserException, SystemException {
2228        try {
2229            for (int i = 0; i < userPKs.length; i++) {
2230                addUser.add(pk, userPKs[i]);
2231            }
2232        }
2233        catch (DataAccessException dae) {
2234            throw new SystemException(dae);
2235        }
2236        finally {
2237            FinderCache.clearCache("Users_Orgs");
2238        }
2239    }
2240
2241    public void addUsers(long pk, List users)
2242        throws NoSuchOrganizationException, 
2243            com.liferay.portal.NoSuchUserException, SystemException {
2244        try {
2245            for (int i = 0; i < users.size(); i++) {
2246                com.liferay.portal.model.User user = (com.liferay.portal.model.User)users.get(i);
2247
2248                addUser.add(pk, user.getPrimaryKey());
2249            }
2250        }
2251        catch (DataAccessException dae) {
2252            throw new SystemException(dae);
2253        }
2254        finally {
2255            FinderCache.clearCache("Users_Orgs");
2256        }
2257    }
2258
2259    public void clearUsers(long pk)
2260        throws NoSuchOrganizationException, SystemException {
2261        try {
2262            clearUsers.clear(pk);
2263        }
2264        catch (DataAccessException dae) {
2265            throw new SystemException(dae);
2266        }
2267        finally {
2268            FinderCache.clearCache("Users_Orgs");
2269        }
2270    }
2271
2272    public void removeUser(long pk, long userPK)
2273        throws NoSuchOrganizationException, 
2274            com.liferay.portal.NoSuchUserException, SystemException {
2275        try {
2276            removeUser.remove(pk, userPK);
2277        }
2278        catch (DataAccessException dae) {
2279            throw new SystemException(dae);
2280        }
2281        finally {
2282            FinderCache.clearCache("Users_Orgs");
2283        }
2284    }
2285
2286    public void removeUser(long pk, com.liferay.portal.model.User user)
2287        throws NoSuchOrganizationException, 
2288            com.liferay.portal.NoSuchUserException, SystemException {
2289        try {
2290            removeUser.remove(pk, user.getPrimaryKey());
2291        }
2292        catch (DataAccessException dae) {
2293            throw new SystemException(dae);
2294        }
2295        finally {
2296            FinderCache.clearCache("Users_Orgs");
2297        }
2298    }
2299
2300    public void removeUsers(long pk, long[] userPKs)
2301        throws NoSuchOrganizationException, 
2302            com.liferay.portal.NoSuchUserException, SystemException {
2303        try {
2304            for (int i = 0; i < userPKs.length; i++) {
2305                removeUser.remove(pk, userPKs[i]);
2306            }
2307        }
2308        catch (DataAccessException dae) {
2309            throw new SystemException(dae);
2310        }
2311        finally {
2312            FinderCache.clearCache("Users_Orgs");
2313        }
2314    }
2315
2316    public void removeUsers(long pk, List users)
2317        throws NoSuchOrganizationException, 
2318            com.liferay.portal.NoSuchUserException, SystemException {
2319        try {
2320            for (int i = 0; i < users.size(); i++) {
2321                com.liferay.portal.model.User user = (com.liferay.portal.model.User)users.get(i);
2322
2323                removeUser.remove(pk, user.getPrimaryKey());
2324            }
2325        }
2326        catch (DataAccessException dae) {
2327            throw new SystemException(dae);
2328        }
2329        finally {
2330            FinderCache.clearCache("Users_Orgs");
2331        }
2332    }
2333
2334    public void setUsers(long pk, long[] userPKs)
2335        throws NoSuchOrganizationException, 
2336            com.liferay.portal.NoSuchUserException, SystemException {
2337        try {
2338            clearUsers.clear(pk);
2339
2340            for (int i = 0; i < userPKs.length; i++) {
2341                addUser.add(pk, userPKs[i]);
2342            }
2343        }
2344        catch (DataAccessException dae) {
2345            throw new SystemException(dae);
2346        }
2347        finally {
2348            FinderCache.clearCache("Users_Orgs");
2349        }
2350    }
2351
2352    public void setUsers(long pk, List users)
2353        throws NoSuchOrganizationException, 
2354            com.liferay.portal.NoSuchUserException, SystemException {
2355        try {
2356            clearUsers.clear(pk);
2357
2358            for (int i = 0; i < users.size(); i++) {
2359                com.liferay.portal.model.User user = (com.liferay.portal.model.User)users.get(i);
2360
2361                addUser.add(pk, user.getPrimaryKey());
2362            }
2363        }
2364        catch (DataAccessException dae) {
2365            throw new SystemException(dae);
2366        }
2367        finally {
2368            FinderCache.clearCache("Users_Orgs");
2369        }
2370    }
2371
2372    protected void initDao() {
2373        containsGroup = new ContainsGroup(this);
2374
2375        addGroup = new AddGroup(this);
2376        clearGroups = new ClearGroups(this);
2377        removeGroup = new RemoveGroup(this);
2378
2379        containsUser = new ContainsUser(this);
2380
2381        addUser = new AddUser(this);
2382        clearUsers = new ClearUsers(this);
2383        removeUser = new RemoveUser(this);
2384    }
2385
2386    protected ContainsGroup containsGroup;
2387    protected AddGroup addGroup;
2388    protected ClearGroups clearGroups;
2389    protected RemoveGroup removeGroup;
2390    protected ContainsUser containsUser;
2391    protected AddUser addUser;
2392    protected ClearUsers clearUsers;
2393    protected RemoveUser removeUser;
2394
2395    protected class ContainsGroup extends MappingSqlQuery {
2396        protected ContainsGroup(OrganizationPersistenceImpl persistenceImpl) {
2397            super(persistenceImpl.getDataSource(), _SQL_CONTAINSGROUP);
2398
2399            declareParameter(new SqlParameter(Types.BIGINT));
2400            declareParameter(new SqlParameter(Types.BIGINT));
2401
2402            compile();
2403        }
2404
2405        protected Object mapRow(ResultSet rs, int rowNumber)
2406            throws SQLException {
2407            return new Integer(rs.getInt("COUNT_VALUE"));
2408        }
2409
2410        protected boolean contains(long organizationId, long groupId) {
2411            List results = execute(new Object[] {
2412                        new Long(organizationId), new Long(groupId)
2413                    });
2414
2415            if (results.size() > 0) {
2416                Integer count = (Integer)results.get(0);
2417
2418                if (count.intValue() > 0) {
2419                    return true;
2420                }
2421            }
2422
2423            return false;
2424        }
2425    }
2426
2427    protected class AddGroup extends SqlUpdate {
2428        protected AddGroup(OrganizationPersistenceImpl persistenceImpl) {
2429            super(persistenceImpl.getDataSource(),
2430                "INSERT INTO Groups_Orgs (organizationId, groupId) VALUES (?, ?)");
2431
2432            _persistenceImpl = persistenceImpl;
2433
2434            declareParameter(new SqlParameter(Types.BIGINT));
2435            declareParameter(new SqlParameter(Types.BIGINT));
2436
2437            compile();
2438        }
2439
2440        protected void add(long organizationId, long groupId) {
2441            if (!_persistenceImpl.containsGroup.contains(organizationId, groupId)) {
2442                update(new Object[] { new Long(organizationId), new Long(
2443                            groupId) });
2444            }
2445        }
2446
2447        private OrganizationPersistenceImpl _persistenceImpl;
2448    }
2449
2450    protected class ClearGroups extends SqlUpdate {
2451        protected ClearGroups(OrganizationPersistenceImpl persistenceImpl) {
2452            super(persistenceImpl.getDataSource(),
2453                "DELETE FROM Groups_Orgs WHERE organizationId = ?");
2454
2455            declareParameter(new SqlParameter(Types.BIGINT));
2456
2457            compile();
2458        }
2459
2460        protected void clear(long organizationId) {
2461            update(new Object[] { new Long(organizationId) });
2462        }
2463    }
2464
2465    protected class RemoveGroup extends SqlUpdate {
2466        protected RemoveGroup(OrganizationPersistenceImpl persistenceImpl) {
2467            super(persistenceImpl.getDataSource(),
2468                "DELETE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?");
2469
2470            declareParameter(new SqlParameter(Types.BIGINT));
2471            declareParameter(new SqlParameter(Types.BIGINT));
2472
2473            compile();
2474        }
2475
2476        protected void remove(long organizationId, long groupId) {
2477            update(new Object[] { new Long(organizationId), new Long(groupId) });
2478        }
2479    }
2480
2481    protected class ContainsUser extends MappingSqlQuery {
2482        protected ContainsUser(OrganizationPersistenceImpl persistenceImpl) {
2483            super(persistenceImpl.getDataSource(), _SQL_CONTAINSUSER);
2484
2485            declareParameter(new SqlParameter(Types.BIGINT));
2486            declareParameter(new SqlParameter(Types.BIGINT));
2487
2488            compile();
2489        }
2490
2491        protected Object mapRow(ResultSet rs, int rowNumber)
2492            throws SQLException {
2493            return new Integer(rs.getInt("COUNT_VALUE"));
2494        }
2495
2496        protected boolean contains(long organizationId, long userId) {
2497            List results = execute(new Object[] {
2498                        new Long(organizationId), new Long(userId)
2499                    });
2500
2501            if (results.size() > 0) {
2502                Integer count = (Integer)results.get(0);
2503
2504                if (count.intValue() > 0) {
2505                    return true;
2506                }
2507            }
2508
2509            return false;
2510        }
2511    }
2512
2513    protected class AddUser extends SqlUpdate {
2514        protected AddUser(OrganizationPersistenceImpl persistenceImpl) {
2515            super(persistenceImpl.getDataSource(),
2516                "INSERT INTO Users_Orgs (organizationId, userId) VALUES (?, ?)");
2517
2518            _persistenceImpl = persistenceImpl;
2519
2520            declareParameter(new SqlParameter(Types.BIGINT));
2521            declareParameter(new SqlParameter(Types.BIGINT));
2522
2523            compile();
2524        }
2525
2526        protected void add(long organizationId, long userId) {
2527            if (!_persistenceImpl.containsUser.contains(organizationId, userId)) {
2528                update(new Object[] { new Long(organizationId), new Long(userId) });
2529            }
2530        }
2531
2532        private OrganizationPersistenceImpl _persistenceImpl;
2533    }
2534
2535    protected class ClearUsers extends SqlUpdate {
2536        protected ClearUsers(OrganizationPersistenceImpl persistenceImpl) {
2537            super(persistenceImpl.getDataSource(),
2538                "DELETE FROM Users_Orgs WHERE organizationId = ?");
2539
2540            declareParameter(new SqlParameter(Types.BIGINT));
2541
2542            compile();
2543        }
2544
2545        protected void clear(long organizationId) {
2546            update(new Object[] { new Long(organizationId) });
2547        }
2548    }
2549
2550    protected class RemoveUser extends SqlUpdate {
2551        protected RemoveUser(OrganizationPersistenceImpl persistenceImpl) {
2552            super(persistenceImpl.getDataSource(),
2553                "DELETE FROM Users_Orgs WHERE organizationId = ? AND userId = ?");
2554
2555            declareParameter(new SqlParameter(Types.BIGINT));
2556            declareParameter(new SqlParameter(Types.BIGINT));
2557
2558            compile();
2559        }
2560
2561        protected void remove(long organizationId, long userId) {
2562            update(new Object[] { new Long(organizationId), new Long(userId) });
2563        }
2564    }
2565
2566    private static ModelListener _getListener() {
2567        if (Validator.isNotNull(_LISTENER)) {
2568            try {
2569                return (ModelListener)Class.forName(_LISTENER).newInstance();
2570            }
2571            catch (Exception e) {
2572                _log.error(e);
2573            }
2574        }
2575
2576        return null;
2577    }
2578
2579    private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Orgs ON (Groups_Orgs.groupId = Group_.groupId) WHERE (Groups_Orgs.organizationId = ?)";
2580    private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ?";
2581    private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?";
2582    private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Orgs ON (Users_Orgs.userId = User_.userId) WHERE (Users_Orgs.organizationId = ?)";
2583    private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ?";
2584    private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ? AND userId = ?";
2585    private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
2586                "value.object.listener.com.liferay.portal.model.Organization"));
2587    private static Log _log = LogFactory.getLog(OrganizationPersistenceImpl.class);
2588}