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