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