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