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             if (BatchSessionUtil.isEnabled()) {
159                 Object staleObject = session.get(OrganizationImpl.class,
160                         organization.getPrimaryKeyObj());
161 
162                 if (staleObject != null) {
163                     session.evict(staleObject);
164                 }
165             }
166 
167             session.delete(organization);
168 
169             session.flush();
170 
171             return organization;
172         }
173         catch (Exception e) {
174             throw processException(e);
175         }
176         finally {
177             closeSession(session);
178 
179             FinderCacheUtil.clearCache(Organization.class.getName());
180         }
181     }
182 
183     /**
184      * @deprecated Use <code>update(Organization organization, boolean merge)</code>.
185      */
186     public Organization update(Organization organization)
187         throws SystemException {
188         if (_log.isWarnEnabled()) {
189             _log.warn(
190                 "Using the deprecated update(Organization organization) method. Use update(Organization organization, boolean merge) instead.");
191         }
192 
193         return update(organization, false);
194     }
195 
196     /**
197      * Add, update, or merge, the entity. This method also calls the model
198      * listeners to trigger the proper events associated with adding, deleting,
199      * or updating an entity.
200      *
201      * @param        organization the entity to add, update, or merge
202      * @param        merge boolean value for whether to merge the entity. The
203      *                default value is false. Setting merge to true is more
204      *                expensive and should only be true when organization is
205      *                transient. See LEP-5473 for a detailed discussion of this
206      *                method.
207      * @return        true if the portlet can be displayed via Ajax
208      */
209     public Organization update(Organization organization, boolean merge)
210         throws SystemException {
211         boolean isNew = organization.isNew();
212 
213         if (_listeners.length > 0) {
214             for (ModelListener listener : _listeners) {
215                 if (isNew) {
216                     listener.onBeforeCreate(organization);
217                 }
218                 else {
219                     listener.onBeforeUpdate(organization);
220                 }
221             }
222         }
223 
224         organization = updateImpl(organization, merge);
225 
226         if (_listeners.length > 0) {
227             for (ModelListener listener : _listeners) {
228                 if (isNew) {
229                     listener.onAfterCreate(organization);
230                 }
231                 else {
232                     listener.onAfterUpdate(organization);
233                 }
234             }
235         }
236 
237         return organization;
238     }
239 
240     public Organization updateImpl(
241         com.liferay.portal.model.Organization organization, boolean merge)
242         throws SystemException {
243         FinderCacheUtil.clearCache("Groups_Orgs");
244         FinderCacheUtil.clearCache("Users_Orgs");
245 
246         Session session = null;
247 
248         try {
249             session = openSession();
250 
251             BatchSessionUtil.update(session, organization, merge);
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 = null;
1269
1270                if (obc == null) {
1271                    list = (List<Organization>)QueryUtil.list(q, getDialect(),
1272                            start, end, false);
1273
1274                    Collections.sort(list);
1275                }
1276                else {
1277                    list = (List<Organization>)QueryUtil.list(q, getDialect(),
1278                            start, end);
1279                }
1280
1281                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1282                    finderClassName, finderMethodName, finderParams,
1283                    finderArgs, list);
1284
1285                return list;
1286            }
1287            catch (Exception e) {
1288                throw processException(e);
1289            }
1290            finally {
1291                closeSession(session);
1292            }
1293        }
1294        else {
1295            return (List<Organization>)result;
1296        }
1297    }
1298
1299    public void removeByCompanyId(long companyId) throws SystemException {
1300        for (Organization organization : findByCompanyId(companyId)) {
1301            remove(organization);
1302        }
1303    }
1304
1305    public void removeByLocations(long companyId) throws SystemException {
1306        for (Organization organization : findByLocations(companyId)) {
1307            remove(organization);
1308        }
1309    }
1310
1311    public void removeByC_P(long companyId, long parentOrganizationId)
1312        throws SystemException {
1313        for (Organization organization : findByC_P(companyId,
1314                parentOrganizationId)) {
1315            remove(organization);
1316        }
1317    }
1318
1319    public void removeByC_N(long companyId, String name)
1320        throws NoSuchOrganizationException, SystemException {
1321        Organization organization = findByC_N(companyId, name);
1322
1323        remove(organization);
1324    }
1325
1326    public void removeAll() throws SystemException {
1327        for (Organization organization : findAll()) {
1328            remove(organization);
1329        }
1330    }
1331
1332    public int countByCompanyId(long companyId) throws SystemException {
1333        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1334        String finderClassName = Organization.class.getName();
1335        String finderMethodName = "countByCompanyId";
1336        String[] finderParams = new String[] { Long.class.getName() };
1337        Object[] finderArgs = new Object[] { new Long(companyId) };
1338
1339        Object result = null;
1340
1341        if (finderClassNameCacheEnabled) {
1342            result = FinderCacheUtil.getResult(finderClassName,
1343                    finderMethodName, finderParams, finderArgs, this);
1344        }
1345
1346        if (result == null) {
1347            Session session = null;
1348
1349            try {
1350                session = openSession();
1351
1352                StringBuilder query = new StringBuilder();
1353
1354                query.append("SELECT COUNT(*) ");
1355                query.append(
1356                    "FROM com.liferay.portal.model.Organization WHERE ");
1357
1358                query.append("companyId = ?");
1359
1360                query.append(" ");
1361
1362                Query q = session.createQuery(query.toString());
1363
1364                QueryPos qPos = QueryPos.getInstance(q);
1365
1366                qPos.add(companyId);
1367
1368                Long count = null;
1369
1370                Iterator<Long> itr = q.list().iterator();
1371
1372                if (itr.hasNext()) {
1373                    count = itr.next();
1374                }
1375
1376                if (count == null) {
1377                    count = new Long(0);
1378                }
1379
1380                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1381                    finderClassName, finderMethodName, finderParams,
1382                    finderArgs, count);
1383
1384                return count.intValue();
1385            }
1386            catch (Exception e) {
1387                throw processException(e);
1388            }
1389            finally {
1390                closeSession(session);
1391            }
1392        }
1393        else {
1394            return ((Long)result).intValue();
1395        }
1396    }
1397
1398    public int countByLocations(long companyId) throws SystemException {
1399        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1400        String finderClassName = Organization.class.getName();
1401        String finderMethodName = "countByLocations";
1402        String[] finderParams = new String[] { Long.class.getName() };
1403        Object[] finderArgs = new Object[] { new Long(companyId) };
1404
1405        Object result = null;
1406
1407        if (finderClassNameCacheEnabled) {
1408            result = FinderCacheUtil.getResult(finderClassName,
1409                    finderMethodName, finderParams, finderArgs, this);
1410        }
1411
1412        if (result == null) {
1413            Session session = null;
1414
1415            try {
1416                session = openSession();
1417
1418                StringBuilder query = new StringBuilder();
1419
1420                query.append("SELECT COUNT(*) ");
1421                query.append(
1422                    "FROM com.liferay.portal.model.Organization WHERE ");
1423
1424                query.append("companyId = ?");
1425
1426                query.append(" AND parentOrganizationId != 0 ");
1427
1428                Query q = session.createQuery(query.toString());
1429
1430                QueryPos qPos = QueryPos.getInstance(q);
1431
1432                qPos.add(companyId);
1433
1434                Long count = null;
1435
1436                Iterator<Long> itr = q.list().iterator();
1437
1438                if (itr.hasNext()) {
1439                    count = itr.next();
1440                }
1441
1442                if (count == null) {
1443                    count = new Long(0);
1444                }
1445
1446                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1447                    finderClassName, finderMethodName, finderParams,
1448                    finderArgs, count);
1449
1450                return count.intValue();
1451            }
1452            catch (Exception e) {
1453                throw processException(e);
1454            }
1455            finally {
1456                closeSession(session);
1457            }
1458        }
1459        else {
1460            return ((Long)result).intValue();
1461        }
1462    }
1463
1464    public int countByC_P(long companyId, long parentOrganizationId)
1465        throws SystemException {
1466        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1467        String finderClassName = Organization.class.getName();
1468        String finderMethodName = "countByC_P";
1469        String[] finderParams = new String[] {
1470                Long.class.getName(), Long.class.getName()
1471            };
1472        Object[] finderArgs = new Object[] {
1473                new Long(companyId), new Long(parentOrganizationId)
1474            };
1475
1476        Object result = null;
1477
1478        if (finderClassNameCacheEnabled) {
1479            result = FinderCacheUtil.getResult(finderClassName,
1480                    finderMethodName, finderParams, finderArgs, this);
1481        }
1482
1483        if (result == null) {
1484            Session session = null;
1485
1486            try {
1487                session = openSession();
1488
1489                StringBuilder query = new StringBuilder();
1490
1491                query.append("SELECT COUNT(*) ");
1492                query.append(
1493                    "FROM com.liferay.portal.model.Organization WHERE ");
1494
1495                query.append("companyId = ?");
1496
1497                query.append(" AND ");
1498
1499                query.append("parentOrganizationId = ?");
1500
1501                query.append(" ");
1502
1503                Query q = session.createQuery(query.toString());
1504
1505                QueryPos qPos = QueryPos.getInstance(q);
1506
1507                qPos.add(companyId);
1508
1509                qPos.add(parentOrganizationId);
1510
1511                Long count = null;
1512
1513                Iterator<Long> itr = q.list().iterator();
1514
1515                if (itr.hasNext()) {
1516                    count = itr.next();
1517                }
1518
1519                if (count == null) {
1520                    count = new Long(0);
1521                }
1522
1523                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1524                    finderClassName, finderMethodName, finderParams,
1525                    finderArgs, count);
1526
1527                return count.intValue();
1528            }
1529            catch (Exception e) {
1530                throw processException(e);
1531            }
1532            finally {
1533                closeSession(session);
1534            }
1535        }
1536        else {
1537            return ((Long)result).intValue();
1538        }
1539    }
1540
1541    public int countByC_N(long companyId, String name)
1542        throws SystemException {
1543        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1544        String finderClassName = Organization.class.getName();
1545        String finderMethodName = "countByC_N";
1546        String[] finderParams = new String[] {
1547                Long.class.getName(), String.class.getName()
1548            };
1549        Object[] finderArgs = new Object[] { new Long(companyId), name };
1550
1551        Object result = null;
1552
1553        if (finderClassNameCacheEnabled) {
1554            result = FinderCacheUtil.getResult(finderClassName,
1555                    finderMethodName, finderParams, finderArgs, this);
1556        }
1557
1558        if (result == null) {
1559            Session session = null;
1560
1561            try {
1562                session = openSession();
1563
1564                StringBuilder query = new StringBuilder();
1565
1566                query.append("SELECT COUNT(*) ");
1567                query.append(
1568                    "FROM com.liferay.portal.model.Organization WHERE ");
1569
1570                query.append("companyId = ?");
1571
1572                query.append(" AND ");
1573
1574                if (name == null) {
1575                    query.append("name IS NULL");
1576                }
1577                else {
1578                    query.append("name = ?");
1579                }
1580
1581                query.append(" ");
1582
1583                Query q = session.createQuery(query.toString());
1584
1585                QueryPos qPos = QueryPos.getInstance(q);
1586
1587                qPos.add(companyId);
1588
1589                if (name != null) {
1590                    qPos.add(name);
1591                }
1592
1593                Long count = null;
1594
1595                Iterator<Long> itr = q.list().iterator();
1596
1597                if (itr.hasNext()) {
1598                    count = itr.next();
1599                }
1600
1601                if (count == null) {
1602                    count = new Long(0);
1603                }
1604
1605                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1606                    finderClassName, finderMethodName, finderParams,
1607                    finderArgs, count);
1608
1609                return count.intValue();
1610            }
1611            catch (Exception e) {
1612                throw processException(e);
1613            }
1614            finally {
1615                closeSession(session);
1616            }
1617        }
1618        else {
1619            return ((Long)result).intValue();
1620        }
1621    }
1622
1623    public int countAll() throws SystemException {
1624        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED;
1625        String finderClassName = Organization.class.getName();
1626        String finderMethodName = "countAll";
1627        String[] finderParams = new String[] {  };
1628        Object[] finderArgs = new Object[] {  };
1629
1630        Object result = null;
1631
1632        if (finderClassNameCacheEnabled) {
1633            result = FinderCacheUtil.getResult(finderClassName,
1634                    finderMethodName, finderParams, finderArgs, this);
1635        }
1636
1637        if (result == null) {
1638            Session session = null;
1639
1640            try {
1641                session = openSession();
1642
1643                Query q = session.createQuery(
1644                        "SELECT COUNT(*) FROM com.liferay.portal.model.Organization");
1645
1646                Long count = null;
1647
1648                Iterator<Long> itr = q.list().iterator();
1649
1650                if (itr.hasNext()) {
1651                    count = itr.next();
1652                }
1653
1654                if (count == null) {
1655                    count = new Long(0);
1656                }
1657
1658                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1659                    finderClassName, finderMethodName, finderParams,
1660                    finderArgs, count);
1661
1662                return count.intValue();
1663            }
1664            catch (Exception e) {
1665                throw processException(e);
1666            }
1667            finally {
1668                closeSession(session);
1669            }
1670        }
1671        else {
1672            return ((Long)result).intValue();
1673        }
1674    }
1675
1676    public List<com.liferay.portal.model.Group> getGroups(long pk)
1677        throws SystemException {
1678        return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1679    }
1680
1681    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1682        int end) throws SystemException {
1683        return getGroups(pk, start, end, null);
1684    }
1685
1686    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1687        int end, OrderByComparator obc) throws SystemException {
1688        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1689
1690        String finderClassName = "Groups_Orgs";
1691
1692        String finderMethodName = "getGroups";
1693        String[] finderParams = new String[] {
1694                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1695                "com.liferay.portal.kernel.util.OrderByComparator"
1696            };
1697        Object[] finderArgs = new Object[] {
1698                new Long(pk), String.valueOf(start), String.valueOf(end),
1699                String.valueOf(obc)
1700            };
1701
1702        Object result = null;
1703
1704        if (finderClassNameCacheEnabled) {
1705            result = FinderCacheUtil.getResult(finderClassName,
1706                    finderMethodName, finderParams, finderArgs, this);
1707        }
1708
1709        if (result == null) {
1710            Session session = null;
1711
1712            try {
1713                session = openSession();
1714
1715                StringBuilder sb = new StringBuilder();
1716
1717                sb.append(_SQL_GETGROUPS);
1718
1719                if (obc != null) {
1720                    sb.append("ORDER BY ");
1721                    sb.append(obc.getOrderBy());
1722                }
1723
1724                else {
1725                    sb.append("ORDER BY ");
1726
1727                    sb.append("Group_.name ASC");
1728                }
1729
1730                String sql = sb.toString();
1731
1732                SQLQuery q = session.createSQLQuery(sql);
1733
1734                q.addEntity("Group_",
1735                    com.liferay.portal.model.impl.GroupImpl.class);
1736
1737                QueryPos qPos = QueryPos.getInstance(q);
1738
1739                qPos.add(pk);
1740
1741                List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1742                        getDialect(), start, end);
1743
1744                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1745                    finderClassName, finderMethodName, finderParams,
1746                    finderArgs, list);
1747
1748                return list;
1749            }
1750            catch (Exception e) {
1751                throw processException(e);
1752            }
1753            finally {
1754                closeSession(session);
1755            }
1756        }
1757        else {
1758            return (List<com.liferay.portal.model.Group>)result;
1759        }
1760    }
1761
1762    public int getGroupsSize(long pk) throws SystemException {
1763        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1764
1765        String finderClassName = "Groups_Orgs";
1766
1767        String finderMethodName = "getGroupsSize";
1768        String[] finderParams = new String[] { Long.class.getName() };
1769        Object[] finderArgs = new Object[] { new Long(pk) };
1770
1771        Object result = null;
1772
1773        if (finderClassNameCacheEnabled) {
1774            result = FinderCacheUtil.getResult(finderClassName,
1775                    finderMethodName, finderParams, finderArgs, this);
1776        }
1777
1778        if (result == null) {
1779            Session session = null;
1780
1781            try {
1782                session = openSession();
1783
1784                SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1785
1786                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1787
1788                QueryPos qPos = QueryPos.getInstance(q);
1789
1790                qPos.add(pk);
1791
1792                Long count = null;
1793
1794                Iterator<Long> itr = q.list().iterator();
1795
1796                if (itr.hasNext()) {
1797                    count = itr.next();
1798                }
1799
1800                if (count == null) {
1801                    count = new Long(0);
1802                }
1803
1804                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1805                    finderClassName, finderMethodName, finderParams,
1806                    finderArgs, count);
1807
1808                return count.intValue();
1809            }
1810            catch (Exception e) {
1811                throw processException(e);
1812            }
1813            finally {
1814                closeSession(session);
1815            }
1816        }
1817        else {
1818            return ((Long)result).intValue();
1819        }
1820    }
1821
1822    public boolean containsGroup(long pk, long groupPK)
1823        throws SystemException {
1824        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1825
1826        String finderClassName = "Groups_Orgs";
1827
1828        String finderMethodName = "containsGroups";
1829        String[] finderParams = new String[] {
1830                Long.class.getName(),
1831                
1832                Long.class.getName()
1833            };
1834        Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
1835
1836        Object result = null;
1837
1838        if (finderClassNameCacheEnabled) {
1839            result = FinderCacheUtil.getResult(finderClassName,
1840                    finderMethodName, finderParams, finderArgs, this);
1841        }
1842
1843        if (result == null) {
1844            try {
1845                Boolean value = Boolean.valueOf(containsGroup.contains(pk,
1846                            groupPK));
1847
1848                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1849                    finderClassName, finderMethodName, finderParams,
1850                    finderArgs, value);
1851
1852                return value.booleanValue();
1853            }
1854            catch (Exception e) {
1855                throw processException(e);
1856            }
1857        }
1858        else {
1859            return ((Boolean)result).booleanValue();
1860        }
1861    }
1862
1863    public boolean containsGroups(long pk) throws SystemException {
1864        if (getGroupsSize(pk) > 0) {
1865            return true;
1866        }
1867        else {
1868            return false;
1869        }
1870    }
1871
1872    public void addGroup(long pk, long groupPK) throws SystemException {
1873        try {
1874            addGroup.add(pk, groupPK);
1875        }
1876        catch (Exception e) {
1877            throw processException(e);
1878        }
1879        finally {
1880            FinderCacheUtil.clearCache("Groups_Orgs");
1881        }
1882    }
1883
1884    public void addGroup(long pk, com.liferay.portal.model.Group group)
1885        throws SystemException {
1886        try {
1887            addGroup.add(pk, group.getPrimaryKey());
1888        }
1889        catch (Exception e) {
1890            throw processException(e);
1891        }
1892        finally {
1893            FinderCacheUtil.clearCache("Groups_Orgs");
1894        }
1895    }
1896
1897    public void addGroups(long pk, long[] groupPKs) throws SystemException {
1898        try {
1899            for (long groupPK : groupPKs) {
1900                addGroup.add(pk, groupPK);
1901            }
1902        }
1903        catch (Exception e) {
1904            throw processException(e);
1905        }
1906        finally {
1907            FinderCacheUtil.clearCache("Groups_Orgs");
1908        }
1909    }
1910
1911    public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1912        throws SystemException {
1913        try {
1914            for (com.liferay.portal.model.Group group : groups) {
1915                addGroup.add(pk, group.getPrimaryKey());
1916            }
1917        }
1918        catch (Exception e) {
1919            throw processException(e);
1920        }
1921        finally {
1922            FinderCacheUtil.clearCache("Groups_Orgs");
1923        }
1924    }
1925
1926    public void clearGroups(long pk) throws SystemException {
1927        try {
1928            clearGroups.clear(pk);
1929        }
1930        catch (Exception e) {
1931            throw processException(e);
1932        }
1933        finally {
1934            FinderCacheUtil.clearCache("Groups_Orgs");
1935        }
1936    }
1937
1938    public void removeGroup(long pk, long groupPK) throws SystemException {
1939        try {
1940            removeGroup.remove(pk, groupPK);
1941        }
1942        catch (Exception e) {
1943            throw processException(e);
1944        }
1945        finally {
1946            FinderCacheUtil.clearCache("Groups_Orgs");
1947        }
1948    }
1949
1950    public void removeGroup(long pk, com.liferay.portal.model.Group group)
1951        throws SystemException {
1952        try {
1953            removeGroup.remove(pk, group.getPrimaryKey());
1954        }
1955        catch (Exception e) {
1956            throw processException(e);
1957        }
1958        finally {
1959            FinderCacheUtil.clearCache("Groups_Orgs");
1960        }
1961    }
1962
1963    public void removeGroups(long pk, long[] groupPKs)
1964        throws SystemException {
1965        try {
1966            for (long groupPK : groupPKs) {
1967                removeGroup.remove(pk, groupPK);
1968            }
1969        }
1970        catch (Exception e) {
1971            throw processException(e);
1972        }
1973        finally {
1974            FinderCacheUtil.clearCache("Groups_Orgs");
1975        }
1976    }
1977
1978    public void removeGroups(long pk,
1979        List<com.liferay.portal.model.Group> groups) throws SystemException {
1980        try {
1981            for (com.liferay.portal.model.Group group : groups) {
1982                removeGroup.remove(pk, group.getPrimaryKey());
1983            }
1984        }
1985        catch (Exception e) {
1986            throw processException(e);
1987        }
1988        finally {
1989            FinderCacheUtil.clearCache("Groups_Orgs");
1990        }
1991    }
1992
1993    public void setGroups(long pk, long[] groupPKs) throws SystemException {
1994        try {
1995            clearGroups.clear(pk);
1996
1997            for (long groupPK : groupPKs) {
1998                addGroup.add(pk, groupPK);
1999            }
2000        }
2001        catch (Exception e) {
2002            throw processException(e);
2003        }
2004        finally {
2005            FinderCacheUtil.clearCache("Groups_Orgs");
2006        }
2007    }
2008
2009    public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
2010        throws SystemException {
2011        try {
2012            clearGroups.clear(pk);
2013
2014            for (com.liferay.portal.model.Group group : groups) {
2015                addGroup.add(pk, group.getPrimaryKey());
2016            }
2017        }
2018        catch (Exception e) {
2019            throw processException(e);
2020        }
2021        finally {
2022            FinderCacheUtil.clearCache("Groups_Orgs");
2023        }
2024    }
2025
2026    public List<com.liferay.portal.model.User> getUsers(long pk)
2027        throws SystemException {
2028        return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2029    }
2030
2031    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2032        int end) throws SystemException {
2033        return getUsers(pk, start, end, null);
2034    }
2035
2036    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2037        int end, OrderByComparator obc) throws SystemException {
2038        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
2039
2040        String finderClassName = "Users_Orgs";
2041
2042        String finderMethodName = "getUsers";
2043        String[] finderParams = new String[] {
2044                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2045                "com.liferay.portal.kernel.util.OrderByComparator"
2046            };
2047        Object[] finderArgs = new Object[] {
2048                new Long(pk), String.valueOf(start), String.valueOf(end),
2049                String.valueOf(obc)
2050            };
2051
2052        Object result = null;
2053
2054        if (finderClassNameCacheEnabled) {
2055            result = FinderCacheUtil.getResult(finderClassName,
2056                    finderMethodName, finderParams, finderArgs, this);
2057        }
2058
2059        if (result == null) {
2060            Session session = null;
2061
2062            try {
2063                session = openSession();
2064
2065                StringBuilder sb = new StringBuilder();
2066
2067                sb.append(_SQL_GETUSERS);
2068
2069                if (obc != null) {
2070                    sb.append("ORDER BY ");
2071                    sb.append(obc.getOrderBy());
2072                }
2073
2074                String sql = sb.toString();
2075
2076                SQLQuery q = session.createSQLQuery(sql);
2077
2078                q.addEntity("User_",
2079                    com.liferay.portal.model.impl.UserImpl.class);
2080
2081                QueryPos qPos = QueryPos.getInstance(q);
2082
2083                qPos.add(pk);
2084
2085                List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2086                        getDialect(), start, end);
2087
2088                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2089                    finderClassName, finderMethodName, finderParams,
2090                    finderArgs, list);
2091
2092                return list;
2093            }
2094            catch (Exception e) {
2095                throw processException(e);
2096            }
2097            finally {
2098                closeSession(session);
2099            }
2100        }
2101        else {
2102            return (List<com.liferay.portal.model.User>)result;
2103        }
2104    }
2105
2106    public int getUsersSize(long pk) throws SystemException {
2107        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
2108
2109        String finderClassName = "Users_Orgs";
2110
2111        String finderMethodName = "getUsersSize";
2112        String[] finderParams = new String[] { Long.class.getName() };
2113        Object[] finderArgs = new Object[] { new Long(pk) };
2114
2115        Object result = null;
2116
2117        if (finderClassNameCacheEnabled) {
2118            result = FinderCacheUtil.getResult(finderClassName,
2119                    finderMethodName, finderParams, finderArgs, this);
2120        }
2121
2122        if (result == null) {
2123            Session session = null;
2124
2125            try {
2126                session = openSession();
2127
2128                SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2129
2130                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2131
2132                QueryPos qPos = QueryPos.getInstance(q);
2133
2134                qPos.add(pk);
2135
2136                Long count = null;
2137
2138                Iterator<Long> itr = q.list().iterator();
2139
2140                if (itr.hasNext()) {
2141                    count = itr.next();
2142                }
2143
2144                if (count == null) {
2145                    count = new Long(0);
2146                }
2147
2148                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2149                    finderClassName, finderMethodName, finderParams,
2150                    finderArgs, count);
2151
2152                return count.intValue();
2153            }
2154            catch (Exception e) {
2155                throw processException(e);
2156            }
2157            finally {
2158                closeSession(session);
2159            }
2160        }
2161        else {
2162            return ((Long)result).intValue();
2163        }
2164    }
2165
2166    public boolean containsUser(long pk, long userPK) throws SystemException {
2167        boolean finderClassNameCacheEnabled = OrganizationModelImpl.CACHE_ENABLED_USERS_ORGS;
2168
2169        String finderClassName = "Users_Orgs";
2170
2171        String finderMethodName = "containsUsers";
2172        String[] finderParams = new String[] {
2173                Long.class.getName(),
2174                
2175                Long.class.getName()
2176            };
2177        Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
2178
2179        Object result = null;
2180
2181        if (finderClassNameCacheEnabled) {
2182            result = FinderCacheUtil.getResult(finderClassName,
2183                    finderMethodName, finderParams, finderArgs, this);
2184        }
2185
2186        if (result == null) {
2187            try {
2188                Boolean value = Boolean.valueOf(containsUser.contains(pk, userPK));
2189
2190                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2191                    finderClassName, finderMethodName, finderParams,
2192                    finderArgs, value);
2193
2194                return value.booleanValue();
2195            }
2196            catch (Exception e) {
2197                throw processException(e);
2198            }
2199        }
2200        else {
2201            return ((Boolean)result).booleanValue();
2202        }
2203    }
2204
2205    public boolean containsUsers(long pk) throws SystemException {
2206        if (getUsersSize(pk) > 0) {
2207            return true;
2208        }
2209        else {
2210            return false;
2211        }
2212    }
2213
2214    public void addUser(long pk, long userPK) throws SystemException {
2215        try {
2216            addUser.add(pk, userPK);
2217        }
2218        catch (Exception e) {
2219            throw processException(e);
2220        }
2221        finally {
2222            FinderCacheUtil.clearCache("Users_Orgs");
2223        }
2224    }
2225
2226    public void addUser(long pk, com.liferay.portal.model.User user)
2227        throws SystemException {
2228        try {
2229            addUser.add(pk, user.getPrimaryKey());
2230        }
2231        catch (Exception e) {
2232            throw processException(e);
2233        }
2234        finally {
2235            FinderCacheUtil.clearCache("Users_Orgs");
2236        }
2237    }
2238
2239    public void addUsers(long pk, long[] userPKs) throws SystemException {
2240        try {
2241            for (long userPK : userPKs) {
2242                addUser.add(pk, userPK);
2243            }
2244        }
2245        catch (Exception e) {
2246            throw processException(e);
2247        }
2248        finally {
2249            FinderCacheUtil.clearCache("Users_Orgs");
2250        }
2251    }
2252
2253    public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2254        throws SystemException {
2255        try {
2256            for (com.liferay.portal.model.User user : users) {
2257                addUser.add(pk, user.getPrimaryKey());
2258            }
2259        }
2260        catch (Exception e) {
2261            throw processException(e);
2262        }
2263        finally {
2264            FinderCacheUtil.clearCache("Users_Orgs");
2265        }
2266    }
2267
2268    public void clearUsers(long pk) throws SystemException {
2269        try {
2270            clearUsers.clear(pk);
2271        }
2272        catch (Exception e) {
2273            throw processException(e);
2274        }
2275        finally {
2276            FinderCacheUtil.clearCache("Users_Orgs");
2277        }
2278    }
2279
2280    public void removeUser(long pk, long userPK) throws SystemException {
2281        try {
2282            removeUser.remove(pk, userPK);
2283        }
2284        catch (Exception e) {
2285            throw processException(e);
2286        }
2287        finally {
2288            FinderCacheUtil.clearCache("Users_Orgs");
2289        }
2290    }
2291
2292    public void removeUser(long pk, com.liferay.portal.model.User user)
2293        throws SystemException {
2294        try {
2295            removeUser.remove(pk, user.getPrimaryKey());
2296        }
2297        catch (Exception e) {
2298            throw processException(e);
2299        }
2300        finally {
2301            FinderCacheUtil.clearCache("Users_Orgs");
2302        }
2303    }
2304
2305    public void removeUsers(long pk, long[] userPKs) throws SystemException {
2306        try {
2307            for (long userPK : userPKs) {
2308                removeUser.remove(pk, userPK);
2309            }
2310        }
2311        catch (Exception e) {
2312            throw processException(e);
2313        }
2314        finally {
2315            FinderCacheUtil.clearCache("Users_Orgs");
2316        }
2317    }
2318
2319    public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2320        throws SystemException {
2321        try {
2322            for (com.liferay.portal.model.User user : users) {
2323                removeUser.remove(pk, user.getPrimaryKey());
2324            }
2325        }
2326        catch (Exception e) {
2327            throw processException(e);
2328        }
2329        finally {
2330            FinderCacheUtil.clearCache("Users_Orgs");
2331        }
2332    }
2333
2334    public void setUsers(long pk, long[] userPKs) throws SystemException {
2335        try {
2336            clearUsers.clear(pk);
2337
2338            for (long userPK : userPKs) {
2339                addUser.add(pk, userPK);
2340            }
2341        }
2342        catch (Exception e) {
2343            throw processException(e);
2344        }
2345        finally {
2346            FinderCacheUtil.clearCache("Users_Orgs");
2347        }
2348    }
2349
2350    public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2351        throws SystemException {
2352        try {
2353            clearUsers.clear(pk);
2354
2355            for (com.liferay.portal.model.User user : users) {
2356                addUser.add(pk, user.getPrimaryKey());
2357            }
2358        }
2359        catch (Exception e) {
2360            throw processException(e);
2361        }
2362        finally {
2363            FinderCacheUtil.clearCache("Users_Orgs");
2364        }
2365    }
2366
2367    public void registerListener(ModelListener listener) {
2368        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2369
2370        listeners.add(listener);
2371
2372        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2373    }
2374
2375    public void unregisterListener(ModelListener listener) {
2376        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2377
2378        listeners.remove(listener);
2379
2380        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2381    }
2382
2383    public void afterPropertiesSet() {
2384        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2385                    com.liferay.portal.util.PropsUtil.get(
2386                        "value.object.listener.com.liferay.portal.model.Organization")));
2387
2388        if (listenerClassNames.length > 0) {
2389            try {
2390                List<ModelListener> listeners = new ArrayList<ModelListener>();
2391
2392                for (String listenerClassName : listenerClassNames) {
2393                    listeners.add((ModelListener)Class.forName(
2394                            listenerClassName).newInstance());
2395                }
2396
2397                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2398            }
2399            catch (Exception e) {
2400                _log.error(e);
2401            }
2402        }
2403
2404        containsGroup = new ContainsGroup(this);
2405
2406        addGroup = new AddGroup(this);
2407        clearGroups = new ClearGroups(this);
2408        removeGroup = new RemoveGroup(this);
2409
2410        containsUser = new ContainsUser(this);
2411
2412        addUser = new AddUser(this);
2413        clearUsers = new ClearUsers(this);
2414        removeUser = new RemoveUser(this);
2415    }
2416
2417    protected ContainsGroup containsGroup;
2418    protected AddGroup addGroup;
2419    protected ClearGroups clearGroups;
2420    protected RemoveGroup removeGroup;
2421    protected ContainsUser containsUser;
2422    protected AddUser addUser;
2423    protected ClearUsers clearUsers;
2424    protected RemoveUser removeUser;
2425
2426    protected class ContainsGroup {
2427        protected ContainsGroup(OrganizationPersistenceImpl persistenceImpl) {
2428            super();
2429
2430            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2431                    _SQL_CONTAINSGROUP,
2432                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2433        }
2434
2435        protected boolean contains(long organizationId, long groupId) {
2436            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2437                        new Long(organizationId), new Long(groupId)
2438                    });
2439
2440            if (results.size() > 0) {
2441                Integer count = results.get(0);
2442
2443                if (count.intValue() > 0) {
2444                    return true;
2445                }
2446            }
2447
2448            return false;
2449        }
2450
2451        private MappingSqlQuery _mappingSqlQuery;
2452    }
2453
2454    protected class AddGroup {
2455        protected AddGroup(OrganizationPersistenceImpl persistenceImpl) {
2456            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2457                    "INSERT INTO Groups_Orgs (organizationId, groupId) VALUES (?, ?)",
2458                    new int[] { Types.BIGINT, Types.BIGINT });
2459            _persistenceImpl = persistenceImpl;
2460        }
2461
2462        protected void add(long organizationId, long groupId) {
2463            if (!_persistenceImpl.containsGroup.contains(organizationId, groupId)) {
2464                _sqlUpdate.update(new Object[] {
2465                        new Long(organizationId), new Long(groupId)
2466                    });
2467            }
2468        }
2469
2470        private SqlUpdate _sqlUpdate;
2471        private OrganizationPersistenceImpl _persistenceImpl;
2472    }
2473
2474    protected class ClearGroups {
2475        protected ClearGroups(OrganizationPersistenceImpl persistenceImpl) {
2476            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2477                    "DELETE FROM Groups_Orgs WHERE organizationId = ?",
2478                    new int[] { Types.BIGINT });
2479        }
2480
2481        protected void clear(long organizationId) {
2482            _sqlUpdate.update(new Object[] { new Long(organizationId) });
2483        }
2484
2485        private SqlUpdate _sqlUpdate;
2486    }
2487
2488    protected class RemoveGroup {
2489        protected RemoveGroup(OrganizationPersistenceImpl persistenceImpl) {
2490            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2491                    "DELETE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?",
2492                    new int[] { Types.BIGINT, Types.BIGINT });
2493        }
2494
2495        protected void remove(long organizationId, long groupId) {
2496            _sqlUpdate.update(new Object[] {
2497                    new Long(organizationId), new Long(groupId)
2498                });
2499        }
2500
2501        private SqlUpdate _sqlUpdate;
2502    }
2503
2504    protected class ContainsUser {
2505        protected ContainsUser(OrganizationPersistenceImpl persistenceImpl) {
2506            super();
2507
2508            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2509                    _SQL_CONTAINSUSER,
2510                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2511        }
2512
2513        protected boolean contains(long organizationId, long userId) {
2514            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2515                        new Long(organizationId), new Long(userId)
2516                    });
2517
2518            if (results.size() > 0) {
2519                Integer count = results.get(0);
2520
2521                if (count.intValue() > 0) {
2522                    return true;
2523                }
2524            }
2525
2526            return false;
2527        }
2528
2529        private MappingSqlQuery _mappingSqlQuery;
2530    }
2531
2532    protected class AddUser {
2533        protected AddUser(OrganizationPersistenceImpl persistenceImpl) {
2534            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2535                    "INSERT INTO Users_Orgs (organizationId, userId) VALUES (?, ?)",
2536                    new int[] { Types.BIGINT, Types.BIGINT });
2537            _persistenceImpl = persistenceImpl;
2538        }
2539
2540        protected void add(long organizationId, long userId) {
2541            if (!_persistenceImpl.containsUser.contains(organizationId, userId)) {
2542                _sqlUpdate.update(new Object[] {
2543                        new Long(organizationId), new Long(userId)
2544                    });
2545            }
2546        }
2547
2548        private SqlUpdate _sqlUpdate;
2549        private OrganizationPersistenceImpl _persistenceImpl;
2550    }
2551
2552    protected class ClearUsers {
2553        protected ClearUsers(OrganizationPersistenceImpl persistenceImpl) {
2554            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2555                    "DELETE FROM Users_Orgs WHERE organizationId = ?",
2556                    new int[] { Types.BIGINT });
2557        }
2558
2559        protected void clear(long organizationId) {
2560            _sqlUpdate.update(new Object[] { new Long(organizationId) });
2561        }
2562
2563        private SqlUpdate _sqlUpdate;
2564    }
2565
2566    protected class RemoveUser {
2567        protected RemoveUser(OrganizationPersistenceImpl persistenceImpl) {
2568            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2569                    "DELETE FROM Users_Orgs WHERE organizationId = ? AND userId = ?",
2570                    new int[] { Types.BIGINT, Types.BIGINT });
2571        }
2572
2573        protected void remove(long organizationId, long userId) {
2574            _sqlUpdate.update(new Object[] {
2575                    new Long(organizationId), new Long(userId)
2576                });
2577        }
2578
2579        private SqlUpdate _sqlUpdate;
2580    }
2581
2582    private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Orgs ON (Groups_Orgs.groupId = Group_.groupId) WHERE (Groups_Orgs.organizationId = ?)";
2583    private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ?";
2584    private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE organizationId = ? AND groupId = ?";
2585    private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Orgs ON (Users_Orgs.userId = User_.userId) WHERE (Users_Orgs.organizationId = ?)";
2586    private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ?";
2587    private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Orgs WHERE organizationId = ? AND userId = ?";
2588    private static Log _log = LogFactory.getLog(OrganizationPersistenceImpl.class);
2589    private ModelListener[] _listeners = new ModelListener[0];
2590}