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