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