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