001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchResourceTypePermissionException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.ResourceTypePermission;
040 import com.liferay.portal.model.impl.ResourceTypePermissionImpl;
041 import com.liferay.portal.model.impl.ResourceTypePermissionModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class ResourceTypePermissionPersistenceImpl extends BasePersistenceImpl<ResourceTypePermission>
063 implements ResourceTypePermissionPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = ResourceTypePermissionImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
075 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
076 ResourceTypePermissionImpl.class,
077 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
079 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
080 ResourceTypePermissionImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
083 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
086 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
087 ResourceTypePermissionImpl.class,
088 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
089 new String[] {
090 Long.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
096 new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
097 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
098 ResourceTypePermissionImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
100 new String[] { Long.class.getName() },
101 ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
103 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
105 new String[] { Long.class.getName() });
106
107
114 public List<ResourceTypePermission> findByRoleId(long roleId)
115 throws SystemException {
116 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117 }
118
119
132 public List<ResourceTypePermission> findByRoleId(long roleId, int start,
133 int end) throws SystemException {
134 return findByRoleId(roleId, start, end, null);
135 }
136
137
151 public List<ResourceTypePermission> findByRoleId(long roleId, int start,
152 int end, OrderByComparator orderByComparator) throws SystemException {
153 boolean pagination = true;
154 FinderPath finderPath = null;
155 Object[] finderArgs = null;
156
157 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158 (orderByComparator == null)) {
159 pagination = false;
160 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
161 finderArgs = new Object[] { roleId };
162 }
163 else {
164 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
165 finderArgs = new Object[] { roleId, start, end, orderByComparator };
166 }
167
168 List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
169 finderArgs, this);
170
171 if ((list != null) && !list.isEmpty()) {
172 for (ResourceTypePermission resourceTypePermission : list) {
173 if ((roleId != resourceTypePermission.getRoleId())) {
174 list = null;
175
176 break;
177 }
178 }
179 }
180
181 if (list == null) {
182 StringBundler query = null;
183
184 if (orderByComparator != null) {
185 query = new StringBundler(3 +
186 (orderByComparator.getOrderByFields().length * 3));
187 }
188 else {
189 query = new StringBundler(3);
190 }
191
192 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
193
194 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
195
196 if (orderByComparator != null) {
197 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
198 orderByComparator);
199 }
200 else
201 if (pagination) {
202 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
203 }
204
205 String sql = query.toString();
206
207 Session session = null;
208
209 try {
210 session = openSession();
211
212 Query q = session.createQuery(sql);
213
214 QueryPos qPos = QueryPos.getInstance(q);
215
216 qPos.add(roleId);
217
218 if (!pagination) {
219 list = (List<ResourceTypePermission>)QueryUtil.list(q,
220 getDialect(), start, end, false);
221
222 Collections.sort(list);
223
224 list = new UnmodifiableList<ResourceTypePermission>(list);
225 }
226 else {
227 list = (List<ResourceTypePermission>)QueryUtil.list(q,
228 getDialect(), start, end);
229 }
230
231 cacheResult(list);
232
233 FinderCacheUtil.putResult(finderPath, finderArgs, list);
234 }
235 catch (Exception e) {
236 FinderCacheUtil.removeResult(finderPath, finderArgs);
237
238 throw processException(e);
239 }
240 finally {
241 closeSession(session);
242 }
243 }
244
245 return list;
246 }
247
248
257 public ResourceTypePermission findByRoleId_First(long roleId,
258 OrderByComparator orderByComparator)
259 throws NoSuchResourceTypePermissionException, SystemException {
260 ResourceTypePermission resourceTypePermission = fetchByRoleId_First(roleId,
261 orderByComparator);
262
263 if (resourceTypePermission != null) {
264 return resourceTypePermission;
265 }
266
267 StringBundler msg = new StringBundler(4);
268
269 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
270
271 msg.append("roleId=");
272 msg.append(roleId);
273
274 msg.append(StringPool.CLOSE_CURLY_BRACE);
275
276 throw new NoSuchResourceTypePermissionException(msg.toString());
277 }
278
279
287 public ResourceTypePermission fetchByRoleId_First(long roleId,
288 OrderByComparator orderByComparator) throws SystemException {
289 List<ResourceTypePermission> list = findByRoleId(roleId, 0, 1,
290 orderByComparator);
291
292 if (!list.isEmpty()) {
293 return list.get(0);
294 }
295
296 return null;
297 }
298
299
308 public ResourceTypePermission findByRoleId_Last(long roleId,
309 OrderByComparator orderByComparator)
310 throws NoSuchResourceTypePermissionException, SystemException {
311 ResourceTypePermission resourceTypePermission = fetchByRoleId_Last(roleId,
312 orderByComparator);
313
314 if (resourceTypePermission != null) {
315 return resourceTypePermission;
316 }
317
318 StringBundler msg = new StringBundler(4);
319
320 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
321
322 msg.append("roleId=");
323 msg.append(roleId);
324
325 msg.append(StringPool.CLOSE_CURLY_BRACE);
326
327 throw new NoSuchResourceTypePermissionException(msg.toString());
328 }
329
330
338 public ResourceTypePermission fetchByRoleId_Last(long roleId,
339 OrderByComparator orderByComparator) throws SystemException {
340 int count = countByRoleId(roleId);
341
342 List<ResourceTypePermission> list = findByRoleId(roleId, count - 1,
343 count, orderByComparator);
344
345 if (!list.isEmpty()) {
346 return list.get(0);
347 }
348
349 return null;
350 }
351
352
362 public ResourceTypePermission[] findByRoleId_PrevAndNext(
363 long resourceTypePermissionId, long roleId,
364 OrderByComparator orderByComparator)
365 throws NoSuchResourceTypePermissionException, SystemException {
366 ResourceTypePermission resourceTypePermission = findByPrimaryKey(resourceTypePermissionId);
367
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 ResourceTypePermission[] array = new ResourceTypePermissionImpl[3];
374
375 array[0] = getByRoleId_PrevAndNext(session, resourceTypePermission,
376 roleId, orderByComparator, true);
377
378 array[1] = resourceTypePermission;
379
380 array[2] = getByRoleId_PrevAndNext(session, resourceTypePermission,
381 roleId, orderByComparator, false);
382
383 return array;
384 }
385 catch (Exception e) {
386 throw processException(e);
387 }
388 finally {
389 closeSession(session);
390 }
391 }
392
393 protected ResourceTypePermission getByRoleId_PrevAndNext(Session session,
394 ResourceTypePermission resourceTypePermission, long roleId,
395 OrderByComparator orderByComparator, boolean previous) {
396 StringBundler query = null;
397
398 if (orderByComparator != null) {
399 query = new StringBundler(6 +
400 (orderByComparator.getOrderByFields().length * 6));
401 }
402 else {
403 query = new StringBundler(3);
404 }
405
406 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
407
408 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
409
410 if (orderByComparator != null) {
411 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
412
413 if (orderByConditionFields.length > 0) {
414 query.append(WHERE_AND);
415 }
416
417 for (int i = 0; i < orderByConditionFields.length; i++) {
418 query.append(_ORDER_BY_ENTITY_ALIAS);
419 query.append(orderByConditionFields[i]);
420
421 if ((i + 1) < orderByConditionFields.length) {
422 if (orderByComparator.isAscending() ^ previous) {
423 query.append(WHERE_GREATER_THAN_HAS_NEXT);
424 }
425 else {
426 query.append(WHERE_LESSER_THAN_HAS_NEXT);
427 }
428 }
429 else {
430 if (orderByComparator.isAscending() ^ previous) {
431 query.append(WHERE_GREATER_THAN);
432 }
433 else {
434 query.append(WHERE_LESSER_THAN);
435 }
436 }
437 }
438
439 query.append(ORDER_BY_CLAUSE);
440
441 String[] orderByFields = orderByComparator.getOrderByFields();
442
443 for (int i = 0; i < orderByFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByFields[i]);
446
447 if ((i + 1) < orderByFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(ORDER_BY_ASC_HAS_NEXT);
450 }
451 else {
452 query.append(ORDER_BY_DESC_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(ORDER_BY_ASC);
458 }
459 else {
460 query.append(ORDER_BY_DESC);
461 }
462 }
463 }
464 }
465 else {
466 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
467 }
468
469 String sql = query.toString();
470
471 Query q = session.createQuery(sql);
472
473 q.setFirstResult(0);
474 q.setMaxResults(2);
475
476 QueryPos qPos = QueryPos.getInstance(q);
477
478 qPos.add(roleId);
479
480 if (orderByComparator != null) {
481 Object[] values = orderByComparator.getOrderByConditionValues(resourceTypePermission);
482
483 for (Object value : values) {
484 qPos.add(value);
485 }
486 }
487
488 List<ResourceTypePermission> list = q.list();
489
490 if (list.size() == 2) {
491 return list.get(1);
492 }
493 else {
494 return null;
495 }
496 }
497
498
504 public void removeByRoleId(long roleId) throws SystemException {
505 for (ResourceTypePermission resourceTypePermission : findByRoleId(
506 roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
507 remove(resourceTypePermission);
508 }
509 }
510
511
518 public int countByRoleId(long roleId) throws SystemException {
519 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
520
521 Object[] finderArgs = new Object[] { roleId };
522
523 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
524 this);
525
526 if (count == null) {
527 StringBundler query = new StringBundler(2);
528
529 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
530
531 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
532
533 String sql = query.toString();
534
535 Session session = null;
536
537 try {
538 session = openSession();
539
540 Query q = session.createQuery(sql);
541
542 QueryPos qPos = QueryPos.getInstance(q);
543
544 qPos.add(roleId);
545
546 count = (Long)q.uniqueResult();
547
548 FinderCacheUtil.putResult(finderPath, finderArgs, count);
549 }
550 catch (Exception e) {
551 FinderCacheUtil.removeResult(finderPath, finderArgs);
552
553 throw processException(e);
554 }
555 finally {
556 closeSession(session);
557 }
558 }
559
560 return count.intValue();
561 }
562
563 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourceTypePermission.roleId = ?";
564 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
565 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
566 ResourceTypePermissionImpl.class,
567 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_R",
568 new String[] {
569 Long.class.getName(), String.class.getName(),
570 Long.class.getName(),
571
572 Integer.class.getName(), Integer.class.getName(),
573 OrderByComparator.class.getName()
574 });
575 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
576 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
577 ResourceTypePermissionImpl.class,
578 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_R",
579 new String[] {
580 Long.class.getName(), String.class.getName(),
581 Long.class.getName()
582 },
583 ResourceTypePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
584 ResourceTypePermissionModelImpl.NAME_COLUMN_BITMASK |
585 ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
586 public static final FinderPath FINDER_PATH_COUNT_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
587 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
588 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_R",
589 new String[] {
590 Long.class.getName(), String.class.getName(),
591 Long.class.getName()
592 });
593
594
603 public List<ResourceTypePermission> findByC_N_R(long companyId,
604 String name, long roleId) throws SystemException {
605 return findByC_N_R(companyId, name, roleId, QueryUtil.ALL_POS,
606 QueryUtil.ALL_POS, null);
607 }
608
609
624 public List<ResourceTypePermission> findByC_N_R(long companyId,
625 String name, long roleId, int start, int end) throws SystemException {
626 return findByC_N_R(companyId, name, roleId, start, end, null);
627 }
628
629
645 public List<ResourceTypePermission> findByC_N_R(long companyId,
646 String name, long roleId, int start, int end,
647 OrderByComparator orderByComparator) throws SystemException {
648 boolean pagination = true;
649 FinderPath finderPath = null;
650 Object[] finderArgs = null;
651
652 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
653 (orderByComparator == null)) {
654 pagination = false;
655 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R;
656 finderArgs = new Object[] { companyId, name, roleId };
657 }
658 else {
659 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_R;
660 finderArgs = new Object[] {
661 companyId, name, roleId,
662
663 start, end, orderByComparator
664 };
665 }
666
667 List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
668 finderArgs, this);
669
670 if ((list != null) && !list.isEmpty()) {
671 for (ResourceTypePermission resourceTypePermission : list) {
672 if ((companyId != resourceTypePermission.getCompanyId()) ||
673 !Validator.equals(name, resourceTypePermission.getName()) ||
674 (roleId != resourceTypePermission.getRoleId())) {
675 list = null;
676
677 break;
678 }
679 }
680 }
681
682 if (list == null) {
683 StringBundler query = null;
684
685 if (orderByComparator != null) {
686 query = new StringBundler(5 +
687 (orderByComparator.getOrderByFields().length * 3));
688 }
689 else {
690 query = new StringBundler(5);
691 }
692
693 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
694
695 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
696
697 boolean bindName = false;
698
699 if (name == null) {
700 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
701 }
702 else if (name.equals(StringPool.BLANK)) {
703 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
704 }
705 else {
706 bindName = true;
707
708 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
709 }
710
711 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
712
713 if (orderByComparator != null) {
714 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
715 orderByComparator);
716 }
717 else
718 if (pagination) {
719 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
720 }
721
722 String sql = query.toString();
723
724 Session session = null;
725
726 try {
727 session = openSession();
728
729 Query q = session.createQuery(sql);
730
731 QueryPos qPos = QueryPos.getInstance(q);
732
733 qPos.add(companyId);
734
735 if (bindName) {
736 qPos.add(name);
737 }
738
739 qPos.add(roleId);
740
741 if (!pagination) {
742 list = (List<ResourceTypePermission>)QueryUtil.list(q,
743 getDialect(), start, end, false);
744
745 Collections.sort(list);
746
747 list = new UnmodifiableList<ResourceTypePermission>(list);
748 }
749 else {
750 list = (List<ResourceTypePermission>)QueryUtil.list(q,
751 getDialect(), start, end);
752 }
753
754 cacheResult(list);
755
756 FinderCacheUtil.putResult(finderPath, finderArgs, list);
757 }
758 catch (Exception e) {
759 FinderCacheUtil.removeResult(finderPath, finderArgs);
760
761 throw processException(e);
762 }
763 finally {
764 closeSession(session);
765 }
766 }
767
768 return list;
769 }
770
771
782 public ResourceTypePermission findByC_N_R_First(long companyId,
783 String name, long roleId, OrderByComparator orderByComparator)
784 throws NoSuchResourceTypePermissionException, SystemException {
785 ResourceTypePermission resourceTypePermission = fetchByC_N_R_First(companyId,
786 name, roleId, orderByComparator);
787
788 if (resourceTypePermission != null) {
789 return resourceTypePermission;
790 }
791
792 StringBundler msg = new StringBundler(8);
793
794 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
795
796 msg.append("companyId=");
797 msg.append(companyId);
798
799 msg.append(", name=");
800 msg.append(name);
801
802 msg.append(", roleId=");
803 msg.append(roleId);
804
805 msg.append(StringPool.CLOSE_CURLY_BRACE);
806
807 throw new NoSuchResourceTypePermissionException(msg.toString());
808 }
809
810
820 public ResourceTypePermission fetchByC_N_R_First(long companyId,
821 String name, long roleId, OrderByComparator orderByComparator)
822 throws SystemException {
823 List<ResourceTypePermission> list = findByC_N_R(companyId, name,
824 roleId, 0, 1, orderByComparator);
825
826 if (!list.isEmpty()) {
827 return list.get(0);
828 }
829
830 return null;
831 }
832
833
844 public ResourceTypePermission findByC_N_R_Last(long companyId, String name,
845 long roleId, OrderByComparator orderByComparator)
846 throws NoSuchResourceTypePermissionException, SystemException {
847 ResourceTypePermission resourceTypePermission = fetchByC_N_R_Last(companyId,
848 name, roleId, orderByComparator);
849
850 if (resourceTypePermission != null) {
851 return resourceTypePermission;
852 }
853
854 StringBundler msg = new StringBundler(8);
855
856 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
857
858 msg.append("companyId=");
859 msg.append(companyId);
860
861 msg.append(", name=");
862 msg.append(name);
863
864 msg.append(", roleId=");
865 msg.append(roleId);
866
867 msg.append(StringPool.CLOSE_CURLY_BRACE);
868
869 throw new NoSuchResourceTypePermissionException(msg.toString());
870 }
871
872
882 public ResourceTypePermission fetchByC_N_R_Last(long companyId,
883 String name, long roleId, OrderByComparator orderByComparator)
884 throws SystemException {
885 int count = countByC_N_R(companyId, name, roleId);
886
887 List<ResourceTypePermission> list = findByC_N_R(companyId, name,
888 roleId, count - 1, count, orderByComparator);
889
890 if (!list.isEmpty()) {
891 return list.get(0);
892 }
893
894 return null;
895 }
896
897
909 public ResourceTypePermission[] findByC_N_R_PrevAndNext(
910 long resourceTypePermissionId, long companyId, String name,
911 long roleId, OrderByComparator orderByComparator)
912 throws NoSuchResourceTypePermissionException, SystemException {
913 ResourceTypePermission resourceTypePermission = findByPrimaryKey(resourceTypePermissionId);
914
915 Session session = null;
916
917 try {
918 session = openSession();
919
920 ResourceTypePermission[] array = new ResourceTypePermissionImpl[3];
921
922 array[0] = getByC_N_R_PrevAndNext(session, resourceTypePermission,
923 companyId, name, roleId, orderByComparator, true);
924
925 array[1] = resourceTypePermission;
926
927 array[2] = getByC_N_R_PrevAndNext(session, resourceTypePermission,
928 companyId, name, roleId, orderByComparator, false);
929
930 return array;
931 }
932 catch (Exception e) {
933 throw processException(e);
934 }
935 finally {
936 closeSession(session);
937 }
938 }
939
940 protected ResourceTypePermission getByC_N_R_PrevAndNext(Session session,
941 ResourceTypePermission resourceTypePermission, long companyId,
942 String name, long roleId, OrderByComparator orderByComparator,
943 boolean previous) {
944 StringBundler query = null;
945
946 if (orderByComparator != null) {
947 query = new StringBundler(6 +
948 (orderByComparator.getOrderByFields().length * 6));
949 }
950 else {
951 query = new StringBundler(3);
952 }
953
954 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
955
956 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
957
958 boolean bindName = false;
959
960 if (name == null) {
961 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
962 }
963 else if (name.equals(StringPool.BLANK)) {
964 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
965 }
966 else {
967 bindName = true;
968
969 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
970 }
971
972 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
973
974 if (orderByComparator != null) {
975 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
976
977 if (orderByConditionFields.length > 0) {
978 query.append(WHERE_AND);
979 }
980
981 for (int i = 0; i < orderByConditionFields.length; i++) {
982 query.append(_ORDER_BY_ENTITY_ALIAS);
983 query.append(orderByConditionFields[i]);
984
985 if ((i + 1) < orderByConditionFields.length) {
986 if (orderByComparator.isAscending() ^ previous) {
987 query.append(WHERE_GREATER_THAN_HAS_NEXT);
988 }
989 else {
990 query.append(WHERE_LESSER_THAN_HAS_NEXT);
991 }
992 }
993 else {
994 if (orderByComparator.isAscending() ^ previous) {
995 query.append(WHERE_GREATER_THAN);
996 }
997 else {
998 query.append(WHERE_LESSER_THAN);
999 }
1000 }
1001 }
1002
1003 query.append(ORDER_BY_CLAUSE);
1004
1005 String[] orderByFields = orderByComparator.getOrderByFields();
1006
1007 for (int i = 0; i < orderByFields.length; i++) {
1008 query.append(_ORDER_BY_ENTITY_ALIAS);
1009 query.append(orderByFields[i]);
1010
1011 if ((i + 1) < orderByFields.length) {
1012 if (orderByComparator.isAscending() ^ previous) {
1013 query.append(ORDER_BY_ASC_HAS_NEXT);
1014 }
1015 else {
1016 query.append(ORDER_BY_DESC_HAS_NEXT);
1017 }
1018 }
1019 else {
1020 if (orderByComparator.isAscending() ^ previous) {
1021 query.append(ORDER_BY_ASC);
1022 }
1023 else {
1024 query.append(ORDER_BY_DESC);
1025 }
1026 }
1027 }
1028 }
1029 else {
1030 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
1031 }
1032
1033 String sql = query.toString();
1034
1035 Query q = session.createQuery(sql);
1036
1037 q.setFirstResult(0);
1038 q.setMaxResults(2);
1039
1040 QueryPos qPos = QueryPos.getInstance(q);
1041
1042 qPos.add(companyId);
1043
1044 if (bindName) {
1045 qPos.add(name);
1046 }
1047
1048 qPos.add(roleId);
1049
1050 if (orderByComparator != null) {
1051 Object[] values = orderByComparator.getOrderByConditionValues(resourceTypePermission);
1052
1053 for (Object value : values) {
1054 qPos.add(value);
1055 }
1056 }
1057
1058 List<ResourceTypePermission> list = q.list();
1059
1060 if (list.size() == 2) {
1061 return list.get(1);
1062 }
1063 else {
1064 return null;
1065 }
1066 }
1067
1068
1076 public void removeByC_N_R(long companyId, String name, long roleId)
1077 throws SystemException {
1078 for (ResourceTypePermission resourceTypePermission : findByC_N_R(
1079 companyId, name, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1080 null)) {
1081 remove(resourceTypePermission);
1082 }
1083 }
1084
1085
1094 public int countByC_N_R(long companyId, String name, long roleId)
1095 throws SystemException {
1096 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_R;
1097
1098 Object[] finderArgs = new Object[] { companyId, name, roleId };
1099
1100 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1101 this);
1102
1103 if (count == null) {
1104 StringBundler query = new StringBundler(4);
1105
1106 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1107
1108 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
1109
1110 boolean bindName = false;
1111
1112 if (name == null) {
1113 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
1114 }
1115 else if (name.equals(StringPool.BLANK)) {
1116 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
1117 }
1118 else {
1119 bindName = true;
1120
1121 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
1122 }
1123
1124 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
1125
1126 String sql = query.toString();
1127
1128 Session session = null;
1129
1130 try {
1131 session = openSession();
1132
1133 Query q = session.createQuery(sql);
1134
1135 QueryPos qPos = QueryPos.getInstance(q);
1136
1137 qPos.add(companyId);
1138
1139 if (bindName) {
1140 qPos.add(name);
1141 }
1142
1143 qPos.add(roleId);
1144
1145 count = (Long)q.uniqueResult();
1146
1147 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1148 }
1149 catch (Exception e) {
1150 FinderCacheUtil.removeResult(finderPath, finderArgs);
1151
1152 throw processException(e);
1153 }
1154 finally {
1155 closeSession(session);
1156 }
1157 }
1158
1159 return count.intValue();
1160 }
1161
1162 private static final String _FINDER_COLUMN_C_N_R_COMPANYID_2 = "resourceTypePermission.companyId = ? AND ";
1163 private static final String _FINDER_COLUMN_C_N_R_NAME_1 = "resourceTypePermission.name IS NULL AND ";
1164 private static final String _FINDER_COLUMN_C_N_R_NAME_2 = "resourceTypePermission.name = ? AND ";
1165 private static final String _FINDER_COLUMN_C_N_R_NAME_3 = "(resourceTypePermission.name IS NULL OR resourceTypePermission.name = '') AND ";
1166 private static final String _FINDER_COLUMN_C_N_R_ROLEID_2 = "resourceTypePermission.roleId = ?";
1167 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1168 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
1169 ResourceTypePermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
1170 "fetchByC_G_N_R",
1171 new String[] {
1172 Long.class.getName(), Long.class.getName(),
1173 String.class.getName(), Long.class.getName()
1174 },
1175 ResourceTypePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
1176 ResourceTypePermissionModelImpl.GROUPID_COLUMN_BITMASK |
1177 ResourceTypePermissionModelImpl.NAME_COLUMN_BITMASK |
1178 ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
1179 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1180 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1181 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_R",
1182 new String[] {
1183 Long.class.getName(), Long.class.getName(),
1184 String.class.getName(), Long.class.getName()
1185 });
1186
1187
1198 public ResourceTypePermission findByC_G_N_R(long companyId, long groupId,
1199 String name, long roleId)
1200 throws NoSuchResourceTypePermissionException, SystemException {
1201 ResourceTypePermission resourceTypePermission = fetchByC_G_N_R(companyId,
1202 groupId, name, roleId);
1203
1204 if (resourceTypePermission == null) {
1205 StringBundler msg = new StringBundler(10);
1206
1207 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1208
1209 msg.append("companyId=");
1210 msg.append(companyId);
1211
1212 msg.append(", groupId=");
1213 msg.append(groupId);
1214
1215 msg.append(", name=");
1216 msg.append(name);
1217
1218 msg.append(", roleId=");
1219 msg.append(roleId);
1220
1221 msg.append(StringPool.CLOSE_CURLY_BRACE);
1222
1223 if (_log.isWarnEnabled()) {
1224 _log.warn(msg.toString());
1225 }
1226
1227 throw new NoSuchResourceTypePermissionException(msg.toString());
1228 }
1229
1230 return resourceTypePermission;
1231 }
1232
1233
1243 public ResourceTypePermission fetchByC_G_N_R(long companyId, long groupId,
1244 String name, long roleId) throws SystemException {
1245 return fetchByC_G_N_R(companyId, groupId, name, roleId, true);
1246 }
1247
1248
1259 public ResourceTypePermission fetchByC_G_N_R(long companyId, long groupId,
1260 String name, long roleId, boolean retrieveFromCache)
1261 throws SystemException {
1262 Object[] finderArgs = new Object[] { companyId, groupId, name, roleId };
1263
1264 Object result = null;
1265
1266 if (retrieveFromCache) {
1267 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1268 finderArgs, this);
1269 }
1270
1271 if (result instanceof ResourceTypePermission) {
1272 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)result;
1273
1274 if ((companyId != resourceTypePermission.getCompanyId()) ||
1275 (groupId != resourceTypePermission.getGroupId()) ||
1276 !Validator.equals(name, resourceTypePermission.getName()) ||
1277 (roleId != resourceTypePermission.getRoleId())) {
1278 result = null;
1279 }
1280 }
1281
1282 if (result == null) {
1283 StringBundler query = new StringBundler(6);
1284
1285 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
1286
1287 query.append(_FINDER_COLUMN_C_G_N_R_COMPANYID_2);
1288
1289 query.append(_FINDER_COLUMN_C_G_N_R_GROUPID_2);
1290
1291 boolean bindName = false;
1292
1293 if (name == null) {
1294 query.append(_FINDER_COLUMN_C_G_N_R_NAME_1);
1295 }
1296 else if (name.equals(StringPool.BLANK)) {
1297 query.append(_FINDER_COLUMN_C_G_N_R_NAME_3);
1298 }
1299 else {
1300 bindName = true;
1301
1302 query.append(_FINDER_COLUMN_C_G_N_R_NAME_2);
1303 }
1304
1305 query.append(_FINDER_COLUMN_C_G_N_R_ROLEID_2);
1306
1307 String sql = query.toString();
1308
1309 Session session = null;
1310
1311 try {
1312 session = openSession();
1313
1314 Query q = session.createQuery(sql);
1315
1316 QueryPos qPos = QueryPos.getInstance(q);
1317
1318 qPos.add(companyId);
1319
1320 qPos.add(groupId);
1321
1322 if (bindName) {
1323 qPos.add(name);
1324 }
1325
1326 qPos.add(roleId);
1327
1328 List<ResourceTypePermission> list = q.list();
1329
1330 if (list.isEmpty()) {
1331 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1332 finderArgs, list);
1333 }
1334 else {
1335 ResourceTypePermission resourceTypePermission = list.get(0);
1336
1337 result = resourceTypePermission;
1338
1339 cacheResult(resourceTypePermission);
1340
1341 if ((resourceTypePermission.getCompanyId() != companyId) ||
1342 (resourceTypePermission.getGroupId() != groupId) ||
1343 (resourceTypePermission.getName() == null) ||
1344 !resourceTypePermission.getName().equals(name) ||
1345 (resourceTypePermission.getRoleId() != roleId)) {
1346 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1347 finderArgs, resourceTypePermission);
1348 }
1349 }
1350 }
1351 catch (Exception e) {
1352 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1353 finderArgs);
1354
1355 throw processException(e);
1356 }
1357 finally {
1358 closeSession(session);
1359 }
1360 }
1361
1362 if (result instanceof List<?>) {
1363 return null;
1364 }
1365 else {
1366 return (ResourceTypePermission)result;
1367 }
1368 }
1369
1370
1380 public ResourceTypePermission removeByC_G_N_R(long companyId, long groupId,
1381 String name, long roleId)
1382 throws NoSuchResourceTypePermissionException, SystemException {
1383 ResourceTypePermission resourceTypePermission = findByC_G_N_R(companyId,
1384 groupId, name, roleId);
1385
1386 return remove(resourceTypePermission);
1387 }
1388
1389
1399 public int countByC_G_N_R(long companyId, long groupId, String name,
1400 long roleId) throws SystemException {
1401 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N_R;
1402
1403 Object[] finderArgs = new Object[] { companyId, groupId, name, roleId };
1404
1405 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1406 this);
1407
1408 if (count == null) {
1409 StringBundler query = new StringBundler(5);
1410
1411 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1412
1413 query.append(_FINDER_COLUMN_C_G_N_R_COMPANYID_2);
1414
1415 query.append(_FINDER_COLUMN_C_G_N_R_GROUPID_2);
1416
1417 boolean bindName = false;
1418
1419 if (name == null) {
1420 query.append(_FINDER_COLUMN_C_G_N_R_NAME_1);
1421 }
1422 else if (name.equals(StringPool.BLANK)) {
1423 query.append(_FINDER_COLUMN_C_G_N_R_NAME_3);
1424 }
1425 else {
1426 bindName = true;
1427
1428 query.append(_FINDER_COLUMN_C_G_N_R_NAME_2);
1429 }
1430
1431 query.append(_FINDER_COLUMN_C_G_N_R_ROLEID_2);
1432
1433 String sql = query.toString();
1434
1435 Session session = null;
1436
1437 try {
1438 session = openSession();
1439
1440 Query q = session.createQuery(sql);
1441
1442 QueryPos qPos = QueryPos.getInstance(q);
1443
1444 qPos.add(companyId);
1445
1446 qPos.add(groupId);
1447
1448 if (bindName) {
1449 qPos.add(name);
1450 }
1451
1452 qPos.add(roleId);
1453
1454 count = (Long)q.uniqueResult();
1455
1456 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1457 }
1458 catch (Exception e) {
1459 FinderCacheUtil.removeResult(finderPath, finderArgs);
1460
1461 throw processException(e);
1462 }
1463 finally {
1464 closeSession(session);
1465 }
1466 }
1467
1468 return count.intValue();
1469 }
1470
1471 private static final String _FINDER_COLUMN_C_G_N_R_COMPANYID_2 = "resourceTypePermission.companyId = ? AND ";
1472 private static final String _FINDER_COLUMN_C_G_N_R_GROUPID_2 = "resourceTypePermission.groupId = ? AND ";
1473 private static final String _FINDER_COLUMN_C_G_N_R_NAME_1 = "resourceTypePermission.name IS NULL AND ";
1474 private static final String _FINDER_COLUMN_C_G_N_R_NAME_2 = "resourceTypePermission.name = ? AND ";
1475 private static final String _FINDER_COLUMN_C_G_N_R_NAME_3 = "(resourceTypePermission.name IS NULL OR resourceTypePermission.name = '') AND ";
1476 private static final String _FINDER_COLUMN_C_G_N_R_ROLEID_2 = "resourceTypePermission.roleId = ?";
1477
1478
1483 public void cacheResult(ResourceTypePermission resourceTypePermission) {
1484 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1485 ResourceTypePermissionImpl.class,
1486 resourceTypePermission.getPrimaryKey(), resourceTypePermission);
1487
1488 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1489 new Object[] {
1490 resourceTypePermission.getCompanyId(),
1491 resourceTypePermission.getGroupId(),
1492 resourceTypePermission.getName(),
1493 resourceTypePermission.getRoleId()
1494 }, resourceTypePermission);
1495
1496 resourceTypePermission.resetOriginalValues();
1497 }
1498
1499
1504 public void cacheResult(
1505 List<ResourceTypePermission> resourceTypePermissions) {
1506 for (ResourceTypePermission resourceTypePermission : resourceTypePermissions) {
1507 if (EntityCacheUtil.getResult(
1508 ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1509 ResourceTypePermissionImpl.class,
1510 resourceTypePermission.getPrimaryKey()) == null) {
1511 cacheResult(resourceTypePermission);
1512 }
1513 else {
1514 resourceTypePermission.resetOriginalValues();
1515 }
1516 }
1517 }
1518
1519
1526 @Override
1527 public void clearCache() {
1528 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1529 CacheRegistryUtil.clear(ResourceTypePermissionImpl.class.getName());
1530 }
1531
1532 EntityCacheUtil.clearCache(ResourceTypePermissionImpl.class.getName());
1533
1534 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1535 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1536 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1537 }
1538
1539
1546 @Override
1547 public void clearCache(ResourceTypePermission resourceTypePermission) {
1548 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1549 ResourceTypePermissionImpl.class,
1550 resourceTypePermission.getPrimaryKey());
1551
1552 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1553 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1554
1555 clearUniqueFindersCache(resourceTypePermission);
1556 }
1557
1558 @Override
1559 public void clearCache(List<ResourceTypePermission> resourceTypePermissions) {
1560 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1561 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1562
1563 for (ResourceTypePermission resourceTypePermission : resourceTypePermissions) {
1564 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1565 ResourceTypePermissionImpl.class,
1566 resourceTypePermission.getPrimaryKey());
1567
1568 clearUniqueFindersCache(resourceTypePermission);
1569 }
1570 }
1571
1572 protected void cacheUniqueFindersCache(
1573 ResourceTypePermission resourceTypePermission) {
1574 if (resourceTypePermission.isNew()) {
1575 Object[] args = new Object[] {
1576 resourceTypePermission.getCompanyId(),
1577 resourceTypePermission.getGroupId(),
1578 resourceTypePermission.getName(),
1579 resourceTypePermission.getRoleId()
1580 };
1581
1582 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_R, args,
1583 Long.valueOf(1));
1584 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R, args,
1585 resourceTypePermission);
1586 }
1587 else {
1588 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1589
1590 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1591 FINDER_PATH_FETCH_BY_C_G_N_R.getColumnBitmask()) != 0) {
1592 Object[] args = new Object[] {
1593 resourceTypePermission.getCompanyId(),
1594 resourceTypePermission.getGroupId(),
1595 resourceTypePermission.getName(),
1596 resourceTypePermission.getRoleId()
1597 };
1598
1599 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_R, args,
1600 Long.valueOf(1));
1601 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R, args,
1602 resourceTypePermission);
1603 }
1604 }
1605 }
1606
1607 protected void clearUniqueFindersCache(
1608 ResourceTypePermission resourceTypePermission) {
1609 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1610
1611 Object[] args = new Object[] {
1612 resourceTypePermission.getCompanyId(),
1613 resourceTypePermission.getGroupId(),
1614 resourceTypePermission.getName(),
1615 resourceTypePermission.getRoleId()
1616 };
1617
1618 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_R, args);
1619 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R, args);
1620
1621 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1622 FINDER_PATH_FETCH_BY_C_G_N_R.getColumnBitmask()) != 0) {
1623 args = new Object[] {
1624 resourceTypePermissionModelImpl.getOriginalCompanyId(),
1625 resourceTypePermissionModelImpl.getOriginalGroupId(),
1626 resourceTypePermissionModelImpl.getOriginalName(),
1627 resourceTypePermissionModelImpl.getOriginalRoleId()
1628 };
1629
1630 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_R, args);
1631 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R, args);
1632 }
1633 }
1634
1635
1641 public ResourceTypePermission create(long resourceTypePermissionId) {
1642 ResourceTypePermission resourceTypePermission = new ResourceTypePermissionImpl();
1643
1644 resourceTypePermission.setNew(true);
1645 resourceTypePermission.setPrimaryKey(resourceTypePermissionId);
1646
1647 return resourceTypePermission;
1648 }
1649
1650
1658 public ResourceTypePermission remove(long resourceTypePermissionId)
1659 throws NoSuchResourceTypePermissionException, SystemException {
1660 return remove((Serializable)resourceTypePermissionId);
1661 }
1662
1663
1671 @Override
1672 public ResourceTypePermission remove(Serializable primaryKey)
1673 throws NoSuchResourceTypePermissionException, SystemException {
1674 Session session = null;
1675
1676 try {
1677 session = openSession();
1678
1679 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1680 primaryKey);
1681
1682 if (resourceTypePermission == null) {
1683 if (_log.isWarnEnabled()) {
1684 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1685 }
1686
1687 throw new NoSuchResourceTypePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1688 primaryKey);
1689 }
1690
1691 return remove(resourceTypePermission);
1692 }
1693 catch (NoSuchResourceTypePermissionException nsee) {
1694 throw nsee;
1695 }
1696 catch (Exception e) {
1697 throw processException(e);
1698 }
1699 finally {
1700 closeSession(session);
1701 }
1702 }
1703
1704 @Override
1705 protected ResourceTypePermission removeImpl(
1706 ResourceTypePermission resourceTypePermission)
1707 throws SystemException {
1708 resourceTypePermission = toUnwrappedModel(resourceTypePermission);
1709
1710 Session session = null;
1711
1712 try {
1713 session = openSession();
1714
1715 if (!session.contains(resourceTypePermission)) {
1716 resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1717 resourceTypePermission.getPrimaryKeyObj());
1718 }
1719
1720 if (resourceTypePermission != null) {
1721 session.delete(resourceTypePermission);
1722 }
1723 }
1724 catch (Exception e) {
1725 throw processException(e);
1726 }
1727 finally {
1728 closeSession(session);
1729 }
1730
1731 if (resourceTypePermission != null) {
1732 clearCache(resourceTypePermission);
1733 }
1734
1735 return resourceTypePermission;
1736 }
1737
1738 @Override
1739 public ResourceTypePermission updateImpl(
1740 com.liferay.portal.model.ResourceTypePermission resourceTypePermission)
1741 throws SystemException {
1742 resourceTypePermission = toUnwrappedModel(resourceTypePermission);
1743
1744 boolean isNew = resourceTypePermission.isNew();
1745
1746 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1747
1748 Session session = null;
1749
1750 try {
1751 session = openSession();
1752
1753 if (resourceTypePermission.isNew()) {
1754 session.save(resourceTypePermission);
1755
1756 resourceTypePermission.setNew(false);
1757 }
1758 else {
1759 session.merge(resourceTypePermission);
1760 }
1761 }
1762 catch (Exception e) {
1763 throw processException(e);
1764 }
1765 finally {
1766 closeSession(session);
1767 }
1768
1769 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1770
1771 if (isNew || !ResourceTypePermissionModelImpl.COLUMN_BITMASK_ENABLED) {
1772 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1773 }
1774
1775 else {
1776 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1777 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1778 Object[] args = new Object[] {
1779 resourceTypePermissionModelImpl.getOriginalRoleId()
1780 };
1781
1782 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1783 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1784 args);
1785
1786 args = new Object[] { resourceTypePermissionModelImpl.getRoleId() };
1787
1788 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1789 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1790 args);
1791 }
1792
1793 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1794 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R.getColumnBitmask()) != 0) {
1795 Object[] args = new Object[] {
1796 resourceTypePermissionModelImpl.getOriginalCompanyId(),
1797 resourceTypePermissionModelImpl.getOriginalName(),
1798 resourceTypePermissionModelImpl.getOriginalRoleId()
1799 };
1800
1801 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_R, args);
1802 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R,
1803 args);
1804
1805 args = new Object[] {
1806 resourceTypePermissionModelImpl.getCompanyId(),
1807 resourceTypePermissionModelImpl.getName(),
1808 resourceTypePermissionModelImpl.getRoleId()
1809 };
1810
1811 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_R, args);
1812 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R,
1813 args);
1814 }
1815 }
1816
1817 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1818 ResourceTypePermissionImpl.class,
1819 resourceTypePermission.getPrimaryKey(), resourceTypePermission);
1820
1821 clearUniqueFindersCache(resourceTypePermission);
1822 cacheUniqueFindersCache(resourceTypePermission);
1823
1824 return resourceTypePermission;
1825 }
1826
1827 protected ResourceTypePermission toUnwrappedModel(
1828 ResourceTypePermission resourceTypePermission) {
1829 if (resourceTypePermission instanceof ResourceTypePermissionImpl) {
1830 return resourceTypePermission;
1831 }
1832
1833 ResourceTypePermissionImpl resourceTypePermissionImpl = new ResourceTypePermissionImpl();
1834
1835 resourceTypePermissionImpl.setNew(resourceTypePermission.isNew());
1836 resourceTypePermissionImpl.setPrimaryKey(resourceTypePermission.getPrimaryKey());
1837
1838 resourceTypePermissionImpl.setResourceTypePermissionId(resourceTypePermission.getResourceTypePermissionId());
1839 resourceTypePermissionImpl.setCompanyId(resourceTypePermission.getCompanyId());
1840 resourceTypePermissionImpl.setGroupId(resourceTypePermission.getGroupId());
1841 resourceTypePermissionImpl.setName(resourceTypePermission.getName());
1842 resourceTypePermissionImpl.setRoleId(resourceTypePermission.getRoleId());
1843 resourceTypePermissionImpl.setActionIds(resourceTypePermission.getActionIds());
1844
1845 return resourceTypePermissionImpl;
1846 }
1847
1848
1856 @Override
1857 public ResourceTypePermission findByPrimaryKey(Serializable primaryKey)
1858 throws NoSuchResourceTypePermissionException, SystemException {
1859 ResourceTypePermission resourceTypePermission = fetchByPrimaryKey(primaryKey);
1860
1861 if (resourceTypePermission == null) {
1862 if (_log.isWarnEnabled()) {
1863 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1864 }
1865
1866 throw new NoSuchResourceTypePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1867 primaryKey);
1868 }
1869
1870 return resourceTypePermission;
1871 }
1872
1873
1881 public ResourceTypePermission findByPrimaryKey(
1882 long resourceTypePermissionId)
1883 throws NoSuchResourceTypePermissionException, SystemException {
1884 return findByPrimaryKey((Serializable)resourceTypePermissionId);
1885 }
1886
1887
1894 @Override
1895 public ResourceTypePermission fetchByPrimaryKey(Serializable primaryKey)
1896 throws SystemException {
1897 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)EntityCacheUtil.getResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1898 ResourceTypePermissionImpl.class, primaryKey);
1899
1900 if (resourceTypePermission == _nullResourceTypePermission) {
1901 return null;
1902 }
1903
1904 if (resourceTypePermission == null) {
1905 Session session = null;
1906
1907 try {
1908 session = openSession();
1909
1910 resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1911 primaryKey);
1912
1913 if (resourceTypePermission != null) {
1914 cacheResult(resourceTypePermission);
1915 }
1916 else {
1917 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1918 ResourceTypePermissionImpl.class, primaryKey,
1919 _nullResourceTypePermission);
1920 }
1921 }
1922 catch (Exception e) {
1923 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1924 ResourceTypePermissionImpl.class, primaryKey);
1925
1926 throw processException(e);
1927 }
1928 finally {
1929 closeSession(session);
1930 }
1931 }
1932
1933 return resourceTypePermission;
1934 }
1935
1936
1943 public ResourceTypePermission fetchByPrimaryKey(
1944 long resourceTypePermissionId) throws SystemException {
1945 return fetchByPrimaryKey((Serializable)resourceTypePermissionId);
1946 }
1947
1948
1954 public List<ResourceTypePermission> findAll() throws SystemException {
1955 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1956 }
1957
1958
1970 public List<ResourceTypePermission> findAll(int start, int end)
1971 throws SystemException {
1972 return findAll(start, end, null);
1973 }
1974
1975
1988 public List<ResourceTypePermission> findAll(int start, int end,
1989 OrderByComparator orderByComparator) throws SystemException {
1990 boolean pagination = true;
1991 FinderPath finderPath = null;
1992 Object[] finderArgs = null;
1993
1994 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1995 (orderByComparator == null)) {
1996 pagination = false;
1997 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1998 finderArgs = FINDER_ARGS_EMPTY;
1999 }
2000 else {
2001 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2002 finderArgs = new Object[] { start, end, orderByComparator };
2003 }
2004
2005 List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
2006 finderArgs, this);
2007
2008 if (list == null) {
2009 StringBundler query = null;
2010 String sql = null;
2011
2012 if (orderByComparator != null) {
2013 query = new StringBundler(2 +
2014 (orderByComparator.getOrderByFields().length * 3));
2015
2016 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION);
2017
2018 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2019 orderByComparator);
2020
2021 sql = query.toString();
2022 }
2023 else {
2024 sql = _SQL_SELECT_RESOURCETYPEPERMISSION;
2025
2026 if (pagination) {
2027 sql = sql.concat(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
2028 }
2029 }
2030
2031 Session session = null;
2032
2033 try {
2034 session = openSession();
2035
2036 Query q = session.createQuery(sql);
2037
2038 if (!pagination) {
2039 list = (List<ResourceTypePermission>)QueryUtil.list(q,
2040 getDialect(), start, end, false);
2041
2042 Collections.sort(list);
2043
2044 list = new UnmodifiableList<ResourceTypePermission>(list);
2045 }
2046 else {
2047 list = (List<ResourceTypePermission>)QueryUtil.list(q,
2048 getDialect(), start, end);
2049 }
2050
2051 cacheResult(list);
2052
2053 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2054 }
2055 catch (Exception e) {
2056 FinderCacheUtil.removeResult(finderPath, finderArgs);
2057
2058 throw processException(e);
2059 }
2060 finally {
2061 closeSession(session);
2062 }
2063 }
2064
2065 return list;
2066 }
2067
2068
2073 public void removeAll() throws SystemException {
2074 for (ResourceTypePermission resourceTypePermission : findAll()) {
2075 remove(resourceTypePermission);
2076 }
2077 }
2078
2079
2085 public int countAll() throws SystemException {
2086 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2087 FINDER_ARGS_EMPTY, this);
2088
2089 if (count == null) {
2090 Session session = null;
2091
2092 try {
2093 session = openSession();
2094
2095 Query q = session.createQuery(_SQL_COUNT_RESOURCETYPEPERMISSION);
2096
2097 count = (Long)q.uniqueResult();
2098
2099 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2100 FINDER_ARGS_EMPTY, count);
2101 }
2102 catch (Exception e) {
2103 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2104 FINDER_ARGS_EMPTY);
2105
2106 throw processException(e);
2107 }
2108 finally {
2109 closeSession(session);
2110 }
2111 }
2112
2113 return count.intValue();
2114 }
2115
2116
2119 public void afterPropertiesSet() {
2120 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2121 com.liferay.portal.util.PropsUtil.get(
2122 "value.object.listener.com.liferay.portal.model.ResourceTypePermission")));
2123
2124 if (listenerClassNames.length > 0) {
2125 try {
2126 List<ModelListener<ResourceTypePermission>> listenersList = new ArrayList<ModelListener<ResourceTypePermission>>();
2127
2128 for (String listenerClassName : listenerClassNames) {
2129 listenersList.add((ModelListener<ResourceTypePermission>)InstanceFactory.newInstance(
2130 getClassLoader(), listenerClassName));
2131 }
2132
2133 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2134 }
2135 catch (Exception e) {
2136 _log.error(e);
2137 }
2138 }
2139 }
2140
2141 public void destroy() {
2142 EntityCacheUtil.removeCache(ResourceTypePermissionImpl.class.getName());
2143 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2144 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2145 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2146 }
2147
2148 private static final String _SQL_SELECT_RESOURCETYPEPERMISSION = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission";
2149 private static final String _SQL_SELECT_RESOURCETYPEPERMISSION_WHERE = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission WHERE ";
2150 private static final String _SQL_COUNT_RESOURCETYPEPERMISSION = "SELECT COUNT(resourceTypePermission) FROM ResourceTypePermission resourceTypePermission";
2151 private static final String _SQL_COUNT_RESOURCETYPEPERMISSION_WHERE = "SELECT COUNT(resourceTypePermission) FROM ResourceTypePermission resourceTypePermission WHERE ";
2152 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceTypePermission.";
2153 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceTypePermission exists with the primary key ";
2154 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceTypePermission exists with the key {";
2155 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2156 private static Log _log = LogFactoryUtil.getLog(ResourceTypePermissionPersistenceImpl.class);
2157 private static ResourceTypePermission _nullResourceTypePermission = new ResourceTypePermissionImpl() {
2158 @Override
2159 public Object clone() {
2160 return this;
2161 }
2162
2163 @Override
2164 public CacheModel<ResourceTypePermission> toCacheModel() {
2165 return _nullResourceTypePermissionCacheModel;
2166 }
2167 };
2168
2169 private static CacheModel<ResourceTypePermission> _nullResourceTypePermissionCacheModel =
2170 new CacheModel<ResourceTypePermission>() {
2171 public ResourceTypePermission toEntityModel() {
2172 return _nullResourceTypePermission;
2173 }
2174 };
2175 }