001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchRoleException;
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028 import com.liferay.portal.kernel.dao.orm.FinderPath;
029 import com.liferay.portal.kernel.dao.orm.Query;
030 import com.liferay.portal.kernel.dao.orm.QueryPos;
031 import com.liferay.portal.kernel.dao.orm.QueryUtil;
032 import com.liferay.portal.kernel.dao.orm.SQLQuery;
033 import com.liferay.portal.kernel.dao.orm.Session;
034 import com.liferay.portal.kernel.exception.SystemException;
035 import com.liferay.portal.kernel.log.Log;
036 import com.liferay.portal.kernel.log.LogFactoryUtil;
037 import com.liferay.portal.kernel.util.GetterUtil;
038 import com.liferay.portal.kernel.util.InstanceFactory;
039 import com.liferay.portal.kernel.util.OrderByComparator;
040 import com.liferay.portal.kernel.util.SetUtil;
041 import com.liferay.portal.kernel.util.StringBundler;
042 import com.liferay.portal.kernel.util.StringPool;
043 import com.liferay.portal.kernel.util.StringUtil;
044 import com.liferay.portal.kernel.util.Validator;
045 import com.liferay.portal.model.CacheModel;
046 import com.liferay.portal.model.ModelListener;
047 import com.liferay.portal.model.Role;
048 import com.liferay.portal.model.impl.RoleImpl;
049 import com.liferay.portal.model.impl.RoleModelImpl;
050 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
051 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
052
053 import java.io.Serializable;
054
055 import java.util.ArrayList;
056 import java.util.Collections;
057 import java.util.List;
058 import java.util.Set;
059
060
072 public class RolePersistenceImpl extends BasePersistenceImpl<Role>
073 implements RolePersistence {
074
079 public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
080 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List1";
082 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083 ".List2";
084 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
085 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
086 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
088 new String[] {
089 Long.class.getName(),
090
091 "java.lang.Integer", "java.lang.Integer",
092 "com.liferay.portal.kernel.util.OrderByComparator"
093 });
094 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
095 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
096 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
098 new String[] { Long.class.getName() },
099 RoleModelImpl.COMPANYID_COLUMN_BITMASK);
100 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
101 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
103 new String[] { Long.class.getName() });
104 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
105 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
106 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
107 new String[] {
108 String.class.getName(),
109
110 "java.lang.Integer", "java.lang.Integer",
111 "com.liferay.portal.kernel.util.OrderByComparator"
112 });
113 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
114 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
116 new String[] { String.class.getName() },
117 RoleModelImpl.NAME_COLUMN_BITMASK);
118 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
119 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
121 new String[] { String.class.getName() });
122 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
123 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
124 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype",
125 new String[] {
126 String.class.getName(),
127
128 "java.lang.Integer", "java.lang.Integer",
129 "com.liferay.portal.kernel.util.OrderByComparator"
130 });
131 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE =
132 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
133 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
134 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype",
135 new String[] { String.class.getName() },
136 RoleModelImpl.SUBTYPE_COLUMN_BITMASK);
137 public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
138 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
139 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype",
140 new String[] { String.class.getName() });
141 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
142 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
143 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
144 new String[] { Long.class.getName(), String.class.getName() },
145 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
146 RoleModelImpl.NAME_COLUMN_BITMASK);
147 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
148 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
149 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
150 new String[] { Long.class.getName(), String.class.getName() });
151 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
152 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
153 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
154 new String[] {
155 Integer.class.getName(), String.class.getName(),
156
157 "java.lang.Integer", "java.lang.Integer",
158 "com.liferay.portal.kernel.util.OrderByComparator"
159 });
160 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
161 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
162 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
163 new String[] { Integer.class.getName(), String.class.getName() },
164 RoleModelImpl.TYPE_COLUMN_BITMASK |
165 RoleModelImpl.SUBTYPE_COLUMN_BITMASK);
166 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
167 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
168 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
169 new String[] { Integer.class.getName(), String.class.getName() });
170 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
171 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
172 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
173 new String[] {
174 Long.class.getName(), Long.class.getName(), Long.class.getName()
175 },
176 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
177 RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
178 RoleModelImpl.CLASSPK_COLUMN_BITMASK);
179 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
180 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
181 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
182 new String[] {
183 Long.class.getName(), Long.class.getName(), Long.class.getName()
184 });
185 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
186 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
187 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
188 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
189 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
190 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
191 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
192 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
193 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
194
195
200 public void cacheResult(Role role) {
201 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
202 RoleImpl.class, role.getPrimaryKey(), role);
203
204 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
205 new Object[] { Long.valueOf(role.getCompanyId()), role.getName() },
206 role);
207
208 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
209 new Object[] {
210 Long.valueOf(role.getCompanyId()),
211 Long.valueOf(role.getClassNameId()),
212 Long.valueOf(role.getClassPK())
213 }, role);
214
215 role.resetOriginalValues();
216 }
217
218
223 public void cacheResult(List<Role> roles) {
224 for (Role role : roles) {
225 if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
226 RoleImpl.class, role.getPrimaryKey()) == null) {
227 cacheResult(role);
228 }
229 else {
230 role.resetOriginalValues();
231 }
232 }
233 }
234
235
242 @Override
243 public void clearCache() {
244 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
245 CacheRegistryUtil.clear(RoleImpl.class.getName());
246 }
247
248 EntityCacheUtil.clearCache(RoleImpl.class.getName());
249
250 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
251 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
252 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
253 }
254
255
262 @Override
263 public void clearCache(Role role) {
264 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
265 RoleImpl.class, role.getPrimaryKey());
266
267 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
268 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
269
270 clearUniqueFindersCache(role);
271 }
272
273 @Override
274 public void clearCache(List<Role> roles) {
275 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
276 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
277
278 for (Role role : roles) {
279 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
280 RoleImpl.class, role.getPrimaryKey());
281
282 clearUniqueFindersCache(role);
283 }
284 }
285
286 protected void clearUniqueFindersCache(Role role) {
287 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
288 new Object[] { Long.valueOf(role.getCompanyId()), role.getName() });
289
290 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
291 new Object[] {
292 Long.valueOf(role.getCompanyId()),
293 Long.valueOf(role.getClassNameId()),
294 Long.valueOf(role.getClassPK())
295 });
296 }
297
298
304 public Role create(long roleId) {
305 Role role = new RoleImpl();
306
307 role.setNew(true);
308 role.setPrimaryKey(roleId);
309
310 return role;
311 }
312
313
321 public Role remove(long roleId) throws NoSuchRoleException, SystemException {
322 return remove(Long.valueOf(roleId));
323 }
324
325
333 @Override
334 public Role remove(Serializable primaryKey)
335 throws NoSuchRoleException, SystemException {
336 Session session = null;
337
338 try {
339 session = openSession();
340
341 Role role = (Role)session.get(RoleImpl.class, primaryKey);
342
343 if (role == null) {
344 if (_log.isWarnEnabled()) {
345 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
346 }
347
348 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
349 primaryKey);
350 }
351
352 return remove(role);
353 }
354 catch (NoSuchRoleException nsee) {
355 throw nsee;
356 }
357 catch (Exception e) {
358 throw processException(e);
359 }
360 finally {
361 closeSession(session);
362 }
363 }
364
365 @Override
366 protected Role removeImpl(Role role) throws SystemException {
367 role = toUnwrappedModel(role);
368
369 try {
370 clearGroups.clear(role.getPrimaryKey());
371 }
372 catch (Exception e) {
373 throw processException(e);
374 }
375 finally {
376 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
377 }
378
379 try {
380 clearUsers.clear(role.getPrimaryKey());
381 }
382 catch (Exception e) {
383 throw processException(e);
384 }
385 finally {
386 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
387 }
388
389 Session session = null;
390
391 try {
392 session = openSession();
393
394 if (role.isCachedModel()) {
395 role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj());
396 }
397
398 session.delete(role);
399 }
400 catch (Exception e) {
401 throw processException(e);
402 }
403 finally {
404 closeSession(session);
405 }
406
407 clearCache(role);
408
409 return role;
410 }
411
412 @Override
413 public Role updateImpl(com.liferay.portal.model.Role role)
414 throws SystemException {
415 role = toUnwrappedModel(role);
416
417 boolean isNew = role.isNew();
418
419 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
420
421 Session session = null;
422
423 try {
424 session = openSession();
425
426 if (role.isNew()) {
427 session.save(role);
428
429 role.setNew(false);
430 }
431 else {
432 session.merge(role);
433 }
434 }
435 catch (Exception e) {
436 throw processException(e);
437 }
438 finally {
439 closeSession(session);
440 }
441
442 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
443
444 if (isNew || !RoleModelImpl.COLUMN_BITMASK_ENABLED) {
445 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
446 }
447
448 else {
449 if ((roleModelImpl.getColumnBitmask() &
450 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
451 Object[] args = new Object[] {
452 Long.valueOf(roleModelImpl.getOriginalCompanyId())
453 };
454
455 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
456 args);
457 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
458 args);
459
460 args = new Object[] { Long.valueOf(roleModelImpl.getCompanyId()) };
461
462 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
463 args);
464 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
465 args);
466 }
467
468 if ((roleModelImpl.getColumnBitmask() &
469 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
470 Object[] args = new Object[] { roleModelImpl.getOriginalName() };
471
472 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
473 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
474 args);
475
476 args = new Object[] { roleModelImpl.getName() };
477
478 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
479 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
480 args);
481 }
482
483 if ((roleModelImpl.getColumnBitmask() &
484 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) {
485 Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() };
486
487 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
488 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
489 args);
490
491 args = new Object[] { roleModelImpl.getSubtype() };
492
493 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
494 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
495 args);
496 }
497
498 if ((roleModelImpl.getColumnBitmask() &
499 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
500 Object[] args = new Object[] {
501 Integer.valueOf(roleModelImpl.getOriginalType()),
502
503 roleModelImpl.getOriginalSubtype()
504 };
505
506 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
507 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
508 args);
509
510 args = new Object[] {
511 Integer.valueOf(roleModelImpl.getType()),
512
513 roleModelImpl.getSubtype()
514 };
515
516 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
517 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
518 args);
519 }
520 }
521
522 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
523 RoleImpl.class, role.getPrimaryKey(), role);
524
525 if (isNew) {
526 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
527 new Object[] { Long.valueOf(role.getCompanyId()), role.getName() },
528 role);
529
530 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
531 new Object[] {
532 Long.valueOf(role.getCompanyId()),
533 Long.valueOf(role.getClassNameId()),
534 Long.valueOf(role.getClassPK())
535 }, role);
536 }
537 else {
538 if ((roleModelImpl.getColumnBitmask() &
539 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
540 Object[] args = new Object[] {
541 Long.valueOf(roleModelImpl.getOriginalCompanyId()),
542
543 roleModelImpl.getOriginalName()
544 };
545
546 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
547
548 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
549
550 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
551 new Object[] {
552 Long.valueOf(role.getCompanyId()),
553
554 role.getName()
555 }, role);
556 }
557
558 if ((roleModelImpl.getColumnBitmask() &
559 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
560 Object[] args = new Object[] {
561 Long.valueOf(roleModelImpl.getOriginalCompanyId()),
562 Long.valueOf(roleModelImpl.getOriginalClassNameId()),
563 Long.valueOf(roleModelImpl.getOriginalClassPK())
564 };
565
566 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
567
568 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
569
570 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
571 new Object[] {
572 Long.valueOf(role.getCompanyId()),
573 Long.valueOf(role.getClassNameId()),
574 Long.valueOf(role.getClassPK())
575 }, role);
576 }
577 }
578
579 return role;
580 }
581
582 protected Role toUnwrappedModel(Role role) {
583 if (role instanceof RoleImpl) {
584 return role;
585 }
586
587 RoleImpl roleImpl = new RoleImpl();
588
589 roleImpl.setNew(role.isNew());
590 roleImpl.setPrimaryKey(role.getPrimaryKey());
591
592 roleImpl.setRoleId(role.getRoleId());
593 roleImpl.setCompanyId(role.getCompanyId());
594 roleImpl.setClassNameId(role.getClassNameId());
595 roleImpl.setClassPK(role.getClassPK());
596 roleImpl.setName(role.getName());
597 roleImpl.setTitle(role.getTitle());
598 roleImpl.setDescription(role.getDescription());
599 roleImpl.setType(role.getType());
600 roleImpl.setSubtype(role.getSubtype());
601
602 return roleImpl;
603 }
604
605
613 @Override
614 public Role findByPrimaryKey(Serializable primaryKey)
615 throws NoSuchModelException, SystemException {
616 return findByPrimaryKey(((Long)primaryKey).longValue());
617 }
618
619
627 public Role findByPrimaryKey(long roleId)
628 throws NoSuchRoleException, SystemException {
629 Role role = fetchByPrimaryKey(roleId);
630
631 if (role == null) {
632 if (_log.isWarnEnabled()) {
633 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + roleId);
634 }
635
636 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
637 roleId);
638 }
639
640 return role;
641 }
642
643
650 @Override
651 public Role fetchByPrimaryKey(Serializable primaryKey)
652 throws SystemException {
653 return fetchByPrimaryKey(((Long)primaryKey).longValue());
654 }
655
656
663 public Role fetchByPrimaryKey(long roleId) throws SystemException {
664 Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
665 RoleImpl.class, roleId);
666
667 if (role == _nullRole) {
668 return null;
669 }
670
671 if (role == null) {
672 Session session = null;
673
674 boolean hasException = false;
675
676 try {
677 session = openSession();
678
679 role = (Role)session.get(RoleImpl.class, Long.valueOf(roleId));
680 }
681 catch (Exception e) {
682 hasException = true;
683
684 throw processException(e);
685 }
686 finally {
687 if (role != null) {
688 cacheResult(role);
689 }
690 else if (!hasException) {
691 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
692 RoleImpl.class, roleId, _nullRole);
693 }
694
695 closeSession(session);
696 }
697 }
698
699 return role;
700 }
701
702
709 public List<Role> findByCompanyId(long companyId) throws SystemException {
710 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
711 null);
712 }
713
714
727 public List<Role> findByCompanyId(long companyId, int start, int end)
728 throws SystemException {
729 return findByCompanyId(companyId, start, end, null);
730 }
731
732
746 public List<Role> findByCompanyId(long companyId, int start, int end,
747 OrderByComparator orderByComparator) throws SystemException {
748 FinderPath finderPath = null;
749 Object[] finderArgs = null;
750
751 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
752 (orderByComparator == null)) {
753 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
754 finderArgs = new Object[] { companyId };
755 }
756 else {
757 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
758 finderArgs = new Object[] { companyId, start, end, orderByComparator };
759 }
760
761 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
762 finderArgs, this);
763
764 if ((list != null) && !list.isEmpty()) {
765 for (Role role : list) {
766 if ((companyId != role.getCompanyId())) {
767 list = null;
768
769 break;
770 }
771 }
772 }
773
774 if (list == null) {
775 StringBundler query = null;
776
777 if (orderByComparator != null) {
778 query = new StringBundler(3 +
779 (orderByComparator.getOrderByFields().length * 3));
780 }
781 else {
782 query = new StringBundler(3);
783 }
784
785 query.append(_SQL_SELECT_ROLE_WHERE);
786
787 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
788
789 if (orderByComparator != null) {
790 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
791 orderByComparator);
792 }
793
794 else {
795 query.append(RoleModelImpl.ORDER_BY_JPQL);
796 }
797
798 String sql = query.toString();
799
800 Session session = null;
801
802 try {
803 session = openSession();
804
805 Query q = session.createQuery(sql);
806
807 QueryPos qPos = QueryPos.getInstance(q);
808
809 qPos.add(companyId);
810
811 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
812 }
813 catch (Exception e) {
814 throw processException(e);
815 }
816 finally {
817 if (list == null) {
818 FinderCacheUtil.removeResult(finderPath, finderArgs);
819 }
820 else {
821 cacheResult(list);
822
823 FinderCacheUtil.putResult(finderPath, finderArgs, list);
824 }
825
826 closeSession(session);
827 }
828 }
829
830 return list;
831 }
832
833
842 public Role findByCompanyId_First(long companyId,
843 OrderByComparator orderByComparator)
844 throws NoSuchRoleException, SystemException {
845 Role role = fetchByCompanyId_First(companyId, orderByComparator);
846
847 if (role != null) {
848 return role;
849 }
850
851 StringBundler msg = new StringBundler(4);
852
853 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
854
855 msg.append("companyId=");
856 msg.append(companyId);
857
858 msg.append(StringPool.CLOSE_CURLY_BRACE);
859
860 throw new NoSuchRoleException(msg.toString());
861 }
862
863
871 public Role fetchByCompanyId_First(long companyId,
872 OrderByComparator orderByComparator) throws SystemException {
873 List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
874
875 if (!list.isEmpty()) {
876 return list.get(0);
877 }
878
879 return null;
880 }
881
882
891 public Role findByCompanyId_Last(long companyId,
892 OrderByComparator orderByComparator)
893 throws NoSuchRoleException, SystemException {
894 Role role = fetchByCompanyId_Last(companyId, orderByComparator);
895
896 if (role != null) {
897 return role;
898 }
899
900 StringBundler msg = new StringBundler(4);
901
902 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
903
904 msg.append("companyId=");
905 msg.append(companyId);
906
907 msg.append(StringPool.CLOSE_CURLY_BRACE);
908
909 throw new NoSuchRoleException(msg.toString());
910 }
911
912
920 public Role fetchByCompanyId_Last(long companyId,
921 OrderByComparator orderByComparator) throws SystemException {
922 int count = countByCompanyId(companyId);
923
924 List<Role> list = findByCompanyId(companyId, count - 1, count,
925 orderByComparator);
926
927 if (!list.isEmpty()) {
928 return list.get(0);
929 }
930
931 return null;
932 }
933
934
944 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
945 OrderByComparator orderByComparator)
946 throws NoSuchRoleException, SystemException {
947 Role role = findByPrimaryKey(roleId);
948
949 Session session = null;
950
951 try {
952 session = openSession();
953
954 Role[] array = new RoleImpl[3];
955
956 array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
957 orderByComparator, true);
958
959 array[1] = role;
960
961 array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
962 orderByComparator, false);
963
964 return array;
965 }
966 catch (Exception e) {
967 throw processException(e);
968 }
969 finally {
970 closeSession(session);
971 }
972 }
973
974 protected Role getByCompanyId_PrevAndNext(Session session, Role role,
975 long companyId, OrderByComparator orderByComparator, boolean previous) {
976 StringBundler query = null;
977
978 if (orderByComparator != null) {
979 query = new StringBundler(6 +
980 (orderByComparator.getOrderByFields().length * 6));
981 }
982 else {
983 query = new StringBundler(3);
984 }
985
986 query.append(_SQL_SELECT_ROLE_WHERE);
987
988 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
989
990 if (orderByComparator != null) {
991 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
992
993 if (orderByConditionFields.length > 0) {
994 query.append(WHERE_AND);
995 }
996
997 for (int i = 0; i < orderByConditionFields.length; i++) {
998 query.append(_ORDER_BY_ENTITY_ALIAS);
999 query.append(orderByConditionFields[i]);
1000
1001 if ((i + 1) < orderByConditionFields.length) {
1002 if (orderByComparator.isAscending() ^ previous) {
1003 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1004 }
1005 else {
1006 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1007 }
1008 }
1009 else {
1010 if (orderByComparator.isAscending() ^ previous) {
1011 query.append(WHERE_GREATER_THAN);
1012 }
1013 else {
1014 query.append(WHERE_LESSER_THAN);
1015 }
1016 }
1017 }
1018
1019 query.append(ORDER_BY_CLAUSE);
1020
1021 String[] orderByFields = orderByComparator.getOrderByFields();
1022
1023 for (int i = 0; i < orderByFields.length; i++) {
1024 query.append(_ORDER_BY_ENTITY_ALIAS);
1025 query.append(orderByFields[i]);
1026
1027 if ((i + 1) < orderByFields.length) {
1028 if (orderByComparator.isAscending() ^ previous) {
1029 query.append(ORDER_BY_ASC_HAS_NEXT);
1030 }
1031 else {
1032 query.append(ORDER_BY_DESC_HAS_NEXT);
1033 }
1034 }
1035 else {
1036 if (orderByComparator.isAscending() ^ previous) {
1037 query.append(ORDER_BY_ASC);
1038 }
1039 else {
1040 query.append(ORDER_BY_DESC);
1041 }
1042 }
1043 }
1044 }
1045
1046 else {
1047 query.append(RoleModelImpl.ORDER_BY_JPQL);
1048 }
1049
1050 String sql = query.toString();
1051
1052 Query q = session.createQuery(sql);
1053
1054 q.setFirstResult(0);
1055 q.setMaxResults(2);
1056
1057 QueryPos qPos = QueryPos.getInstance(q);
1058
1059 qPos.add(companyId);
1060
1061 if (orderByComparator != null) {
1062 Object[] values = orderByComparator.getOrderByConditionValues(role);
1063
1064 for (Object value : values) {
1065 qPos.add(value);
1066 }
1067 }
1068
1069 List<Role> list = q.list();
1070
1071 if (list.size() == 2) {
1072 return list.get(1);
1073 }
1074 else {
1075 return null;
1076 }
1077 }
1078
1079
1086 public List<Role> filterFindByCompanyId(long companyId)
1087 throws SystemException {
1088 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
1089 QueryUtil.ALL_POS, null);
1090 }
1091
1092
1105 public List<Role> filterFindByCompanyId(long companyId, int start, int end)
1106 throws SystemException {
1107 return filterFindByCompanyId(companyId, start, end, null);
1108 }
1109
1110
1124 public List<Role> filterFindByCompanyId(long companyId, int start, int end,
1125 OrderByComparator orderByComparator) throws SystemException {
1126 if (!InlineSQLHelperUtil.isEnabled()) {
1127 return findByCompanyId(companyId, start, end, orderByComparator);
1128 }
1129
1130 StringBundler query = null;
1131
1132 if (orderByComparator != null) {
1133 query = new StringBundler(3 +
1134 (orderByComparator.getOrderByFields().length * 3));
1135 }
1136 else {
1137 query = new StringBundler(3);
1138 }
1139
1140 if (getDB().isSupportsInlineDistinct()) {
1141 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1142 }
1143 else {
1144 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1145 }
1146
1147 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1148
1149 if (!getDB().isSupportsInlineDistinct()) {
1150 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1151 }
1152
1153 if (orderByComparator != null) {
1154 if (getDB().isSupportsInlineDistinct()) {
1155 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1156 orderByComparator);
1157 }
1158 else {
1159 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1160 orderByComparator);
1161 }
1162 }
1163
1164 else {
1165 if (getDB().isSupportsInlineDistinct()) {
1166 query.append(RoleModelImpl.ORDER_BY_JPQL);
1167 }
1168 else {
1169 query.append(RoleModelImpl.ORDER_BY_SQL);
1170 }
1171 }
1172
1173 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1174 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1175
1176 Session session = null;
1177
1178 try {
1179 session = openSession();
1180
1181 SQLQuery q = session.createSQLQuery(sql);
1182
1183 if (getDB().isSupportsInlineDistinct()) {
1184 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1185 }
1186 else {
1187 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1188 }
1189
1190 QueryPos qPos = QueryPos.getInstance(q);
1191
1192 qPos.add(companyId);
1193
1194 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1195 }
1196 catch (Exception e) {
1197 throw processException(e);
1198 }
1199 finally {
1200 closeSession(session);
1201 }
1202 }
1203
1204
1214 public Role[] filterFindByCompanyId_PrevAndNext(long roleId,
1215 long companyId, OrderByComparator orderByComparator)
1216 throws NoSuchRoleException, SystemException {
1217 if (!InlineSQLHelperUtil.isEnabled()) {
1218 return findByCompanyId_PrevAndNext(roleId, companyId,
1219 orderByComparator);
1220 }
1221
1222 Role role = findByPrimaryKey(roleId);
1223
1224 Session session = null;
1225
1226 try {
1227 session = openSession();
1228
1229 Role[] array = new RoleImpl[3];
1230
1231 array[0] = filterGetByCompanyId_PrevAndNext(session, role,
1232 companyId, orderByComparator, true);
1233
1234 array[1] = role;
1235
1236 array[2] = filterGetByCompanyId_PrevAndNext(session, role,
1237 companyId, orderByComparator, false);
1238
1239 return array;
1240 }
1241 catch (Exception e) {
1242 throw processException(e);
1243 }
1244 finally {
1245 closeSession(session);
1246 }
1247 }
1248
1249 protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role,
1250 long companyId, OrderByComparator orderByComparator, boolean previous) {
1251 StringBundler query = null;
1252
1253 if (orderByComparator != null) {
1254 query = new StringBundler(6 +
1255 (orderByComparator.getOrderByFields().length * 6));
1256 }
1257 else {
1258 query = new StringBundler(3);
1259 }
1260
1261 if (getDB().isSupportsInlineDistinct()) {
1262 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1263 }
1264 else {
1265 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1266 }
1267
1268 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1269
1270 if (!getDB().isSupportsInlineDistinct()) {
1271 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1272 }
1273
1274 if (orderByComparator != null) {
1275 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1276
1277 if (orderByConditionFields.length > 0) {
1278 query.append(WHERE_AND);
1279 }
1280
1281 for (int i = 0; i < orderByConditionFields.length; i++) {
1282 if (getDB().isSupportsInlineDistinct()) {
1283 query.append(_ORDER_BY_ENTITY_ALIAS);
1284 }
1285 else {
1286 query.append(_ORDER_BY_ENTITY_TABLE);
1287 }
1288
1289 query.append(orderByConditionFields[i]);
1290
1291 if ((i + 1) < orderByConditionFields.length) {
1292 if (orderByComparator.isAscending() ^ previous) {
1293 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1294 }
1295 else {
1296 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1297 }
1298 }
1299 else {
1300 if (orderByComparator.isAscending() ^ previous) {
1301 query.append(WHERE_GREATER_THAN);
1302 }
1303 else {
1304 query.append(WHERE_LESSER_THAN);
1305 }
1306 }
1307 }
1308
1309 query.append(ORDER_BY_CLAUSE);
1310
1311 String[] orderByFields = orderByComparator.getOrderByFields();
1312
1313 for (int i = 0; i < orderByFields.length; i++) {
1314 if (getDB().isSupportsInlineDistinct()) {
1315 query.append(_ORDER_BY_ENTITY_ALIAS);
1316 }
1317 else {
1318 query.append(_ORDER_BY_ENTITY_TABLE);
1319 }
1320
1321 query.append(orderByFields[i]);
1322
1323 if ((i + 1) < orderByFields.length) {
1324 if (orderByComparator.isAscending() ^ previous) {
1325 query.append(ORDER_BY_ASC_HAS_NEXT);
1326 }
1327 else {
1328 query.append(ORDER_BY_DESC_HAS_NEXT);
1329 }
1330 }
1331 else {
1332 if (orderByComparator.isAscending() ^ previous) {
1333 query.append(ORDER_BY_ASC);
1334 }
1335 else {
1336 query.append(ORDER_BY_DESC);
1337 }
1338 }
1339 }
1340 }
1341
1342 else {
1343 if (getDB().isSupportsInlineDistinct()) {
1344 query.append(RoleModelImpl.ORDER_BY_JPQL);
1345 }
1346 else {
1347 query.append(RoleModelImpl.ORDER_BY_SQL);
1348 }
1349 }
1350
1351 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1352 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1353
1354 SQLQuery q = session.createSQLQuery(sql);
1355
1356 q.setFirstResult(0);
1357 q.setMaxResults(2);
1358
1359 if (getDB().isSupportsInlineDistinct()) {
1360 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1361 }
1362 else {
1363 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1364 }
1365
1366 QueryPos qPos = QueryPos.getInstance(q);
1367
1368 qPos.add(companyId);
1369
1370 if (orderByComparator != null) {
1371 Object[] values = orderByComparator.getOrderByConditionValues(role);
1372
1373 for (Object value : values) {
1374 qPos.add(value);
1375 }
1376 }
1377
1378 List<Role> list = q.list();
1379
1380 if (list.size() == 2) {
1381 return list.get(1);
1382 }
1383 else {
1384 return null;
1385 }
1386 }
1387
1388
1395 public List<Role> findByName(String name) throws SystemException {
1396 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1397 }
1398
1399
1412 public List<Role> findByName(String name, int start, int end)
1413 throws SystemException {
1414 return findByName(name, start, end, null);
1415 }
1416
1417
1431 public List<Role> findByName(String name, int start, int end,
1432 OrderByComparator orderByComparator) throws SystemException {
1433 FinderPath finderPath = null;
1434 Object[] finderArgs = null;
1435
1436 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1437 (orderByComparator == null)) {
1438 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
1439 finderArgs = new Object[] { name };
1440 }
1441 else {
1442 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
1443 finderArgs = new Object[] { name, start, end, orderByComparator };
1444 }
1445
1446 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
1447 finderArgs, this);
1448
1449 if ((list != null) && !list.isEmpty()) {
1450 for (Role role : list) {
1451 if (!Validator.equals(name, role.getName())) {
1452 list = null;
1453
1454 break;
1455 }
1456 }
1457 }
1458
1459 if (list == null) {
1460 StringBundler query = null;
1461
1462 if (orderByComparator != null) {
1463 query = new StringBundler(3 +
1464 (orderByComparator.getOrderByFields().length * 3));
1465 }
1466 else {
1467 query = new StringBundler(3);
1468 }
1469
1470 query.append(_SQL_SELECT_ROLE_WHERE);
1471
1472 if (name == null) {
1473 query.append(_FINDER_COLUMN_NAME_NAME_1);
1474 }
1475 else {
1476 if (name.equals(StringPool.BLANK)) {
1477 query.append(_FINDER_COLUMN_NAME_NAME_3);
1478 }
1479 else {
1480 query.append(_FINDER_COLUMN_NAME_NAME_2);
1481 }
1482 }
1483
1484 if (orderByComparator != null) {
1485 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1486 orderByComparator);
1487 }
1488
1489 else {
1490 query.append(RoleModelImpl.ORDER_BY_JPQL);
1491 }
1492
1493 String sql = query.toString();
1494
1495 Session session = null;
1496
1497 try {
1498 session = openSession();
1499
1500 Query q = session.createQuery(sql);
1501
1502 QueryPos qPos = QueryPos.getInstance(q);
1503
1504 if (name != null) {
1505 qPos.add(name);
1506 }
1507
1508 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1509 }
1510 catch (Exception e) {
1511 throw processException(e);
1512 }
1513 finally {
1514 if (list == null) {
1515 FinderCacheUtil.removeResult(finderPath, finderArgs);
1516 }
1517 else {
1518 cacheResult(list);
1519
1520 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1521 }
1522
1523 closeSession(session);
1524 }
1525 }
1526
1527 return list;
1528 }
1529
1530
1539 public Role findByName_First(String name,
1540 OrderByComparator orderByComparator)
1541 throws NoSuchRoleException, SystemException {
1542 Role role = fetchByName_First(name, orderByComparator);
1543
1544 if (role != null) {
1545 return role;
1546 }
1547
1548 StringBundler msg = new StringBundler(4);
1549
1550 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1551
1552 msg.append("name=");
1553 msg.append(name);
1554
1555 msg.append(StringPool.CLOSE_CURLY_BRACE);
1556
1557 throw new NoSuchRoleException(msg.toString());
1558 }
1559
1560
1568 public Role fetchByName_First(String name,
1569 OrderByComparator orderByComparator) throws SystemException {
1570 List<Role> list = findByName(name, 0, 1, orderByComparator);
1571
1572 if (!list.isEmpty()) {
1573 return list.get(0);
1574 }
1575
1576 return null;
1577 }
1578
1579
1588 public Role findByName_Last(String name, OrderByComparator orderByComparator)
1589 throws NoSuchRoleException, SystemException {
1590 Role role = fetchByName_Last(name, orderByComparator);
1591
1592 if (role != null) {
1593 return role;
1594 }
1595
1596 StringBundler msg = new StringBundler(4);
1597
1598 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1599
1600 msg.append("name=");
1601 msg.append(name);
1602
1603 msg.append(StringPool.CLOSE_CURLY_BRACE);
1604
1605 throw new NoSuchRoleException(msg.toString());
1606 }
1607
1608
1616 public Role fetchByName_Last(String name,
1617 OrderByComparator orderByComparator) throws SystemException {
1618 int count = countByName(name);
1619
1620 List<Role> list = findByName(name, count - 1, count, orderByComparator);
1621
1622 if (!list.isEmpty()) {
1623 return list.get(0);
1624 }
1625
1626 return null;
1627 }
1628
1629
1639 public Role[] findByName_PrevAndNext(long roleId, String name,
1640 OrderByComparator orderByComparator)
1641 throws NoSuchRoleException, SystemException {
1642 Role role = findByPrimaryKey(roleId);
1643
1644 Session session = null;
1645
1646 try {
1647 session = openSession();
1648
1649 Role[] array = new RoleImpl[3];
1650
1651 array[0] = getByName_PrevAndNext(session, role, name,
1652 orderByComparator, true);
1653
1654 array[1] = role;
1655
1656 array[2] = getByName_PrevAndNext(session, role, name,
1657 orderByComparator, false);
1658
1659 return array;
1660 }
1661 catch (Exception e) {
1662 throw processException(e);
1663 }
1664 finally {
1665 closeSession(session);
1666 }
1667 }
1668
1669 protected Role getByName_PrevAndNext(Session session, Role role,
1670 String name, OrderByComparator orderByComparator, boolean previous) {
1671 StringBundler query = null;
1672
1673 if (orderByComparator != null) {
1674 query = new StringBundler(6 +
1675 (orderByComparator.getOrderByFields().length * 6));
1676 }
1677 else {
1678 query = new StringBundler(3);
1679 }
1680
1681 query.append(_SQL_SELECT_ROLE_WHERE);
1682
1683 if (name == null) {
1684 query.append(_FINDER_COLUMN_NAME_NAME_1);
1685 }
1686 else {
1687 if (name.equals(StringPool.BLANK)) {
1688 query.append(_FINDER_COLUMN_NAME_NAME_3);
1689 }
1690 else {
1691 query.append(_FINDER_COLUMN_NAME_NAME_2);
1692 }
1693 }
1694
1695 if (orderByComparator != null) {
1696 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1697
1698 if (orderByConditionFields.length > 0) {
1699 query.append(WHERE_AND);
1700 }
1701
1702 for (int i = 0; i < orderByConditionFields.length; i++) {
1703 query.append(_ORDER_BY_ENTITY_ALIAS);
1704 query.append(orderByConditionFields[i]);
1705
1706 if ((i + 1) < orderByConditionFields.length) {
1707 if (orderByComparator.isAscending() ^ previous) {
1708 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1709 }
1710 else {
1711 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1712 }
1713 }
1714 else {
1715 if (orderByComparator.isAscending() ^ previous) {
1716 query.append(WHERE_GREATER_THAN);
1717 }
1718 else {
1719 query.append(WHERE_LESSER_THAN);
1720 }
1721 }
1722 }
1723
1724 query.append(ORDER_BY_CLAUSE);
1725
1726 String[] orderByFields = orderByComparator.getOrderByFields();
1727
1728 for (int i = 0; i < orderByFields.length; i++) {
1729 query.append(_ORDER_BY_ENTITY_ALIAS);
1730 query.append(orderByFields[i]);
1731
1732 if ((i + 1) < orderByFields.length) {
1733 if (orderByComparator.isAscending() ^ previous) {
1734 query.append(ORDER_BY_ASC_HAS_NEXT);
1735 }
1736 else {
1737 query.append(ORDER_BY_DESC_HAS_NEXT);
1738 }
1739 }
1740 else {
1741 if (orderByComparator.isAscending() ^ previous) {
1742 query.append(ORDER_BY_ASC);
1743 }
1744 else {
1745 query.append(ORDER_BY_DESC);
1746 }
1747 }
1748 }
1749 }
1750
1751 else {
1752 query.append(RoleModelImpl.ORDER_BY_JPQL);
1753 }
1754
1755 String sql = query.toString();
1756
1757 Query q = session.createQuery(sql);
1758
1759 q.setFirstResult(0);
1760 q.setMaxResults(2);
1761
1762 QueryPos qPos = QueryPos.getInstance(q);
1763
1764 if (name != null) {
1765 qPos.add(name);
1766 }
1767
1768 if (orderByComparator != null) {
1769 Object[] values = orderByComparator.getOrderByConditionValues(role);
1770
1771 for (Object value : values) {
1772 qPos.add(value);
1773 }
1774 }
1775
1776 List<Role> list = q.list();
1777
1778 if (list.size() == 2) {
1779 return list.get(1);
1780 }
1781 else {
1782 return null;
1783 }
1784 }
1785
1786
1793 public List<Role> filterFindByName(String name) throws SystemException {
1794 return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1795 }
1796
1797
1810 public List<Role> filterFindByName(String name, int start, int end)
1811 throws SystemException {
1812 return filterFindByName(name, start, end, null);
1813 }
1814
1815
1829 public List<Role> filterFindByName(String name, int start, int end,
1830 OrderByComparator orderByComparator) throws SystemException {
1831 if (!InlineSQLHelperUtil.isEnabled()) {
1832 return findByName(name, start, end, orderByComparator);
1833 }
1834
1835 StringBundler query = null;
1836
1837 if (orderByComparator != null) {
1838 query = new StringBundler(3 +
1839 (orderByComparator.getOrderByFields().length * 3));
1840 }
1841 else {
1842 query = new StringBundler(3);
1843 }
1844
1845 if (getDB().isSupportsInlineDistinct()) {
1846 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1847 }
1848 else {
1849 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1850 }
1851
1852 if (name == null) {
1853 query.append(_FINDER_COLUMN_NAME_NAME_1);
1854 }
1855 else {
1856 if (name.equals(StringPool.BLANK)) {
1857 query.append(_FINDER_COLUMN_NAME_NAME_3);
1858 }
1859 else {
1860 query.append(_FINDER_COLUMN_NAME_NAME_2);
1861 }
1862 }
1863
1864 if (!getDB().isSupportsInlineDistinct()) {
1865 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1866 }
1867
1868 if (orderByComparator != null) {
1869 if (getDB().isSupportsInlineDistinct()) {
1870 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1871 orderByComparator);
1872 }
1873 else {
1874 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1875 orderByComparator);
1876 }
1877 }
1878
1879 else {
1880 if (getDB().isSupportsInlineDistinct()) {
1881 query.append(RoleModelImpl.ORDER_BY_JPQL);
1882 }
1883 else {
1884 query.append(RoleModelImpl.ORDER_BY_SQL);
1885 }
1886 }
1887
1888 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1889 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1890
1891 Session session = null;
1892
1893 try {
1894 session = openSession();
1895
1896 SQLQuery q = session.createSQLQuery(sql);
1897
1898 if (getDB().isSupportsInlineDistinct()) {
1899 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1900 }
1901 else {
1902 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1903 }
1904
1905 QueryPos qPos = QueryPos.getInstance(q);
1906
1907 if (name != null) {
1908 qPos.add(name);
1909 }
1910
1911 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1912 }
1913 catch (Exception e) {
1914 throw processException(e);
1915 }
1916 finally {
1917 closeSession(session);
1918 }
1919 }
1920
1921
1931 public Role[] filterFindByName_PrevAndNext(long roleId, String name,
1932 OrderByComparator orderByComparator)
1933 throws NoSuchRoleException, SystemException {
1934 if (!InlineSQLHelperUtil.isEnabled()) {
1935 return findByName_PrevAndNext(roleId, name, orderByComparator);
1936 }
1937
1938 Role role = findByPrimaryKey(roleId);
1939
1940 Session session = null;
1941
1942 try {
1943 session = openSession();
1944
1945 Role[] array = new RoleImpl[3];
1946
1947 array[0] = filterGetByName_PrevAndNext(session, role, name,
1948 orderByComparator, true);
1949
1950 array[1] = role;
1951
1952 array[2] = filterGetByName_PrevAndNext(session, role, name,
1953 orderByComparator, false);
1954
1955 return array;
1956 }
1957 catch (Exception e) {
1958 throw processException(e);
1959 }
1960 finally {
1961 closeSession(session);
1962 }
1963 }
1964
1965 protected Role filterGetByName_PrevAndNext(Session session, Role role,
1966 String name, OrderByComparator orderByComparator, boolean previous) {
1967 StringBundler query = null;
1968
1969 if (orderByComparator != null) {
1970 query = new StringBundler(6 +
1971 (orderByComparator.getOrderByFields().length * 6));
1972 }
1973 else {
1974 query = new StringBundler(3);
1975 }
1976
1977 if (getDB().isSupportsInlineDistinct()) {
1978 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1979 }
1980 else {
1981 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1982 }
1983
1984 if (name == null) {
1985 query.append(_FINDER_COLUMN_NAME_NAME_1);
1986 }
1987 else {
1988 if (name.equals(StringPool.BLANK)) {
1989 query.append(_FINDER_COLUMN_NAME_NAME_3);
1990 }
1991 else {
1992 query.append(_FINDER_COLUMN_NAME_NAME_2);
1993 }
1994 }
1995
1996 if (!getDB().isSupportsInlineDistinct()) {
1997 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1998 }
1999
2000 if (orderByComparator != null) {
2001 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2002
2003 if (orderByConditionFields.length > 0) {
2004 query.append(WHERE_AND);
2005 }
2006
2007 for (int i = 0; i < orderByConditionFields.length; i++) {
2008 if (getDB().isSupportsInlineDistinct()) {
2009 query.append(_ORDER_BY_ENTITY_ALIAS);
2010 }
2011 else {
2012 query.append(_ORDER_BY_ENTITY_TABLE);
2013 }
2014
2015 query.append(orderByConditionFields[i]);
2016
2017 if ((i + 1) < orderByConditionFields.length) {
2018 if (orderByComparator.isAscending() ^ previous) {
2019 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2020 }
2021 else {
2022 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2023 }
2024 }
2025 else {
2026 if (orderByComparator.isAscending() ^ previous) {
2027 query.append(WHERE_GREATER_THAN);
2028 }
2029 else {
2030 query.append(WHERE_LESSER_THAN);
2031 }
2032 }
2033 }
2034
2035 query.append(ORDER_BY_CLAUSE);
2036
2037 String[] orderByFields = orderByComparator.getOrderByFields();
2038
2039 for (int i = 0; i < orderByFields.length; i++) {
2040 if (getDB().isSupportsInlineDistinct()) {
2041 query.append(_ORDER_BY_ENTITY_ALIAS);
2042 }
2043 else {
2044 query.append(_ORDER_BY_ENTITY_TABLE);
2045 }
2046
2047 query.append(orderByFields[i]);
2048
2049 if ((i + 1) < orderByFields.length) {
2050 if (orderByComparator.isAscending() ^ previous) {
2051 query.append(ORDER_BY_ASC_HAS_NEXT);
2052 }
2053 else {
2054 query.append(ORDER_BY_DESC_HAS_NEXT);
2055 }
2056 }
2057 else {
2058 if (orderByComparator.isAscending() ^ previous) {
2059 query.append(ORDER_BY_ASC);
2060 }
2061 else {
2062 query.append(ORDER_BY_DESC);
2063 }
2064 }
2065 }
2066 }
2067
2068 else {
2069 if (getDB().isSupportsInlineDistinct()) {
2070 query.append(RoleModelImpl.ORDER_BY_JPQL);
2071 }
2072 else {
2073 query.append(RoleModelImpl.ORDER_BY_SQL);
2074 }
2075 }
2076
2077 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2078 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2079
2080 SQLQuery q = session.createSQLQuery(sql);
2081
2082 q.setFirstResult(0);
2083 q.setMaxResults(2);
2084
2085 if (getDB().isSupportsInlineDistinct()) {
2086 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2087 }
2088 else {
2089 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2090 }
2091
2092 QueryPos qPos = QueryPos.getInstance(q);
2093
2094 if (name != null) {
2095 qPos.add(name);
2096 }
2097
2098 if (orderByComparator != null) {
2099 Object[] values = orderByComparator.getOrderByConditionValues(role);
2100
2101 for (Object value : values) {
2102 qPos.add(value);
2103 }
2104 }
2105
2106 List<Role> list = q.list();
2107
2108 if (list.size() == 2) {
2109 return list.get(1);
2110 }
2111 else {
2112 return null;
2113 }
2114 }
2115
2116
2123 public List<Role> findBySubtype(String subtype) throws SystemException {
2124 return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2125 }
2126
2127
2140 public List<Role> findBySubtype(String subtype, int start, int end)
2141 throws SystemException {
2142 return findBySubtype(subtype, start, end, null);
2143 }
2144
2145
2159 public List<Role> findBySubtype(String subtype, int start, int end,
2160 OrderByComparator orderByComparator) throws SystemException {
2161 FinderPath finderPath = null;
2162 Object[] finderArgs = null;
2163
2164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2165 (orderByComparator == null)) {
2166 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE;
2167 finderArgs = new Object[] { subtype };
2168 }
2169 else {
2170 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE;
2171 finderArgs = new Object[] { subtype, start, end, orderByComparator };
2172 }
2173
2174 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2175 finderArgs, this);
2176
2177 if ((list != null) && !list.isEmpty()) {
2178 for (Role role : list) {
2179 if (!Validator.equals(subtype, role.getSubtype())) {
2180 list = null;
2181
2182 break;
2183 }
2184 }
2185 }
2186
2187 if (list == null) {
2188 StringBundler query = null;
2189
2190 if (orderByComparator != null) {
2191 query = new StringBundler(3 +
2192 (orderByComparator.getOrderByFields().length * 3));
2193 }
2194 else {
2195 query = new StringBundler(3);
2196 }
2197
2198 query.append(_SQL_SELECT_ROLE_WHERE);
2199
2200 if (subtype == null) {
2201 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2202 }
2203 else {
2204 if (subtype.equals(StringPool.BLANK)) {
2205 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2206 }
2207 else {
2208 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2209 }
2210 }
2211
2212 if (orderByComparator != null) {
2213 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2214 orderByComparator);
2215 }
2216
2217 else {
2218 query.append(RoleModelImpl.ORDER_BY_JPQL);
2219 }
2220
2221 String sql = query.toString();
2222
2223 Session session = null;
2224
2225 try {
2226 session = openSession();
2227
2228 Query q = session.createQuery(sql);
2229
2230 QueryPos qPos = QueryPos.getInstance(q);
2231
2232 if (subtype != null) {
2233 qPos.add(subtype);
2234 }
2235
2236 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2237 }
2238 catch (Exception e) {
2239 throw processException(e);
2240 }
2241 finally {
2242 if (list == null) {
2243 FinderCacheUtil.removeResult(finderPath, finderArgs);
2244 }
2245 else {
2246 cacheResult(list);
2247
2248 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2249 }
2250
2251 closeSession(session);
2252 }
2253 }
2254
2255 return list;
2256 }
2257
2258
2267 public Role findBySubtype_First(String subtype,
2268 OrderByComparator orderByComparator)
2269 throws NoSuchRoleException, SystemException {
2270 Role role = fetchBySubtype_First(subtype, orderByComparator);
2271
2272 if (role != null) {
2273 return role;
2274 }
2275
2276 StringBundler msg = new StringBundler(4);
2277
2278 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2279
2280 msg.append("subtype=");
2281 msg.append(subtype);
2282
2283 msg.append(StringPool.CLOSE_CURLY_BRACE);
2284
2285 throw new NoSuchRoleException(msg.toString());
2286 }
2287
2288
2296 public Role fetchBySubtype_First(String subtype,
2297 OrderByComparator orderByComparator) throws SystemException {
2298 List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
2299
2300 if (!list.isEmpty()) {
2301 return list.get(0);
2302 }
2303
2304 return null;
2305 }
2306
2307
2316 public Role findBySubtype_Last(String subtype,
2317 OrderByComparator orderByComparator)
2318 throws NoSuchRoleException, SystemException {
2319 Role role = fetchBySubtype_Last(subtype, orderByComparator);
2320
2321 if (role != null) {
2322 return role;
2323 }
2324
2325 StringBundler msg = new StringBundler(4);
2326
2327 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2328
2329 msg.append("subtype=");
2330 msg.append(subtype);
2331
2332 msg.append(StringPool.CLOSE_CURLY_BRACE);
2333
2334 throw new NoSuchRoleException(msg.toString());
2335 }
2336
2337
2345 public Role fetchBySubtype_Last(String subtype,
2346 OrderByComparator orderByComparator) throws SystemException {
2347 int count = countBySubtype(subtype);
2348
2349 List<Role> list = findBySubtype(subtype, count - 1, count,
2350 orderByComparator);
2351
2352 if (!list.isEmpty()) {
2353 return list.get(0);
2354 }
2355
2356 return null;
2357 }
2358
2359
2369 public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
2370 OrderByComparator orderByComparator)
2371 throws NoSuchRoleException, SystemException {
2372 Role role = findByPrimaryKey(roleId);
2373
2374 Session session = null;
2375
2376 try {
2377 session = openSession();
2378
2379 Role[] array = new RoleImpl[3];
2380
2381 array[0] = getBySubtype_PrevAndNext(session, role, subtype,
2382 orderByComparator, true);
2383
2384 array[1] = role;
2385
2386 array[2] = getBySubtype_PrevAndNext(session, role, subtype,
2387 orderByComparator, false);
2388
2389 return array;
2390 }
2391 catch (Exception e) {
2392 throw processException(e);
2393 }
2394 finally {
2395 closeSession(session);
2396 }
2397 }
2398
2399 protected Role getBySubtype_PrevAndNext(Session session, Role role,
2400 String subtype, OrderByComparator orderByComparator, boolean previous) {
2401 StringBundler query = null;
2402
2403 if (orderByComparator != null) {
2404 query = new StringBundler(6 +
2405 (orderByComparator.getOrderByFields().length * 6));
2406 }
2407 else {
2408 query = new StringBundler(3);
2409 }
2410
2411 query.append(_SQL_SELECT_ROLE_WHERE);
2412
2413 if (subtype == null) {
2414 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2415 }
2416 else {
2417 if (subtype.equals(StringPool.BLANK)) {
2418 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2419 }
2420 else {
2421 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2422 }
2423 }
2424
2425 if (orderByComparator != null) {
2426 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2427
2428 if (orderByConditionFields.length > 0) {
2429 query.append(WHERE_AND);
2430 }
2431
2432 for (int i = 0; i < orderByConditionFields.length; i++) {
2433 query.append(_ORDER_BY_ENTITY_ALIAS);
2434 query.append(orderByConditionFields[i]);
2435
2436 if ((i + 1) < orderByConditionFields.length) {
2437 if (orderByComparator.isAscending() ^ previous) {
2438 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2439 }
2440 else {
2441 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2442 }
2443 }
2444 else {
2445 if (orderByComparator.isAscending() ^ previous) {
2446 query.append(WHERE_GREATER_THAN);
2447 }
2448 else {
2449 query.append(WHERE_LESSER_THAN);
2450 }
2451 }
2452 }
2453
2454 query.append(ORDER_BY_CLAUSE);
2455
2456 String[] orderByFields = orderByComparator.getOrderByFields();
2457
2458 for (int i = 0; i < orderByFields.length; i++) {
2459 query.append(_ORDER_BY_ENTITY_ALIAS);
2460 query.append(orderByFields[i]);
2461
2462 if ((i + 1) < orderByFields.length) {
2463 if (orderByComparator.isAscending() ^ previous) {
2464 query.append(ORDER_BY_ASC_HAS_NEXT);
2465 }
2466 else {
2467 query.append(ORDER_BY_DESC_HAS_NEXT);
2468 }
2469 }
2470 else {
2471 if (orderByComparator.isAscending() ^ previous) {
2472 query.append(ORDER_BY_ASC);
2473 }
2474 else {
2475 query.append(ORDER_BY_DESC);
2476 }
2477 }
2478 }
2479 }
2480
2481 else {
2482 query.append(RoleModelImpl.ORDER_BY_JPQL);
2483 }
2484
2485 String sql = query.toString();
2486
2487 Query q = session.createQuery(sql);
2488
2489 q.setFirstResult(0);
2490 q.setMaxResults(2);
2491
2492 QueryPos qPos = QueryPos.getInstance(q);
2493
2494 if (subtype != null) {
2495 qPos.add(subtype);
2496 }
2497
2498 if (orderByComparator != null) {
2499 Object[] values = orderByComparator.getOrderByConditionValues(role);
2500
2501 for (Object value : values) {
2502 qPos.add(value);
2503 }
2504 }
2505
2506 List<Role> list = q.list();
2507
2508 if (list.size() == 2) {
2509 return list.get(1);
2510 }
2511 else {
2512 return null;
2513 }
2514 }
2515
2516
2523 public List<Role> filterFindBySubtype(String subtype)
2524 throws SystemException {
2525 return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
2526 QueryUtil.ALL_POS, null);
2527 }
2528
2529
2542 public List<Role> filterFindBySubtype(String subtype, int start, int end)
2543 throws SystemException {
2544 return filterFindBySubtype(subtype, start, end, null);
2545 }
2546
2547
2561 public List<Role> filterFindBySubtype(String subtype, int start, int end,
2562 OrderByComparator orderByComparator) throws SystemException {
2563 if (!InlineSQLHelperUtil.isEnabled()) {
2564 return findBySubtype(subtype, start, end, orderByComparator);
2565 }
2566
2567 StringBundler query = null;
2568
2569 if (orderByComparator != null) {
2570 query = new StringBundler(3 +
2571 (orderByComparator.getOrderByFields().length * 3));
2572 }
2573 else {
2574 query = new StringBundler(3);
2575 }
2576
2577 if (getDB().isSupportsInlineDistinct()) {
2578 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2579 }
2580 else {
2581 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2582 }
2583
2584 if (subtype == null) {
2585 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2586 }
2587 else {
2588 if (subtype.equals(StringPool.BLANK)) {
2589 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2590 }
2591 else {
2592 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2593 }
2594 }
2595
2596 if (!getDB().isSupportsInlineDistinct()) {
2597 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2598 }
2599
2600 if (orderByComparator != null) {
2601 if (getDB().isSupportsInlineDistinct()) {
2602 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2603 orderByComparator);
2604 }
2605 else {
2606 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2607 orderByComparator);
2608 }
2609 }
2610
2611 else {
2612 if (getDB().isSupportsInlineDistinct()) {
2613 query.append(RoleModelImpl.ORDER_BY_JPQL);
2614 }
2615 else {
2616 query.append(RoleModelImpl.ORDER_BY_SQL);
2617 }
2618 }
2619
2620 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2621 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2622
2623 Session session = null;
2624
2625 try {
2626 session = openSession();
2627
2628 SQLQuery q = session.createSQLQuery(sql);
2629
2630 if (getDB().isSupportsInlineDistinct()) {
2631 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2632 }
2633 else {
2634 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2635 }
2636
2637 QueryPos qPos = QueryPos.getInstance(q);
2638
2639 if (subtype != null) {
2640 qPos.add(subtype);
2641 }
2642
2643 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2644 }
2645 catch (Exception e) {
2646 throw processException(e);
2647 }
2648 finally {
2649 closeSession(session);
2650 }
2651 }
2652
2653
2663 public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype,
2664 OrderByComparator orderByComparator)
2665 throws NoSuchRoleException, SystemException {
2666 if (!InlineSQLHelperUtil.isEnabled()) {
2667 return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator);
2668 }
2669
2670 Role role = findByPrimaryKey(roleId);
2671
2672 Session session = null;
2673
2674 try {
2675 session = openSession();
2676
2677 Role[] array = new RoleImpl[3];
2678
2679 array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype,
2680 orderByComparator, true);
2681
2682 array[1] = role;
2683
2684 array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype,
2685 orderByComparator, false);
2686
2687 return array;
2688 }
2689 catch (Exception e) {
2690 throw processException(e);
2691 }
2692 finally {
2693 closeSession(session);
2694 }
2695 }
2696
2697 protected Role filterGetBySubtype_PrevAndNext(Session session, Role role,
2698 String subtype, OrderByComparator orderByComparator, boolean previous) {
2699 StringBundler query = null;
2700
2701 if (orderByComparator != null) {
2702 query = new StringBundler(6 +
2703 (orderByComparator.getOrderByFields().length * 6));
2704 }
2705 else {
2706 query = new StringBundler(3);
2707 }
2708
2709 if (getDB().isSupportsInlineDistinct()) {
2710 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2711 }
2712 else {
2713 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2714 }
2715
2716 if (subtype == null) {
2717 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2718 }
2719 else {
2720 if (subtype.equals(StringPool.BLANK)) {
2721 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2722 }
2723 else {
2724 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2725 }
2726 }
2727
2728 if (!getDB().isSupportsInlineDistinct()) {
2729 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2730 }
2731
2732 if (orderByComparator != null) {
2733 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2734
2735 if (orderByConditionFields.length > 0) {
2736 query.append(WHERE_AND);
2737 }
2738
2739 for (int i = 0; i < orderByConditionFields.length; i++) {
2740 if (getDB().isSupportsInlineDistinct()) {
2741 query.append(_ORDER_BY_ENTITY_ALIAS);
2742 }
2743 else {
2744 query.append(_ORDER_BY_ENTITY_TABLE);
2745 }
2746
2747 query.append(orderByConditionFields[i]);
2748
2749 if ((i + 1) < orderByConditionFields.length) {
2750 if (orderByComparator.isAscending() ^ previous) {
2751 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2752 }
2753 else {
2754 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2755 }
2756 }
2757 else {
2758 if (orderByComparator.isAscending() ^ previous) {
2759 query.append(WHERE_GREATER_THAN);
2760 }
2761 else {
2762 query.append(WHERE_LESSER_THAN);
2763 }
2764 }
2765 }
2766
2767 query.append(ORDER_BY_CLAUSE);
2768
2769 String[] orderByFields = orderByComparator.getOrderByFields();
2770
2771 for (int i = 0; i < orderByFields.length; i++) {
2772 if (getDB().isSupportsInlineDistinct()) {
2773 query.append(_ORDER_BY_ENTITY_ALIAS);
2774 }
2775 else {
2776 query.append(_ORDER_BY_ENTITY_TABLE);
2777 }
2778
2779 query.append(orderByFields[i]);
2780
2781 if ((i + 1) < orderByFields.length) {
2782 if (orderByComparator.isAscending() ^ previous) {
2783 query.append(ORDER_BY_ASC_HAS_NEXT);
2784 }
2785 else {
2786 query.append(ORDER_BY_DESC_HAS_NEXT);
2787 }
2788 }
2789 else {
2790 if (orderByComparator.isAscending() ^ previous) {
2791 query.append(ORDER_BY_ASC);
2792 }
2793 else {
2794 query.append(ORDER_BY_DESC);
2795 }
2796 }
2797 }
2798 }
2799
2800 else {
2801 if (getDB().isSupportsInlineDistinct()) {
2802 query.append(RoleModelImpl.ORDER_BY_JPQL);
2803 }
2804 else {
2805 query.append(RoleModelImpl.ORDER_BY_SQL);
2806 }
2807 }
2808
2809 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2810 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2811
2812 SQLQuery q = session.createSQLQuery(sql);
2813
2814 q.setFirstResult(0);
2815 q.setMaxResults(2);
2816
2817 if (getDB().isSupportsInlineDistinct()) {
2818 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2819 }
2820 else {
2821 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2822 }
2823
2824 QueryPos qPos = QueryPos.getInstance(q);
2825
2826 if (subtype != null) {
2827 qPos.add(subtype);
2828 }
2829
2830 if (orderByComparator != null) {
2831 Object[] values = orderByComparator.getOrderByConditionValues(role);
2832
2833 for (Object value : values) {
2834 qPos.add(value);
2835 }
2836 }
2837
2838 List<Role> list = q.list();
2839
2840 if (list.size() == 2) {
2841 return list.get(1);
2842 }
2843 else {
2844 return null;
2845 }
2846 }
2847
2848
2857 public Role findByC_N(long companyId, String name)
2858 throws NoSuchRoleException, SystemException {
2859 Role role = fetchByC_N(companyId, name);
2860
2861 if (role == null) {
2862 StringBundler msg = new StringBundler(6);
2863
2864 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2865
2866 msg.append("companyId=");
2867 msg.append(companyId);
2868
2869 msg.append(", name=");
2870 msg.append(name);
2871
2872 msg.append(StringPool.CLOSE_CURLY_BRACE);
2873
2874 if (_log.isWarnEnabled()) {
2875 _log.warn(msg.toString());
2876 }
2877
2878 throw new NoSuchRoleException(msg.toString());
2879 }
2880
2881 return role;
2882 }
2883
2884
2892 public Role fetchByC_N(long companyId, String name)
2893 throws SystemException {
2894 return fetchByC_N(companyId, name, true);
2895 }
2896
2897
2906 public Role fetchByC_N(long companyId, String name,
2907 boolean retrieveFromCache) throws SystemException {
2908 Object[] finderArgs = new Object[] { companyId, name };
2909
2910 Object result = null;
2911
2912 if (retrieveFromCache) {
2913 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
2914 finderArgs, this);
2915 }
2916
2917 if (result instanceof Role) {
2918 Role role = (Role)result;
2919
2920 if ((companyId != role.getCompanyId()) ||
2921 !Validator.equals(name, role.getName())) {
2922 result = null;
2923 }
2924 }
2925
2926 if (result == null) {
2927 StringBundler query = new StringBundler(4);
2928
2929 query.append(_SQL_SELECT_ROLE_WHERE);
2930
2931 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2932
2933 if (name == null) {
2934 query.append(_FINDER_COLUMN_C_N_NAME_1);
2935 }
2936 else {
2937 if (name.equals(StringPool.BLANK)) {
2938 query.append(_FINDER_COLUMN_C_N_NAME_3);
2939 }
2940 else {
2941 query.append(_FINDER_COLUMN_C_N_NAME_2);
2942 }
2943 }
2944
2945 query.append(RoleModelImpl.ORDER_BY_JPQL);
2946
2947 String sql = query.toString();
2948
2949 Session session = null;
2950
2951 try {
2952 session = openSession();
2953
2954 Query q = session.createQuery(sql);
2955
2956 QueryPos qPos = QueryPos.getInstance(q);
2957
2958 qPos.add(companyId);
2959
2960 if (name != null) {
2961 qPos.add(name);
2962 }
2963
2964 List<Role> list = q.list();
2965
2966 result = list;
2967
2968 Role role = null;
2969
2970 if (list.isEmpty()) {
2971 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2972 finderArgs, list);
2973 }
2974 else {
2975 role = list.get(0);
2976
2977 cacheResult(role);
2978
2979 if ((role.getCompanyId() != companyId) ||
2980 (role.getName() == null) ||
2981 !role.getName().equals(name)) {
2982 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2983 finderArgs, role);
2984 }
2985 }
2986
2987 return role;
2988 }
2989 catch (Exception e) {
2990 throw processException(e);
2991 }
2992 finally {
2993 if (result == null) {
2994 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
2995 finderArgs);
2996 }
2997
2998 closeSession(session);
2999 }
3000 }
3001 else {
3002 if (result instanceof List<?>) {
3003 return null;
3004 }
3005 else {
3006 return (Role)result;
3007 }
3008 }
3009 }
3010
3011
3019 public List<Role> findByT_S(int type, String subtype)
3020 throws SystemException {
3021 return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3022 null);
3023 }
3024
3025
3039 public List<Role> findByT_S(int type, String subtype, int start, int end)
3040 throws SystemException {
3041 return findByT_S(type, subtype, start, end, null);
3042 }
3043
3044
3059 public List<Role> findByT_S(int type, String subtype, int start, int end,
3060 OrderByComparator orderByComparator) throws SystemException {
3061 FinderPath finderPath = null;
3062 Object[] finderArgs = null;
3063
3064 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3065 (orderByComparator == null)) {
3066 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
3067 finderArgs = new Object[] { type, subtype };
3068 }
3069 else {
3070 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
3071 finderArgs = new Object[] {
3072 type, subtype,
3073
3074 start, end, orderByComparator
3075 };
3076 }
3077
3078 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
3079 finderArgs, this);
3080
3081 if ((list != null) && !list.isEmpty()) {
3082 for (Role role : list) {
3083 if ((type != role.getType()) ||
3084 !Validator.equals(subtype, role.getSubtype())) {
3085 list = null;
3086
3087 break;
3088 }
3089 }
3090 }
3091
3092 if (list == null) {
3093 StringBundler query = null;
3094
3095 if (orderByComparator != null) {
3096 query = new StringBundler(4 +
3097 (orderByComparator.getOrderByFields().length * 3));
3098 }
3099 else {
3100 query = new StringBundler(4);
3101 }
3102
3103 query.append(_SQL_SELECT_ROLE_WHERE);
3104
3105 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3106
3107 if (subtype == null) {
3108 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3109 }
3110 else {
3111 if (subtype.equals(StringPool.BLANK)) {
3112 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3113 }
3114 else {
3115 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3116 }
3117 }
3118
3119 if (orderByComparator != null) {
3120 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3121 orderByComparator);
3122 }
3123
3124 else {
3125 query.append(RoleModelImpl.ORDER_BY_JPQL);
3126 }
3127
3128 String sql = query.toString();
3129
3130 Session session = null;
3131
3132 try {
3133 session = openSession();
3134
3135 Query q = session.createQuery(sql);
3136
3137 QueryPos qPos = QueryPos.getInstance(q);
3138
3139 qPos.add(type);
3140
3141 if (subtype != null) {
3142 qPos.add(subtype);
3143 }
3144
3145 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3146 }
3147 catch (Exception e) {
3148 throw processException(e);
3149 }
3150 finally {
3151 if (list == null) {
3152 FinderCacheUtil.removeResult(finderPath, finderArgs);
3153 }
3154 else {
3155 cacheResult(list);
3156
3157 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3158 }
3159
3160 closeSession(session);
3161 }
3162 }
3163
3164 return list;
3165 }
3166
3167
3177 public Role findByT_S_First(int type, String subtype,
3178 OrderByComparator orderByComparator)
3179 throws NoSuchRoleException, SystemException {
3180 Role role = fetchByT_S_First(type, subtype, orderByComparator);
3181
3182 if (role != null) {
3183 return role;
3184 }
3185
3186 StringBundler msg = new StringBundler(6);
3187
3188 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3189
3190 msg.append("type=");
3191 msg.append(type);
3192
3193 msg.append(", subtype=");
3194 msg.append(subtype);
3195
3196 msg.append(StringPool.CLOSE_CURLY_BRACE);
3197
3198 throw new NoSuchRoleException(msg.toString());
3199 }
3200
3201
3210 public Role fetchByT_S_First(int type, String subtype,
3211 OrderByComparator orderByComparator) throws SystemException {
3212 List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
3213
3214 if (!list.isEmpty()) {
3215 return list.get(0);
3216 }
3217
3218 return null;
3219 }
3220
3221
3231 public Role findByT_S_Last(int type, String subtype,
3232 OrderByComparator orderByComparator)
3233 throws NoSuchRoleException, SystemException {
3234 Role role = fetchByT_S_Last(type, subtype, orderByComparator);
3235
3236 if (role != null) {
3237 return role;
3238 }
3239
3240 StringBundler msg = new StringBundler(6);
3241
3242 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3243
3244 msg.append("type=");
3245 msg.append(type);
3246
3247 msg.append(", subtype=");
3248 msg.append(subtype);
3249
3250 msg.append(StringPool.CLOSE_CURLY_BRACE);
3251
3252 throw new NoSuchRoleException(msg.toString());
3253 }
3254
3255
3264 public Role fetchByT_S_Last(int type, String subtype,
3265 OrderByComparator orderByComparator) throws SystemException {
3266 int count = countByT_S(type, subtype);
3267
3268 List<Role> list = findByT_S(type, subtype, count - 1, count,
3269 orderByComparator);
3270
3271 if (!list.isEmpty()) {
3272 return list.get(0);
3273 }
3274
3275 return null;
3276 }
3277
3278
3289 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
3290 OrderByComparator orderByComparator)
3291 throws NoSuchRoleException, SystemException {
3292 Role role = findByPrimaryKey(roleId);
3293
3294 Session session = null;
3295
3296 try {
3297 session = openSession();
3298
3299 Role[] array = new RoleImpl[3];
3300
3301 array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
3302 orderByComparator, true);
3303
3304 array[1] = role;
3305
3306 array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
3307 orderByComparator, false);
3308
3309 return array;
3310 }
3311 catch (Exception e) {
3312 throw processException(e);
3313 }
3314 finally {
3315 closeSession(session);
3316 }
3317 }
3318
3319 protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
3320 String subtype, OrderByComparator orderByComparator, boolean previous) {
3321 StringBundler query = null;
3322
3323 if (orderByComparator != null) {
3324 query = new StringBundler(6 +
3325 (orderByComparator.getOrderByFields().length * 6));
3326 }
3327 else {
3328 query = new StringBundler(3);
3329 }
3330
3331 query.append(_SQL_SELECT_ROLE_WHERE);
3332
3333 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3334
3335 if (subtype == null) {
3336 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3337 }
3338 else {
3339 if (subtype.equals(StringPool.BLANK)) {
3340 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3341 }
3342 else {
3343 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3344 }
3345 }
3346
3347 if (orderByComparator != null) {
3348 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3349
3350 if (orderByConditionFields.length > 0) {
3351 query.append(WHERE_AND);
3352 }
3353
3354 for (int i = 0; i < orderByConditionFields.length; i++) {
3355 query.append(_ORDER_BY_ENTITY_ALIAS);
3356 query.append(orderByConditionFields[i]);
3357
3358 if ((i + 1) < orderByConditionFields.length) {
3359 if (orderByComparator.isAscending() ^ previous) {
3360 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3361 }
3362 else {
3363 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3364 }
3365 }
3366 else {
3367 if (orderByComparator.isAscending() ^ previous) {
3368 query.append(WHERE_GREATER_THAN);
3369 }
3370 else {
3371 query.append(WHERE_LESSER_THAN);
3372 }
3373 }
3374 }
3375
3376 query.append(ORDER_BY_CLAUSE);
3377
3378 String[] orderByFields = orderByComparator.getOrderByFields();
3379
3380 for (int i = 0; i < orderByFields.length; i++) {
3381 query.append(_ORDER_BY_ENTITY_ALIAS);
3382 query.append(orderByFields[i]);
3383
3384 if ((i + 1) < orderByFields.length) {
3385 if (orderByComparator.isAscending() ^ previous) {
3386 query.append(ORDER_BY_ASC_HAS_NEXT);
3387 }
3388 else {
3389 query.append(ORDER_BY_DESC_HAS_NEXT);
3390 }
3391 }
3392 else {
3393 if (orderByComparator.isAscending() ^ previous) {
3394 query.append(ORDER_BY_ASC);
3395 }
3396 else {
3397 query.append(ORDER_BY_DESC);
3398 }
3399 }
3400 }
3401 }
3402
3403 else {
3404 query.append(RoleModelImpl.ORDER_BY_JPQL);
3405 }
3406
3407 String sql = query.toString();
3408
3409 Query q = session.createQuery(sql);
3410
3411 q.setFirstResult(0);
3412 q.setMaxResults(2);
3413
3414 QueryPos qPos = QueryPos.getInstance(q);
3415
3416 qPos.add(type);
3417
3418 if (subtype != null) {
3419 qPos.add(subtype);
3420 }
3421
3422 if (orderByComparator != null) {
3423 Object[] values = orderByComparator.getOrderByConditionValues(role);
3424
3425 for (Object value : values) {
3426 qPos.add(value);
3427 }
3428 }
3429
3430 List<Role> list = q.list();
3431
3432 if (list.size() == 2) {
3433 return list.get(1);
3434 }
3435 else {
3436 return null;
3437 }
3438 }
3439
3440
3448 public List<Role> filterFindByT_S(int type, String subtype)
3449 throws SystemException {
3450 return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
3451 QueryUtil.ALL_POS, null);
3452 }
3453
3454
3468 public List<Role> filterFindByT_S(int type, String subtype, int start,
3469 int end) throws SystemException {
3470 return filterFindByT_S(type, subtype, start, end, null);
3471 }
3472
3473
3488 public List<Role> filterFindByT_S(int type, String subtype, int start,
3489 int end, OrderByComparator orderByComparator) throws SystemException {
3490 if (!InlineSQLHelperUtil.isEnabled()) {
3491 return findByT_S(type, subtype, start, end, orderByComparator);
3492 }
3493
3494 StringBundler query = null;
3495
3496 if (orderByComparator != null) {
3497 query = new StringBundler(4 +
3498 (orderByComparator.getOrderByFields().length * 3));
3499 }
3500 else {
3501 query = new StringBundler(4);
3502 }
3503
3504 if (getDB().isSupportsInlineDistinct()) {
3505 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3506 }
3507 else {
3508 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3509 }
3510
3511 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3512
3513 if (subtype == null) {
3514 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3515 }
3516 else {
3517 if (subtype.equals(StringPool.BLANK)) {
3518 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3519 }
3520 else {
3521 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3522 }
3523 }
3524
3525 if (!getDB().isSupportsInlineDistinct()) {
3526 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3527 }
3528
3529 if (orderByComparator != null) {
3530 if (getDB().isSupportsInlineDistinct()) {
3531 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3532 orderByComparator);
3533 }
3534 else {
3535 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3536 orderByComparator);
3537 }
3538 }
3539
3540 else {
3541 if (getDB().isSupportsInlineDistinct()) {
3542 query.append(RoleModelImpl.ORDER_BY_JPQL);
3543 }
3544 else {
3545 query.append(RoleModelImpl.ORDER_BY_SQL);
3546 }
3547 }
3548
3549 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3550 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3551
3552 Session session = null;
3553
3554 try {
3555 session = openSession();
3556
3557 SQLQuery q = session.createSQLQuery(sql);
3558
3559 if (getDB().isSupportsInlineDistinct()) {
3560 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3561 }
3562 else {
3563 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3564 }
3565
3566 QueryPos qPos = QueryPos.getInstance(q);
3567
3568 qPos.add(type);
3569
3570 if (subtype != null) {
3571 qPos.add(subtype);
3572 }
3573
3574 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3575 }
3576 catch (Exception e) {
3577 throw processException(e);
3578 }
3579 finally {
3580 closeSession(session);
3581 }
3582 }
3583
3584
3595 public Role[] filterFindByT_S_PrevAndNext(long roleId, int type,
3596 String subtype, OrderByComparator orderByComparator)
3597 throws NoSuchRoleException, SystemException {
3598 if (!InlineSQLHelperUtil.isEnabled()) {
3599 return findByT_S_PrevAndNext(roleId, type, subtype,
3600 orderByComparator);
3601 }
3602
3603 Role role = findByPrimaryKey(roleId);
3604
3605 Session session = null;
3606
3607 try {
3608 session = openSession();
3609
3610 Role[] array = new RoleImpl[3];
3611
3612 array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
3613 orderByComparator, true);
3614
3615 array[1] = role;
3616
3617 array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
3618 orderByComparator, false);
3619
3620 return array;
3621 }
3622 catch (Exception e) {
3623 throw processException(e);
3624 }
3625 finally {
3626 closeSession(session);
3627 }
3628 }
3629
3630 protected Role filterGetByT_S_PrevAndNext(Session session, Role role,
3631 int type, String subtype, OrderByComparator orderByComparator,
3632 boolean previous) {
3633 StringBundler query = null;
3634
3635 if (orderByComparator != null) {
3636 query = new StringBundler(6 +
3637 (orderByComparator.getOrderByFields().length * 6));
3638 }
3639 else {
3640 query = new StringBundler(3);
3641 }
3642
3643 if (getDB().isSupportsInlineDistinct()) {
3644 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3645 }
3646 else {
3647 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3648 }
3649
3650 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3651
3652 if (subtype == null) {
3653 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3654 }
3655 else {
3656 if (subtype.equals(StringPool.BLANK)) {
3657 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3658 }
3659 else {
3660 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3661 }
3662 }
3663
3664 if (!getDB().isSupportsInlineDistinct()) {
3665 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3666 }
3667
3668 if (orderByComparator != null) {
3669 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3670
3671 if (orderByConditionFields.length > 0) {
3672 query.append(WHERE_AND);
3673 }
3674
3675 for (int i = 0; i < orderByConditionFields.length; i++) {
3676 if (getDB().isSupportsInlineDistinct()) {
3677 query.append(_ORDER_BY_ENTITY_ALIAS);
3678 }
3679 else {
3680 query.append(_ORDER_BY_ENTITY_TABLE);
3681 }
3682
3683 query.append(orderByConditionFields[i]);
3684
3685 if ((i + 1) < orderByConditionFields.length) {
3686 if (orderByComparator.isAscending() ^ previous) {
3687 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3688 }
3689 else {
3690 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3691 }
3692 }
3693 else {
3694 if (orderByComparator.isAscending() ^ previous) {
3695 query.append(WHERE_GREATER_THAN);
3696 }
3697 else {
3698 query.append(WHERE_LESSER_THAN);
3699 }
3700 }
3701 }
3702
3703 query.append(ORDER_BY_CLAUSE);
3704
3705 String[] orderByFields = orderByComparator.getOrderByFields();
3706
3707 for (int i = 0; i < orderByFields.length; i++) {
3708 if (getDB().isSupportsInlineDistinct()) {
3709 query.append(_ORDER_BY_ENTITY_ALIAS);
3710 }
3711 else {
3712 query.append(_ORDER_BY_ENTITY_TABLE);
3713 }
3714
3715 query.append(orderByFields[i]);
3716
3717 if ((i + 1) < orderByFields.length) {
3718 if (orderByComparator.isAscending() ^ previous) {
3719 query.append(ORDER_BY_ASC_HAS_NEXT);
3720 }
3721 else {
3722 query.append(ORDER_BY_DESC_HAS_NEXT);
3723 }
3724 }
3725 else {
3726 if (orderByComparator.isAscending() ^ previous) {
3727 query.append(ORDER_BY_ASC);
3728 }
3729 else {
3730 query.append(ORDER_BY_DESC);
3731 }
3732 }
3733 }
3734 }
3735
3736 else {
3737 if (getDB().isSupportsInlineDistinct()) {
3738 query.append(RoleModelImpl.ORDER_BY_JPQL);
3739 }
3740 else {
3741 query.append(RoleModelImpl.ORDER_BY_SQL);
3742 }
3743 }
3744
3745 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3746 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3747
3748 SQLQuery q = session.createSQLQuery(sql);
3749
3750 q.setFirstResult(0);
3751 q.setMaxResults(2);
3752
3753 if (getDB().isSupportsInlineDistinct()) {
3754 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3755 }
3756 else {
3757 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3758 }
3759
3760 QueryPos qPos = QueryPos.getInstance(q);
3761
3762 qPos.add(type);
3763
3764 if (subtype != null) {
3765 qPos.add(subtype);
3766 }
3767
3768 if (orderByComparator != null) {
3769 Object[] values = orderByComparator.getOrderByConditionValues(role);
3770
3771 for (Object value : values) {
3772 qPos.add(value);
3773 }
3774 }
3775
3776 List<Role> list = q.list();
3777
3778 if (list.size() == 2) {
3779 return list.get(1);
3780 }
3781 else {
3782 return null;
3783 }
3784 }
3785
3786
3796 public Role findByC_C_C(long companyId, long classNameId, long classPK)
3797 throws NoSuchRoleException, SystemException {
3798 Role role = fetchByC_C_C(companyId, classNameId, classPK);
3799
3800 if (role == null) {
3801 StringBundler msg = new StringBundler(8);
3802
3803 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3804
3805 msg.append("companyId=");
3806 msg.append(companyId);
3807
3808 msg.append(", classNameId=");
3809 msg.append(classNameId);
3810
3811 msg.append(", classPK=");
3812 msg.append(classPK);
3813
3814 msg.append(StringPool.CLOSE_CURLY_BRACE);
3815
3816 if (_log.isWarnEnabled()) {
3817 _log.warn(msg.toString());
3818 }
3819
3820 throw new NoSuchRoleException(msg.toString());
3821 }
3822
3823 return role;
3824 }
3825
3826
3835 public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
3836 throws SystemException {
3837 return fetchByC_C_C(companyId, classNameId, classPK, true);
3838 }
3839
3840
3850 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
3851 boolean retrieveFromCache) throws SystemException {
3852 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
3853
3854 Object result = null;
3855
3856 if (retrieveFromCache) {
3857 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
3858 finderArgs, this);
3859 }
3860
3861 if (result instanceof Role) {
3862 Role role = (Role)result;
3863
3864 if ((companyId != role.getCompanyId()) ||
3865 (classNameId != role.getClassNameId()) ||
3866 (classPK != role.getClassPK())) {
3867 result = null;
3868 }
3869 }
3870
3871 if (result == null) {
3872 StringBundler query = new StringBundler(5);
3873
3874 query.append(_SQL_SELECT_ROLE_WHERE);
3875
3876 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
3877
3878 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
3879
3880 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
3881
3882 query.append(RoleModelImpl.ORDER_BY_JPQL);
3883
3884 String sql = query.toString();
3885
3886 Session session = null;
3887
3888 try {
3889 session = openSession();
3890
3891 Query q = session.createQuery(sql);
3892
3893 QueryPos qPos = QueryPos.getInstance(q);
3894
3895 qPos.add(companyId);
3896
3897 qPos.add(classNameId);
3898
3899 qPos.add(classPK);
3900
3901 List<Role> list = q.list();
3902
3903 result = list;
3904
3905 Role role = null;
3906
3907 if (list.isEmpty()) {
3908 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
3909 finderArgs, list);
3910 }
3911 else {
3912 role = list.get(0);
3913
3914 cacheResult(role);
3915
3916 if ((role.getCompanyId() != companyId) ||
3917 (role.getClassNameId() != classNameId) ||
3918 (role.getClassPK() != classPK)) {
3919 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
3920 finderArgs, role);
3921 }
3922 }
3923
3924 return role;
3925 }
3926 catch (Exception e) {
3927 throw processException(e);
3928 }
3929 finally {
3930 if (result == null) {
3931 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
3932 finderArgs);
3933 }
3934
3935 closeSession(session);
3936 }
3937 }
3938 else {
3939 if (result instanceof List<?>) {
3940 return null;
3941 }
3942 else {
3943 return (Role)result;
3944 }
3945 }
3946 }
3947
3948
3954 public List<Role> findAll() throws SystemException {
3955 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3956 }
3957
3958
3970 public List<Role> findAll(int start, int end) throws SystemException {
3971 return findAll(start, end, null);
3972 }
3973
3974
3987 public List<Role> findAll(int start, int end,
3988 OrderByComparator orderByComparator) throws SystemException {
3989 FinderPath finderPath = null;
3990 Object[] finderArgs = new Object[] { start, end, orderByComparator };
3991
3992 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3993 (orderByComparator == null)) {
3994 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3995 finderArgs = FINDER_ARGS_EMPTY;
3996 }
3997 else {
3998 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3999 finderArgs = new Object[] { start, end, orderByComparator };
4000 }
4001
4002 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
4003 finderArgs, this);
4004
4005 if (list == null) {
4006 StringBundler query = null;
4007 String sql = null;
4008
4009 if (orderByComparator != null) {
4010 query = new StringBundler(2 +
4011 (orderByComparator.getOrderByFields().length * 3));
4012
4013 query.append(_SQL_SELECT_ROLE);
4014
4015 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4016 orderByComparator);
4017
4018 sql = query.toString();
4019 }
4020 else {
4021 sql = _SQL_SELECT_ROLE.concat(RoleModelImpl.ORDER_BY_JPQL);
4022 }
4023
4024 Session session = null;
4025
4026 try {
4027 session = openSession();
4028
4029 Query q = session.createQuery(sql);
4030
4031 if (orderByComparator == null) {
4032 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4033 end, false);
4034
4035 Collections.sort(list);
4036 }
4037 else {
4038 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4039 end);
4040 }
4041 }
4042 catch (Exception e) {
4043 throw processException(e);
4044 }
4045 finally {
4046 if (list == null) {
4047 FinderCacheUtil.removeResult(finderPath, finderArgs);
4048 }
4049 else {
4050 cacheResult(list);
4051
4052 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4053 }
4054
4055 closeSession(session);
4056 }
4057 }
4058
4059 return list;
4060 }
4061
4062
4068 public void removeByCompanyId(long companyId) throws SystemException {
4069 for (Role role : findByCompanyId(companyId)) {
4070 remove(role);
4071 }
4072 }
4073
4074
4080 public void removeByName(String name) throws SystemException {
4081 for (Role role : findByName(name)) {
4082 remove(role);
4083 }
4084 }
4085
4086
4092 public void removeBySubtype(String subtype) throws SystemException {
4093 for (Role role : findBySubtype(subtype)) {
4094 remove(role);
4095 }
4096 }
4097
4098
4106 public Role removeByC_N(long companyId, String name)
4107 throws NoSuchRoleException, SystemException {
4108 Role role = findByC_N(companyId, name);
4109
4110 return remove(role);
4111 }
4112
4113
4120 public void removeByT_S(int type, String subtype) throws SystemException {
4121 for (Role role : findByT_S(type, subtype)) {
4122 remove(role);
4123 }
4124 }
4125
4126
4135 public Role removeByC_C_C(long companyId, long classNameId, long classPK)
4136 throws NoSuchRoleException, SystemException {
4137 Role role = findByC_C_C(companyId, classNameId, classPK);
4138
4139 return remove(role);
4140 }
4141
4142
4147 public void removeAll() throws SystemException {
4148 for (Role role : findAll()) {
4149 remove(role);
4150 }
4151 }
4152
4153
4160 public int countByCompanyId(long companyId) throws SystemException {
4161 Object[] finderArgs = new Object[] { companyId };
4162
4163 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4164 finderArgs, this);
4165
4166 if (count == null) {
4167 StringBundler query = new StringBundler(2);
4168
4169 query.append(_SQL_COUNT_ROLE_WHERE);
4170
4171 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4172
4173 String sql = query.toString();
4174
4175 Session session = null;
4176
4177 try {
4178 session = openSession();
4179
4180 Query q = session.createQuery(sql);
4181
4182 QueryPos qPos = QueryPos.getInstance(q);
4183
4184 qPos.add(companyId);
4185
4186 count = (Long)q.uniqueResult();
4187 }
4188 catch (Exception e) {
4189 throw processException(e);
4190 }
4191 finally {
4192 if (count == null) {
4193 count = Long.valueOf(0);
4194 }
4195
4196 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4197 finderArgs, count);
4198
4199 closeSession(session);
4200 }
4201 }
4202
4203 return count.intValue();
4204 }
4205
4206
4213 public int filterCountByCompanyId(long companyId) throws SystemException {
4214 if (!InlineSQLHelperUtil.isEnabled()) {
4215 return countByCompanyId(companyId);
4216 }
4217
4218 StringBundler query = new StringBundler(2);
4219
4220 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4221
4222 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4223
4224 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4225 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4226
4227 Session session = null;
4228
4229 try {
4230 session = openSession();
4231
4232 SQLQuery q = session.createSQLQuery(sql);
4233
4234 q.addScalar(COUNT_COLUMN_NAME,
4235 com.liferay.portal.kernel.dao.orm.Type.LONG);
4236
4237 QueryPos qPos = QueryPos.getInstance(q);
4238
4239 qPos.add(companyId);
4240
4241 Long count = (Long)q.uniqueResult();
4242
4243 return count.intValue();
4244 }
4245 catch (Exception e) {
4246 throw processException(e);
4247 }
4248 finally {
4249 closeSession(session);
4250 }
4251 }
4252
4253
4260 public int countByName(String name) throws SystemException {
4261 Object[] finderArgs = new Object[] { name };
4262
4263 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
4264 finderArgs, this);
4265
4266 if (count == null) {
4267 StringBundler query = new StringBundler(2);
4268
4269 query.append(_SQL_COUNT_ROLE_WHERE);
4270
4271 if (name == null) {
4272 query.append(_FINDER_COLUMN_NAME_NAME_1);
4273 }
4274 else {
4275 if (name.equals(StringPool.BLANK)) {
4276 query.append(_FINDER_COLUMN_NAME_NAME_3);
4277 }
4278 else {
4279 query.append(_FINDER_COLUMN_NAME_NAME_2);
4280 }
4281 }
4282
4283 String sql = query.toString();
4284
4285 Session session = null;
4286
4287 try {
4288 session = openSession();
4289
4290 Query q = session.createQuery(sql);
4291
4292 QueryPos qPos = QueryPos.getInstance(q);
4293
4294 if (name != null) {
4295 qPos.add(name);
4296 }
4297
4298 count = (Long)q.uniqueResult();
4299 }
4300 catch (Exception e) {
4301 throw processException(e);
4302 }
4303 finally {
4304 if (count == null) {
4305 count = Long.valueOf(0);
4306 }
4307
4308 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
4309 finderArgs, count);
4310
4311 closeSession(session);
4312 }
4313 }
4314
4315 return count.intValue();
4316 }
4317
4318
4325 public int filterCountByName(String name) throws SystemException {
4326 if (!InlineSQLHelperUtil.isEnabled()) {
4327 return countByName(name);
4328 }
4329
4330 StringBundler query = new StringBundler(2);
4331
4332 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4333
4334 if (name == null) {
4335 query.append(_FINDER_COLUMN_NAME_NAME_1);
4336 }
4337 else {
4338 if (name.equals(StringPool.BLANK)) {
4339 query.append(_FINDER_COLUMN_NAME_NAME_3);
4340 }
4341 else {
4342 query.append(_FINDER_COLUMN_NAME_NAME_2);
4343 }
4344 }
4345
4346 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4347 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4348
4349 Session session = null;
4350
4351 try {
4352 session = openSession();
4353
4354 SQLQuery q = session.createSQLQuery(sql);
4355
4356 q.addScalar(COUNT_COLUMN_NAME,
4357 com.liferay.portal.kernel.dao.orm.Type.LONG);
4358
4359 QueryPos qPos = QueryPos.getInstance(q);
4360
4361 if (name != null) {
4362 qPos.add(name);
4363 }
4364
4365 Long count = (Long)q.uniqueResult();
4366
4367 return count.intValue();
4368 }
4369 catch (Exception e) {
4370 throw processException(e);
4371 }
4372 finally {
4373 closeSession(session);
4374 }
4375 }
4376
4377
4384 public int countBySubtype(String subtype) throws SystemException {
4385 Object[] finderArgs = new Object[] { subtype };
4386
4387 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SUBTYPE,
4388 finderArgs, this);
4389
4390 if (count == null) {
4391 StringBundler query = new StringBundler(2);
4392
4393 query.append(_SQL_COUNT_ROLE_WHERE);
4394
4395 if (subtype == null) {
4396 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4397 }
4398 else {
4399 if (subtype.equals(StringPool.BLANK)) {
4400 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4401 }
4402 else {
4403 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4404 }
4405 }
4406
4407 String sql = query.toString();
4408
4409 Session session = null;
4410
4411 try {
4412 session = openSession();
4413
4414 Query q = session.createQuery(sql);
4415
4416 QueryPos qPos = QueryPos.getInstance(q);
4417
4418 if (subtype != null) {
4419 qPos.add(subtype);
4420 }
4421
4422 count = (Long)q.uniqueResult();
4423 }
4424 catch (Exception e) {
4425 throw processException(e);
4426 }
4427 finally {
4428 if (count == null) {
4429 count = Long.valueOf(0);
4430 }
4431
4432 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SUBTYPE,
4433 finderArgs, count);
4434
4435 closeSession(session);
4436 }
4437 }
4438
4439 return count.intValue();
4440 }
4441
4442
4449 public int filterCountBySubtype(String subtype) throws SystemException {
4450 if (!InlineSQLHelperUtil.isEnabled()) {
4451 return countBySubtype(subtype);
4452 }
4453
4454 StringBundler query = new StringBundler(2);
4455
4456 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4457
4458 if (subtype == null) {
4459 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4460 }
4461 else {
4462 if (subtype.equals(StringPool.BLANK)) {
4463 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4464 }
4465 else {
4466 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4467 }
4468 }
4469
4470 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4471 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4472
4473 Session session = null;
4474
4475 try {
4476 session = openSession();
4477
4478 SQLQuery q = session.createSQLQuery(sql);
4479
4480 q.addScalar(COUNT_COLUMN_NAME,
4481 com.liferay.portal.kernel.dao.orm.Type.LONG);
4482
4483 QueryPos qPos = QueryPos.getInstance(q);
4484
4485 if (subtype != null) {
4486 qPos.add(subtype);
4487 }
4488
4489 Long count = (Long)q.uniqueResult();
4490
4491 return count.intValue();
4492 }
4493 catch (Exception e) {
4494 throw processException(e);
4495 }
4496 finally {
4497 closeSession(session);
4498 }
4499 }
4500
4501
4509 public int countByC_N(long companyId, String name)
4510 throws SystemException {
4511 Object[] finderArgs = new Object[] { companyId, name };
4512
4513 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
4514 finderArgs, this);
4515
4516 if (count == null) {
4517 StringBundler query = new StringBundler(3);
4518
4519 query.append(_SQL_COUNT_ROLE_WHERE);
4520
4521 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
4522
4523 if (name == null) {
4524 query.append(_FINDER_COLUMN_C_N_NAME_1);
4525 }
4526 else {
4527 if (name.equals(StringPool.BLANK)) {
4528 query.append(_FINDER_COLUMN_C_N_NAME_3);
4529 }
4530 else {
4531 query.append(_FINDER_COLUMN_C_N_NAME_2);
4532 }
4533 }
4534
4535 String sql = query.toString();
4536
4537 Session session = null;
4538
4539 try {
4540 session = openSession();
4541
4542 Query q = session.createQuery(sql);
4543
4544 QueryPos qPos = QueryPos.getInstance(q);
4545
4546 qPos.add(companyId);
4547
4548 if (name != null) {
4549 qPos.add(name);
4550 }
4551
4552 count = (Long)q.uniqueResult();
4553 }
4554 catch (Exception e) {
4555 throw processException(e);
4556 }
4557 finally {
4558 if (count == null) {
4559 count = Long.valueOf(0);
4560 }
4561
4562 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
4563 count);
4564
4565 closeSession(session);
4566 }
4567 }
4568
4569 return count.intValue();
4570 }
4571
4572
4580 public int countByT_S(int type, String subtype) throws SystemException {
4581 Object[] finderArgs = new Object[] { type, subtype };
4582
4583 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
4584 finderArgs, this);
4585
4586 if (count == null) {
4587 StringBundler query = new StringBundler(3);
4588
4589 query.append(_SQL_COUNT_ROLE_WHERE);
4590
4591 query.append(_FINDER_COLUMN_T_S_TYPE_2);
4592
4593 if (subtype == null) {
4594 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
4595 }
4596 else {
4597 if (subtype.equals(StringPool.BLANK)) {
4598 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
4599 }
4600 else {
4601 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
4602 }
4603 }
4604
4605 String sql = query.toString();
4606
4607 Session session = null;
4608
4609 try {
4610 session = openSession();
4611
4612 Query q = session.createQuery(sql);
4613
4614 QueryPos qPos = QueryPos.getInstance(q);
4615
4616 qPos.add(type);
4617
4618 if (subtype != null) {
4619 qPos.add(subtype);
4620 }
4621
4622 count = (Long)q.uniqueResult();
4623 }
4624 catch (Exception e) {
4625 throw processException(e);
4626 }
4627 finally {
4628 if (count == null) {
4629 count = Long.valueOf(0);
4630 }
4631
4632 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
4633 count);
4634
4635 closeSession(session);
4636 }
4637 }
4638
4639 return count.intValue();
4640 }
4641
4642
4650 public int filterCountByT_S(int type, String subtype)
4651 throws SystemException {
4652 if (!InlineSQLHelperUtil.isEnabled()) {
4653 return countByT_S(type, subtype);
4654 }
4655
4656 StringBundler query = new StringBundler(3);
4657
4658 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4659
4660 query.append(_FINDER_COLUMN_T_S_TYPE_2);
4661
4662 if (subtype == null) {
4663 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
4664 }
4665 else {
4666 if (subtype.equals(StringPool.BLANK)) {
4667 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
4668 }
4669 else {
4670 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
4671 }
4672 }
4673
4674 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4675 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4676
4677 Session session = null;
4678
4679 try {
4680 session = openSession();
4681
4682 SQLQuery q = session.createSQLQuery(sql);
4683
4684 q.addScalar(COUNT_COLUMN_NAME,
4685 com.liferay.portal.kernel.dao.orm.Type.LONG);
4686
4687 QueryPos qPos = QueryPos.getInstance(q);
4688
4689 qPos.add(type);
4690
4691 if (subtype != null) {
4692 qPos.add(subtype);
4693 }
4694
4695 Long count = (Long)q.uniqueResult();
4696
4697 return count.intValue();
4698 }
4699 catch (Exception e) {
4700 throw processException(e);
4701 }
4702 finally {
4703 closeSession(session);
4704 }
4705 }
4706
4707
4716 public int countByC_C_C(long companyId, long classNameId, long classPK)
4717 throws SystemException {
4718 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
4719
4720 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
4721 finderArgs, this);
4722
4723 if (count == null) {
4724 StringBundler query = new StringBundler(4);
4725
4726 query.append(_SQL_COUNT_ROLE_WHERE);
4727
4728 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
4729
4730 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
4731
4732 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
4733
4734 String sql = query.toString();
4735
4736 Session session = null;
4737
4738 try {
4739 session = openSession();
4740
4741 Query q = session.createQuery(sql);
4742
4743 QueryPos qPos = QueryPos.getInstance(q);
4744
4745 qPos.add(companyId);
4746
4747 qPos.add(classNameId);
4748
4749 qPos.add(classPK);
4750
4751 count = (Long)q.uniqueResult();
4752 }
4753 catch (Exception e) {
4754 throw processException(e);
4755 }
4756 finally {
4757 if (count == null) {
4758 count = Long.valueOf(0);
4759 }
4760
4761 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
4762 finderArgs, count);
4763
4764 closeSession(session);
4765 }
4766 }
4767
4768 return count.intValue();
4769 }
4770
4771
4777 public int countAll() throws SystemException {
4778 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4779 FINDER_ARGS_EMPTY, this);
4780
4781 if (count == null) {
4782 Session session = null;
4783
4784 try {
4785 session = openSession();
4786
4787 Query q = session.createQuery(_SQL_COUNT_ROLE);
4788
4789 count = (Long)q.uniqueResult();
4790 }
4791 catch (Exception e) {
4792 throw processException(e);
4793 }
4794 finally {
4795 if (count == null) {
4796 count = Long.valueOf(0);
4797 }
4798
4799 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4800 FINDER_ARGS_EMPTY, count);
4801
4802 closeSession(session);
4803 }
4804 }
4805
4806 return count.intValue();
4807 }
4808
4809
4816 public List<com.liferay.portal.model.Group> getGroups(long pk)
4817 throws SystemException {
4818 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4819 }
4820
4821
4834 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
4835 int end) throws SystemException {
4836 return getGroups(pk, start, end, null);
4837 }
4838
4839 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
4840 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
4841 com.liferay.portal.model.impl.GroupImpl.class,
4842 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroups",
4843 new String[] {
4844 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
4845 "com.liferay.portal.kernel.util.OrderByComparator"
4846 });
4847
4848 static {
4849 FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
4850 }
4851
4852
4866 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
4867 int end, OrderByComparator orderByComparator) throws SystemException {
4868 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
4869
4870 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
4871 finderArgs, this);
4872
4873 if (list == null) {
4874 Session session = null;
4875
4876 try {
4877 session = openSession();
4878
4879 String sql = null;
4880
4881 if (orderByComparator != null) {
4882 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
4883 .concat(orderByComparator.getOrderBy());
4884 }
4885 else {
4886 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
4887 }
4888
4889 SQLQuery q = session.createSQLQuery(sql);
4890
4891 q.addEntity("Group_",
4892 com.liferay.portal.model.impl.GroupImpl.class);
4893
4894 QueryPos qPos = QueryPos.getInstance(q);
4895
4896 qPos.add(pk);
4897
4898 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
4899 getDialect(), start, end);
4900 }
4901 catch (Exception e) {
4902 throw processException(e);
4903 }
4904 finally {
4905 if (list == null) {
4906 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
4907 finderArgs);
4908 }
4909 else {
4910 groupPersistence.cacheResult(list);
4911
4912 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
4913 finderArgs, list);
4914 }
4915
4916 closeSession(session);
4917 }
4918 }
4919
4920 return list;
4921 }
4922
4923 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
4924 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, Long.class,
4925 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroupsSize",
4926 new String[] { Long.class.getName() });
4927
4928 static {
4929 FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
4930 }
4931
4932
4939 public int getGroupsSize(long pk) throws SystemException {
4940 Object[] finderArgs = new Object[] { pk };
4941
4942 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
4943 finderArgs, this);
4944
4945 if (count == null) {
4946 Session session = null;
4947
4948 try {
4949 session = openSession();
4950
4951 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
4952
4953 q.addScalar(COUNT_COLUMN_NAME,
4954 com.liferay.portal.kernel.dao.orm.Type.LONG);
4955
4956 QueryPos qPos = QueryPos.getInstance(q);
4957
4958 qPos.add(pk);
4959
4960 count = (Long)q.uniqueResult();
4961 }
4962 catch (Exception e) {
4963 throw processException(e);
4964 }
4965 finally {
4966 if (count == null) {
4967 count = Long.valueOf(0);
4968 }
4969
4970 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
4971 finderArgs, count);
4972
4973 closeSession(session);
4974 }
4975 }
4976
4977 return count.intValue();
4978 }
4979
4980 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
4981 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, Boolean.class,
4982 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "containsGroup",
4983 new String[] { Long.class.getName(), Long.class.getName() });
4984
4985
4993 public boolean containsGroup(long pk, long groupPK)
4994 throws SystemException {
4995 Object[] finderArgs = new Object[] { pk, groupPK };
4996
4997 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
4998 finderArgs, this);
4999
5000 if (value == null) {
5001 try {
5002 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
5003 }
5004 catch (Exception e) {
5005 throw processException(e);
5006 }
5007 finally {
5008 if (value == null) {
5009 value = Boolean.FALSE;
5010 }
5011
5012 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
5013 finderArgs, value);
5014 }
5015 }
5016
5017 return value.booleanValue();
5018 }
5019
5020
5027 public boolean containsGroups(long pk) throws SystemException {
5028 if (getGroupsSize(pk) > 0) {
5029 return true;
5030 }
5031 else {
5032 return false;
5033 }
5034 }
5035
5036
5043 public void addGroup(long pk, long groupPK) throws SystemException {
5044 try {
5045 addGroup.add(pk, groupPK);
5046 }
5047 catch (Exception e) {
5048 throw processException(e);
5049 }
5050 finally {
5051 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5052 }
5053 }
5054
5055
5062 public void addGroup(long pk, com.liferay.portal.model.Group group)
5063 throws SystemException {
5064 try {
5065 addGroup.add(pk, group.getPrimaryKey());
5066 }
5067 catch (Exception e) {
5068 throw processException(e);
5069 }
5070 finally {
5071 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5072 }
5073 }
5074
5075
5082 public void addGroups(long pk, long[] groupPKs) throws SystemException {
5083 try {
5084 for (long groupPK : groupPKs) {
5085 addGroup.add(pk, groupPK);
5086 }
5087 }
5088 catch (Exception e) {
5089 throw processException(e);
5090 }
5091 finally {
5092 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5093 }
5094 }
5095
5096
5103 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
5104 throws SystemException {
5105 try {
5106 for (com.liferay.portal.model.Group group : groups) {
5107 addGroup.add(pk, group.getPrimaryKey());
5108 }
5109 }
5110 catch (Exception e) {
5111 throw processException(e);
5112 }
5113 finally {
5114 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5115 }
5116 }
5117
5118
5124 public void clearGroups(long pk) throws SystemException {
5125 try {
5126 clearGroups.clear(pk);
5127 }
5128 catch (Exception e) {
5129 throw processException(e);
5130 }
5131 finally {
5132 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5133 }
5134 }
5135
5136
5143 public void removeGroup(long pk, long groupPK) throws SystemException {
5144 try {
5145 removeGroup.remove(pk, groupPK);
5146 }
5147 catch (Exception e) {
5148 throw processException(e);
5149 }
5150 finally {
5151 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5152 }
5153 }
5154
5155
5162 public void removeGroup(long pk, com.liferay.portal.model.Group group)
5163 throws SystemException {
5164 try {
5165 removeGroup.remove(pk, group.getPrimaryKey());
5166 }
5167 catch (Exception e) {
5168 throw processException(e);
5169 }
5170 finally {
5171 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5172 }
5173 }
5174
5175
5182 public void removeGroups(long pk, long[] groupPKs)
5183 throws SystemException {
5184 try {
5185 for (long groupPK : groupPKs) {
5186 removeGroup.remove(pk, groupPK);
5187 }
5188 }
5189 catch (Exception e) {
5190 throw processException(e);
5191 }
5192 finally {
5193 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5194 }
5195 }
5196
5197
5204 public void removeGroups(long pk,
5205 List<com.liferay.portal.model.Group> groups) throws SystemException {
5206 try {
5207 for (com.liferay.portal.model.Group group : groups) {
5208 removeGroup.remove(pk, group.getPrimaryKey());
5209 }
5210 }
5211 catch (Exception e) {
5212 throw processException(e);
5213 }
5214 finally {
5215 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5216 }
5217 }
5218
5219
5226 public void setGroups(long pk, long[] groupPKs) throws SystemException {
5227 try {
5228 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
5229
5230 List<com.liferay.portal.model.Group> groups = getGroups(pk);
5231
5232 for (com.liferay.portal.model.Group group : groups) {
5233 if (!groupPKSet.remove(group.getPrimaryKey())) {
5234 removeGroup.remove(pk, group.getPrimaryKey());
5235 }
5236 }
5237
5238 for (Long groupPK : groupPKSet) {
5239 addGroup.add(pk, groupPK);
5240 }
5241 }
5242 catch (Exception e) {
5243 throw processException(e);
5244 }
5245 finally {
5246 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5247 }
5248 }
5249
5250
5257 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
5258 throws SystemException {
5259 try {
5260 long[] groupPKs = new long[groups.size()];
5261
5262 for (int i = 0; i < groups.size(); i++) {
5263 com.liferay.portal.model.Group group = groups.get(i);
5264
5265 groupPKs[i] = group.getPrimaryKey();
5266 }
5267
5268 setGroups(pk, groupPKs);
5269 }
5270 catch (Exception e) {
5271 throw processException(e);
5272 }
5273 finally {
5274 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5275 }
5276 }
5277
5278
5285 public List<com.liferay.portal.model.User> getUsers(long pk)
5286 throws SystemException {
5287 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
5288 }
5289
5290
5303 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
5304 int end) throws SystemException {
5305 return getUsers(pk, start, end, null);
5306 }
5307
5308 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5309 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
5310 com.liferay.portal.model.impl.UserImpl.class,
5311 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsers",
5312 new String[] {
5313 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
5314 "com.liferay.portal.kernel.util.OrderByComparator"
5315 });
5316
5317 static {
5318 FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
5319 }
5320
5321
5335 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
5336 int end, OrderByComparator orderByComparator) throws SystemException {
5337 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
5338
5339 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
5340 finderArgs, this);
5341
5342 if (list == null) {
5343 Session session = null;
5344
5345 try {
5346 session = openSession();
5347
5348 String sql = null;
5349
5350 if (orderByComparator != null) {
5351 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
5352 .concat(orderByComparator.getOrderBy());
5353 }
5354 else {
5355 sql = _SQL_GETUSERS;
5356 }
5357
5358 SQLQuery q = session.createSQLQuery(sql);
5359
5360 q.addEntity("User_",
5361 com.liferay.portal.model.impl.UserImpl.class);
5362
5363 QueryPos qPos = QueryPos.getInstance(q);
5364
5365 qPos.add(pk);
5366
5367 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
5368 getDialect(), start, end);
5369 }
5370 catch (Exception e) {
5371 throw processException(e);
5372 }
5373 finally {
5374 if (list == null) {
5375 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
5376 finderArgs);
5377 }
5378 else {
5379 userPersistence.cacheResult(list);
5380
5381 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
5382 finderArgs, list);
5383 }
5384
5385 closeSession(session);
5386 }
5387 }
5388
5389 return list;
5390 }
5391
5392 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5393 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, Long.class,
5394 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsersSize",
5395 new String[] { Long.class.getName() });
5396
5397 static {
5398 FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
5399 }
5400
5401
5408 public int getUsersSize(long pk) throws SystemException {
5409 Object[] finderArgs = new Object[] { pk };
5410
5411 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
5412 finderArgs, this);
5413
5414 if (count == null) {
5415 Session session = null;
5416
5417 try {
5418 session = openSession();
5419
5420 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
5421
5422 q.addScalar(COUNT_COLUMN_NAME,
5423 com.liferay.portal.kernel.dao.orm.Type.LONG);
5424
5425 QueryPos qPos = QueryPos.getInstance(q);
5426
5427 qPos.add(pk);
5428
5429 count = (Long)q.uniqueResult();
5430 }
5431 catch (Exception e) {
5432 throw processException(e);
5433 }
5434 finally {
5435 if (count == null) {
5436 count = Long.valueOf(0);
5437 }
5438
5439 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
5440 finderArgs, count);
5441
5442 closeSession(session);
5443 }
5444 }
5445
5446 return count.intValue();
5447 }
5448
5449 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5450 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, Boolean.class,
5451 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "containsUser",
5452 new String[] { Long.class.getName(), Long.class.getName() });
5453
5454
5462 public boolean containsUser(long pk, long userPK) throws SystemException {
5463 Object[] finderArgs = new Object[] { pk, userPK };
5464
5465 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
5466 finderArgs, this);
5467
5468 if (value == null) {
5469 try {
5470 value = Boolean.valueOf(containsUser.contains(pk, userPK));
5471 }
5472 catch (Exception e) {
5473 throw processException(e);
5474 }
5475 finally {
5476 if (value == null) {
5477 value = Boolean.FALSE;
5478 }
5479
5480 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
5481 finderArgs, value);
5482 }
5483 }
5484
5485 return value.booleanValue();
5486 }
5487
5488
5495 public boolean containsUsers(long pk) throws SystemException {
5496 if (getUsersSize(pk) > 0) {
5497 return true;
5498 }
5499 else {
5500 return false;
5501 }
5502 }
5503
5504
5511 public void addUser(long pk, long userPK) throws SystemException {
5512 try {
5513 addUser.add(pk, userPK);
5514 }
5515 catch (Exception e) {
5516 throw processException(e);
5517 }
5518 finally {
5519 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5520 }
5521 }
5522
5523
5530 public void addUser(long pk, com.liferay.portal.model.User user)
5531 throws SystemException {
5532 try {
5533 addUser.add(pk, user.getPrimaryKey());
5534 }
5535 catch (Exception e) {
5536 throw processException(e);
5537 }
5538 finally {
5539 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5540 }
5541 }
5542
5543
5550 public void addUsers(long pk, long[] userPKs) throws SystemException {
5551 try {
5552 for (long userPK : userPKs) {
5553 addUser.add(pk, userPK);
5554 }
5555 }
5556 catch (Exception e) {
5557 throw processException(e);
5558 }
5559 finally {
5560 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5561 }
5562 }
5563
5564
5571 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
5572 throws SystemException {
5573 try {
5574 for (com.liferay.portal.model.User user : users) {
5575 addUser.add(pk, user.getPrimaryKey());
5576 }
5577 }
5578 catch (Exception e) {
5579 throw processException(e);
5580 }
5581 finally {
5582 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5583 }
5584 }
5585
5586
5592 public void clearUsers(long pk) throws SystemException {
5593 try {
5594 clearUsers.clear(pk);
5595 }
5596 catch (Exception e) {
5597 throw processException(e);
5598 }
5599 finally {
5600 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5601 }
5602 }
5603
5604
5611 public void removeUser(long pk, long userPK) throws SystemException {
5612 try {
5613 removeUser.remove(pk, userPK);
5614 }
5615 catch (Exception e) {
5616 throw processException(e);
5617 }
5618 finally {
5619 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5620 }
5621 }
5622
5623
5630 public void removeUser(long pk, com.liferay.portal.model.User user)
5631 throws SystemException {
5632 try {
5633 removeUser.remove(pk, user.getPrimaryKey());
5634 }
5635 catch (Exception e) {
5636 throw processException(e);
5637 }
5638 finally {
5639 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5640 }
5641 }
5642
5643
5650 public void removeUsers(long pk, long[] userPKs) throws SystemException {
5651 try {
5652 for (long userPK : userPKs) {
5653 removeUser.remove(pk, userPK);
5654 }
5655 }
5656 catch (Exception e) {
5657 throw processException(e);
5658 }
5659 finally {
5660 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5661 }
5662 }
5663
5664
5671 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
5672 throws SystemException {
5673 try {
5674 for (com.liferay.portal.model.User user : users) {
5675 removeUser.remove(pk, user.getPrimaryKey());
5676 }
5677 }
5678 catch (Exception e) {
5679 throw processException(e);
5680 }
5681 finally {
5682 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5683 }
5684 }
5685
5686
5693 public void setUsers(long pk, long[] userPKs) throws SystemException {
5694 try {
5695 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
5696
5697 List<com.liferay.portal.model.User> users = getUsers(pk);
5698
5699 for (com.liferay.portal.model.User user : users) {
5700 if (!userPKSet.remove(user.getPrimaryKey())) {
5701 removeUser.remove(pk, user.getPrimaryKey());
5702 }
5703 }
5704
5705 for (Long userPK : userPKSet) {
5706 addUser.add(pk, userPK);
5707 }
5708 }
5709 catch (Exception e) {
5710 throw processException(e);
5711 }
5712 finally {
5713 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5714 }
5715 }
5716
5717
5724 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
5725 throws SystemException {
5726 try {
5727 long[] userPKs = new long[users.size()];
5728
5729 for (int i = 0; i < users.size(); i++) {
5730 com.liferay.portal.model.User user = users.get(i);
5731
5732 userPKs[i] = user.getPrimaryKey();
5733 }
5734
5735 setUsers(pk, userPKs);
5736 }
5737 catch (Exception e) {
5738 throw processException(e);
5739 }
5740 finally {
5741 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5742 }
5743 }
5744
5745
5748 public void afterPropertiesSet() {
5749 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5750 com.liferay.portal.util.PropsUtil.get(
5751 "value.object.listener.com.liferay.portal.model.Role")));
5752
5753 if (listenerClassNames.length > 0) {
5754 try {
5755 List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
5756
5757 for (String listenerClassName : listenerClassNames) {
5758 listenersList.add((ModelListener<Role>)InstanceFactory.newInstance(
5759 listenerClassName));
5760 }
5761
5762 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5763 }
5764 catch (Exception e) {
5765 _log.error(e);
5766 }
5767 }
5768
5769 containsGroup = new ContainsGroup();
5770
5771 addGroup = new AddGroup();
5772 clearGroups = new ClearGroups();
5773 removeGroup = new RemoveGroup();
5774
5775 containsUser = new ContainsUser();
5776
5777 addUser = new AddUser();
5778 clearUsers = new ClearUsers();
5779 removeUser = new RemoveUser();
5780 }
5781
5782 public void destroy() {
5783 EntityCacheUtil.removeCache(RoleImpl.class.getName());
5784 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5785 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5786 }
5787
5788 @BeanReference(type = AccountPersistence.class)
5789 protected AccountPersistence accountPersistence;
5790 @BeanReference(type = AddressPersistence.class)
5791 protected AddressPersistence addressPersistence;
5792 @BeanReference(type = BrowserTrackerPersistence.class)
5793 protected BrowserTrackerPersistence browserTrackerPersistence;
5794 @BeanReference(type = ClassNamePersistence.class)
5795 protected ClassNamePersistence classNamePersistence;
5796 @BeanReference(type = ClusterGroupPersistence.class)
5797 protected ClusterGroupPersistence clusterGroupPersistence;
5798 @BeanReference(type = CompanyPersistence.class)
5799 protected CompanyPersistence companyPersistence;
5800 @BeanReference(type = ContactPersistence.class)
5801 protected ContactPersistence contactPersistence;
5802 @BeanReference(type = CountryPersistence.class)
5803 protected CountryPersistence countryPersistence;
5804 @BeanReference(type = EmailAddressPersistence.class)
5805 protected EmailAddressPersistence emailAddressPersistence;
5806 @BeanReference(type = GroupPersistence.class)
5807 protected GroupPersistence groupPersistence;
5808 @BeanReference(type = ImagePersistence.class)
5809 protected ImagePersistence imagePersistence;
5810 @BeanReference(type = LayoutPersistence.class)
5811 protected LayoutPersistence layoutPersistence;
5812 @BeanReference(type = LayoutBranchPersistence.class)
5813 protected LayoutBranchPersistence layoutBranchPersistence;
5814 @BeanReference(type = LayoutPrototypePersistence.class)
5815 protected LayoutPrototypePersistence layoutPrototypePersistence;
5816 @BeanReference(type = LayoutRevisionPersistence.class)
5817 protected LayoutRevisionPersistence layoutRevisionPersistence;
5818 @BeanReference(type = LayoutSetPersistence.class)
5819 protected LayoutSetPersistence layoutSetPersistence;
5820 @BeanReference(type = LayoutSetBranchPersistence.class)
5821 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
5822 @BeanReference(type = LayoutSetPrototypePersistence.class)
5823 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
5824 @BeanReference(type = ListTypePersistence.class)
5825 protected ListTypePersistence listTypePersistence;
5826 @BeanReference(type = LockPersistence.class)
5827 protected LockPersistence lockPersistence;
5828 @BeanReference(type = MembershipRequestPersistence.class)
5829 protected MembershipRequestPersistence membershipRequestPersistence;
5830 @BeanReference(type = OrganizationPersistence.class)
5831 protected OrganizationPersistence organizationPersistence;
5832 @BeanReference(type = OrgGroupRolePersistence.class)
5833 protected OrgGroupRolePersistence orgGroupRolePersistence;
5834 @BeanReference(type = OrgLaborPersistence.class)
5835 protected OrgLaborPersistence orgLaborPersistence;
5836 @BeanReference(type = PasswordPolicyPersistence.class)
5837 protected PasswordPolicyPersistence passwordPolicyPersistence;
5838 @BeanReference(type = PasswordPolicyRelPersistence.class)
5839 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
5840 @BeanReference(type = PasswordTrackerPersistence.class)
5841 protected PasswordTrackerPersistence passwordTrackerPersistence;
5842 @BeanReference(type = PhonePersistence.class)
5843 protected PhonePersistence phonePersistence;
5844 @BeanReference(type = PluginSettingPersistence.class)
5845 protected PluginSettingPersistence pluginSettingPersistence;
5846 @BeanReference(type = PortalPreferencesPersistence.class)
5847 protected PortalPreferencesPersistence portalPreferencesPersistence;
5848 @BeanReference(type = PortletPersistence.class)
5849 protected PortletPersistence portletPersistence;
5850 @BeanReference(type = PortletItemPersistence.class)
5851 protected PortletItemPersistence portletItemPersistence;
5852 @BeanReference(type = PortletPreferencesPersistence.class)
5853 protected PortletPreferencesPersistence portletPreferencesPersistence;
5854 @BeanReference(type = RegionPersistence.class)
5855 protected RegionPersistence regionPersistence;
5856 @BeanReference(type = ReleasePersistence.class)
5857 protected ReleasePersistence releasePersistence;
5858 @BeanReference(type = RepositoryPersistence.class)
5859 protected RepositoryPersistence repositoryPersistence;
5860 @BeanReference(type = RepositoryEntryPersistence.class)
5861 protected RepositoryEntryPersistence repositoryEntryPersistence;
5862 @BeanReference(type = ResourceActionPersistence.class)
5863 protected ResourceActionPersistence resourceActionPersistence;
5864 @BeanReference(type = ResourceBlockPersistence.class)
5865 protected ResourceBlockPersistence resourceBlockPersistence;
5866 @BeanReference(type = ResourceBlockPermissionPersistence.class)
5867 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
5868 @BeanReference(type = ResourcePermissionPersistence.class)
5869 protected ResourcePermissionPersistence resourcePermissionPersistence;
5870 @BeanReference(type = ResourceTypePermissionPersistence.class)
5871 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
5872 @BeanReference(type = RolePersistence.class)
5873 protected RolePersistence rolePersistence;
5874 @BeanReference(type = ServiceComponentPersistence.class)
5875 protected ServiceComponentPersistence serviceComponentPersistence;
5876 @BeanReference(type = ShardPersistence.class)
5877 protected ShardPersistence shardPersistence;
5878 @BeanReference(type = SubscriptionPersistence.class)
5879 protected SubscriptionPersistence subscriptionPersistence;
5880 @BeanReference(type = TeamPersistence.class)
5881 protected TeamPersistence teamPersistence;
5882 @BeanReference(type = TicketPersistence.class)
5883 protected TicketPersistence ticketPersistence;
5884 @BeanReference(type = UserPersistence.class)
5885 protected UserPersistence userPersistence;
5886 @BeanReference(type = UserGroupPersistence.class)
5887 protected UserGroupPersistence userGroupPersistence;
5888 @BeanReference(type = UserGroupGroupRolePersistence.class)
5889 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
5890 @BeanReference(type = UserGroupRolePersistence.class)
5891 protected UserGroupRolePersistence userGroupRolePersistence;
5892 @BeanReference(type = UserIdMapperPersistence.class)
5893 protected UserIdMapperPersistence userIdMapperPersistence;
5894 @BeanReference(type = UserNotificationEventPersistence.class)
5895 protected UserNotificationEventPersistence userNotificationEventPersistence;
5896 @BeanReference(type = UserTrackerPersistence.class)
5897 protected UserTrackerPersistence userTrackerPersistence;
5898 @BeanReference(type = UserTrackerPathPersistence.class)
5899 protected UserTrackerPathPersistence userTrackerPathPersistence;
5900 @BeanReference(type = VirtualHostPersistence.class)
5901 protected VirtualHostPersistence virtualHostPersistence;
5902 @BeanReference(type = WebDAVPropsPersistence.class)
5903 protected WebDAVPropsPersistence webDAVPropsPersistence;
5904 @BeanReference(type = WebsitePersistence.class)
5905 protected WebsitePersistence websitePersistence;
5906 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
5907 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
5908 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
5909 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
5910 protected ContainsGroup containsGroup;
5911 protected AddGroup addGroup;
5912 protected ClearGroups clearGroups;
5913 protected RemoveGroup removeGroup;
5914 protected ContainsUser containsUser;
5915 protected AddUser addUser;
5916 protected ClearUsers clearUsers;
5917 protected RemoveUser removeUser;
5918
5919 protected class ContainsGroup {
5920 protected ContainsGroup() {
5921 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5922 _SQL_CONTAINSGROUP,
5923 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
5924 RowMapper.COUNT);
5925 }
5926
5927 protected boolean contains(long roleId, long groupId) {
5928 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5929 new Long(roleId), new Long(groupId)
5930 });
5931
5932 if (results.size() > 0) {
5933 Integer count = results.get(0);
5934
5935 if (count.intValue() > 0) {
5936 return true;
5937 }
5938 }
5939
5940 return false;
5941 }
5942
5943 private MappingSqlQuery<Integer> _mappingSqlQuery;
5944 }
5945
5946 protected class AddGroup {
5947 protected AddGroup() {
5948 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5949 "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)",
5950 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
5951 }
5952
5953 protected void add(long roleId, long groupId) throws SystemException {
5954 if (!containsGroup.contains(roleId, groupId)) {
5955 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
5956
5957 for (ModelListener<Role> listener : listeners) {
5958 listener.onBeforeAddAssociation(roleId,
5959 com.liferay.portal.model.Group.class.getName(), groupId);
5960 }
5961
5962 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
5963 listener.onBeforeAddAssociation(groupId,
5964 Role.class.getName(), roleId);
5965 }
5966
5967 _sqlUpdate.update(new Object[] {
5968 new Long(roleId), new Long(groupId)
5969 });
5970
5971 for (ModelListener<Role> listener : listeners) {
5972 listener.onAfterAddAssociation(roleId,
5973 com.liferay.portal.model.Group.class.getName(), groupId);
5974 }
5975
5976 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
5977 listener.onAfterAddAssociation(groupId,
5978 Role.class.getName(), roleId);
5979 }
5980 }
5981 }
5982
5983 private SqlUpdate _sqlUpdate;
5984 }
5985
5986 protected class ClearGroups {
5987 protected ClearGroups() {
5988 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5989 "DELETE FROM Groups_Roles WHERE roleId = ?",
5990 new int[] { java.sql.Types.BIGINT });
5991 }
5992
5993 protected void clear(long roleId) throws SystemException {
5994 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
5995
5996 List<com.liferay.portal.model.Group> groups = null;
5997
5998 if ((listeners.length > 0) || (groupListeners.length > 0)) {
5999 groups = getGroups(roleId);
6000
6001 for (com.liferay.portal.model.Group group : groups) {
6002 for (ModelListener<Role> listener : listeners) {
6003 listener.onBeforeRemoveAssociation(roleId,
6004 com.liferay.portal.model.Group.class.getName(),
6005 group.getPrimaryKey());
6006 }
6007
6008 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6009 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
6010 Role.class.getName(), roleId);
6011 }
6012 }
6013 }
6014
6015 _sqlUpdate.update(new Object[] { new Long(roleId) });
6016
6017 if ((listeners.length > 0) || (groupListeners.length > 0)) {
6018 for (com.liferay.portal.model.Group group : groups) {
6019 for (ModelListener<Role> listener : listeners) {
6020 listener.onAfterRemoveAssociation(roleId,
6021 com.liferay.portal.model.Group.class.getName(),
6022 group.getPrimaryKey());
6023 }
6024
6025 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6026 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
6027 Role.class.getName(), roleId);
6028 }
6029 }
6030 }
6031 }
6032
6033 private SqlUpdate _sqlUpdate;
6034 }
6035
6036 protected class RemoveGroup {
6037 protected RemoveGroup() {
6038 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6039 "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
6040 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6041 }
6042
6043 protected void remove(long roleId, long groupId)
6044 throws SystemException {
6045 if (containsGroup.contains(roleId, groupId)) {
6046 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
6047
6048 for (ModelListener<Role> listener : listeners) {
6049 listener.onBeforeRemoveAssociation(roleId,
6050 com.liferay.portal.model.Group.class.getName(), groupId);
6051 }
6052
6053 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6054 listener.onBeforeRemoveAssociation(groupId,
6055 Role.class.getName(), roleId);
6056 }
6057
6058 _sqlUpdate.update(new Object[] {
6059 new Long(roleId), new Long(groupId)
6060 });
6061
6062 for (ModelListener<Role> listener : listeners) {
6063 listener.onAfterRemoveAssociation(roleId,
6064 com.liferay.portal.model.Group.class.getName(), groupId);
6065 }
6066
6067 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6068 listener.onAfterRemoveAssociation(groupId,
6069 Role.class.getName(), roleId);
6070 }
6071 }
6072 }
6073
6074 private SqlUpdate _sqlUpdate;
6075 }
6076
6077 protected class ContainsUser {
6078 protected ContainsUser() {
6079 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
6080 _SQL_CONTAINSUSER,
6081 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
6082 RowMapper.COUNT);
6083 }
6084
6085 protected boolean contains(long roleId, long userId) {
6086 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
6087 new Long(roleId), new Long(userId)
6088 });
6089
6090 if (results.size() > 0) {
6091 Integer count = results.get(0);
6092
6093 if (count.intValue() > 0) {
6094 return true;
6095 }
6096 }
6097
6098 return false;
6099 }
6100
6101 private MappingSqlQuery<Integer> _mappingSqlQuery;
6102 }
6103
6104 protected class AddUser {
6105 protected AddUser() {
6106 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6107 "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)",
6108 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6109 }
6110
6111 protected void add(long roleId, long userId) throws SystemException {
6112 if (!containsUser.contains(roleId, userId)) {
6113 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6114
6115 for (ModelListener<Role> listener : listeners) {
6116 listener.onBeforeAddAssociation(roleId,
6117 com.liferay.portal.model.User.class.getName(), userId);
6118 }
6119
6120 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6121 listener.onBeforeAddAssociation(userId,
6122 Role.class.getName(), roleId);
6123 }
6124
6125 _sqlUpdate.update(new Object[] {
6126 new Long(roleId), new Long(userId)
6127 });
6128
6129 for (ModelListener<Role> listener : listeners) {
6130 listener.onAfterAddAssociation(roleId,
6131 com.liferay.portal.model.User.class.getName(), userId);
6132 }
6133
6134 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6135 listener.onAfterAddAssociation(userId,
6136 Role.class.getName(), roleId);
6137 }
6138 }
6139 }
6140
6141 private SqlUpdate _sqlUpdate;
6142 }
6143
6144 protected class ClearUsers {
6145 protected ClearUsers() {
6146 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6147 "DELETE FROM Users_Roles WHERE roleId = ?",
6148 new int[] { java.sql.Types.BIGINT });
6149 }
6150
6151 protected void clear(long roleId) throws SystemException {
6152 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6153
6154 List<com.liferay.portal.model.User> users = null;
6155
6156 if ((listeners.length > 0) || (userListeners.length > 0)) {
6157 users = getUsers(roleId);
6158
6159 for (com.liferay.portal.model.User user : users) {
6160 for (ModelListener<Role> listener : listeners) {
6161 listener.onBeforeRemoveAssociation(roleId,
6162 com.liferay.portal.model.User.class.getName(),
6163 user.getPrimaryKey());
6164 }
6165
6166 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6167 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
6168 Role.class.getName(), roleId);
6169 }
6170 }
6171 }
6172
6173 _sqlUpdate.update(new Object[] { new Long(roleId) });
6174
6175 if ((listeners.length > 0) || (userListeners.length > 0)) {
6176 for (com.liferay.portal.model.User user : users) {
6177 for (ModelListener<Role> listener : listeners) {
6178 listener.onAfterRemoveAssociation(roleId,
6179 com.liferay.portal.model.User.class.getName(),
6180 user.getPrimaryKey());
6181 }
6182
6183 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6184 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
6185 Role.class.getName(), roleId);
6186 }
6187 }
6188 }
6189 }
6190
6191 private SqlUpdate _sqlUpdate;
6192 }
6193
6194 protected class RemoveUser {
6195 protected RemoveUser() {
6196 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6197 "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?",
6198 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6199 }
6200
6201 protected void remove(long roleId, long userId)
6202 throws SystemException {
6203 if (containsUser.contains(roleId, userId)) {
6204 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6205
6206 for (ModelListener<Role> listener : listeners) {
6207 listener.onBeforeRemoveAssociation(roleId,
6208 com.liferay.portal.model.User.class.getName(), userId);
6209 }
6210
6211 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6212 listener.onBeforeRemoveAssociation(userId,
6213 Role.class.getName(), roleId);
6214 }
6215
6216 _sqlUpdate.update(new Object[] {
6217 new Long(roleId), new Long(userId)
6218 });
6219
6220 for (ModelListener<Role> listener : listeners) {
6221 listener.onAfterRemoveAssociation(roleId,
6222 com.liferay.portal.model.User.class.getName(), userId);
6223 }
6224
6225 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6226 listener.onAfterRemoveAssociation(userId,
6227 Role.class.getName(), roleId);
6228 }
6229 }
6230 }
6231
6232 private SqlUpdate _sqlUpdate;
6233 }
6234
6235 private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
6236 private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
6237 private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
6238 private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
6239 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
6240 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
6241 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ? AND groupId = ?";
6242 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
6243 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
6244 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ? AND userId = ?";
6245 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
6246 private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL";
6247 private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?";
6248 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = ?)";
6249 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
6250 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
6251 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = ?)";
6252 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
6253 private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
6254 private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = lower(CAST_TEXT(?))";
6255 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR lower(role.name) = lower(CAST_TEXT(?)))";
6256 private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
6257 private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
6258 private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
6259 private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = ?)";
6260 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
6261 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
6262 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
6263 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId";
6264 private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
6265 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
6266 "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
6267 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
6268 ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
6269 private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
6270 private static final String _FILTER_ENTITY_ALIAS = "role";
6271 private static final String _FILTER_ENTITY_TABLE = "Role_";
6272 private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
6273 private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
6274 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
6275 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
6276 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6277 private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
6278 private static Role _nullRole = new RoleImpl() {
6279 @Override
6280 public Object clone() {
6281 return this;
6282 }
6283
6284 @Override
6285 public CacheModel<Role> toCacheModel() {
6286 return _nullRoleCacheModel;
6287 }
6288 };
6289
6290 private static CacheModel<Role> _nullRoleCacheModel = new CacheModel<Role>() {
6291 public Role toEntityModel() {
6292 return _nullRole;
6293 }
6294 };
6295 }