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