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.annotation.BeanReference;
28 import com.liferay.portal.kernel.cache.CacheRegistry;
29 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
30 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
31 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
32 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
33 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
34 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
35 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
36 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
37 import com.liferay.portal.kernel.dao.orm.FinderPath;
38 import com.liferay.portal.kernel.dao.orm.Query;
39 import com.liferay.portal.kernel.dao.orm.QueryPos;
40 import com.liferay.portal.kernel.dao.orm.QueryUtil;
41 import com.liferay.portal.kernel.dao.orm.SQLQuery;
42 import com.liferay.portal.kernel.dao.orm.Session;
43 import com.liferay.portal.kernel.dao.orm.Type;
44 import com.liferay.portal.kernel.log.Log;
45 import com.liferay.portal.kernel.log.LogFactoryUtil;
46 import com.liferay.portal.kernel.util.GetterUtil;
47 import com.liferay.portal.kernel.util.OrderByComparator;
48 import com.liferay.portal.kernel.util.StringPool;
49 import com.liferay.portal.kernel.util.StringUtil;
50 import com.liferay.portal.kernel.util.Validator;
51 import com.liferay.portal.model.ModelListener;
52 import com.liferay.portal.model.Role;
53 import com.liferay.portal.model.impl.RoleImpl;
54 import com.liferay.portal.model.impl.RoleModelImpl;
55 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
56
57 import java.sql.Types;
58
59 import java.util.ArrayList;
60 import java.util.Collections;
61 import java.util.List;
62
63
69 public class RolePersistenceImpl extends BasePersistenceImpl
70 implements RolePersistence {
71 public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
72 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
73 ".List";
74 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
75 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
76 "findByCompanyId", new String[] { Long.class.getName() });
77 public static final FinderPath FINDER_PATH_FIND_BY_OBC_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
78 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
79 "findByCompanyId",
80 new String[] {
81 Long.class.getName(),
82
83 "java.lang.Integer", "java.lang.Integer",
84 "com.liferay.portal.kernel.util.OrderByComparator"
85 });
86 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
87 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
88 "countByCompanyId", new String[] { Long.class.getName() });
89 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
90 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
91 "fetchByC_N",
92 new String[] { Long.class.getName(), String.class.getName() });
93 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
94 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
95 "countByC_N",
96 new String[] { Long.class.getName(), String.class.getName() });
97 public static final FinderPath FINDER_PATH_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
98 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
99 "findByT_S",
100 new String[] { Integer.class.getName(), String.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_BY_OBC_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
102 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103 "findByT_S",
104 new String[] {
105 Integer.class.getName(), String.class.getName(),
106
107 "java.lang.Integer", "java.lang.Integer",
108 "com.liferay.portal.kernel.util.OrderByComparator"
109 });
110 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
111 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
112 "countByT_S",
113 new String[] { Integer.class.getName(), String.class.getName() });
114 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
115 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
116 "fetchByC_C_C",
117 new String[] {
118 Long.class.getName(), Long.class.getName(), Long.class.getName()
119 });
120 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
121 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
122 "countByC_C_C",
123 new String[] {
124 Long.class.getName(), Long.class.getName(), Long.class.getName()
125 });
126 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
127 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
128 "findAll", new String[0]);
129 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
130 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
131 "countAll", new String[0]);
132
133 public void cacheResult(Role role) {
134 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
135 RoleImpl.class, role.getPrimaryKey(), role);
136
137 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
138 new Object[] { new Long(role.getCompanyId()), role.getName() }, role);
139
140 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
141 new Object[] {
142 new Long(role.getCompanyId()), new Long(role.getClassNameId()),
143 new Long(role.getClassPK())
144 }, role);
145 }
146
147 public void cacheResult(List<Role> roles) {
148 for (Role role : roles) {
149 if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
150 RoleImpl.class, role.getPrimaryKey(), this) == null) {
151 cacheResult(role);
152 }
153 }
154 }
155
156 public void clearCache() {
157 CacheRegistry.clear(RoleImpl.class.getName());
158 EntityCacheUtil.clearCache(RoleImpl.class.getName());
159 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
160 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
161 }
162
163 public Role create(long roleId) {
164 Role role = new RoleImpl();
165
166 role.setNew(true);
167 role.setPrimaryKey(roleId);
168
169 return role;
170 }
171
172 public Role remove(long roleId) throws NoSuchRoleException, SystemException {
173 Session session = null;
174
175 try {
176 session = openSession();
177
178 Role role = (Role)session.get(RoleImpl.class, new Long(roleId));
179
180 if (role == null) {
181 if (_log.isWarnEnabled()) {
182 _log.warn("No Role exists with the primary key " + roleId);
183 }
184
185 throw new NoSuchRoleException(
186 "No Role exists with the primary key " + roleId);
187 }
188
189 return remove(role);
190 }
191 catch (NoSuchRoleException nsee) {
192 throw nsee;
193 }
194 catch (Exception e) {
195 throw processException(e);
196 }
197 finally {
198 closeSession(session);
199 }
200 }
201
202 public Role remove(Role role) throws SystemException {
203 for (ModelListener<Role> listener : listeners) {
204 listener.onBeforeRemove(role);
205 }
206
207 role = removeImpl(role);
208
209 for (ModelListener<Role> listener : listeners) {
210 listener.onAfterRemove(role);
211 }
212
213 return role;
214 }
215
216 protected Role removeImpl(Role role) throws SystemException {
217 try {
218 clearGroups.clear(role.getPrimaryKey());
219 }
220 catch (Exception e) {
221 throw processException(e);
222 }
223 finally {
224 FinderCacheUtil.clearCache("Groups_Roles");
225 }
226
227 try {
228 clearPermissions.clear(role.getPrimaryKey());
229 }
230 catch (Exception e) {
231 throw processException(e);
232 }
233 finally {
234 FinderCacheUtil.clearCache("Roles_Permissions");
235 }
236
237 try {
238 clearUsers.clear(role.getPrimaryKey());
239 }
240 catch (Exception e) {
241 throw processException(e);
242 }
243 finally {
244 FinderCacheUtil.clearCache("Users_Roles");
245 }
246
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 if (role.isCachedModel() || BatchSessionUtil.isEnabled()) {
253 Object staleObject = session.get(RoleImpl.class,
254 role.getPrimaryKeyObj());
255
256 if (staleObject != null) {
257 session.evict(staleObject);
258 }
259 }
260
261 session.delete(role);
262
263 session.flush();
264 }
265 catch (Exception e) {
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271
272 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
273
274 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
275
276 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
277 new Object[] {
278 new Long(roleModelImpl.getOriginalCompanyId()),
279
280 roleModelImpl.getOriginalName()
281 });
282
283 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
284 new Object[] {
285 new Long(roleModelImpl.getOriginalCompanyId()),
286 new Long(roleModelImpl.getOriginalClassNameId()),
287 new Long(roleModelImpl.getOriginalClassPK())
288 });
289
290 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
291 RoleImpl.class, role.getPrimaryKey());
292
293 return role;
294 }
295
296
299 public Role update(Role role) throws SystemException {
300 if (_log.isWarnEnabled()) {
301 _log.warn(
302 "Using the deprecated update(Role role) method. Use update(Role role, boolean merge) instead.");
303 }
304
305 return update(role, false);
306 }
307
308
321 public Role update(Role role, boolean merge) throws SystemException {
322 boolean isNew = role.isNew();
323
324 for (ModelListener<Role> listener : listeners) {
325 if (isNew) {
326 listener.onBeforeCreate(role);
327 }
328 else {
329 listener.onBeforeUpdate(role);
330 }
331 }
332
333 role = updateImpl(role, merge);
334
335 for (ModelListener<Role> listener : listeners) {
336 if (isNew) {
337 listener.onAfterCreate(role);
338 }
339 else {
340 listener.onAfterUpdate(role);
341 }
342 }
343
344 return role;
345 }
346
347 public Role updateImpl(com.liferay.portal.model.Role role, boolean merge)
348 throws SystemException {
349 boolean isNew = role.isNew();
350
351 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
352
353 Session session = null;
354
355 try {
356 session = openSession();
357
358 BatchSessionUtil.update(session, role, merge);
359
360 role.setNew(false);
361 }
362 catch (Exception e) {
363 throw processException(e);
364 }
365 finally {
366 closeSession(session);
367 }
368
369 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
370
371 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
372 RoleImpl.class, role.getPrimaryKey(), role);
373
374 if (!isNew &&
375 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
376 !Validator.equals(role.getName(),
377 roleModelImpl.getOriginalName()))) {
378 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
379 new Object[] {
380 new Long(roleModelImpl.getOriginalCompanyId()),
381
382 roleModelImpl.getOriginalName()
383 });
384 }
385
386 if (isNew ||
387 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
388 !Validator.equals(role.getName(),
389 roleModelImpl.getOriginalName()))) {
390 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
391 new Object[] { new Long(role.getCompanyId()), role.getName() },
392 role);
393 }
394
395 if (!isNew &&
396 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
397 (role.getClassNameId() != roleModelImpl.getOriginalClassNameId()) ||
398 (role.getClassPK() != roleModelImpl.getOriginalClassPK()))) {
399 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
400 new Object[] {
401 new Long(roleModelImpl.getOriginalCompanyId()),
402 new Long(roleModelImpl.getOriginalClassNameId()),
403 new Long(roleModelImpl.getOriginalClassPK())
404 });
405 }
406
407 if (isNew ||
408 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
409 (role.getClassNameId() != roleModelImpl.getOriginalClassNameId()) ||
410 (role.getClassPK() != roleModelImpl.getOriginalClassPK()))) {
411 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
412 new Object[] {
413 new Long(role.getCompanyId()),
414 new Long(role.getClassNameId()), new Long(role.getClassPK())
415 }, role);
416 }
417
418 return role;
419 }
420
421 public Role findByPrimaryKey(long roleId)
422 throws NoSuchRoleException, SystemException {
423 Role role = fetchByPrimaryKey(roleId);
424
425 if (role == null) {
426 if (_log.isWarnEnabled()) {
427 _log.warn("No Role exists with the primary key " + roleId);
428 }
429
430 throw new NoSuchRoleException(
431 "No Role exists with the primary key " + roleId);
432 }
433
434 return role;
435 }
436
437 public Role fetchByPrimaryKey(long roleId) throws SystemException {
438 Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
439 RoleImpl.class, roleId, this);
440
441 if (role == null) {
442 Session session = null;
443
444 try {
445 session = openSession();
446
447 role = (Role)session.get(RoleImpl.class, new Long(roleId));
448 }
449 catch (Exception e) {
450 throw processException(e);
451 }
452 finally {
453 if (role != null) {
454 cacheResult(role);
455 }
456
457 closeSession(session);
458 }
459 }
460
461 return role;
462 }
463
464 public List<Role> findByCompanyId(long companyId) throws SystemException {
465 Object[] finderArgs = new Object[] { new Long(companyId) };
466
467 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
468 finderArgs, this);
469
470 if (list == null) {
471 Session session = null;
472
473 try {
474 session = openSession();
475
476 StringBuilder query = new StringBuilder();
477
478 query.append("FROM com.liferay.portal.model.Role WHERE ");
479
480 query.append("companyId = ?");
481
482 query.append(" ");
483
484 query.append("ORDER BY ");
485
486 query.append("name ASC");
487
488 Query q = session.createQuery(query.toString());
489
490 QueryPos qPos = QueryPos.getInstance(q);
491
492 qPos.add(companyId);
493
494 list = q.list();
495 }
496 catch (Exception e) {
497 throw processException(e);
498 }
499 finally {
500 if (list == null) {
501 list = new ArrayList<Role>();
502 }
503
504 cacheResult(list);
505
506 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
507 finderArgs, list);
508
509 closeSession(session);
510 }
511 }
512
513 return list;
514 }
515
516 public List<Role> findByCompanyId(long companyId, int start, int end)
517 throws SystemException {
518 return findByCompanyId(companyId, start, end, null);
519 }
520
521 public List<Role> findByCompanyId(long companyId, int start, int end,
522 OrderByComparator obc) throws SystemException {
523 Object[] finderArgs = new Object[] {
524 new Long(companyId),
525
526 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
527 };
528
529 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
530 finderArgs, this);
531
532 if (list == null) {
533 Session session = null;
534
535 try {
536 session = openSession();
537
538 StringBuilder query = new StringBuilder();
539
540 query.append("FROM com.liferay.portal.model.Role WHERE ");
541
542 query.append("companyId = ?");
543
544 query.append(" ");
545
546 if (obc != null) {
547 query.append("ORDER BY ");
548 query.append(obc.getOrderBy());
549 }
550
551 else {
552 query.append("ORDER BY ");
553
554 query.append("name ASC");
555 }
556
557 Query q = session.createQuery(query.toString());
558
559 QueryPos qPos = QueryPos.getInstance(q);
560
561 qPos.add(companyId);
562
563 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
564 }
565 catch (Exception e) {
566 throw processException(e);
567 }
568 finally {
569 if (list == null) {
570 list = new ArrayList<Role>();
571 }
572
573 cacheResult(list);
574
575 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_COMPANYID,
576 finderArgs, list);
577
578 closeSession(session);
579 }
580 }
581
582 return list;
583 }
584
585 public Role findByCompanyId_First(long companyId, OrderByComparator obc)
586 throws NoSuchRoleException, SystemException {
587 List<Role> list = findByCompanyId(companyId, 0, 1, obc);
588
589 if (list.isEmpty()) {
590 StringBuilder msg = new StringBuilder();
591
592 msg.append("No Role exists with the key {");
593
594 msg.append("companyId=" + companyId);
595
596 msg.append(StringPool.CLOSE_CURLY_BRACE);
597
598 throw new NoSuchRoleException(msg.toString());
599 }
600 else {
601 return list.get(0);
602 }
603 }
604
605 public Role findByCompanyId_Last(long companyId, OrderByComparator obc)
606 throws NoSuchRoleException, SystemException {
607 int count = countByCompanyId(companyId);
608
609 List<Role> list = findByCompanyId(companyId, count - 1, count, obc);
610
611 if (list.isEmpty()) {
612 StringBuilder msg = new StringBuilder();
613
614 msg.append("No Role exists with the key {");
615
616 msg.append("companyId=" + companyId);
617
618 msg.append(StringPool.CLOSE_CURLY_BRACE);
619
620 throw new NoSuchRoleException(msg.toString());
621 }
622 else {
623 return list.get(0);
624 }
625 }
626
627 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
628 OrderByComparator obc) throws NoSuchRoleException, SystemException {
629 Role role = findByPrimaryKey(roleId);
630
631 int count = countByCompanyId(companyId);
632
633 Session session = null;
634
635 try {
636 session = openSession();
637
638 StringBuilder query = new StringBuilder();
639
640 query.append("FROM com.liferay.portal.model.Role WHERE ");
641
642 query.append("companyId = ?");
643
644 query.append(" ");
645
646 if (obc != null) {
647 query.append("ORDER BY ");
648 query.append(obc.getOrderBy());
649 }
650
651 else {
652 query.append("ORDER BY ");
653
654 query.append("name ASC");
655 }
656
657 Query q = session.createQuery(query.toString());
658
659 QueryPos qPos = QueryPos.getInstance(q);
660
661 qPos.add(companyId);
662
663 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, role);
664
665 Role[] array = new RoleImpl[3];
666
667 array[0] = (Role)objArray[0];
668 array[1] = (Role)objArray[1];
669 array[2] = (Role)objArray[2];
670
671 return array;
672 }
673 catch (Exception e) {
674 throw processException(e);
675 }
676 finally {
677 closeSession(session);
678 }
679 }
680
681 public Role findByC_N(long companyId, String name)
682 throws NoSuchRoleException, SystemException {
683 Role role = fetchByC_N(companyId, name);
684
685 if (role == null) {
686 StringBuilder msg = new StringBuilder();
687
688 msg.append("No Role exists with the key {");
689
690 msg.append("companyId=" + companyId);
691
692 msg.append(", ");
693 msg.append("name=" + name);
694
695 msg.append(StringPool.CLOSE_CURLY_BRACE);
696
697 if (_log.isWarnEnabled()) {
698 _log.warn(msg.toString());
699 }
700
701 throw new NoSuchRoleException(msg.toString());
702 }
703
704 return role;
705 }
706
707 public Role fetchByC_N(long companyId, String name)
708 throws SystemException {
709 return fetchByC_N(companyId, name, true);
710 }
711
712 public Role fetchByC_N(long companyId, String name,
713 boolean retrieveFromCache) throws SystemException {
714 Object[] finderArgs = new Object[] { new Long(companyId), name };
715
716 Object result = null;
717
718 if (retrieveFromCache) {
719 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
720 finderArgs, this);
721 }
722
723 if (result == null) {
724 Session session = null;
725
726 try {
727 session = openSession();
728
729 StringBuilder query = new StringBuilder();
730
731 query.append("FROM com.liferay.portal.model.Role WHERE ");
732
733 query.append("companyId = ?");
734
735 query.append(" AND ");
736
737 if (name == null) {
738 query.append("name IS NULL");
739 }
740 else {
741 query.append("name = ?");
742 }
743
744 query.append(" ");
745
746 query.append("ORDER BY ");
747
748 query.append("name ASC");
749
750 Query q = session.createQuery(query.toString());
751
752 QueryPos qPos = QueryPos.getInstance(q);
753
754 qPos.add(companyId);
755
756 if (name != null) {
757 qPos.add(name);
758 }
759
760 List<Role> list = q.list();
761
762 result = list;
763
764 Role role = null;
765
766 if (list.isEmpty()) {
767 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
768 finderArgs, list);
769 }
770 else {
771 role = list.get(0);
772
773 cacheResult(role);
774
775 if ((role.getCompanyId() != companyId) ||
776 (role.getName() == null) ||
777 !role.getName().equals(name)) {
778 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
779 finderArgs, role);
780 }
781 }
782
783 return role;
784 }
785 catch (Exception e) {
786 throw processException(e);
787 }
788 finally {
789 if (result == null) {
790 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
791 finderArgs, new ArrayList<Role>());
792 }
793
794 closeSession(session);
795 }
796 }
797 else {
798 if (result instanceof List) {
799 return null;
800 }
801 else {
802 return (Role)result;
803 }
804 }
805 }
806
807 public List<Role> findByT_S(int type, String subtype)
808 throws SystemException {
809 Object[] finderArgs = new Object[] { new Integer(type), subtype };
810
811 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_S,
812 finderArgs, this);
813
814 if (list == null) {
815 Session session = null;
816
817 try {
818 session = openSession();
819
820 StringBuilder query = new StringBuilder();
821
822 query.append("FROM com.liferay.portal.model.Role WHERE ");
823
824 query.append("type_ = ?");
825
826 query.append(" AND ");
827
828 if (subtype == null) {
829 query.append("subtype IS NULL");
830 }
831 else {
832 query.append("subtype = ?");
833 }
834
835 query.append(" ");
836
837 query.append("ORDER BY ");
838
839 query.append("name ASC");
840
841 Query q = session.createQuery(query.toString());
842
843 QueryPos qPos = QueryPos.getInstance(q);
844
845 qPos.add(type);
846
847 if (subtype != null) {
848 qPos.add(subtype);
849 }
850
851 list = q.list();
852 }
853 catch (Exception e) {
854 throw processException(e);
855 }
856 finally {
857 if (list == null) {
858 list = new ArrayList<Role>();
859 }
860
861 cacheResult(list);
862
863 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_S, finderArgs,
864 list);
865
866 closeSession(session);
867 }
868 }
869
870 return list;
871 }
872
873 public List<Role> findByT_S(int type, String subtype, int start, int end)
874 throws SystemException {
875 return findByT_S(type, subtype, start, end, null);
876 }
877
878 public List<Role> findByT_S(int type, String subtype, int start, int end,
879 OrderByComparator obc) throws SystemException {
880 Object[] finderArgs = new Object[] {
881 new Integer(type),
882
883 subtype,
884
885 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
886 };
887
888 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_T_S,
889 finderArgs, this);
890
891 if (list == null) {
892 Session session = null;
893
894 try {
895 session = openSession();
896
897 StringBuilder query = new StringBuilder();
898
899 query.append("FROM com.liferay.portal.model.Role WHERE ");
900
901 query.append("type_ = ?");
902
903 query.append(" AND ");
904
905 if (subtype == null) {
906 query.append("subtype IS NULL");
907 }
908 else {
909 query.append("subtype = ?");
910 }
911
912 query.append(" ");
913
914 if (obc != null) {
915 query.append("ORDER BY ");
916 query.append(obc.getOrderBy());
917 }
918
919 else {
920 query.append("ORDER BY ");
921
922 query.append("name ASC");
923 }
924
925 Query q = session.createQuery(query.toString());
926
927 QueryPos qPos = QueryPos.getInstance(q);
928
929 qPos.add(type);
930
931 if (subtype != null) {
932 qPos.add(subtype);
933 }
934
935 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
936 }
937 catch (Exception e) {
938 throw processException(e);
939 }
940 finally {
941 if (list == null) {
942 list = new ArrayList<Role>();
943 }
944
945 cacheResult(list);
946
947 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_T_S,
948 finderArgs, list);
949
950 closeSession(session);
951 }
952 }
953
954 return list;
955 }
956
957 public Role findByT_S_First(int type, String subtype, OrderByComparator obc)
958 throws NoSuchRoleException, SystemException {
959 List<Role> list = findByT_S(type, subtype, 0, 1, obc);
960
961 if (list.isEmpty()) {
962 StringBuilder msg = new StringBuilder();
963
964 msg.append("No Role exists with the key {");
965
966 msg.append("type=" + type);
967
968 msg.append(", ");
969 msg.append("subtype=" + subtype);
970
971 msg.append(StringPool.CLOSE_CURLY_BRACE);
972
973 throw new NoSuchRoleException(msg.toString());
974 }
975 else {
976 return list.get(0);
977 }
978 }
979
980 public Role findByT_S_Last(int type, String subtype, OrderByComparator obc)
981 throws NoSuchRoleException, SystemException {
982 int count = countByT_S(type, subtype);
983
984 List<Role> list = findByT_S(type, subtype, count - 1, count, obc);
985
986 if (list.isEmpty()) {
987 StringBuilder msg = new StringBuilder();
988
989 msg.append("No Role exists with the key {");
990
991 msg.append("type=" + type);
992
993 msg.append(", ");
994 msg.append("subtype=" + subtype);
995
996 msg.append(StringPool.CLOSE_CURLY_BRACE);
997
998 throw new NoSuchRoleException(msg.toString());
999 }
1000 else {
1001 return list.get(0);
1002 }
1003 }
1004
1005 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
1006 OrderByComparator obc) throws NoSuchRoleException, SystemException {
1007 Role role = findByPrimaryKey(roleId);
1008
1009 int count = countByT_S(type, subtype);
1010
1011 Session session = null;
1012
1013 try {
1014 session = openSession();
1015
1016 StringBuilder query = new StringBuilder();
1017
1018 query.append("FROM com.liferay.portal.model.Role WHERE ");
1019
1020 query.append("type_ = ?");
1021
1022 query.append(" AND ");
1023
1024 if (subtype == null) {
1025 query.append("subtype IS NULL");
1026 }
1027 else {
1028 query.append("subtype = ?");
1029 }
1030
1031 query.append(" ");
1032
1033 if (obc != null) {
1034 query.append("ORDER BY ");
1035 query.append(obc.getOrderBy());
1036 }
1037
1038 else {
1039 query.append("ORDER BY ");
1040
1041 query.append("name ASC");
1042 }
1043
1044 Query q = session.createQuery(query.toString());
1045
1046 QueryPos qPos = QueryPos.getInstance(q);
1047
1048 qPos.add(type);
1049
1050 if (subtype != null) {
1051 qPos.add(subtype);
1052 }
1053
1054 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, role);
1055
1056 Role[] array = new RoleImpl[3];
1057
1058 array[0] = (Role)objArray[0];
1059 array[1] = (Role)objArray[1];
1060 array[2] = (Role)objArray[2];
1061
1062 return array;
1063 }
1064 catch (Exception e) {
1065 throw processException(e);
1066 }
1067 finally {
1068 closeSession(session);
1069 }
1070 }
1071
1072 public Role findByC_C_C(long companyId, long classNameId, long classPK)
1073 throws NoSuchRoleException, SystemException {
1074 Role role = fetchByC_C_C(companyId, classNameId, classPK);
1075
1076 if (role == null) {
1077 StringBuilder msg = new StringBuilder();
1078
1079 msg.append("No Role exists with the key {");
1080
1081 msg.append("companyId=" + companyId);
1082
1083 msg.append(", ");
1084 msg.append("classNameId=" + classNameId);
1085
1086 msg.append(", ");
1087 msg.append("classPK=" + classPK);
1088
1089 msg.append(StringPool.CLOSE_CURLY_BRACE);
1090
1091 if (_log.isWarnEnabled()) {
1092 _log.warn(msg.toString());
1093 }
1094
1095 throw new NoSuchRoleException(msg.toString());
1096 }
1097
1098 return role;
1099 }
1100
1101 public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
1102 throws SystemException {
1103 return fetchByC_C_C(companyId, classNameId, classPK, true);
1104 }
1105
1106 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
1107 boolean retrieveFromCache) throws SystemException {
1108 Object[] finderArgs = new Object[] {
1109 new Long(companyId), new Long(classNameId), new Long(classPK)
1110 };
1111
1112 Object result = null;
1113
1114 if (retrieveFromCache) {
1115 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
1116 finderArgs, this);
1117 }
1118
1119 if (result == null) {
1120 Session session = null;
1121
1122 try {
1123 session = openSession();
1124
1125 StringBuilder query = new StringBuilder();
1126
1127 query.append("FROM com.liferay.portal.model.Role WHERE ");
1128
1129 query.append("companyId = ?");
1130
1131 query.append(" AND ");
1132
1133 query.append("classNameId = ?");
1134
1135 query.append(" AND ");
1136
1137 query.append("classPK = ?");
1138
1139 query.append(" ");
1140
1141 query.append("ORDER BY ");
1142
1143 query.append("name ASC");
1144
1145 Query q = session.createQuery(query.toString());
1146
1147 QueryPos qPos = QueryPos.getInstance(q);
1148
1149 qPos.add(companyId);
1150
1151 qPos.add(classNameId);
1152
1153 qPos.add(classPK);
1154
1155 List<Role> list = q.list();
1156
1157 result = list;
1158
1159 Role role = null;
1160
1161 if (list.isEmpty()) {
1162 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1163 finderArgs, list);
1164 }
1165 else {
1166 role = list.get(0);
1167
1168 cacheResult(role);
1169
1170 if ((role.getCompanyId() != companyId) ||
1171 (role.getClassNameId() != classNameId) ||
1172 (role.getClassPK() != classPK)) {
1173 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1174 finderArgs, role);
1175 }
1176 }
1177
1178 return role;
1179 }
1180 catch (Exception e) {
1181 throw processException(e);
1182 }
1183 finally {
1184 if (result == null) {
1185 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1186 finderArgs, new ArrayList<Role>());
1187 }
1188
1189 closeSession(session);
1190 }
1191 }
1192 else {
1193 if (result instanceof List) {
1194 return null;
1195 }
1196 else {
1197 return (Role)result;
1198 }
1199 }
1200 }
1201
1202 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1203 throws SystemException {
1204 Session session = null;
1205
1206 try {
1207 session = openSession();
1208
1209 dynamicQuery.compile(session);
1210
1211 return dynamicQuery.list();
1212 }
1213 catch (Exception e) {
1214 throw processException(e);
1215 }
1216 finally {
1217 closeSession(session);
1218 }
1219 }
1220
1221 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1222 int start, int end) throws SystemException {
1223 Session session = null;
1224
1225 try {
1226 session = openSession();
1227
1228 dynamicQuery.setLimit(start, end);
1229
1230 dynamicQuery.compile(session);
1231
1232 return dynamicQuery.list();
1233 }
1234 catch (Exception e) {
1235 throw processException(e);
1236 }
1237 finally {
1238 closeSession(session);
1239 }
1240 }
1241
1242 public List<Role> findAll() throws SystemException {
1243 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1244 }
1245
1246 public List<Role> findAll(int start, int end) throws SystemException {
1247 return findAll(start, end, null);
1248 }
1249
1250 public List<Role> findAll(int start, int end, OrderByComparator obc)
1251 throws SystemException {
1252 Object[] finderArgs = new Object[] {
1253 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1254 };
1255
1256 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1257 finderArgs, this);
1258
1259 if (list == null) {
1260 Session session = null;
1261
1262 try {
1263 session = openSession();
1264
1265 StringBuilder query = new StringBuilder();
1266
1267 query.append("FROM com.liferay.portal.model.Role ");
1268
1269 if (obc != null) {
1270 query.append("ORDER BY ");
1271 query.append(obc.getOrderBy());
1272 }
1273
1274 else {
1275 query.append("ORDER BY ");
1276
1277 query.append("name ASC");
1278 }
1279
1280 Query q = session.createQuery(query.toString());
1281
1282 if (obc == null) {
1283 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1284 end, false);
1285
1286 Collections.sort(list);
1287 }
1288 else {
1289 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1290 end);
1291 }
1292 }
1293 catch (Exception e) {
1294 throw processException(e);
1295 }
1296 finally {
1297 if (list == null) {
1298 list = new ArrayList<Role>();
1299 }
1300
1301 cacheResult(list);
1302
1303 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1304
1305 closeSession(session);
1306 }
1307 }
1308
1309 return list;
1310 }
1311
1312 public void removeByCompanyId(long companyId) throws SystemException {
1313 for (Role role : findByCompanyId(companyId)) {
1314 remove(role);
1315 }
1316 }
1317
1318 public void removeByC_N(long companyId, String name)
1319 throws NoSuchRoleException, SystemException {
1320 Role role = findByC_N(companyId, name);
1321
1322 remove(role);
1323 }
1324
1325 public void removeByT_S(int type, String subtype) throws SystemException {
1326 for (Role role : findByT_S(type, subtype)) {
1327 remove(role);
1328 }
1329 }
1330
1331 public void removeByC_C_C(long companyId, long classNameId, long classPK)
1332 throws NoSuchRoleException, SystemException {
1333 Role role = findByC_C_C(companyId, classNameId, classPK);
1334
1335 remove(role);
1336 }
1337
1338 public void removeAll() throws SystemException {
1339 for (Role role : findAll()) {
1340 remove(role);
1341 }
1342 }
1343
1344 public int countByCompanyId(long companyId) throws SystemException {
1345 Object[] finderArgs = new Object[] { new Long(companyId) };
1346
1347 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
1348 finderArgs, this);
1349
1350 if (count == null) {
1351 Session session = null;
1352
1353 try {
1354 session = openSession();
1355
1356 StringBuilder query = new StringBuilder();
1357
1358 query.append("SELECT COUNT(*) ");
1359 query.append("FROM com.liferay.portal.model.Role WHERE ");
1360
1361 query.append("companyId = ?");
1362
1363 query.append(" ");
1364
1365 Query q = session.createQuery(query.toString());
1366
1367 QueryPos qPos = QueryPos.getInstance(q);
1368
1369 qPos.add(companyId);
1370
1371 count = (Long)q.uniqueResult();
1372 }
1373 catch (Exception e) {
1374 throw processException(e);
1375 }
1376 finally {
1377 if (count == null) {
1378 count = Long.valueOf(0);
1379 }
1380
1381 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
1382 finderArgs, count);
1383
1384 closeSession(session);
1385 }
1386 }
1387
1388 return count.intValue();
1389 }
1390
1391 public int countByC_N(long companyId, String name)
1392 throws SystemException {
1393 Object[] finderArgs = new Object[] { new Long(companyId), name };
1394
1395 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1396 finderArgs, this);
1397
1398 if (count == null) {
1399 Session session = null;
1400
1401 try {
1402 session = openSession();
1403
1404 StringBuilder query = new StringBuilder();
1405
1406 query.append("SELECT COUNT(*) ");
1407 query.append("FROM com.liferay.portal.model.Role WHERE ");
1408
1409 query.append("companyId = ?");
1410
1411 query.append(" AND ");
1412
1413 if (name == null) {
1414 query.append("name IS NULL");
1415 }
1416 else {
1417 query.append("name = ?");
1418 }
1419
1420 query.append(" ");
1421
1422 Query q = session.createQuery(query.toString());
1423
1424 QueryPos qPos = QueryPos.getInstance(q);
1425
1426 qPos.add(companyId);
1427
1428 if (name != null) {
1429 qPos.add(name);
1430 }
1431
1432 count = (Long)q.uniqueResult();
1433 }
1434 catch (Exception e) {
1435 throw processException(e);
1436 }
1437 finally {
1438 if (count == null) {
1439 count = Long.valueOf(0);
1440 }
1441
1442 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1443 count);
1444
1445 closeSession(session);
1446 }
1447 }
1448
1449 return count.intValue();
1450 }
1451
1452 public int countByT_S(int type, String subtype) throws SystemException {
1453 Object[] finderArgs = new Object[] { new Integer(type), subtype };
1454
1455 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
1456 finderArgs, this);
1457
1458 if (count == null) {
1459 Session session = null;
1460
1461 try {
1462 session = openSession();
1463
1464 StringBuilder query = new StringBuilder();
1465
1466 query.append("SELECT COUNT(*) ");
1467 query.append("FROM com.liferay.portal.model.Role WHERE ");
1468
1469 query.append("type_ = ?");
1470
1471 query.append(" AND ");
1472
1473 if (subtype == null) {
1474 query.append("subtype IS NULL");
1475 }
1476 else {
1477 query.append("subtype = ?");
1478 }
1479
1480 query.append(" ");
1481
1482 Query q = session.createQuery(query.toString());
1483
1484 QueryPos qPos = QueryPos.getInstance(q);
1485
1486 qPos.add(type);
1487
1488 if (subtype != null) {
1489 qPos.add(subtype);
1490 }
1491
1492 count = (Long)q.uniqueResult();
1493 }
1494 catch (Exception e) {
1495 throw processException(e);
1496 }
1497 finally {
1498 if (count == null) {
1499 count = Long.valueOf(0);
1500 }
1501
1502 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
1503 count);
1504
1505 closeSession(session);
1506 }
1507 }
1508
1509 return count.intValue();
1510 }
1511
1512 public int countByC_C_C(long companyId, long classNameId, long classPK)
1513 throws SystemException {
1514 Object[] finderArgs = new Object[] {
1515 new Long(companyId), new Long(classNameId), new Long(classPK)
1516 };
1517
1518 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
1519 finderArgs, this);
1520
1521 if (count == null) {
1522 Session session = null;
1523
1524 try {
1525 session = openSession();
1526
1527 StringBuilder query = new StringBuilder();
1528
1529 query.append("SELECT COUNT(*) ");
1530 query.append("FROM com.liferay.portal.model.Role WHERE ");
1531
1532 query.append("companyId = ?");
1533
1534 query.append(" AND ");
1535
1536 query.append("classNameId = ?");
1537
1538 query.append(" AND ");
1539
1540 query.append("classPK = ?");
1541
1542 query.append(" ");
1543
1544 Query q = session.createQuery(query.toString());
1545
1546 QueryPos qPos = QueryPos.getInstance(q);
1547
1548 qPos.add(companyId);
1549
1550 qPos.add(classNameId);
1551
1552 qPos.add(classPK);
1553
1554 count = (Long)q.uniqueResult();
1555 }
1556 catch (Exception e) {
1557 throw processException(e);
1558 }
1559 finally {
1560 if (count == null) {
1561 count = Long.valueOf(0);
1562 }
1563
1564 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
1565 finderArgs, count);
1566
1567 closeSession(session);
1568 }
1569 }
1570
1571 return count.intValue();
1572 }
1573
1574 public int countAll() throws SystemException {
1575 Object[] finderArgs = new Object[0];
1576
1577 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1578 finderArgs, this);
1579
1580 if (count == null) {
1581 Session session = null;
1582
1583 try {
1584 session = openSession();
1585
1586 Query q = session.createQuery(
1587 "SELECT COUNT(*) FROM com.liferay.portal.model.Role");
1588
1589 count = (Long)q.uniqueResult();
1590 }
1591 catch (Exception e) {
1592 throw processException(e);
1593 }
1594 finally {
1595 if (count == null) {
1596 count = Long.valueOf(0);
1597 }
1598
1599 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1600 count);
1601
1602 closeSession(session);
1603 }
1604 }
1605
1606 return count.intValue();
1607 }
1608
1609 public List<com.liferay.portal.model.Group> getGroups(long pk)
1610 throws SystemException {
1611 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1612 }
1613
1614 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1615 int end) throws SystemException {
1616 return getGroups(pk, start, end, null);
1617 }
1618
1619 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1620 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
1621 "getGroups",
1622 new String[] {
1623 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1624 "com.liferay.portal.kernel.util.OrderByComparator"
1625 });
1626
1627 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1628 int end, OrderByComparator obc) throws SystemException {
1629 Object[] finderArgs = new Object[] {
1630 new Long(pk), String.valueOf(start), String.valueOf(end),
1631 String.valueOf(obc)
1632 };
1633
1634 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1635 finderArgs, this);
1636
1637 if (list == null) {
1638 Session session = null;
1639
1640 try {
1641 session = openSession();
1642
1643 StringBuilder sb = new StringBuilder();
1644
1645 sb.append(_SQL_GETGROUPS);
1646
1647 if (obc != null) {
1648 sb.append("ORDER BY ");
1649 sb.append(obc.getOrderBy());
1650 }
1651
1652 else {
1653 sb.append("ORDER BY ");
1654
1655 sb.append("Group_.name ASC");
1656 }
1657
1658 String sql = sb.toString();
1659
1660 SQLQuery q = session.createSQLQuery(sql);
1661
1662 q.addEntity("Group_",
1663 com.liferay.portal.model.impl.GroupImpl.class);
1664
1665 QueryPos qPos = QueryPos.getInstance(q);
1666
1667 qPos.add(pk);
1668
1669 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1670 getDialect(), start, end);
1671 }
1672 catch (Exception e) {
1673 throw processException(e);
1674 }
1675 finally {
1676 if (list == null) {
1677 list = new ArrayList<com.liferay.portal.model.Group>();
1678 }
1679
1680 groupPersistence.cacheResult(list);
1681
1682 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
1683 list);
1684
1685 closeSession(session);
1686 }
1687 }
1688
1689 return list;
1690 }
1691
1692 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1693 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
1694 "getGroupsSize", new String[] { Long.class.getName() });
1695
1696 public int getGroupsSize(long pk) throws SystemException {
1697 Object[] finderArgs = new Object[] { new Long(pk) };
1698
1699 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1700 finderArgs, this);
1701
1702 if (count == null) {
1703 Session session = null;
1704
1705 try {
1706 session = openSession();
1707
1708 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1709
1710 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1711
1712 QueryPos qPos = QueryPos.getInstance(q);
1713
1714 qPos.add(pk);
1715
1716 count = (Long)q.uniqueResult();
1717 }
1718 catch (Exception e) {
1719 throw processException(e);
1720 }
1721 finally {
1722 if (count == null) {
1723 count = Long.valueOf(0);
1724 }
1725
1726 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1727 finderArgs, count);
1728
1729 closeSession(session);
1730 }
1731 }
1732
1733 return count.intValue();
1734 }
1735
1736 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1737 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
1738 "containsGroup",
1739 new String[] { Long.class.getName(), Long.class.getName() });
1740
1741 public boolean containsGroup(long pk, long groupPK)
1742 throws SystemException {
1743 Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
1744
1745 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1746 finderArgs, this);
1747
1748 if (value == null) {
1749 try {
1750 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1751 }
1752 catch (Exception e) {
1753 throw processException(e);
1754 }
1755 finally {
1756 if (value == null) {
1757 value = Boolean.FALSE;
1758 }
1759
1760 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1761 finderArgs, value);
1762 }
1763 }
1764
1765 return value.booleanValue();
1766 }
1767
1768 public boolean containsGroups(long pk) throws SystemException {
1769 if (getGroupsSize(pk) > 0) {
1770 return true;
1771 }
1772 else {
1773 return false;
1774 }
1775 }
1776
1777 public void addGroup(long pk, long groupPK) throws SystemException {
1778 try {
1779 addGroup.add(pk, groupPK);
1780 }
1781 catch (Exception e) {
1782 throw processException(e);
1783 }
1784 finally {
1785 FinderCacheUtil.clearCache("Groups_Roles");
1786 }
1787 }
1788
1789 public void addGroup(long pk, com.liferay.portal.model.Group group)
1790 throws SystemException {
1791 try {
1792 addGroup.add(pk, group.getPrimaryKey());
1793 }
1794 catch (Exception e) {
1795 throw processException(e);
1796 }
1797 finally {
1798 FinderCacheUtil.clearCache("Groups_Roles");
1799 }
1800 }
1801
1802 public void addGroups(long pk, long[] groupPKs) throws SystemException {
1803 try {
1804 for (long groupPK : groupPKs) {
1805 addGroup.add(pk, groupPK);
1806 }
1807 }
1808 catch (Exception e) {
1809 throw processException(e);
1810 }
1811 finally {
1812 FinderCacheUtil.clearCache("Groups_Roles");
1813 }
1814 }
1815
1816 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1817 throws SystemException {
1818 try {
1819 for (com.liferay.portal.model.Group group : groups) {
1820 addGroup.add(pk, group.getPrimaryKey());
1821 }
1822 }
1823 catch (Exception e) {
1824 throw processException(e);
1825 }
1826 finally {
1827 FinderCacheUtil.clearCache("Groups_Roles");
1828 }
1829 }
1830
1831 public void clearGroups(long pk) throws SystemException {
1832 try {
1833 clearGroups.clear(pk);
1834 }
1835 catch (Exception e) {
1836 throw processException(e);
1837 }
1838 finally {
1839 FinderCacheUtil.clearCache("Groups_Roles");
1840 }
1841 }
1842
1843 public void removeGroup(long pk, long groupPK) throws SystemException {
1844 try {
1845 removeGroup.remove(pk, groupPK);
1846 }
1847 catch (Exception e) {
1848 throw processException(e);
1849 }
1850 finally {
1851 FinderCacheUtil.clearCache("Groups_Roles");
1852 }
1853 }
1854
1855 public void removeGroup(long pk, com.liferay.portal.model.Group group)
1856 throws SystemException {
1857 try {
1858 removeGroup.remove(pk, group.getPrimaryKey());
1859 }
1860 catch (Exception e) {
1861 throw processException(e);
1862 }
1863 finally {
1864 FinderCacheUtil.clearCache("Groups_Roles");
1865 }
1866 }
1867
1868 public void removeGroups(long pk, long[] groupPKs)
1869 throws SystemException {
1870 try {
1871 for (long groupPK : groupPKs) {
1872 removeGroup.remove(pk, groupPK);
1873 }
1874 }
1875 catch (Exception e) {
1876 throw processException(e);
1877 }
1878 finally {
1879 FinderCacheUtil.clearCache("Groups_Roles");
1880 }
1881 }
1882
1883 public void removeGroups(long pk,
1884 List<com.liferay.portal.model.Group> groups) throws SystemException {
1885 try {
1886 for (com.liferay.portal.model.Group group : groups) {
1887 removeGroup.remove(pk, group.getPrimaryKey());
1888 }
1889 }
1890 catch (Exception e) {
1891 throw processException(e);
1892 }
1893 finally {
1894 FinderCacheUtil.clearCache("Groups_Roles");
1895 }
1896 }
1897
1898 public void setGroups(long pk, long[] groupPKs) throws SystemException {
1899 try {
1900 clearGroups.clear(pk);
1901
1902 for (long groupPK : groupPKs) {
1903 addGroup.add(pk, groupPK);
1904 }
1905 }
1906 catch (Exception e) {
1907 throw processException(e);
1908 }
1909 finally {
1910 FinderCacheUtil.clearCache("Groups_Roles");
1911 }
1912 }
1913
1914 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1915 throws SystemException {
1916 try {
1917 clearGroups.clear(pk);
1918
1919 for (com.liferay.portal.model.Group group : groups) {
1920 addGroup.add(pk, group.getPrimaryKey());
1921 }
1922 }
1923 catch (Exception e) {
1924 throw processException(e);
1925 }
1926 finally {
1927 FinderCacheUtil.clearCache("Groups_Roles");
1928 }
1929 }
1930
1931 public List<com.liferay.portal.model.Permission> getPermissions(long pk)
1932 throws SystemException {
1933 return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1934 }
1935
1936 public List<com.liferay.portal.model.Permission> getPermissions(long pk,
1937 int start, int end) throws SystemException {
1938 return getPermissions(pk, start, end, null);
1939 }
1940
1941 public static final FinderPath FINDER_PATH_GET_PERMISSIONS = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
1942 RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1943 "Roles_Permissions", "getPermissions",
1944 new String[] {
1945 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1946 "com.liferay.portal.kernel.util.OrderByComparator"
1947 });
1948
1949 public List<com.liferay.portal.model.Permission> getPermissions(long pk,
1950 int start, int end, OrderByComparator obc) throws SystemException {
1951 Object[] finderArgs = new Object[] {
1952 new Long(pk), String.valueOf(start), String.valueOf(end),
1953 String.valueOf(obc)
1954 };
1955
1956 List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS,
1957 finderArgs, this);
1958
1959 if (list == null) {
1960 Session session = null;
1961
1962 try {
1963 session = openSession();
1964
1965 StringBuilder sb = new StringBuilder();
1966
1967 sb.append(_SQL_GETPERMISSIONS);
1968
1969 if (obc != null) {
1970 sb.append("ORDER BY ");
1971 sb.append(obc.getOrderBy());
1972 }
1973
1974 String sql = sb.toString();
1975
1976 SQLQuery q = session.createSQLQuery(sql);
1977
1978 q.addEntity("Permission_",
1979 com.liferay.portal.model.impl.PermissionImpl.class);
1980
1981 QueryPos qPos = QueryPos.getInstance(q);
1982
1983 qPos.add(pk);
1984
1985 list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
1986 getDialect(), start, end);
1987 }
1988 catch (Exception e) {
1989 throw processException(e);
1990 }
1991 finally {
1992 if (list == null) {
1993 list = new ArrayList<com.liferay.portal.model.Permission>();
1994 }
1995
1996 permissionPersistence.cacheResult(list);
1997
1998 FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS,
1999 finderArgs, list);
2000
2001 closeSession(session);
2002 }
2003 }
2004
2005 return list;
2006 }
2007
2008 public static final FinderPath FINDER_PATH_GET_PERMISSIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2009 RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
2010 "Roles_Permissions", "getPermissionsSize",
2011 new String[] { Long.class.getName() });
2012
2013 public int getPermissionsSize(long pk) throws SystemException {
2014 Object[] finderArgs = new Object[] { new Long(pk) };
2015
2016 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
2017 finderArgs, this);
2018
2019 if (count == null) {
2020 Session session = null;
2021
2022 try {
2023 session = openSession();
2024
2025 SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
2026
2027 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2028
2029 QueryPos qPos = QueryPos.getInstance(q);
2030
2031 qPos.add(pk);
2032
2033 count = (Long)q.uniqueResult();
2034 }
2035 catch (Exception e) {
2036 throw processException(e);
2037 }
2038 finally {
2039 if (count == null) {
2040 count = Long.valueOf(0);
2041 }
2042
2043 FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
2044 finderArgs, count);
2045
2046 closeSession(session);
2047 }
2048 }
2049
2050 return count.intValue();
2051 }
2052
2053 public static final FinderPath FINDER_PATH_CONTAINS_PERMISSION = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2054 RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
2055 "Roles_Permissions", "containsPermission",
2056 new String[] { Long.class.getName(), Long.class.getName() });
2057
2058 public boolean containsPermission(long pk, long permissionPK)
2059 throws SystemException {
2060 Object[] finderArgs = new Object[] { new Long(pk), new Long(permissionPK) };
2061
2062 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_PERMISSION,
2063 finderArgs, this);
2064
2065 if (value == null) {
2066 try {
2067 value = Boolean.valueOf(containsPermission.contains(pk,
2068 permissionPK));
2069 }
2070 catch (Exception e) {
2071 throw processException(e);
2072 }
2073 finally {
2074 if (value == null) {
2075 value = Boolean.FALSE;
2076 }
2077
2078 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_PERMISSION,
2079 finderArgs, value);
2080 }
2081 }
2082
2083 return value.booleanValue();
2084 }
2085
2086 public boolean containsPermissions(long pk) throws SystemException {
2087 if (getPermissionsSize(pk) > 0) {
2088 return true;
2089 }
2090 else {
2091 return false;
2092 }
2093 }
2094
2095 public void addPermission(long pk, long permissionPK)
2096 throws SystemException {
2097 try {
2098 addPermission.add(pk, permissionPK);
2099 }
2100 catch (Exception e) {
2101 throw processException(e);
2102 }
2103 finally {
2104 FinderCacheUtil.clearCache("Roles_Permissions");
2105 }
2106 }
2107
2108 public void addPermission(long pk,
2109 com.liferay.portal.model.Permission permission)
2110 throws SystemException {
2111 try {
2112 addPermission.add(pk, permission.getPrimaryKey());
2113 }
2114 catch (Exception e) {
2115 throw processException(e);
2116 }
2117 finally {
2118 FinderCacheUtil.clearCache("Roles_Permissions");
2119 }
2120 }
2121
2122 public void addPermissions(long pk, long[] permissionPKs)
2123 throws SystemException {
2124 try {
2125 for (long permissionPK : permissionPKs) {
2126 addPermission.add(pk, permissionPK);
2127 }
2128 }
2129 catch (Exception e) {
2130 throw processException(e);
2131 }
2132 finally {
2133 FinderCacheUtil.clearCache("Roles_Permissions");
2134 }
2135 }
2136
2137 public void addPermissions(long pk,
2138 List<com.liferay.portal.model.Permission> permissions)
2139 throws SystemException {
2140 try {
2141 for (com.liferay.portal.model.Permission permission : permissions) {
2142 addPermission.add(pk, permission.getPrimaryKey());
2143 }
2144 }
2145 catch (Exception e) {
2146 throw processException(e);
2147 }
2148 finally {
2149 FinderCacheUtil.clearCache("Roles_Permissions");
2150 }
2151 }
2152
2153 public void clearPermissions(long pk) throws SystemException {
2154 try {
2155 clearPermissions.clear(pk);
2156 }
2157 catch (Exception e) {
2158 throw processException(e);
2159 }
2160 finally {
2161 FinderCacheUtil.clearCache("Roles_Permissions");
2162 }
2163 }
2164
2165 public void removePermission(long pk, long permissionPK)
2166 throws SystemException {
2167 try {
2168 removePermission.remove(pk, permissionPK);
2169 }
2170 catch (Exception e) {
2171 throw processException(e);
2172 }
2173 finally {
2174 FinderCacheUtil.clearCache("Roles_Permissions");
2175 }
2176 }
2177
2178 public void removePermission(long pk,
2179 com.liferay.portal.model.Permission permission)
2180 throws SystemException {
2181 try {
2182 removePermission.remove(pk, permission.getPrimaryKey());
2183 }
2184 catch (Exception e) {
2185 throw processException(e);
2186 }
2187 finally {
2188 FinderCacheUtil.clearCache("Roles_Permissions");
2189 }
2190 }
2191
2192 public void removePermissions(long pk, long[] permissionPKs)
2193 throws SystemException {
2194 try {
2195 for (long permissionPK : permissionPKs) {
2196 removePermission.remove(pk, permissionPK);
2197 }
2198 }
2199 catch (Exception e) {
2200 throw processException(e);
2201 }
2202 finally {
2203 FinderCacheUtil.clearCache("Roles_Permissions");
2204 }
2205 }
2206
2207 public void removePermissions(long pk,
2208 List<com.liferay.portal.model.Permission> permissions)
2209 throws SystemException {
2210 try {
2211 for (com.liferay.portal.model.Permission permission : permissions) {
2212 removePermission.remove(pk, permission.getPrimaryKey());
2213 }
2214 }
2215 catch (Exception e) {
2216 throw processException(e);
2217 }
2218 finally {
2219 FinderCacheUtil.clearCache("Roles_Permissions");
2220 }
2221 }
2222
2223 public void setPermissions(long pk, long[] permissionPKs)
2224 throws SystemException {
2225 try {
2226 clearPermissions.clear(pk);
2227
2228 for (long permissionPK : permissionPKs) {
2229 addPermission.add(pk, permissionPK);
2230 }
2231 }
2232 catch (Exception e) {
2233 throw processException(e);
2234 }
2235 finally {
2236 FinderCacheUtil.clearCache("Roles_Permissions");
2237 }
2238 }
2239
2240 public void setPermissions(long pk,
2241 List<com.liferay.portal.model.Permission> permissions)
2242 throws SystemException {
2243 try {
2244 clearPermissions.clear(pk);
2245
2246 for (com.liferay.portal.model.Permission permission : permissions) {
2247 addPermission.add(pk, permission.getPrimaryKey());
2248 }
2249 }
2250 catch (Exception e) {
2251 throw processException(e);
2252 }
2253 finally {
2254 FinderCacheUtil.clearCache("Roles_Permissions");
2255 }
2256 }
2257
2258 public List<com.liferay.portal.model.User> getUsers(long pk)
2259 throws SystemException {
2260 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2261 }
2262
2263 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2264 int end) throws SystemException {
2265 return getUsers(pk, start, end, null);
2266 }
2267
2268 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2269 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, "Users_Roles",
2270 "getUsers",
2271 new String[] {
2272 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2273 "com.liferay.portal.kernel.util.OrderByComparator"
2274 });
2275
2276 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2277 int end, OrderByComparator obc) throws SystemException {
2278 Object[] finderArgs = new Object[] {
2279 new Long(pk), String.valueOf(start), String.valueOf(end),
2280 String.valueOf(obc)
2281 };
2282
2283 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
2284 finderArgs, this);
2285
2286 if (list == null) {
2287 Session session = null;
2288
2289 try {
2290 session = openSession();
2291
2292 StringBuilder sb = new StringBuilder();
2293
2294 sb.append(_SQL_GETUSERS);
2295
2296 if (obc != null) {
2297 sb.append("ORDER BY ");
2298 sb.append(obc.getOrderBy());
2299 }
2300
2301 String sql = sb.toString();
2302
2303 SQLQuery q = session.createSQLQuery(sql);
2304
2305 q.addEntity("User_",
2306 com.liferay.portal.model.impl.UserImpl.class);
2307
2308 QueryPos qPos = QueryPos.getInstance(q);
2309
2310 qPos.add(pk);
2311
2312 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2313 getDialect(), start, end);
2314 }
2315 catch (Exception e) {
2316 throw processException(e);
2317 }
2318 finally {
2319 if (list == null) {
2320 list = new ArrayList<com.liferay.portal.model.User>();
2321 }
2322
2323 userPersistence.cacheResult(list);
2324
2325 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
2326 list);
2327
2328 closeSession(session);
2329 }
2330 }
2331
2332 return list;
2333 }
2334
2335 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2336 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, "Users_Roles",
2337 "getUsersSize", new String[] { Long.class.getName() });
2338
2339 public int getUsersSize(long pk) throws SystemException {
2340 Object[] finderArgs = new Object[] { new Long(pk) };
2341
2342 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
2343 finderArgs, this);
2344
2345 if (count == null) {
2346 Session session = null;
2347
2348 try {
2349 session = openSession();
2350
2351 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2352
2353 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2354
2355 QueryPos qPos = QueryPos.getInstance(q);
2356
2357 qPos.add(pk);
2358
2359 count = (Long)q.uniqueResult();
2360 }
2361 catch (Exception e) {
2362 throw processException(e);
2363 }
2364 finally {
2365 if (count == null) {
2366 count = Long.valueOf(0);
2367 }
2368
2369 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
2370 finderArgs, count);
2371
2372 closeSession(session);
2373 }
2374 }
2375
2376 return count.intValue();
2377 }
2378
2379 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2380 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, "Users_Roles",
2381 "containsUser",
2382 new String[] { Long.class.getName(), Long.class.getName() });
2383
2384 public boolean containsUser(long pk, long userPK) throws SystemException {
2385 Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
2386
2387 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
2388 finderArgs, this);
2389
2390 if (value == null) {
2391 try {
2392 value = Boolean.valueOf(containsUser.contains(pk, userPK));
2393 }
2394 catch (Exception e) {
2395 throw processException(e);
2396 }
2397 finally {
2398 if (value == null) {
2399 value = Boolean.FALSE;
2400 }
2401
2402 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
2403 finderArgs, value);
2404 }
2405 }
2406
2407 return value.booleanValue();
2408 }
2409
2410 public boolean containsUsers(long pk) throws SystemException {
2411 if (getUsersSize(pk) > 0) {
2412 return true;
2413 }
2414 else {
2415 return false;
2416 }
2417 }
2418
2419 public void addUser(long pk, long userPK) throws SystemException {
2420 try {
2421 addUser.add(pk, userPK);
2422 }
2423 catch (Exception e) {
2424 throw processException(e);
2425 }
2426 finally {
2427 FinderCacheUtil.clearCache("Users_Roles");
2428 }
2429 }
2430
2431 public void addUser(long pk, com.liferay.portal.model.User user)
2432 throws SystemException {
2433 try {
2434 addUser.add(pk, user.getPrimaryKey());
2435 }
2436 catch (Exception e) {
2437 throw processException(e);
2438 }
2439 finally {
2440 FinderCacheUtil.clearCache("Users_Roles");
2441 }
2442 }
2443
2444 public void addUsers(long pk, long[] userPKs) throws SystemException {
2445 try {
2446 for (long userPK : userPKs) {
2447 addUser.add(pk, userPK);
2448 }
2449 }
2450 catch (Exception e) {
2451 throw processException(e);
2452 }
2453 finally {
2454 FinderCacheUtil.clearCache("Users_Roles");
2455 }
2456 }
2457
2458 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2459 throws SystemException {
2460 try {
2461 for (com.liferay.portal.model.User user : users) {
2462 addUser.add(pk, user.getPrimaryKey());
2463 }
2464 }
2465 catch (Exception e) {
2466 throw processException(e);
2467 }
2468 finally {
2469 FinderCacheUtil.clearCache("Users_Roles");
2470 }
2471 }
2472
2473 public void clearUsers(long pk) throws SystemException {
2474 try {
2475 clearUsers.clear(pk);
2476 }
2477 catch (Exception e) {
2478 throw processException(e);
2479 }
2480 finally {
2481 FinderCacheUtil.clearCache("Users_Roles");
2482 }
2483 }
2484
2485 public void removeUser(long pk, long userPK) throws SystemException {
2486 try {
2487 removeUser.remove(pk, userPK);
2488 }
2489 catch (Exception e) {
2490 throw processException(e);
2491 }
2492 finally {
2493 FinderCacheUtil.clearCache("Users_Roles");
2494 }
2495 }
2496
2497 public void removeUser(long pk, com.liferay.portal.model.User user)
2498 throws SystemException {
2499 try {
2500 removeUser.remove(pk, user.getPrimaryKey());
2501 }
2502 catch (Exception e) {
2503 throw processException(e);
2504 }
2505 finally {
2506 FinderCacheUtil.clearCache("Users_Roles");
2507 }
2508 }
2509
2510 public void removeUsers(long pk, long[] userPKs) throws SystemException {
2511 try {
2512 for (long userPK : userPKs) {
2513 removeUser.remove(pk, userPK);
2514 }
2515 }
2516 catch (Exception e) {
2517 throw processException(e);
2518 }
2519 finally {
2520 FinderCacheUtil.clearCache("Users_Roles");
2521 }
2522 }
2523
2524 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2525 throws SystemException {
2526 try {
2527 for (com.liferay.portal.model.User user : users) {
2528 removeUser.remove(pk, user.getPrimaryKey());
2529 }
2530 }
2531 catch (Exception e) {
2532 throw processException(e);
2533 }
2534 finally {
2535 FinderCacheUtil.clearCache("Users_Roles");
2536 }
2537 }
2538
2539 public void setUsers(long pk, long[] userPKs) throws SystemException {
2540 try {
2541 clearUsers.clear(pk);
2542
2543 for (long userPK : userPKs) {
2544 addUser.add(pk, userPK);
2545 }
2546 }
2547 catch (Exception e) {
2548 throw processException(e);
2549 }
2550 finally {
2551 FinderCacheUtil.clearCache("Users_Roles");
2552 }
2553 }
2554
2555 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2556 throws SystemException {
2557 try {
2558 clearUsers.clear(pk);
2559
2560 for (com.liferay.portal.model.User user : users) {
2561 addUser.add(pk, user.getPrimaryKey());
2562 }
2563 }
2564 catch (Exception e) {
2565 throw processException(e);
2566 }
2567 finally {
2568 FinderCacheUtil.clearCache("Users_Roles");
2569 }
2570 }
2571
2572 public void afterPropertiesSet() {
2573 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2574 com.liferay.portal.util.PropsUtil.get(
2575 "value.object.listener.com.liferay.portal.model.Role")));
2576
2577 if (listenerClassNames.length > 0) {
2578 try {
2579 List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
2580
2581 for (String listenerClassName : listenerClassNames) {
2582 listenersList.add((ModelListener<Role>)Class.forName(
2583 listenerClassName).newInstance());
2584 }
2585
2586 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2587 }
2588 catch (Exception e) {
2589 _log.error(e);
2590 }
2591 }
2592
2593 containsGroup = new ContainsGroup(this);
2594
2595 addGroup = new AddGroup(this);
2596 clearGroups = new ClearGroups(this);
2597 removeGroup = new RemoveGroup(this);
2598
2599 containsPermission = new ContainsPermission(this);
2600
2601 addPermission = new AddPermission(this);
2602 clearPermissions = new ClearPermissions(this);
2603 removePermission = new RemovePermission(this);
2604
2605 containsUser = new ContainsUser(this);
2606
2607 addUser = new AddUser(this);
2608 clearUsers = new ClearUsers(this);
2609 removeUser = new RemoveUser(this);
2610 }
2611
2612 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
2613 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
2614 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
2615 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
2616 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
2617 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
2618 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
2619 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
2620 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
2621 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
2622 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
2623 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
2624 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
2625 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
2626 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
2627 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
2628 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
2629 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
2630 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
2631 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
2632 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
2633 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
2634 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
2635 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
2636 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
2637 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
2638 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
2639 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
2640 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
2641 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
2642 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
2643 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2644 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
2645 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
2646 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
2647 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
2648 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
2649 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
2650 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
2651 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2652 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
2653 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
2654 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
2655 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
2656 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
2657 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
2658 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
2659 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
2660 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
2661 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
2662 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
2663 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
2664 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
2665 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
2666 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
2667 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
2668 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
2669 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
2670 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2671 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2672 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
2673 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
2674 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
2675 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
2676 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
2677 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
2678 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
2679 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
2680 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
2681 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
2682 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
2683 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
2684 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
2685 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
2686 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2687 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2688 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
2689 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
2690 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
2691 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
2692 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
2693 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
2694 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
2695 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
2696 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
2697 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
2698 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
2699 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
2700 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
2701 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
2702 protected ContainsGroup containsGroup;
2703 protected AddGroup addGroup;
2704 protected ClearGroups clearGroups;
2705 protected RemoveGroup removeGroup;
2706 protected ContainsPermission containsPermission;
2707 protected AddPermission addPermission;
2708 protected ClearPermissions clearPermissions;
2709 protected RemovePermission removePermission;
2710 protected ContainsUser containsUser;
2711 protected AddUser addUser;
2712 protected ClearUsers clearUsers;
2713 protected RemoveUser removeUser;
2714
2715 protected class ContainsGroup {
2716 protected ContainsGroup(RolePersistenceImpl persistenceImpl) {
2717 super();
2718
2719 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2720 _SQL_CONTAINSGROUP,
2721 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2722 }
2723
2724 protected boolean contains(long roleId, long groupId) {
2725 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2726 new Long(roleId), new Long(groupId)
2727 });
2728
2729 if (results.size() > 0) {
2730 Integer count = results.get(0);
2731
2732 if (count.intValue() > 0) {
2733 return true;
2734 }
2735 }
2736
2737 return false;
2738 }
2739
2740 private MappingSqlQuery _mappingSqlQuery;
2741 }
2742
2743 protected class AddGroup {
2744 protected AddGroup(RolePersistenceImpl persistenceImpl) {
2745 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2746 "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)",
2747 new int[] { Types.BIGINT, Types.BIGINT });
2748 _persistenceImpl = persistenceImpl;
2749 }
2750
2751 protected void add(long roleId, long groupId) throws SystemException {
2752 if (!_persistenceImpl.containsGroup.contains(roleId, groupId)) {
2753 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2754
2755 for (ModelListener<Role> listener : listeners) {
2756 listener.onBeforeAddAssociation(roleId,
2757 com.liferay.portal.model.Group.class.getName(), groupId);
2758 }
2759
2760 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2761 listener.onBeforeAddAssociation(groupId,
2762 Role.class.getName(), roleId);
2763 }
2764
2765 _sqlUpdate.update(new Object[] {
2766 new Long(roleId), new Long(groupId)
2767 });
2768
2769 for (ModelListener<Role> listener : listeners) {
2770 listener.onAfterAddAssociation(roleId,
2771 com.liferay.portal.model.Group.class.getName(), groupId);
2772 }
2773
2774 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2775 listener.onAfterAddAssociation(groupId,
2776 Role.class.getName(), roleId);
2777 }
2778 }
2779 }
2780
2781 private SqlUpdate _sqlUpdate;
2782 private RolePersistenceImpl _persistenceImpl;
2783 }
2784
2785 protected class ClearGroups {
2786 protected ClearGroups(RolePersistenceImpl persistenceImpl) {
2787 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2788 "DELETE FROM Groups_Roles WHERE roleId = ?",
2789 new int[] { Types.BIGINT });
2790 }
2791
2792 protected void clear(long roleId) throws SystemException {
2793 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2794
2795 List<com.liferay.portal.model.Group> groups = null;
2796
2797 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2798 groups = getGroups(roleId);
2799
2800 for (com.liferay.portal.model.Group group : groups) {
2801 for (ModelListener<Role> listener : listeners) {
2802 listener.onBeforeRemoveAssociation(roleId,
2803 com.liferay.portal.model.Group.class.getName(),
2804 group.getPrimaryKey());
2805 }
2806
2807 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2808 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2809 Role.class.getName(), roleId);
2810 }
2811 }
2812 }
2813
2814 _sqlUpdate.update(new Object[] { new Long(roleId) });
2815
2816 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2817 for (com.liferay.portal.model.Group group : groups) {
2818 for (ModelListener<Role> listener : listeners) {
2819 listener.onAfterRemoveAssociation(roleId,
2820 com.liferay.portal.model.Group.class.getName(),
2821 group.getPrimaryKey());
2822 }
2823
2824 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2825 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2826 Role.class.getName(), roleId);
2827 }
2828 }
2829 }
2830 }
2831
2832 private SqlUpdate _sqlUpdate;
2833 }
2834
2835 protected class RemoveGroup {
2836 protected RemoveGroup(RolePersistenceImpl persistenceImpl) {
2837 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2838 "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
2839 new int[] { Types.BIGINT, Types.BIGINT });
2840 _persistenceImpl = persistenceImpl;
2841 }
2842
2843 protected void remove(long roleId, long groupId)
2844 throws SystemException {
2845 if (_persistenceImpl.containsGroup.contains(roleId, groupId)) {
2846 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2847
2848 for (ModelListener<Role> listener : listeners) {
2849 listener.onBeforeRemoveAssociation(roleId,
2850 com.liferay.portal.model.Group.class.getName(), groupId);
2851 }
2852
2853 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2854 listener.onBeforeRemoveAssociation(groupId,
2855 Role.class.getName(), roleId);
2856 }
2857
2858 _sqlUpdate.update(new Object[] {
2859 new Long(roleId), new Long(groupId)
2860 });
2861
2862 for (ModelListener<Role> listener : listeners) {
2863 listener.onAfterRemoveAssociation(roleId,
2864 com.liferay.portal.model.Group.class.getName(), groupId);
2865 }
2866
2867 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2868 listener.onAfterRemoveAssociation(groupId,
2869 Role.class.getName(), roleId);
2870 }
2871 }
2872 }
2873
2874 private SqlUpdate _sqlUpdate;
2875 private RolePersistenceImpl _persistenceImpl;
2876 }
2877
2878 protected class ContainsPermission {
2879 protected ContainsPermission(RolePersistenceImpl persistenceImpl) {
2880 super();
2881
2882 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2883 _SQL_CONTAINSPERMISSION,
2884 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2885 }
2886
2887 protected boolean contains(long roleId, long permissionId) {
2888 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2889 new Long(roleId), new Long(permissionId)
2890 });
2891
2892 if (results.size() > 0) {
2893 Integer count = results.get(0);
2894
2895 if (count.intValue() > 0) {
2896 return true;
2897 }
2898 }
2899
2900 return false;
2901 }
2902
2903 private MappingSqlQuery _mappingSqlQuery;
2904 }
2905
2906 protected class AddPermission {
2907 protected AddPermission(RolePersistenceImpl persistenceImpl) {
2908 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2909 "INSERT INTO Roles_Permissions (roleId, permissionId) VALUES (?, ?)",
2910 new int[] { Types.BIGINT, Types.BIGINT });
2911 _persistenceImpl = persistenceImpl;
2912 }
2913
2914 protected void add(long roleId, long permissionId)
2915 throws SystemException {
2916 if (!_persistenceImpl.containsPermission.contains(roleId,
2917 permissionId)) {
2918 ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
2919 permissionPersistence.getListeners();
2920
2921 for (ModelListener<Role> listener : listeners) {
2922 listener.onBeforeAddAssociation(roleId,
2923 com.liferay.portal.model.Permission.class.getName(),
2924 permissionId);
2925 }
2926
2927 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
2928 listener.onBeforeAddAssociation(permissionId,
2929 Role.class.getName(), roleId);
2930 }
2931
2932 _sqlUpdate.update(new Object[] {
2933 new Long(roleId), new Long(permissionId)
2934 });
2935
2936 for (ModelListener<Role> listener : listeners) {
2937 listener.onAfterAddAssociation(roleId,
2938 com.liferay.portal.model.Permission.class.getName(),
2939 permissionId);
2940 }
2941
2942 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
2943 listener.onAfterAddAssociation(permissionId,
2944 Role.class.getName(), roleId);
2945 }
2946 }
2947 }
2948
2949 private SqlUpdate _sqlUpdate;
2950 private RolePersistenceImpl _persistenceImpl;
2951 }
2952
2953 protected class ClearPermissions {
2954 protected ClearPermissions(RolePersistenceImpl persistenceImpl) {
2955 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2956 "DELETE FROM Roles_Permissions WHERE roleId = ?",
2957 new int[] { Types.BIGINT });
2958 }
2959
2960 protected void clear(long roleId) throws SystemException {
2961 ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
2962 permissionPersistence.getListeners();
2963
2964 List<com.liferay.portal.model.Permission> permissions = null;
2965
2966 if ((listeners.length > 0) || (permissionListeners.length > 0)) {
2967 permissions = getPermissions(roleId);
2968
2969 for (com.liferay.portal.model.Permission permission : permissions) {
2970 for (ModelListener<Role> listener : listeners) {
2971 listener.onBeforeRemoveAssociation(roleId,
2972 com.liferay.portal.model.Permission.class.getName(),
2973 permission.getPrimaryKey());
2974 }
2975
2976 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
2977 listener.onBeforeRemoveAssociation(permission.getPrimaryKey(),
2978 Role.class.getName(), roleId);
2979 }
2980 }
2981 }
2982
2983 _sqlUpdate.update(new Object[] { new Long(roleId) });
2984
2985 if ((listeners.length > 0) || (permissionListeners.length > 0)) {
2986 for (com.liferay.portal.model.Permission permission : permissions) {
2987 for (ModelListener<Role> listener : listeners) {
2988 listener.onAfterRemoveAssociation(roleId,
2989 com.liferay.portal.model.Permission.class.getName(),
2990 permission.getPrimaryKey());
2991 }
2992
2993 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
2994 listener.onBeforeRemoveAssociation(permission.getPrimaryKey(),
2995 Role.class.getName(), roleId);
2996 }
2997 }
2998 }
2999 }
3000
3001 private SqlUpdate _sqlUpdate;
3002 }
3003
3004 protected class RemovePermission {
3005 protected RemovePermission(RolePersistenceImpl persistenceImpl) {
3006 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3007 "DELETE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?",
3008 new int[] { Types.BIGINT, Types.BIGINT });
3009 _persistenceImpl = persistenceImpl;
3010 }
3011
3012 protected void remove(long roleId, long permissionId)
3013 throws SystemException {
3014 if (_persistenceImpl.containsPermission.contains(roleId,
3015 permissionId)) {
3016 ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
3017 permissionPersistence.getListeners();
3018
3019 for (ModelListener<Role> listener : listeners) {
3020 listener.onBeforeRemoveAssociation(roleId,
3021 com.liferay.portal.model.Permission.class.getName(),
3022 permissionId);
3023 }
3024
3025 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
3026 listener.onBeforeRemoveAssociation(permissionId,
3027 Role.class.getName(), roleId);
3028 }
3029
3030 _sqlUpdate.update(new Object[] {
3031 new Long(roleId), new Long(permissionId)
3032 });
3033
3034 for (ModelListener<Role> listener : listeners) {
3035 listener.onAfterRemoveAssociation(roleId,
3036 com.liferay.portal.model.Permission.class.getName(),
3037 permissionId);
3038 }
3039
3040 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
3041 listener.onAfterRemoveAssociation(permissionId,
3042 Role.class.getName(), roleId);
3043 }
3044 }
3045 }
3046
3047 private SqlUpdate _sqlUpdate;
3048 private RolePersistenceImpl _persistenceImpl;
3049 }
3050
3051 protected class ContainsUser {
3052 protected ContainsUser(RolePersistenceImpl persistenceImpl) {
3053 super();
3054
3055 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3056 _SQL_CONTAINSUSER,
3057 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3058 }
3059
3060 protected boolean contains(long roleId, long userId) {
3061 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3062 new Long(roleId), new Long(userId)
3063 });
3064
3065 if (results.size() > 0) {
3066 Integer count = results.get(0);
3067
3068 if (count.intValue() > 0) {
3069 return true;
3070 }
3071 }
3072
3073 return false;
3074 }
3075
3076 private MappingSqlQuery _mappingSqlQuery;
3077 }
3078
3079 protected class AddUser {
3080 protected AddUser(RolePersistenceImpl persistenceImpl) {
3081 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3082 "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)",
3083 new int[] { Types.BIGINT, Types.BIGINT });
3084 _persistenceImpl = persistenceImpl;
3085 }
3086
3087 protected void add(long roleId, long userId) throws SystemException {
3088 if (!_persistenceImpl.containsUser.contains(roleId, userId)) {
3089 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3090
3091 for (ModelListener<Role> listener : listeners) {
3092 listener.onBeforeAddAssociation(roleId,
3093 com.liferay.portal.model.User.class.getName(), userId);
3094 }
3095
3096 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3097 listener.onBeforeAddAssociation(userId,
3098 Role.class.getName(), roleId);
3099 }
3100
3101 _sqlUpdate.update(new Object[] {
3102 new Long(roleId), new Long(userId)
3103 });
3104
3105 for (ModelListener<Role> listener : listeners) {
3106 listener.onAfterAddAssociation(roleId,
3107 com.liferay.portal.model.User.class.getName(), userId);
3108 }
3109
3110 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3111 listener.onAfterAddAssociation(userId,
3112 Role.class.getName(), roleId);
3113 }
3114 }
3115 }
3116
3117 private SqlUpdate _sqlUpdate;
3118 private RolePersistenceImpl _persistenceImpl;
3119 }
3120
3121 protected class ClearUsers {
3122 protected ClearUsers(RolePersistenceImpl persistenceImpl) {
3123 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3124 "DELETE FROM Users_Roles WHERE roleId = ?",
3125 new int[] { Types.BIGINT });
3126 }
3127
3128 protected void clear(long roleId) throws SystemException {
3129 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3130
3131 List<com.liferay.portal.model.User> users = null;
3132
3133 if ((listeners.length > 0) || (userListeners.length > 0)) {
3134 users = getUsers(roleId);
3135
3136 for (com.liferay.portal.model.User user : users) {
3137 for (ModelListener<Role> listener : listeners) {
3138 listener.onBeforeRemoveAssociation(roleId,
3139 com.liferay.portal.model.User.class.getName(),
3140 user.getPrimaryKey());
3141 }
3142
3143 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3144 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
3145 Role.class.getName(), roleId);
3146 }
3147 }
3148 }
3149
3150 _sqlUpdate.update(new Object[] { new Long(roleId) });
3151
3152 if ((listeners.length > 0) || (userListeners.length > 0)) {
3153 for (com.liferay.portal.model.User user : users) {
3154 for (ModelListener<Role> listener : listeners) {
3155 listener.onAfterRemoveAssociation(roleId,
3156 com.liferay.portal.model.User.class.getName(),
3157 user.getPrimaryKey());
3158 }
3159
3160 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3161 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
3162 Role.class.getName(), roleId);
3163 }
3164 }
3165 }
3166 }
3167
3168 private SqlUpdate _sqlUpdate;
3169 }
3170
3171 protected class RemoveUser {
3172 protected RemoveUser(RolePersistenceImpl persistenceImpl) {
3173 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3174 "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?",
3175 new int[] { Types.BIGINT, Types.BIGINT });
3176 _persistenceImpl = persistenceImpl;
3177 }
3178
3179 protected void remove(long roleId, long userId)
3180 throws SystemException {
3181 if (_persistenceImpl.containsUser.contains(roleId, userId)) {
3182 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3183
3184 for (ModelListener<Role> listener : listeners) {
3185 listener.onBeforeRemoveAssociation(roleId,
3186 com.liferay.portal.model.User.class.getName(), userId);
3187 }
3188
3189 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3190 listener.onBeforeRemoveAssociation(userId,
3191 Role.class.getName(), roleId);
3192 }
3193
3194 _sqlUpdate.update(new Object[] {
3195 new Long(roleId), new Long(userId)
3196 });
3197
3198 for (ModelListener<Role> listener : listeners) {
3199 listener.onAfterRemoveAssociation(roleId,
3200 com.liferay.portal.model.User.class.getName(), userId);
3201 }
3202
3203 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3204 listener.onAfterRemoveAssociation(userId,
3205 Role.class.getName(), roleId);
3206 }
3207 }
3208 }
3209
3210 private SqlUpdate _sqlUpdate;
3211 private RolePersistenceImpl _persistenceImpl;
3212 }
3213
3214 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
3215 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
3216 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ? AND groupId = ?";
3217 private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Roles_Permissions ON (Roles_Permissions.permissionId = Permission_.permissionId) WHERE (Roles_Permissions.roleId = ?)";
3218 private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ?";
3219 private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?";
3220 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
3221 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
3222 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ? AND userId = ?";
3223 private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
3224}