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