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