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