001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchResourceTypePermissionException;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.Validator;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.model.MVCCModel;
035 import com.liferay.portal.model.ResourceTypePermission;
036 import com.liferay.portal.model.impl.ResourceTypePermissionImpl;
037 import com.liferay.portal.model.impl.ResourceTypePermissionModelImpl;
038 import com.liferay.portal.service.persistence.ResourceTypePermissionPersistence;
039
040 import java.io.Serializable;
041
042 import java.util.Collections;
043 import java.util.HashMap;
044 import java.util.HashSet;
045 import java.util.Iterator;
046 import java.util.List;
047 import java.util.Map;
048 import java.util.Set;
049
050
062 @ProviderType
063 public class ResourceTypePermissionPersistenceImpl extends BasePersistenceImpl<ResourceTypePermission>
064 implements ResourceTypePermissionPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ResourceTypePermissionImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
076 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
077 ResourceTypePermissionImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
080 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
081 ResourceTypePermissionImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
084 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
087 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
088 ResourceTypePermissionImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
090 new String[] {
091 Long.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
097 new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
098 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
099 ResourceTypePermissionImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
101 new String[] { Long.class.getName() },
102 ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
104 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
106 new String[] { Long.class.getName() });
107
108
114 @Override
115 public List<ResourceTypePermission> findByRoleId(long roleId) {
116 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117 }
118
119
131 @Override
132 public List<ResourceTypePermission> findByRoleId(long roleId, int start,
133 int end) {
134 return findByRoleId(roleId, start, end, null);
135 }
136
137
150 @Override
151 public List<ResourceTypePermission> findByRoleId(long roleId, int start,
152 int end, OrderByComparator<ResourceTypePermission> orderByComparator) {
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 = Collections.unmodifiableList(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
256 @Override
257 public ResourceTypePermission findByRoleId_First(long roleId,
258 OrderByComparator<ResourceTypePermission> orderByComparator)
259 throws NoSuchResourceTypePermissionException {
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
286 @Override
287 public ResourceTypePermission fetchByRoleId_First(long roleId,
288 OrderByComparator<ResourceTypePermission> orderByComparator) {
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
307 @Override
308 public ResourceTypePermission findByRoleId_Last(long roleId,
309 OrderByComparator<ResourceTypePermission> orderByComparator)
310 throws NoSuchResourceTypePermissionException {
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
337 @Override
338 public ResourceTypePermission fetchByRoleId_Last(long roleId,
339 OrderByComparator<ResourceTypePermission> orderByComparator) {
340 int count = countByRoleId(roleId);
341
342 if (count == 0) {
343 return null;
344 }
345
346 List<ResourceTypePermission> list = findByRoleId(roleId, count - 1,
347 count, orderByComparator);
348
349 if (!list.isEmpty()) {
350 return list.get(0);
351 }
352
353 return null;
354 }
355
356
365 @Override
366 public ResourceTypePermission[] findByRoleId_PrevAndNext(
367 long resourceTypePermissionId, long roleId,
368 OrderByComparator<ResourceTypePermission> orderByComparator)
369 throws NoSuchResourceTypePermissionException {
370 ResourceTypePermission resourceTypePermission = findByPrimaryKey(resourceTypePermissionId);
371
372 Session session = null;
373
374 try {
375 session = openSession();
376
377 ResourceTypePermission[] array = new ResourceTypePermissionImpl[3];
378
379 array[0] = getByRoleId_PrevAndNext(session, resourceTypePermission,
380 roleId, orderByComparator, true);
381
382 array[1] = resourceTypePermission;
383
384 array[2] = getByRoleId_PrevAndNext(session, resourceTypePermission,
385 roleId, orderByComparator, false);
386
387 return array;
388 }
389 catch (Exception e) {
390 throw processException(e);
391 }
392 finally {
393 closeSession(session);
394 }
395 }
396
397 protected ResourceTypePermission getByRoleId_PrevAndNext(Session session,
398 ResourceTypePermission resourceTypePermission, long roleId,
399 OrderByComparator<ResourceTypePermission> orderByComparator,
400 boolean previous) {
401 StringBundler query = null;
402
403 if (orderByComparator != null) {
404 query = new StringBundler(6 +
405 (orderByComparator.getOrderByFields().length * 6));
406 }
407 else {
408 query = new StringBundler(3);
409 }
410
411 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
412
413 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
414
415 if (orderByComparator != null) {
416 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
417
418 if (orderByConditionFields.length > 0) {
419 query.append(WHERE_AND);
420 }
421
422 for (int i = 0; i < orderByConditionFields.length; i++) {
423 query.append(_ORDER_BY_ENTITY_ALIAS);
424 query.append(orderByConditionFields[i]);
425
426 if ((i + 1) < orderByConditionFields.length) {
427 if (orderByComparator.isAscending() ^ previous) {
428 query.append(WHERE_GREATER_THAN_HAS_NEXT);
429 }
430 else {
431 query.append(WHERE_LESSER_THAN_HAS_NEXT);
432 }
433 }
434 else {
435 if (orderByComparator.isAscending() ^ previous) {
436 query.append(WHERE_GREATER_THAN);
437 }
438 else {
439 query.append(WHERE_LESSER_THAN);
440 }
441 }
442 }
443
444 query.append(ORDER_BY_CLAUSE);
445
446 String[] orderByFields = orderByComparator.getOrderByFields();
447
448 for (int i = 0; i < orderByFields.length; i++) {
449 query.append(_ORDER_BY_ENTITY_ALIAS);
450 query.append(orderByFields[i]);
451
452 if ((i + 1) < orderByFields.length) {
453 if (orderByComparator.isAscending() ^ previous) {
454 query.append(ORDER_BY_ASC_HAS_NEXT);
455 }
456 else {
457 query.append(ORDER_BY_DESC_HAS_NEXT);
458 }
459 }
460 else {
461 if (orderByComparator.isAscending() ^ previous) {
462 query.append(ORDER_BY_ASC);
463 }
464 else {
465 query.append(ORDER_BY_DESC);
466 }
467 }
468 }
469 }
470 else {
471 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
472 }
473
474 String sql = query.toString();
475
476 Query q = session.createQuery(sql);
477
478 q.setFirstResult(0);
479 q.setMaxResults(2);
480
481 QueryPos qPos = QueryPos.getInstance(q);
482
483 qPos.add(roleId);
484
485 if (orderByComparator != null) {
486 Object[] values = orderByComparator.getOrderByConditionValues(resourceTypePermission);
487
488 for (Object value : values) {
489 qPos.add(value);
490 }
491 }
492
493 List<ResourceTypePermission> list = q.list();
494
495 if (list.size() == 2) {
496 return list.get(1);
497 }
498 else {
499 return null;
500 }
501 }
502
503
508 @Override
509 public void removeByRoleId(long roleId) {
510 for (ResourceTypePermission resourceTypePermission : findByRoleId(
511 roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
512 remove(resourceTypePermission);
513 }
514 }
515
516
522 @Override
523 public int countByRoleId(long roleId) {
524 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
525
526 Object[] finderArgs = new Object[] { roleId };
527
528 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
529 this);
530
531 if (count == null) {
532 StringBundler query = new StringBundler(2);
533
534 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
535
536 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
537
538 String sql = query.toString();
539
540 Session session = null;
541
542 try {
543 session = openSession();
544
545 Query q = session.createQuery(sql);
546
547 QueryPos qPos = QueryPos.getInstance(q);
548
549 qPos.add(roleId);
550
551 count = (Long)q.uniqueResult();
552
553 FinderCacheUtil.putResult(finderPath, finderArgs, count);
554 }
555 catch (Exception e) {
556 FinderCacheUtil.removeResult(finderPath, finderArgs);
557
558 throw processException(e);
559 }
560 finally {
561 closeSession(session);
562 }
563 }
564
565 return count.intValue();
566 }
567
568 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourceTypePermission.roleId = ?";
569 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
570 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
571 ResourceTypePermissionImpl.class,
572 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_R",
573 new String[] {
574 Long.class.getName(), String.class.getName(),
575 Long.class.getName(),
576
577 Integer.class.getName(), Integer.class.getName(),
578 OrderByComparator.class.getName()
579 });
580 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
581 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
582 ResourceTypePermissionImpl.class,
583 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_R",
584 new String[] {
585 Long.class.getName(), String.class.getName(),
586 Long.class.getName()
587 },
588 ResourceTypePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
589 ResourceTypePermissionModelImpl.NAME_COLUMN_BITMASK |
590 ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
591 public static final FinderPath FINDER_PATH_COUNT_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
592 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
593 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_R",
594 new String[] {
595 Long.class.getName(), String.class.getName(),
596 Long.class.getName()
597 });
598
599
607 @Override
608 public List<ResourceTypePermission> findByC_N_R(long companyId,
609 String name, long roleId) {
610 return findByC_N_R(companyId, name, roleId, QueryUtil.ALL_POS,
611 QueryUtil.ALL_POS, null);
612 }
613
614
628 @Override
629 public List<ResourceTypePermission> findByC_N_R(long companyId,
630 String name, long roleId, int start, int end) {
631 return findByC_N_R(companyId, name, roleId, start, end, null);
632 }
633
634
649 @Override
650 public List<ResourceTypePermission> findByC_N_R(long companyId,
651 String name, long roleId, int start, int end,
652 OrderByComparator<ResourceTypePermission> orderByComparator) {
653 boolean pagination = true;
654 FinderPath finderPath = null;
655 Object[] finderArgs = null;
656
657 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
658 (orderByComparator == null)) {
659 pagination = false;
660 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R;
661 finderArgs = new Object[] { companyId, name, roleId };
662 }
663 else {
664 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_R;
665 finderArgs = new Object[] {
666 companyId, name, roleId,
667
668 start, end, orderByComparator
669 };
670 }
671
672 List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
673 finderArgs, this);
674
675 if ((list != null) && !list.isEmpty()) {
676 for (ResourceTypePermission resourceTypePermission : list) {
677 if ((companyId != resourceTypePermission.getCompanyId()) ||
678 !Validator.equals(name, resourceTypePermission.getName()) ||
679 (roleId != resourceTypePermission.getRoleId())) {
680 list = null;
681
682 break;
683 }
684 }
685 }
686
687 if (list == null) {
688 StringBundler query = null;
689
690 if (orderByComparator != null) {
691 query = new StringBundler(5 +
692 (orderByComparator.getOrderByFields().length * 3));
693 }
694 else {
695 query = new StringBundler(5);
696 }
697
698 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
699
700 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
701
702 boolean bindName = false;
703
704 if (name == null) {
705 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
706 }
707 else if (name.equals(StringPool.BLANK)) {
708 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
709 }
710 else {
711 bindName = true;
712
713 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
714 }
715
716 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
717
718 if (orderByComparator != null) {
719 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
720 orderByComparator);
721 }
722 else
723 if (pagination) {
724 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
725 }
726
727 String sql = query.toString();
728
729 Session session = null;
730
731 try {
732 session = openSession();
733
734 Query q = session.createQuery(sql);
735
736 QueryPos qPos = QueryPos.getInstance(q);
737
738 qPos.add(companyId);
739
740 if (bindName) {
741 qPos.add(name);
742 }
743
744 qPos.add(roleId);
745
746 if (!pagination) {
747 list = (List<ResourceTypePermission>)QueryUtil.list(q,
748 getDialect(), start, end, false);
749
750 Collections.sort(list);
751
752 list = Collections.unmodifiableList(list);
753 }
754 else {
755 list = (List<ResourceTypePermission>)QueryUtil.list(q,
756 getDialect(), start, end);
757 }
758
759 cacheResult(list);
760
761 FinderCacheUtil.putResult(finderPath, finderArgs, list);
762 }
763 catch (Exception e) {
764 FinderCacheUtil.removeResult(finderPath, finderArgs);
765
766 throw processException(e);
767 }
768 finally {
769 closeSession(session);
770 }
771 }
772
773 return list;
774 }
775
776
786 @Override
787 public ResourceTypePermission findByC_N_R_First(long companyId,
788 String name, long roleId,
789 OrderByComparator<ResourceTypePermission> orderByComparator)
790 throws NoSuchResourceTypePermissionException {
791 ResourceTypePermission resourceTypePermission = fetchByC_N_R_First(companyId,
792 name, roleId, orderByComparator);
793
794 if (resourceTypePermission != null) {
795 return resourceTypePermission;
796 }
797
798 StringBundler msg = new StringBundler(8);
799
800 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
801
802 msg.append("companyId=");
803 msg.append(companyId);
804
805 msg.append(", name=");
806 msg.append(name);
807
808 msg.append(", roleId=");
809 msg.append(roleId);
810
811 msg.append(StringPool.CLOSE_CURLY_BRACE);
812
813 throw new NoSuchResourceTypePermissionException(msg.toString());
814 }
815
816
825 @Override
826 public ResourceTypePermission fetchByC_N_R_First(long companyId,
827 String name, long roleId,
828 OrderByComparator<ResourceTypePermission> orderByComparator) {
829 List<ResourceTypePermission> list = findByC_N_R(companyId, name,
830 roleId, 0, 1, orderByComparator);
831
832 if (!list.isEmpty()) {
833 return list.get(0);
834 }
835
836 return null;
837 }
838
839
849 @Override
850 public ResourceTypePermission findByC_N_R_Last(long companyId, String name,
851 long roleId, OrderByComparator<ResourceTypePermission> orderByComparator)
852 throws NoSuchResourceTypePermissionException {
853 ResourceTypePermission resourceTypePermission = fetchByC_N_R_Last(companyId,
854 name, roleId, orderByComparator);
855
856 if (resourceTypePermission != null) {
857 return resourceTypePermission;
858 }
859
860 StringBundler msg = new StringBundler(8);
861
862 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
863
864 msg.append("companyId=");
865 msg.append(companyId);
866
867 msg.append(", name=");
868 msg.append(name);
869
870 msg.append(", roleId=");
871 msg.append(roleId);
872
873 msg.append(StringPool.CLOSE_CURLY_BRACE);
874
875 throw new NoSuchResourceTypePermissionException(msg.toString());
876 }
877
878
887 @Override
888 public ResourceTypePermission fetchByC_N_R_Last(long companyId,
889 String name, long roleId,
890 OrderByComparator<ResourceTypePermission> orderByComparator) {
891 int count = countByC_N_R(companyId, name, roleId);
892
893 if (count == 0) {
894 return null;
895 }
896
897 List<ResourceTypePermission> list = findByC_N_R(companyId, name,
898 roleId, count - 1, count, orderByComparator);
899
900 if (!list.isEmpty()) {
901 return list.get(0);
902 }
903
904 return null;
905 }
906
907
918 @Override
919 public ResourceTypePermission[] findByC_N_R_PrevAndNext(
920 long resourceTypePermissionId, long companyId, String name,
921 long roleId, OrderByComparator<ResourceTypePermission> orderByComparator)
922 throws NoSuchResourceTypePermissionException {
923 ResourceTypePermission resourceTypePermission = findByPrimaryKey(resourceTypePermissionId);
924
925 Session session = null;
926
927 try {
928 session = openSession();
929
930 ResourceTypePermission[] array = new ResourceTypePermissionImpl[3];
931
932 array[0] = getByC_N_R_PrevAndNext(session, resourceTypePermission,
933 companyId, name, roleId, orderByComparator, true);
934
935 array[1] = resourceTypePermission;
936
937 array[2] = getByC_N_R_PrevAndNext(session, resourceTypePermission,
938 companyId, name, roleId, orderByComparator, false);
939
940 return array;
941 }
942 catch (Exception e) {
943 throw processException(e);
944 }
945 finally {
946 closeSession(session);
947 }
948 }
949
950 protected ResourceTypePermission getByC_N_R_PrevAndNext(Session session,
951 ResourceTypePermission resourceTypePermission, long companyId,
952 String name, long roleId,
953 OrderByComparator<ResourceTypePermission> orderByComparator,
954 boolean previous) {
955 StringBundler query = null;
956
957 if (orderByComparator != null) {
958 query = new StringBundler(6 +
959 (orderByComparator.getOrderByFields().length * 6));
960 }
961 else {
962 query = new StringBundler(3);
963 }
964
965 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
966
967 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
968
969 boolean bindName = false;
970
971 if (name == null) {
972 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
973 }
974 else if (name.equals(StringPool.BLANK)) {
975 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
976 }
977 else {
978 bindName = true;
979
980 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
981 }
982
983 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
984
985 if (orderByComparator != null) {
986 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
987
988 if (orderByConditionFields.length > 0) {
989 query.append(WHERE_AND);
990 }
991
992 for (int i = 0; i < orderByConditionFields.length; i++) {
993 query.append(_ORDER_BY_ENTITY_ALIAS);
994 query.append(orderByConditionFields[i]);
995
996 if ((i + 1) < orderByConditionFields.length) {
997 if (orderByComparator.isAscending() ^ previous) {
998 query.append(WHERE_GREATER_THAN_HAS_NEXT);
999 }
1000 else {
1001 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1002 }
1003 }
1004 else {
1005 if (orderByComparator.isAscending() ^ previous) {
1006 query.append(WHERE_GREATER_THAN);
1007 }
1008 else {
1009 query.append(WHERE_LESSER_THAN);
1010 }
1011 }
1012 }
1013
1014 query.append(ORDER_BY_CLAUSE);
1015
1016 String[] orderByFields = orderByComparator.getOrderByFields();
1017
1018 for (int i = 0; i < orderByFields.length; i++) {
1019 query.append(_ORDER_BY_ENTITY_ALIAS);
1020 query.append(orderByFields[i]);
1021
1022 if ((i + 1) < orderByFields.length) {
1023 if (orderByComparator.isAscending() ^ previous) {
1024 query.append(ORDER_BY_ASC_HAS_NEXT);
1025 }
1026 else {
1027 query.append(ORDER_BY_DESC_HAS_NEXT);
1028 }
1029 }
1030 else {
1031 if (orderByComparator.isAscending() ^ previous) {
1032 query.append(ORDER_BY_ASC);
1033 }
1034 else {
1035 query.append(ORDER_BY_DESC);
1036 }
1037 }
1038 }
1039 }
1040 else {
1041 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
1042 }
1043
1044 String sql = query.toString();
1045
1046 Query q = session.createQuery(sql);
1047
1048 q.setFirstResult(0);
1049 q.setMaxResults(2);
1050
1051 QueryPos qPos = QueryPos.getInstance(q);
1052
1053 qPos.add(companyId);
1054
1055 if (bindName) {
1056 qPos.add(name);
1057 }
1058
1059 qPos.add(roleId);
1060
1061 if (orderByComparator != null) {
1062 Object[] values = orderByComparator.getOrderByConditionValues(resourceTypePermission);
1063
1064 for (Object value : values) {
1065 qPos.add(value);
1066 }
1067 }
1068
1069 List<ResourceTypePermission> list = q.list();
1070
1071 if (list.size() == 2) {
1072 return list.get(1);
1073 }
1074 else {
1075 return null;
1076 }
1077 }
1078
1079
1086 @Override
1087 public void removeByC_N_R(long companyId, String name, long roleId) {
1088 for (ResourceTypePermission resourceTypePermission : findByC_N_R(
1089 companyId, name, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1090 null)) {
1091 remove(resourceTypePermission);
1092 }
1093 }
1094
1095
1103 @Override
1104 public int countByC_N_R(long companyId, String name, long roleId) {
1105 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_R;
1106
1107 Object[] finderArgs = new Object[] { companyId, name, roleId };
1108
1109 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1110 this);
1111
1112 if (count == null) {
1113 StringBundler query = new StringBundler(4);
1114
1115 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1116
1117 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
1118
1119 boolean bindName = false;
1120
1121 if (name == null) {
1122 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
1123 }
1124 else if (name.equals(StringPool.BLANK)) {
1125 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
1126 }
1127 else {
1128 bindName = true;
1129
1130 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
1131 }
1132
1133 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
1134
1135 String sql = query.toString();
1136
1137 Session session = null;
1138
1139 try {
1140 session = openSession();
1141
1142 Query q = session.createQuery(sql);
1143
1144 QueryPos qPos = QueryPos.getInstance(q);
1145
1146 qPos.add(companyId);
1147
1148 if (bindName) {
1149 qPos.add(name);
1150 }
1151
1152 qPos.add(roleId);
1153
1154 count = (Long)q.uniqueResult();
1155
1156 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1157 }
1158 catch (Exception e) {
1159 FinderCacheUtil.removeResult(finderPath, finderArgs);
1160
1161 throw processException(e);
1162 }
1163 finally {
1164 closeSession(session);
1165 }
1166 }
1167
1168 return count.intValue();
1169 }
1170
1171 private static final String _FINDER_COLUMN_C_N_R_COMPANYID_2 = "resourceTypePermission.companyId = ? AND ";
1172 private static final String _FINDER_COLUMN_C_N_R_NAME_1 = "resourceTypePermission.name IS NULL AND ";
1173 private static final String _FINDER_COLUMN_C_N_R_NAME_2 = "resourceTypePermission.name = ? AND ";
1174 private static final String _FINDER_COLUMN_C_N_R_NAME_3 = "(resourceTypePermission.name IS NULL OR resourceTypePermission.name = '') AND ";
1175 private static final String _FINDER_COLUMN_C_N_R_ROLEID_2 = "resourceTypePermission.roleId = ?";
1176 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1177 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
1178 ResourceTypePermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
1179 "fetchByC_G_N_R",
1180 new String[] {
1181 Long.class.getName(), Long.class.getName(),
1182 String.class.getName(), Long.class.getName()
1183 },
1184 ResourceTypePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
1185 ResourceTypePermissionModelImpl.GROUPID_COLUMN_BITMASK |
1186 ResourceTypePermissionModelImpl.NAME_COLUMN_BITMASK |
1187 ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
1188 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1189 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1190 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_R",
1191 new String[] {
1192 Long.class.getName(), Long.class.getName(),
1193 String.class.getName(), Long.class.getName()
1194 });
1195
1196
1206 @Override
1207 public ResourceTypePermission findByC_G_N_R(long companyId, long groupId,
1208 String name, long roleId) throws NoSuchResourceTypePermissionException {
1209 ResourceTypePermission resourceTypePermission = fetchByC_G_N_R(companyId,
1210 groupId, name, roleId);
1211
1212 if (resourceTypePermission == null) {
1213 StringBundler msg = new StringBundler(10);
1214
1215 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1216
1217 msg.append("companyId=");
1218 msg.append(companyId);
1219
1220 msg.append(", groupId=");
1221 msg.append(groupId);
1222
1223 msg.append(", name=");
1224 msg.append(name);
1225
1226 msg.append(", roleId=");
1227 msg.append(roleId);
1228
1229 msg.append(StringPool.CLOSE_CURLY_BRACE);
1230
1231 if (_log.isWarnEnabled()) {
1232 _log.warn(msg.toString());
1233 }
1234
1235 throw new NoSuchResourceTypePermissionException(msg.toString());
1236 }
1237
1238 return resourceTypePermission;
1239 }
1240
1241
1250 @Override
1251 public ResourceTypePermission fetchByC_G_N_R(long companyId, long groupId,
1252 String name, long roleId) {
1253 return fetchByC_G_N_R(companyId, groupId, name, roleId, true);
1254 }
1255
1256
1266 @Override
1267 public ResourceTypePermission fetchByC_G_N_R(long companyId, long groupId,
1268 String name, long roleId, boolean retrieveFromCache) {
1269 Object[] finderArgs = new Object[] { companyId, groupId, name, roleId };
1270
1271 Object result = null;
1272
1273 if (retrieveFromCache) {
1274 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1275 finderArgs, this);
1276 }
1277
1278 if (result instanceof ResourceTypePermission) {
1279 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)result;
1280
1281 if ((companyId != resourceTypePermission.getCompanyId()) ||
1282 (groupId != resourceTypePermission.getGroupId()) ||
1283 !Validator.equals(name, resourceTypePermission.getName()) ||
1284 (roleId != resourceTypePermission.getRoleId())) {
1285 result = null;
1286 }
1287 }
1288
1289 if (result == null) {
1290 StringBundler query = new StringBundler(6);
1291
1292 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
1293
1294 query.append(_FINDER_COLUMN_C_G_N_R_COMPANYID_2);
1295
1296 query.append(_FINDER_COLUMN_C_G_N_R_GROUPID_2);
1297
1298 boolean bindName = false;
1299
1300 if (name == null) {
1301 query.append(_FINDER_COLUMN_C_G_N_R_NAME_1);
1302 }
1303 else if (name.equals(StringPool.BLANK)) {
1304 query.append(_FINDER_COLUMN_C_G_N_R_NAME_3);
1305 }
1306 else {
1307 bindName = true;
1308
1309 query.append(_FINDER_COLUMN_C_G_N_R_NAME_2);
1310 }
1311
1312 query.append(_FINDER_COLUMN_C_G_N_R_ROLEID_2);
1313
1314 String sql = query.toString();
1315
1316 Session session = null;
1317
1318 try {
1319 session = openSession();
1320
1321 Query q = session.createQuery(sql);
1322
1323 QueryPos qPos = QueryPos.getInstance(q);
1324
1325 qPos.add(companyId);
1326
1327 qPos.add(groupId);
1328
1329 if (bindName) {
1330 qPos.add(name);
1331 }
1332
1333 qPos.add(roleId);
1334
1335 List<ResourceTypePermission> list = q.list();
1336
1337 if (list.isEmpty()) {
1338 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1339 finderArgs, list);
1340 }
1341 else {
1342 ResourceTypePermission resourceTypePermission = list.get(0);
1343
1344 result = resourceTypePermission;
1345
1346 cacheResult(resourceTypePermission);
1347
1348 if ((resourceTypePermission.getCompanyId() != companyId) ||
1349 (resourceTypePermission.getGroupId() != groupId) ||
1350 (resourceTypePermission.getName() == null) ||
1351 !resourceTypePermission.getName().equals(name) ||
1352 (resourceTypePermission.getRoleId() != roleId)) {
1353 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1354 finderArgs, resourceTypePermission);
1355 }
1356 }
1357 }
1358 catch (Exception e) {
1359 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1360 finderArgs);
1361
1362 throw processException(e);
1363 }
1364 finally {
1365 closeSession(session);
1366 }
1367 }
1368
1369 if (result instanceof List<?>) {
1370 return null;
1371 }
1372 else {
1373 return (ResourceTypePermission)result;
1374 }
1375 }
1376
1377
1386 @Override
1387 public ResourceTypePermission removeByC_G_N_R(long companyId, long groupId,
1388 String name, long roleId) throws NoSuchResourceTypePermissionException {
1389 ResourceTypePermission resourceTypePermission = findByC_G_N_R(companyId,
1390 groupId, name, roleId);
1391
1392 return remove(resourceTypePermission);
1393 }
1394
1395
1404 @Override
1405 public int countByC_G_N_R(long companyId, long groupId, String name,
1406 long roleId) {
1407 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N_R;
1408
1409 Object[] finderArgs = new Object[] { companyId, groupId, name, roleId };
1410
1411 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1412 this);
1413
1414 if (count == null) {
1415 StringBundler query = new StringBundler(5);
1416
1417 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1418
1419 query.append(_FINDER_COLUMN_C_G_N_R_COMPANYID_2);
1420
1421 query.append(_FINDER_COLUMN_C_G_N_R_GROUPID_2);
1422
1423 boolean bindName = false;
1424
1425 if (name == null) {
1426 query.append(_FINDER_COLUMN_C_G_N_R_NAME_1);
1427 }
1428 else if (name.equals(StringPool.BLANK)) {
1429 query.append(_FINDER_COLUMN_C_G_N_R_NAME_3);
1430 }
1431 else {
1432 bindName = true;
1433
1434 query.append(_FINDER_COLUMN_C_G_N_R_NAME_2);
1435 }
1436
1437 query.append(_FINDER_COLUMN_C_G_N_R_ROLEID_2);
1438
1439 String sql = query.toString();
1440
1441 Session session = null;
1442
1443 try {
1444 session = openSession();
1445
1446 Query q = session.createQuery(sql);
1447
1448 QueryPos qPos = QueryPos.getInstance(q);
1449
1450 qPos.add(companyId);
1451
1452 qPos.add(groupId);
1453
1454 if (bindName) {
1455 qPos.add(name);
1456 }
1457
1458 qPos.add(roleId);
1459
1460 count = (Long)q.uniqueResult();
1461
1462 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1463 }
1464 catch (Exception e) {
1465 FinderCacheUtil.removeResult(finderPath, finderArgs);
1466
1467 throw processException(e);
1468 }
1469 finally {
1470 closeSession(session);
1471 }
1472 }
1473
1474 return count.intValue();
1475 }
1476
1477 private static final String _FINDER_COLUMN_C_G_N_R_COMPANYID_2 = "resourceTypePermission.companyId = ? AND ";
1478 private static final String _FINDER_COLUMN_C_G_N_R_GROUPID_2 = "resourceTypePermission.groupId = ? AND ";
1479 private static final String _FINDER_COLUMN_C_G_N_R_NAME_1 = "resourceTypePermission.name IS NULL AND ";
1480 private static final String _FINDER_COLUMN_C_G_N_R_NAME_2 = "resourceTypePermission.name = ? AND ";
1481 private static final String _FINDER_COLUMN_C_G_N_R_NAME_3 = "(resourceTypePermission.name IS NULL OR resourceTypePermission.name = '') AND ";
1482 private static final String _FINDER_COLUMN_C_G_N_R_ROLEID_2 = "resourceTypePermission.roleId = ?";
1483
1484 public ResourceTypePermissionPersistenceImpl() {
1485 setModelClass(ResourceTypePermission.class);
1486 }
1487
1488
1493 @Override
1494 public void cacheResult(ResourceTypePermission resourceTypePermission) {
1495 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1496 ResourceTypePermissionImpl.class,
1497 resourceTypePermission.getPrimaryKey(), resourceTypePermission);
1498
1499 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1500 new Object[] {
1501 resourceTypePermission.getCompanyId(),
1502 resourceTypePermission.getGroupId(),
1503 resourceTypePermission.getName(),
1504 resourceTypePermission.getRoleId()
1505 }, resourceTypePermission);
1506
1507 resourceTypePermission.resetOriginalValues();
1508 }
1509
1510
1515 @Override
1516 public void cacheResult(
1517 List<ResourceTypePermission> resourceTypePermissions) {
1518 for (ResourceTypePermission resourceTypePermission : resourceTypePermissions) {
1519 if (EntityCacheUtil.getResult(
1520 ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1521 ResourceTypePermissionImpl.class,
1522 resourceTypePermission.getPrimaryKey()) == null) {
1523 cacheResult(resourceTypePermission);
1524 }
1525 else {
1526 resourceTypePermission.resetOriginalValues();
1527 }
1528 }
1529 }
1530
1531
1538 @Override
1539 public void clearCache() {
1540 EntityCacheUtil.clearCache(ResourceTypePermissionImpl.class);
1541
1542 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1543 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1544 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1545 }
1546
1547
1554 @Override
1555 public void clearCache(ResourceTypePermission resourceTypePermission) {
1556 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1557 ResourceTypePermissionImpl.class,
1558 resourceTypePermission.getPrimaryKey());
1559
1560 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1561 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1562
1563 clearUniqueFindersCache(resourceTypePermission);
1564 }
1565
1566 @Override
1567 public void clearCache(List<ResourceTypePermission> resourceTypePermissions) {
1568 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1569 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1570
1571 for (ResourceTypePermission resourceTypePermission : resourceTypePermissions) {
1572 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1573 ResourceTypePermissionImpl.class,
1574 resourceTypePermission.getPrimaryKey());
1575
1576 clearUniqueFindersCache(resourceTypePermission);
1577 }
1578 }
1579
1580 protected void cacheUniqueFindersCache(
1581 ResourceTypePermission resourceTypePermission) {
1582 if (resourceTypePermission.isNew()) {
1583 Object[] args = new Object[] {
1584 resourceTypePermission.getCompanyId(),
1585 resourceTypePermission.getGroupId(),
1586 resourceTypePermission.getName(),
1587 resourceTypePermission.getRoleId()
1588 };
1589
1590 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_R, args,
1591 Long.valueOf(1));
1592 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R, args,
1593 resourceTypePermission);
1594 }
1595 else {
1596 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1597
1598 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1599 FINDER_PATH_FETCH_BY_C_G_N_R.getColumnBitmask()) != 0) {
1600 Object[] args = new Object[] {
1601 resourceTypePermission.getCompanyId(),
1602 resourceTypePermission.getGroupId(),
1603 resourceTypePermission.getName(),
1604 resourceTypePermission.getRoleId()
1605 };
1606
1607 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_R, args,
1608 Long.valueOf(1));
1609 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R, args,
1610 resourceTypePermission);
1611 }
1612 }
1613 }
1614
1615 protected void clearUniqueFindersCache(
1616 ResourceTypePermission resourceTypePermission) {
1617 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1618
1619 Object[] args = new Object[] {
1620 resourceTypePermission.getCompanyId(),
1621 resourceTypePermission.getGroupId(),
1622 resourceTypePermission.getName(),
1623 resourceTypePermission.getRoleId()
1624 };
1625
1626 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_R, args);
1627 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R, args);
1628
1629 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1630 FINDER_PATH_FETCH_BY_C_G_N_R.getColumnBitmask()) != 0) {
1631 args = new Object[] {
1632 resourceTypePermissionModelImpl.getOriginalCompanyId(),
1633 resourceTypePermissionModelImpl.getOriginalGroupId(),
1634 resourceTypePermissionModelImpl.getOriginalName(),
1635 resourceTypePermissionModelImpl.getOriginalRoleId()
1636 };
1637
1638 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_R, args);
1639 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R, args);
1640 }
1641 }
1642
1643
1649 @Override
1650 public ResourceTypePermission create(long resourceTypePermissionId) {
1651 ResourceTypePermission resourceTypePermission = new ResourceTypePermissionImpl();
1652
1653 resourceTypePermission.setNew(true);
1654 resourceTypePermission.setPrimaryKey(resourceTypePermissionId);
1655
1656 return resourceTypePermission;
1657 }
1658
1659
1666 @Override
1667 public ResourceTypePermission remove(long resourceTypePermissionId)
1668 throws NoSuchResourceTypePermissionException {
1669 return remove((Serializable)resourceTypePermissionId);
1670 }
1671
1672
1679 @Override
1680 public ResourceTypePermission remove(Serializable primaryKey)
1681 throws NoSuchResourceTypePermissionException {
1682 Session session = null;
1683
1684 try {
1685 session = openSession();
1686
1687 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1688 primaryKey);
1689
1690 if (resourceTypePermission == null) {
1691 if (_log.isWarnEnabled()) {
1692 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1693 }
1694
1695 throw new NoSuchResourceTypePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1696 primaryKey);
1697 }
1698
1699 return remove(resourceTypePermission);
1700 }
1701 catch (NoSuchResourceTypePermissionException nsee) {
1702 throw nsee;
1703 }
1704 catch (Exception e) {
1705 throw processException(e);
1706 }
1707 finally {
1708 closeSession(session);
1709 }
1710 }
1711
1712 @Override
1713 protected ResourceTypePermission removeImpl(
1714 ResourceTypePermission resourceTypePermission) {
1715 resourceTypePermission = toUnwrappedModel(resourceTypePermission);
1716
1717 Session session = null;
1718
1719 try {
1720 session = openSession();
1721
1722 if (!session.contains(resourceTypePermission)) {
1723 resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1724 resourceTypePermission.getPrimaryKeyObj());
1725 }
1726
1727 if (resourceTypePermission != null) {
1728 session.delete(resourceTypePermission);
1729 }
1730 }
1731 catch (Exception e) {
1732 throw processException(e);
1733 }
1734 finally {
1735 closeSession(session);
1736 }
1737
1738 if (resourceTypePermission != null) {
1739 clearCache(resourceTypePermission);
1740 }
1741
1742 return resourceTypePermission;
1743 }
1744
1745 @Override
1746 public ResourceTypePermission updateImpl(
1747 ResourceTypePermission resourceTypePermission) {
1748 resourceTypePermission = toUnwrappedModel(resourceTypePermission);
1749
1750 boolean isNew = resourceTypePermission.isNew();
1751
1752 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1753
1754 Session session = null;
1755
1756 try {
1757 session = openSession();
1758
1759 if (resourceTypePermission.isNew()) {
1760 session.save(resourceTypePermission);
1761
1762 resourceTypePermission.setNew(false);
1763 }
1764 else {
1765 session.merge(resourceTypePermission);
1766 }
1767 }
1768 catch (Exception e) {
1769 throw processException(e);
1770 }
1771 finally {
1772 closeSession(session);
1773 }
1774
1775 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1776
1777 if (isNew || !ResourceTypePermissionModelImpl.COLUMN_BITMASK_ENABLED) {
1778 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1779 }
1780
1781 else {
1782 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1783 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1784 Object[] args = new Object[] {
1785 resourceTypePermissionModelImpl.getOriginalRoleId()
1786 };
1787
1788 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1789 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1790 args);
1791
1792 args = new Object[] { resourceTypePermissionModelImpl.getRoleId() };
1793
1794 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1795 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1796 args);
1797 }
1798
1799 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1800 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R.getColumnBitmask()) != 0) {
1801 Object[] args = new Object[] {
1802 resourceTypePermissionModelImpl.getOriginalCompanyId(),
1803 resourceTypePermissionModelImpl.getOriginalName(),
1804 resourceTypePermissionModelImpl.getOriginalRoleId()
1805 };
1806
1807 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_R, args);
1808 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R,
1809 args);
1810
1811 args = new Object[] {
1812 resourceTypePermissionModelImpl.getCompanyId(),
1813 resourceTypePermissionModelImpl.getName(),
1814 resourceTypePermissionModelImpl.getRoleId()
1815 };
1816
1817 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_R, args);
1818 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R,
1819 args);
1820 }
1821 }
1822
1823 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1824 ResourceTypePermissionImpl.class,
1825 resourceTypePermission.getPrimaryKey(), resourceTypePermission,
1826 false);
1827
1828 clearUniqueFindersCache(resourceTypePermission);
1829 cacheUniqueFindersCache(resourceTypePermission);
1830
1831 resourceTypePermission.resetOriginalValues();
1832
1833 return resourceTypePermission;
1834 }
1835
1836 protected ResourceTypePermission toUnwrappedModel(
1837 ResourceTypePermission resourceTypePermission) {
1838 if (resourceTypePermission instanceof ResourceTypePermissionImpl) {
1839 return resourceTypePermission;
1840 }
1841
1842 ResourceTypePermissionImpl resourceTypePermissionImpl = new ResourceTypePermissionImpl();
1843
1844 resourceTypePermissionImpl.setNew(resourceTypePermission.isNew());
1845 resourceTypePermissionImpl.setPrimaryKey(resourceTypePermission.getPrimaryKey());
1846
1847 resourceTypePermissionImpl.setMvccVersion(resourceTypePermission.getMvccVersion());
1848 resourceTypePermissionImpl.setResourceTypePermissionId(resourceTypePermission.getResourceTypePermissionId());
1849 resourceTypePermissionImpl.setCompanyId(resourceTypePermission.getCompanyId());
1850 resourceTypePermissionImpl.setGroupId(resourceTypePermission.getGroupId());
1851 resourceTypePermissionImpl.setName(resourceTypePermission.getName());
1852 resourceTypePermissionImpl.setRoleId(resourceTypePermission.getRoleId());
1853 resourceTypePermissionImpl.setActionIds(resourceTypePermission.getActionIds());
1854
1855 return resourceTypePermissionImpl;
1856 }
1857
1858
1865 @Override
1866 public ResourceTypePermission findByPrimaryKey(Serializable primaryKey)
1867 throws NoSuchResourceTypePermissionException {
1868 ResourceTypePermission resourceTypePermission = fetchByPrimaryKey(primaryKey);
1869
1870 if (resourceTypePermission == null) {
1871 if (_log.isWarnEnabled()) {
1872 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1873 }
1874
1875 throw new NoSuchResourceTypePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1876 primaryKey);
1877 }
1878
1879 return resourceTypePermission;
1880 }
1881
1882
1889 @Override
1890 public ResourceTypePermission findByPrimaryKey(
1891 long resourceTypePermissionId)
1892 throws NoSuchResourceTypePermissionException {
1893 return findByPrimaryKey((Serializable)resourceTypePermissionId);
1894 }
1895
1896
1902 @Override
1903 public ResourceTypePermission fetchByPrimaryKey(Serializable primaryKey) {
1904 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)EntityCacheUtil.getResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1905 ResourceTypePermissionImpl.class, primaryKey);
1906
1907 if (resourceTypePermission == _nullResourceTypePermission) {
1908 return null;
1909 }
1910
1911 if (resourceTypePermission == null) {
1912 Session session = null;
1913
1914 try {
1915 session = openSession();
1916
1917 resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1918 primaryKey);
1919
1920 if (resourceTypePermission != null) {
1921 cacheResult(resourceTypePermission);
1922 }
1923 else {
1924 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1925 ResourceTypePermissionImpl.class, primaryKey,
1926 _nullResourceTypePermission);
1927 }
1928 }
1929 catch (Exception e) {
1930 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1931 ResourceTypePermissionImpl.class, primaryKey);
1932
1933 throw processException(e);
1934 }
1935 finally {
1936 closeSession(session);
1937 }
1938 }
1939
1940 return resourceTypePermission;
1941 }
1942
1943
1949 @Override
1950 public ResourceTypePermission fetchByPrimaryKey(
1951 long resourceTypePermissionId) {
1952 return fetchByPrimaryKey((Serializable)resourceTypePermissionId);
1953 }
1954
1955 @Override
1956 public Map<Serializable, ResourceTypePermission> fetchByPrimaryKeys(
1957 Set<Serializable> primaryKeys) {
1958 if (primaryKeys.isEmpty()) {
1959 return Collections.emptyMap();
1960 }
1961
1962 Map<Serializable, ResourceTypePermission> map = new HashMap<Serializable, ResourceTypePermission>();
1963
1964 if (primaryKeys.size() == 1) {
1965 Iterator<Serializable> iterator = primaryKeys.iterator();
1966
1967 Serializable primaryKey = iterator.next();
1968
1969 ResourceTypePermission resourceTypePermission = fetchByPrimaryKey(primaryKey);
1970
1971 if (resourceTypePermission != null) {
1972 map.put(primaryKey, resourceTypePermission);
1973 }
1974
1975 return map;
1976 }
1977
1978 Set<Serializable> uncachedPrimaryKeys = null;
1979
1980 for (Serializable primaryKey : primaryKeys) {
1981 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)EntityCacheUtil.getResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1982 ResourceTypePermissionImpl.class, primaryKey);
1983
1984 if (resourceTypePermission == null) {
1985 if (uncachedPrimaryKeys == null) {
1986 uncachedPrimaryKeys = new HashSet<Serializable>();
1987 }
1988
1989 uncachedPrimaryKeys.add(primaryKey);
1990 }
1991 else {
1992 map.put(primaryKey, resourceTypePermission);
1993 }
1994 }
1995
1996 if (uncachedPrimaryKeys == null) {
1997 return map;
1998 }
1999
2000 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2001 1);
2002
2003 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE_PKS_IN);
2004
2005 for (Serializable primaryKey : uncachedPrimaryKeys) {
2006 query.append(String.valueOf(primaryKey));
2007
2008 query.append(StringPool.COMMA);
2009 }
2010
2011 query.setIndex(query.index() - 1);
2012
2013 query.append(StringPool.CLOSE_PARENTHESIS);
2014
2015 String sql = query.toString();
2016
2017 Session session = null;
2018
2019 try {
2020 session = openSession();
2021
2022 Query q = session.createQuery(sql);
2023
2024 for (ResourceTypePermission resourceTypePermission : (List<ResourceTypePermission>)q.list()) {
2025 map.put(resourceTypePermission.getPrimaryKeyObj(),
2026 resourceTypePermission);
2027
2028 cacheResult(resourceTypePermission);
2029
2030 uncachedPrimaryKeys.remove(resourceTypePermission.getPrimaryKeyObj());
2031 }
2032
2033 for (Serializable primaryKey : uncachedPrimaryKeys) {
2034 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
2035 ResourceTypePermissionImpl.class, primaryKey,
2036 _nullResourceTypePermission);
2037 }
2038 }
2039 catch (Exception e) {
2040 throw processException(e);
2041 }
2042 finally {
2043 closeSession(session);
2044 }
2045
2046 return map;
2047 }
2048
2049
2054 @Override
2055 public List<ResourceTypePermission> findAll() {
2056 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2057 }
2058
2059
2070 @Override
2071 public List<ResourceTypePermission> findAll(int start, int end) {
2072 return findAll(start, end, null);
2073 }
2074
2075
2087 @Override
2088 public List<ResourceTypePermission> findAll(int start, int end,
2089 OrderByComparator<ResourceTypePermission> orderByComparator) {
2090 boolean pagination = true;
2091 FinderPath finderPath = null;
2092 Object[] finderArgs = null;
2093
2094 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2095 (orderByComparator == null)) {
2096 pagination = false;
2097 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2098 finderArgs = FINDER_ARGS_EMPTY;
2099 }
2100 else {
2101 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2102 finderArgs = new Object[] { start, end, orderByComparator };
2103 }
2104
2105 List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
2106 finderArgs, this);
2107
2108 if (list == null) {
2109 StringBundler query = null;
2110 String sql = null;
2111
2112 if (orderByComparator != null) {
2113 query = new StringBundler(2 +
2114 (orderByComparator.getOrderByFields().length * 3));
2115
2116 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION);
2117
2118 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2119 orderByComparator);
2120
2121 sql = query.toString();
2122 }
2123 else {
2124 sql = _SQL_SELECT_RESOURCETYPEPERMISSION;
2125
2126 if (pagination) {
2127 sql = sql.concat(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
2128 }
2129 }
2130
2131 Session session = null;
2132
2133 try {
2134 session = openSession();
2135
2136 Query q = session.createQuery(sql);
2137
2138 if (!pagination) {
2139 list = (List<ResourceTypePermission>)QueryUtil.list(q,
2140 getDialect(), start, end, false);
2141
2142 Collections.sort(list);
2143
2144 list = Collections.unmodifiableList(list);
2145 }
2146 else {
2147 list = (List<ResourceTypePermission>)QueryUtil.list(q,
2148 getDialect(), start, end);
2149 }
2150
2151 cacheResult(list);
2152
2153 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2154 }
2155 catch (Exception e) {
2156 FinderCacheUtil.removeResult(finderPath, finderArgs);
2157
2158 throw processException(e);
2159 }
2160 finally {
2161 closeSession(session);
2162 }
2163 }
2164
2165 return list;
2166 }
2167
2168
2172 @Override
2173 public void removeAll() {
2174 for (ResourceTypePermission resourceTypePermission : findAll()) {
2175 remove(resourceTypePermission);
2176 }
2177 }
2178
2179
2184 @Override
2185 public int countAll() {
2186 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2187 FINDER_ARGS_EMPTY, this);
2188
2189 if (count == null) {
2190 Session session = null;
2191
2192 try {
2193 session = openSession();
2194
2195 Query q = session.createQuery(_SQL_COUNT_RESOURCETYPEPERMISSION);
2196
2197 count = (Long)q.uniqueResult();
2198
2199 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2200 FINDER_ARGS_EMPTY, count);
2201 }
2202 catch (Exception e) {
2203 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2204 FINDER_ARGS_EMPTY);
2205
2206 throw processException(e);
2207 }
2208 finally {
2209 closeSession(session);
2210 }
2211 }
2212
2213 return count.intValue();
2214 }
2215
2216
2219 public void afterPropertiesSet() {
2220 }
2221
2222 public void destroy() {
2223 EntityCacheUtil.removeCache(ResourceTypePermissionImpl.class.getName());
2224 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2225 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2226 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2227 }
2228
2229 private static final String _SQL_SELECT_RESOURCETYPEPERMISSION = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission";
2230 private static final String _SQL_SELECT_RESOURCETYPEPERMISSION_WHERE_PKS_IN = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission WHERE resourceTypePermissionId IN (";
2231 private static final String _SQL_SELECT_RESOURCETYPEPERMISSION_WHERE = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission WHERE ";
2232 private static final String _SQL_COUNT_RESOURCETYPEPERMISSION = "SELECT COUNT(resourceTypePermission) FROM ResourceTypePermission resourceTypePermission";
2233 private static final String _SQL_COUNT_RESOURCETYPEPERMISSION_WHERE = "SELECT COUNT(resourceTypePermission) FROM ResourceTypePermission resourceTypePermission WHERE ";
2234 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceTypePermission.";
2235 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceTypePermission exists with the primary key ";
2236 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceTypePermission exists with the key {";
2237 private static final Log _log = LogFactoryUtil.getLog(ResourceTypePermissionPersistenceImpl.class);
2238 private static final ResourceTypePermission _nullResourceTypePermission = new ResourceTypePermissionImpl() {
2239 @Override
2240 public Object clone() {
2241 return this;
2242 }
2243
2244 @Override
2245 public CacheModel<ResourceTypePermission> toCacheModel() {
2246 return _nullResourceTypePermissionCacheModel;
2247 }
2248 };
2249
2250 private static final CacheModel<ResourceTypePermission> _nullResourceTypePermissionCacheModel =
2251 new NullCacheModel();
2252
2253 private static class NullCacheModel implements CacheModel<ResourceTypePermission>,
2254 MVCCModel {
2255 @Override
2256 public long getMvccVersion() {
2257 return -1;
2258 }
2259
2260 @Override
2261 public void setMvccVersion(long mvccVersion) {
2262 }
2263
2264 @Override
2265 public ResourceTypePermission toEntityModel() {
2266 return _nullResourceTypePermission;
2267 }
2268 }
2269 }