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