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