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 @Override
115 public List<ResourceTypePermission> findByRoleId(long roleId)
116 throws SystemException {
117 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
133 @Override
134 public List<ResourceTypePermission> findByRoleId(long roleId, int start,
135 int end) throws SystemException {
136 return findByRoleId(roleId, start, end, null);
137 }
138
139
153 @Override
154 public List<ResourceTypePermission> findByRoleId(long roleId, int start,
155 int end, OrderByComparator orderByComparator) throws SystemException {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
164 finderArgs = new Object[] { roleId };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
168 finderArgs = new Object[] { roleId, start, end, orderByComparator };
169 }
170
171 List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (ResourceTypePermission resourceTypePermission : list) {
176 if ((roleId != resourceTypePermission.getRoleId())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
196
197 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
198
199 if (orderByComparator != null) {
200 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
201 orderByComparator);
202 }
203 else
204 if (pagination) {
205 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
206 }
207
208 String sql = query.toString();
209
210 Session session = null;
211
212 try {
213 session = openSession();
214
215 Query q = session.createQuery(sql);
216
217 QueryPos qPos = QueryPos.getInstance(q);
218
219 qPos.add(roleId);
220
221 if (!pagination) {
222 list = (List<ResourceTypePermission>)QueryUtil.list(q,
223 getDialect(), start, end, false);
224
225 Collections.sort(list);
226
227 list = new UnmodifiableList<ResourceTypePermission>(list);
228 }
229 else {
230 list = (List<ResourceTypePermission>)QueryUtil.list(q,
231 getDialect(), start, end);
232 }
233
234 cacheResult(list);
235
236 FinderCacheUtil.putResult(finderPath, finderArgs, list);
237 }
238 catch (Exception e) {
239 FinderCacheUtil.removeResult(finderPath, finderArgs);
240
241 throw processException(e);
242 }
243 finally {
244 closeSession(session);
245 }
246 }
247
248 return list;
249 }
250
251
260 @Override
261 public ResourceTypePermission findByRoleId_First(long roleId,
262 OrderByComparator orderByComparator)
263 throws NoSuchResourceTypePermissionException, SystemException {
264 ResourceTypePermission resourceTypePermission = fetchByRoleId_First(roleId,
265 orderByComparator);
266
267 if (resourceTypePermission != null) {
268 return resourceTypePermission;
269 }
270
271 StringBundler msg = new StringBundler(4);
272
273 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
274
275 msg.append("roleId=");
276 msg.append(roleId);
277
278 msg.append(StringPool.CLOSE_CURLY_BRACE);
279
280 throw new NoSuchResourceTypePermissionException(msg.toString());
281 }
282
283
291 @Override
292 public ResourceTypePermission fetchByRoleId_First(long roleId,
293 OrderByComparator orderByComparator) throws SystemException {
294 List<ResourceTypePermission> list = findByRoleId(roleId, 0, 1,
295 orderByComparator);
296
297 if (!list.isEmpty()) {
298 return list.get(0);
299 }
300
301 return null;
302 }
303
304
313 @Override
314 public ResourceTypePermission findByRoleId_Last(long roleId,
315 OrderByComparator orderByComparator)
316 throws NoSuchResourceTypePermissionException, SystemException {
317 ResourceTypePermission resourceTypePermission = fetchByRoleId_Last(roleId,
318 orderByComparator);
319
320 if (resourceTypePermission != null) {
321 return resourceTypePermission;
322 }
323
324 StringBundler msg = new StringBundler(4);
325
326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327
328 msg.append("roleId=");
329 msg.append(roleId);
330
331 msg.append(StringPool.CLOSE_CURLY_BRACE);
332
333 throw new NoSuchResourceTypePermissionException(msg.toString());
334 }
335
336
344 @Override
345 public ResourceTypePermission fetchByRoleId_Last(long roleId,
346 OrderByComparator orderByComparator) throws SystemException {
347 int count = countByRoleId(roleId);
348
349 if (count == 0) {
350 return null;
351 }
352
353 List<ResourceTypePermission> list = findByRoleId(roleId, count - 1,
354 count, orderByComparator);
355
356 if (!list.isEmpty()) {
357 return list.get(0);
358 }
359
360 return null;
361 }
362
363
373 @Override
374 public ResourceTypePermission[] findByRoleId_PrevAndNext(
375 long resourceTypePermissionId, long roleId,
376 OrderByComparator orderByComparator)
377 throws NoSuchResourceTypePermissionException, SystemException {
378 ResourceTypePermission resourceTypePermission = findByPrimaryKey(resourceTypePermissionId);
379
380 Session session = null;
381
382 try {
383 session = openSession();
384
385 ResourceTypePermission[] array = new ResourceTypePermissionImpl[3];
386
387 array[0] = getByRoleId_PrevAndNext(session, resourceTypePermission,
388 roleId, orderByComparator, true);
389
390 array[1] = resourceTypePermission;
391
392 array[2] = getByRoleId_PrevAndNext(session, resourceTypePermission,
393 roleId, orderByComparator, false);
394
395 return array;
396 }
397 catch (Exception e) {
398 throw processException(e);
399 }
400 finally {
401 closeSession(session);
402 }
403 }
404
405 protected ResourceTypePermission getByRoleId_PrevAndNext(Session session,
406 ResourceTypePermission resourceTypePermission, long roleId,
407 OrderByComparator orderByComparator, boolean previous) {
408 StringBundler query = null;
409
410 if (orderByComparator != null) {
411 query = new StringBundler(6 +
412 (orderByComparator.getOrderByFields().length * 6));
413 }
414 else {
415 query = new StringBundler(3);
416 }
417
418 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
419
420 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
421
422 if (orderByComparator != null) {
423 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
424
425 if (orderByConditionFields.length > 0) {
426 query.append(WHERE_AND);
427 }
428
429 for (int i = 0; i < orderByConditionFields.length; i++) {
430 query.append(_ORDER_BY_ENTITY_ALIAS);
431 query.append(orderByConditionFields[i]);
432
433 if ((i + 1) < orderByConditionFields.length) {
434 if (orderByComparator.isAscending() ^ previous) {
435 query.append(WHERE_GREATER_THAN_HAS_NEXT);
436 }
437 else {
438 query.append(WHERE_LESSER_THAN_HAS_NEXT);
439 }
440 }
441 else {
442 if (orderByComparator.isAscending() ^ previous) {
443 query.append(WHERE_GREATER_THAN);
444 }
445 else {
446 query.append(WHERE_LESSER_THAN);
447 }
448 }
449 }
450
451 query.append(ORDER_BY_CLAUSE);
452
453 String[] orderByFields = orderByComparator.getOrderByFields();
454
455 for (int i = 0; i < orderByFields.length; i++) {
456 query.append(_ORDER_BY_ENTITY_ALIAS);
457 query.append(orderByFields[i]);
458
459 if ((i + 1) < orderByFields.length) {
460 if (orderByComparator.isAscending() ^ previous) {
461 query.append(ORDER_BY_ASC_HAS_NEXT);
462 }
463 else {
464 query.append(ORDER_BY_DESC_HAS_NEXT);
465 }
466 }
467 else {
468 if (orderByComparator.isAscending() ^ previous) {
469 query.append(ORDER_BY_ASC);
470 }
471 else {
472 query.append(ORDER_BY_DESC);
473 }
474 }
475 }
476 }
477 else {
478 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
479 }
480
481 String sql = query.toString();
482
483 Query q = session.createQuery(sql);
484
485 q.setFirstResult(0);
486 q.setMaxResults(2);
487
488 QueryPos qPos = QueryPos.getInstance(q);
489
490 qPos.add(roleId);
491
492 if (orderByComparator != null) {
493 Object[] values = orderByComparator.getOrderByConditionValues(resourceTypePermission);
494
495 for (Object value : values) {
496 qPos.add(value);
497 }
498 }
499
500 List<ResourceTypePermission> list = q.list();
501
502 if (list.size() == 2) {
503 return list.get(1);
504 }
505 else {
506 return null;
507 }
508 }
509
510
516 @Override
517 public void removeByRoleId(long roleId) throws SystemException {
518 for (ResourceTypePermission resourceTypePermission : findByRoleId(
519 roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
520 remove(resourceTypePermission);
521 }
522 }
523
524
531 @Override
532 public int countByRoleId(long roleId) throws SystemException {
533 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
534
535 Object[] finderArgs = new Object[] { roleId };
536
537 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
538 this);
539
540 if (count == null) {
541 StringBundler query = new StringBundler(2);
542
543 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
544
545 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
546
547 String sql = query.toString();
548
549 Session session = null;
550
551 try {
552 session = openSession();
553
554 Query q = session.createQuery(sql);
555
556 QueryPos qPos = QueryPos.getInstance(q);
557
558 qPos.add(roleId);
559
560 count = (Long)q.uniqueResult();
561
562 FinderCacheUtil.putResult(finderPath, finderArgs, count);
563 }
564 catch (Exception e) {
565 FinderCacheUtil.removeResult(finderPath, finderArgs);
566
567 throw processException(e);
568 }
569 finally {
570 closeSession(session);
571 }
572 }
573
574 return count.intValue();
575 }
576
577 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourceTypePermission.roleId = ?";
578 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
579 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
580 ResourceTypePermissionImpl.class,
581 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_R",
582 new String[] {
583 Long.class.getName(), String.class.getName(),
584 Long.class.getName(),
585
586 Integer.class.getName(), Integer.class.getName(),
587 OrderByComparator.class.getName()
588 });
589 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
590 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
591 ResourceTypePermissionImpl.class,
592 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_R",
593 new String[] {
594 Long.class.getName(), String.class.getName(),
595 Long.class.getName()
596 },
597 ResourceTypePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
598 ResourceTypePermissionModelImpl.NAME_COLUMN_BITMASK |
599 ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
600 public static final FinderPath FINDER_PATH_COUNT_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
601 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
602 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_R",
603 new String[] {
604 Long.class.getName(), String.class.getName(),
605 Long.class.getName()
606 });
607
608
617 @Override
618 public List<ResourceTypePermission> findByC_N_R(long companyId,
619 String name, long roleId) throws SystemException {
620 return findByC_N_R(companyId, name, roleId, QueryUtil.ALL_POS,
621 QueryUtil.ALL_POS, null);
622 }
623
624
639 @Override
640 public List<ResourceTypePermission> findByC_N_R(long companyId,
641 String name, long roleId, int start, int end) throws SystemException {
642 return findByC_N_R(companyId, name, roleId, start, end, null);
643 }
644
645
661 @Override
662 public List<ResourceTypePermission> findByC_N_R(long companyId,
663 String name, long roleId, int start, int end,
664 OrderByComparator orderByComparator) throws SystemException {
665 boolean pagination = true;
666 FinderPath finderPath = null;
667 Object[] finderArgs = null;
668
669 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
670 (orderByComparator == null)) {
671 pagination = false;
672 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R;
673 finderArgs = new Object[] { companyId, name, roleId };
674 }
675 else {
676 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_R;
677 finderArgs = new Object[] {
678 companyId, name, roleId,
679
680 start, end, orderByComparator
681 };
682 }
683
684 List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
685 finderArgs, this);
686
687 if ((list != null) && !list.isEmpty()) {
688 for (ResourceTypePermission resourceTypePermission : list) {
689 if ((companyId != resourceTypePermission.getCompanyId()) ||
690 !Validator.equals(name, resourceTypePermission.getName()) ||
691 (roleId != resourceTypePermission.getRoleId())) {
692 list = null;
693
694 break;
695 }
696 }
697 }
698
699 if (list == null) {
700 StringBundler query = null;
701
702 if (orderByComparator != null) {
703 query = new StringBundler(5 +
704 (orderByComparator.getOrderByFields().length * 3));
705 }
706 else {
707 query = new StringBundler(5);
708 }
709
710 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
711
712 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
713
714 boolean bindName = false;
715
716 if (name == null) {
717 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
718 }
719 else if (name.equals(StringPool.BLANK)) {
720 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
721 }
722 else {
723 bindName = true;
724
725 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
726 }
727
728 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
729
730 if (orderByComparator != null) {
731 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
732 orderByComparator);
733 }
734 else
735 if (pagination) {
736 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
737 }
738
739 String sql = query.toString();
740
741 Session session = null;
742
743 try {
744 session = openSession();
745
746 Query q = session.createQuery(sql);
747
748 QueryPos qPos = QueryPos.getInstance(q);
749
750 qPos.add(companyId);
751
752 if (bindName) {
753 qPos.add(name);
754 }
755
756 qPos.add(roleId);
757
758 if (!pagination) {
759 list = (List<ResourceTypePermission>)QueryUtil.list(q,
760 getDialect(), start, end, false);
761
762 Collections.sort(list);
763
764 list = new UnmodifiableList<ResourceTypePermission>(list);
765 }
766 else {
767 list = (List<ResourceTypePermission>)QueryUtil.list(q,
768 getDialect(), start, end);
769 }
770
771 cacheResult(list);
772
773 FinderCacheUtil.putResult(finderPath, finderArgs, list);
774 }
775 catch (Exception e) {
776 FinderCacheUtil.removeResult(finderPath, finderArgs);
777
778 throw processException(e);
779 }
780 finally {
781 closeSession(session);
782 }
783 }
784
785 return list;
786 }
787
788
799 @Override
800 public ResourceTypePermission findByC_N_R_First(long companyId,
801 String name, long roleId, OrderByComparator orderByComparator)
802 throws NoSuchResourceTypePermissionException, SystemException {
803 ResourceTypePermission resourceTypePermission = fetchByC_N_R_First(companyId,
804 name, roleId, orderByComparator);
805
806 if (resourceTypePermission != null) {
807 return resourceTypePermission;
808 }
809
810 StringBundler msg = new StringBundler(8);
811
812 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
813
814 msg.append("companyId=");
815 msg.append(companyId);
816
817 msg.append(", name=");
818 msg.append(name);
819
820 msg.append(", roleId=");
821 msg.append(roleId);
822
823 msg.append(StringPool.CLOSE_CURLY_BRACE);
824
825 throw new NoSuchResourceTypePermissionException(msg.toString());
826 }
827
828
838 @Override
839 public ResourceTypePermission fetchByC_N_R_First(long companyId,
840 String name, long roleId, OrderByComparator orderByComparator)
841 throws SystemException {
842 List<ResourceTypePermission> list = findByC_N_R(companyId, name,
843 roleId, 0, 1, orderByComparator);
844
845 if (!list.isEmpty()) {
846 return list.get(0);
847 }
848
849 return null;
850 }
851
852
863 @Override
864 public ResourceTypePermission findByC_N_R_Last(long companyId, String name,
865 long roleId, OrderByComparator orderByComparator)
866 throws NoSuchResourceTypePermissionException, SystemException {
867 ResourceTypePermission resourceTypePermission = fetchByC_N_R_Last(companyId,
868 name, roleId, orderByComparator);
869
870 if (resourceTypePermission != null) {
871 return resourceTypePermission;
872 }
873
874 StringBundler msg = new StringBundler(8);
875
876 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
877
878 msg.append("companyId=");
879 msg.append(companyId);
880
881 msg.append(", name=");
882 msg.append(name);
883
884 msg.append(", roleId=");
885 msg.append(roleId);
886
887 msg.append(StringPool.CLOSE_CURLY_BRACE);
888
889 throw new NoSuchResourceTypePermissionException(msg.toString());
890 }
891
892
902 @Override
903 public ResourceTypePermission fetchByC_N_R_Last(long companyId,
904 String name, long roleId, OrderByComparator orderByComparator)
905 throws SystemException {
906 int count = countByC_N_R(companyId, name, roleId);
907
908 if (count == 0) {
909 return null;
910 }
911
912 List<ResourceTypePermission> list = findByC_N_R(companyId, name,
913 roleId, count - 1, count, orderByComparator);
914
915 if (!list.isEmpty()) {
916 return list.get(0);
917 }
918
919 return null;
920 }
921
922
934 @Override
935 public ResourceTypePermission[] findByC_N_R_PrevAndNext(
936 long resourceTypePermissionId, long companyId, String name,
937 long roleId, OrderByComparator orderByComparator)
938 throws NoSuchResourceTypePermissionException, SystemException {
939 ResourceTypePermission resourceTypePermission = findByPrimaryKey(resourceTypePermissionId);
940
941 Session session = null;
942
943 try {
944 session = openSession();
945
946 ResourceTypePermission[] array = new ResourceTypePermissionImpl[3];
947
948 array[0] = getByC_N_R_PrevAndNext(session, resourceTypePermission,
949 companyId, name, roleId, orderByComparator, true);
950
951 array[1] = resourceTypePermission;
952
953 array[2] = getByC_N_R_PrevAndNext(session, resourceTypePermission,
954 companyId, name, roleId, orderByComparator, false);
955
956 return array;
957 }
958 catch (Exception e) {
959 throw processException(e);
960 }
961 finally {
962 closeSession(session);
963 }
964 }
965
966 protected ResourceTypePermission getByC_N_R_PrevAndNext(Session session,
967 ResourceTypePermission resourceTypePermission, long companyId,
968 String name, long roleId, OrderByComparator orderByComparator,
969 boolean previous) {
970 StringBundler query = null;
971
972 if (orderByComparator != null) {
973 query = new StringBundler(6 +
974 (orderByComparator.getOrderByFields().length * 6));
975 }
976 else {
977 query = new StringBundler(3);
978 }
979
980 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
981
982 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
983
984 boolean bindName = false;
985
986 if (name == null) {
987 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
988 }
989 else if (name.equals(StringPool.BLANK)) {
990 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
991 }
992 else {
993 bindName = true;
994
995 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
996 }
997
998 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
999
1000 if (orderByComparator != null) {
1001 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1002
1003 if (orderByConditionFields.length > 0) {
1004 query.append(WHERE_AND);
1005 }
1006
1007 for (int i = 0; i < orderByConditionFields.length; i++) {
1008 query.append(_ORDER_BY_ENTITY_ALIAS);
1009 query.append(orderByConditionFields[i]);
1010
1011 if ((i + 1) < orderByConditionFields.length) {
1012 if (orderByComparator.isAscending() ^ previous) {
1013 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1014 }
1015 else {
1016 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1017 }
1018 }
1019 else {
1020 if (orderByComparator.isAscending() ^ previous) {
1021 query.append(WHERE_GREATER_THAN);
1022 }
1023 else {
1024 query.append(WHERE_LESSER_THAN);
1025 }
1026 }
1027 }
1028
1029 query.append(ORDER_BY_CLAUSE);
1030
1031 String[] orderByFields = orderByComparator.getOrderByFields();
1032
1033 for (int i = 0; i < orderByFields.length; i++) {
1034 query.append(_ORDER_BY_ENTITY_ALIAS);
1035 query.append(orderByFields[i]);
1036
1037 if ((i + 1) < orderByFields.length) {
1038 if (orderByComparator.isAscending() ^ previous) {
1039 query.append(ORDER_BY_ASC_HAS_NEXT);
1040 }
1041 else {
1042 query.append(ORDER_BY_DESC_HAS_NEXT);
1043 }
1044 }
1045 else {
1046 if (orderByComparator.isAscending() ^ previous) {
1047 query.append(ORDER_BY_ASC);
1048 }
1049 else {
1050 query.append(ORDER_BY_DESC);
1051 }
1052 }
1053 }
1054 }
1055 else {
1056 query.append(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
1057 }
1058
1059 String sql = query.toString();
1060
1061 Query q = session.createQuery(sql);
1062
1063 q.setFirstResult(0);
1064 q.setMaxResults(2);
1065
1066 QueryPos qPos = QueryPos.getInstance(q);
1067
1068 qPos.add(companyId);
1069
1070 if (bindName) {
1071 qPos.add(name);
1072 }
1073
1074 qPos.add(roleId);
1075
1076 if (orderByComparator != null) {
1077 Object[] values = orderByComparator.getOrderByConditionValues(resourceTypePermission);
1078
1079 for (Object value : values) {
1080 qPos.add(value);
1081 }
1082 }
1083
1084 List<ResourceTypePermission> list = q.list();
1085
1086 if (list.size() == 2) {
1087 return list.get(1);
1088 }
1089 else {
1090 return null;
1091 }
1092 }
1093
1094
1102 @Override
1103 public void removeByC_N_R(long companyId, String name, long roleId)
1104 throws SystemException {
1105 for (ResourceTypePermission resourceTypePermission : findByC_N_R(
1106 companyId, name, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1107 null)) {
1108 remove(resourceTypePermission);
1109 }
1110 }
1111
1112
1121 @Override
1122 public int countByC_N_R(long companyId, String name, long roleId)
1123 throws SystemException {
1124 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_R;
1125
1126 Object[] finderArgs = new Object[] { companyId, name, roleId };
1127
1128 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1129 this);
1130
1131 if (count == null) {
1132 StringBundler query = new StringBundler(4);
1133
1134 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1135
1136 query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
1137
1138 boolean bindName = false;
1139
1140 if (name == null) {
1141 query.append(_FINDER_COLUMN_C_N_R_NAME_1);
1142 }
1143 else if (name.equals(StringPool.BLANK)) {
1144 query.append(_FINDER_COLUMN_C_N_R_NAME_3);
1145 }
1146 else {
1147 bindName = true;
1148
1149 query.append(_FINDER_COLUMN_C_N_R_NAME_2);
1150 }
1151
1152 query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
1153
1154 String sql = query.toString();
1155
1156 Session session = null;
1157
1158 try {
1159 session = openSession();
1160
1161 Query q = session.createQuery(sql);
1162
1163 QueryPos qPos = QueryPos.getInstance(q);
1164
1165 qPos.add(companyId);
1166
1167 if (bindName) {
1168 qPos.add(name);
1169 }
1170
1171 qPos.add(roleId);
1172
1173 count = (Long)q.uniqueResult();
1174
1175 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1176 }
1177 catch (Exception e) {
1178 FinderCacheUtil.removeResult(finderPath, finderArgs);
1179
1180 throw processException(e);
1181 }
1182 finally {
1183 closeSession(session);
1184 }
1185 }
1186
1187 return count.intValue();
1188 }
1189
1190 private static final String _FINDER_COLUMN_C_N_R_COMPANYID_2 = "resourceTypePermission.companyId = ? AND ";
1191 private static final String _FINDER_COLUMN_C_N_R_NAME_1 = "resourceTypePermission.name IS NULL AND ";
1192 private static final String _FINDER_COLUMN_C_N_R_NAME_2 = "resourceTypePermission.name = ? AND ";
1193 private static final String _FINDER_COLUMN_C_N_R_NAME_3 = "(resourceTypePermission.name IS NULL OR resourceTypePermission.name = '') AND ";
1194 private static final String _FINDER_COLUMN_C_N_R_ROLEID_2 = "resourceTypePermission.roleId = ?";
1195 public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1196 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
1197 ResourceTypePermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
1198 "fetchByC_G_N_R",
1199 new String[] {
1200 Long.class.getName(), Long.class.getName(),
1201 String.class.getName(), Long.class.getName()
1202 },
1203 ResourceTypePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
1204 ResourceTypePermissionModelImpl.GROUPID_COLUMN_BITMASK |
1205 ResourceTypePermissionModelImpl.NAME_COLUMN_BITMASK |
1206 ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
1207 public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1208 ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1209 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_R",
1210 new String[] {
1211 Long.class.getName(), Long.class.getName(),
1212 String.class.getName(), Long.class.getName()
1213 });
1214
1215
1226 @Override
1227 public ResourceTypePermission findByC_G_N_R(long companyId, long groupId,
1228 String name, long roleId)
1229 throws NoSuchResourceTypePermissionException, SystemException {
1230 ResourceTypePermission resourceTypePermission = fetchByC_G_N_R(companyId,
1231 groupId, name, roleId);
1232
1233 if (resourceTypePermission == null) {
1234 StringBundler msg = new StringBundler(10);
1235
1236 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1237
1238 msg.append("companyId=");
1239 msg.append(companyId);
1240
1241 msg.append(", groupId=");
1242 msg.append(groupId);
1243
1244 msg.append(", name=");
1245 msg.append(name);
1246
1247 msg.append(", roleId=");
1248 msg.append(roleId);
1249
1250 msg.append(StringPool.CLOSE_CURLY_BRACE);
1251
1252 if (_log.isWarnEnabled()) {
1253 _log.warn(msg.toString());
1254 }
1255
1256 throw new NoSuchResourceTypePermissionException(msg.toString());
1257 }
1258
1259 return resourceTypePermission;
1260 }
1261
1262
1272 @Override
1273 public ResourceTypePermission fetchByC_G_N_R(long companyId, long groupId,
1274 String name, long roleId) throws SystemException {
1275 return fetchByC_G_N_R(companyId, groupId, name, roleId, true);
1276 }
1277
1278
1289 @Override
1290 public ResourceTypePermission fetchByC_G_N_R(long companyId, long groupId,
1291 String name, long roleId, boolean retrieveFromCache)
1292 throws SystemException {
1293 Object[] finderArgs = new Object[] { companyId, groupId, name, roleId };
1294
1295 Object result = null;
1296
1297 if (retrieveFromCache) {
1298 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1299 finderArgs, this);
1300 }
1301
1302 if (result instanceof ResourceTypePermission) {
1303 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)result;
1304
1305 if ((companyId != resourceTypePermission.getCompanyId()) ||
1306 (groupId != resourceTypePermission.getGroupId()) ||
1307 !Validator.equals(name, resourceTypePermission.getName()) ||
1308 (roleId != resourceTypePermission.getRoleId())) {
1309 result = null;
1310 }
1311 }
1312
1313 if (result == null) {
1314 StringBundler query = new StringBundler(6);
1315
1316 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
1317
1318 query.append(_FINDER_COLUMN_C_G_N_R_COMPANYID_2);
1319
1320 query.append(_FINDER_COLUMN_C_G_N_R_GROUPID_2);
1321
1322 boolean bindName = false;
1323
1324 if (name == null) {
1325 query.append(_FINDER_COLUMN_C_G_N_R_NAME_1);
1326 }
1327 else if (name.equals(StringPool.BLANK)) {
1328 query.append(_FINDER_COLUMN_C_G_N_R_NAME_3);
1329 }
1330 else {
1331 bindName = true;
1332
1333 query.append(_FINDER_COLUMN_C_G_N_R_NAME_2);
1334 }
1335
1336 query.append(_FINDER_COLUMN_C_G_N_R_ROLEID_2);
1337
1338 String sql = query.toString();
1339
1340 Session session = null;
1341
1342 try {
1343 session = openSession();
1344
1345 Query q = session.createQuery(sql);
1346
1347 QueryPos qPos = QueryPos.getInstance(q);
1348
1349 qPos.add(companyId);
1350
1351 qPos.add(groupId);
1352
1353 if (bindName) {
1354 qPos.add(name);
1355 }
1356
1357 qPos.add(roleId);
1358
1359 List<ResourceTypePermission> list = q.list();
1360
1361 if (list.isEmpty()) {
1362 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1363 finderArgs, list);
1364 }
1365 else {
1366 ResourceTypePermission resourceTypePermission = list.get(0);
1367
1368 result = resourceTypePermission;
1369
1370 cacheResult(resourceTypePermission);
1371
1372 if ((resourceTypePermission.getCompanyId() != companyId) ||
1373 (resourceTypePermission.getGroupId() != groupId) ||
1374 (resourceTypePermission.getName() == null) ||
1375 !resourceTypePermission.getName().equals(name) ||
1376 (resourceTypePermission.getRoleId() != roleId)) {
1377 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1378 finderArgs, resourceTypePermission);
1379 }
1380 }
1381 }
1382 catch (Exception e) {
1383 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1384 finderArgs);
1385
1386 throw processException(e);
1387 }
1388 finally {
1389 closeSession(session);
1390 }
1391 }
1392
1393 if (result instanceof List<?>) {
1394 return null;
1395 }
1396 else {
1397 return (ResourceTypePermission)result;
1398 }
1399 }
1400
1401
1411 @Override
1412 public ResourceTypePermission removeByC_G_N_R(long companyId, long groupId,
1413 String name, long roleId)
1414 throws NoSuchResourceTypePermissionException, SystemException {
1415 ResourceTypePermission resourceTypePermission = findByC_G_N_R(companyId,
1416 groupId, name, roleId);
1417
1418 return remove(resourceTypePermission);
1419 }
1420
1421
1431 @Override
1432 public int countByC_G_N_R(long companyId, long groupId, String name,
1433 long roleId) throws SystemException {
1434 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_G_N_R;
1435
1436 Object[] finderArgs = new Object[] { companyId, groupId, name, roleId };
1437
1438 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1439 this);
1440
1441 if (count == null) {
1442 StringBundler query = new StringBundler(5);
1443
1444 query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1445
1446 query.append(_FINDER_COLUMN_C_G_N_R_COMPANYID_2);
1447
1448 query.append(_FINDER_COLUMN_C_G_N_R_GROUPID_2);
1449
1450 boolean bindName = false;
1451
1452 if (name == null) {
1453 query.append(_FINDER_COLUMN_C_G_N_R_NAME_1);
1454 }
1455 else if (name.equals(StringPool.BLANK)) {
1456 query.append(_FINDER_COLUMN_C_G_N_R_NAME_3);
1457 }
1458 else {
1459 bindName = true;
1460
1461 query.append(_FINDER_COLUMN_C_G_N_R_NAME_2);
1462 }
1463
1464 query.append(_FINDER_COLUMN_C_G_N_R_ROLEID_2);
1465
1466 String sql = query.toString();
1467
1468 Session session = null;
1469
1470 try {
1471 session = openSession();
1472
1473 Query q = session.createQuery(sql);
1474
1475 QueryPos qPos = QueryPos.getInstance(q);
1476
1477 qPos.add(companyId);
1478
1479 qPos.add(groupId);
1480
1481 if (bindName) {
1482 qPos.add(name);
1483 }
1484
1485 qPos.add(roleId);
1486
1487 count = (Long)q.uniqueResult();
1488
1489 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1490 }
1491 catch (Exception e) {
1492 FinderCacheUtil.removeResult(finderPath, finderArgs);
1493
1494 throw processException(e);
1495 }
1496 finally {
1497 closeSession(session);
1498 }
1499 }
1500
1501 return count.intValue();
1502 }
1503
1504 private static final String _FINDER_COLUMN_C_G_N_R_COMPANYID_2 = "resourceTypePermission.companyId = ? AND ";
1505 private static final String _FINDER_COLUMN_C_G_N_R_GROUPID_2 = "resourceTypePermission.groupId = ? AND ";
1506 private static final String _FINDER_COLUMN_C_G_N_R_NAME_1 = "resourceTypePermission.name IS NULL AND ";
1507 private static final String _FINDER_COLUMN_C_G_N_R_NAME_2 = "resourceTypePermission.name = ? AND ";
1508 private static final String _FINDER_COLUMN_C_G_N_R_NAME_3 = "(resourceTypePermission.name IS NULL OR resourceTypePermission.name = '') AND ";
1509 private static final String _FINDER_COLUMN_C_G_N_R_ROLEID_2 = "resourceTypePermission.roleId = ?";
1510
1511
1516 @Override
1517 public void cacheResult(ResourceTypePermission resourceTypePermission) {
1518 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1519 ResourceTypePermissionImpl.class,
1520 resourceTypePermission.getPrimaryKey(), resourceTypePermission);
1521
1522 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1523 new Object[] {
1524 resourceTypePermission.getCompanyId(),
1525 resourceTypePermission.getGroupId(),
1526 resourceTypePermission.getName(),
1527 resourceTypePermission.getRoleId()
1528 }, resourceTypePermission);
1529
1530 resourceTypePermission.resetOriginalValues();
1531 }
1532
1533
1538 @Override
1539 public void cacheResult(
1540 List<ResourceTypePermission> resourceTypePermissions) {
1541 for (ResourceTypePermission resourceTypePermission : resourceTypePermissions) {
1542 if (EntityCacheUtil.getResult(
1543 ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1544 ResourceTypePermissionImpl.class,
1545 resourceTypePermission.getPrimaryKey()) == null) {
1546 cacheResult(resourceTypePermission);
1547 }
1548 else {
1549 resourceTypePermission.resetOriginalValues();
1550 }
1551 }
1552 }
1553
1554
1561 @Override
1562 public void clearCache() {
1563 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1564 CacheRegistryUtil.clear(ResourceTypePermissionImpl.class.getName());
1565 }
1566
1567 EntityCacheUtil.clearCache(ResourceTypePermissionImpl.class.getName());
1568
1569 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1570 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1571 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1572 }
1573
1574
1581 @Override
1582 public void clearCache(ResourceTypePermission resourceTypePermission) {
1583 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1584 ResourceTypePermissionImpl.class,
1585 resourceTypePermission.getPrimaryKey());
1586
1587 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1588 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1589
1590 clearUniqueFindersCache(resourceTypePermission);
1591 }
1592
1593 @Override
1594 public void clearCache(List<ResourceTypePermission> resourceTypePermissions) {
1595 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1596 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1597
1598 for (ResourceTypePermission resourceTypePermission : resourceTypePermissions) {
1599 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1600 ResourceTypePermissionImpl.class,
1601 resourceTypePermission.getPrimaryKey());
1602
1603 clearUniqueFindersCache(resourceTypePermission);
1604 }
1605 }
1606
1607 protected void cacheUniqueFindersCache(
1608 ResourceTypePermission resourceTypePermission) {
1609 if (resourceTypePermission.isNew()) {
1610 Object[] args = new Object[] {
1611 resourceTypePermission.getCompanyId(),
1612 resourceTypePermission.getGroupId(),
1613 resourceTypePermission.getName(),
1614 resourceTypePermission.getRoleId()
1615 };
1616
1617 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_R, args,
1618 Long.valueOf(1));
1619 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R, args,
1620 resourceTypePermission);
1621 }
1622 else {
1623 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1624
1625 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1626 FINDER_PATH_FETCH_BY_C_G_N_R.getColumnBitmask()) != 0) {
1627 Object[] args = new Object[] {
1628 resourceTypePermission.getCompanyId(),
1629 resourceTypePermission.getGroupId(),
1630 resourceTypePermission.getName(),
1631 resourceTypePermission.getRoleId()
1632 };
1633
1634 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_R, args,
1635 Long.valueOf(1));
1636 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R, args,
1637 resourceTypePermission);
1638 }
1639 }
1640 }
1641
1642 protected void clearUniqueFindersCache(
1643 ResourceTypePermission resourceTypePermission) {
1644 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1645
1646 Object[] args = new Object[] {
1647 resourceTypePermission.getCompanyId(),
1648 resourceTypePermission.getGroupId(),
1649 resourceTypePermission.getName(),
1650 resourceTypePermission.getRoleId()
1651 };
1652
1653 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_R, args);
1654 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R, args);
1655
1656 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1657 FINDER_PATH_FETCH_BY_C_G_N_R.getColumnBitmask()) != 0) {
1658 args = new Object[] {
1659 resourceTypePermissionModelImpl.getOriginalCompanyId(),
1660 resourceTypePermissionModelImpl.getOriginalGroupId(),
1661 resourceTypePermissionModelImpl.getOriginalName(),
1662 resourceTypePermissionModelImpl.getOriginalRoleId()
1663 };
1664
1665 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_G_N_R, args);
1666 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R, args);
1667 }
1668 }
1669
1670
1676 @Override
1677 public ResourceTypePermission create(long resourceTypePermissionId) {
1678 ResourceTypePermission resourceTypePermission = new ResourceTypePermissionImpl();
1679
1680 resourceTypePermission.setNew(true);
1681 resourceTypePermission.setPrimaryKey(resourceTypePermissionId);
1682
1683 return resourceTypePermission;
1684 }
1685
1686
1694 @Override
1695 public ResourceTypePermission remove(long resourceTypePermissionId)
1696 throws NoSuchResourceTypePermissionException, SystemException {
1697 return remove((Serializable)resourceTypePermissionId);
1698 }
1699
1700
1708 @Override
1709 public ResourceTypePermission remove(Serializable primaryKey)
1710 throws NoSuchResourceTypePermissionException, SystemException {
1711 Session session = null;
1712
1713 try {
1714 session = openSession();
1715
1716 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1717 primaryKey);
1718
1719 if (resourceTypePermission == null) {
1720 if (_log.isWarnEnabled()) {
1721 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1722 }
1723
1724 throw new NoSuchResourceTypePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1725 primaryKey);
1726 }
1727
1728 return remove(resourceTypePermission);
1729 }
1730 catch (NoSuchResourceTypePermissionException nsee) {
1731 throw nsee;
1732 }
1733 catch (Exception e) {
1734 throw processException(e);
1735 }
1736 finally {
1737 closeSession(session);
1738 }
1739 }
1740
1741 @Override
1742 protected ResourceTypePermission removeImpl(
1743 ResourceTypePermission resourceTypePermission)
1744 throws SystemException {
1745 resourceTypePermission = toUnwrappedModel(resourceTypePermission);
1746
1747 Session session = null;
1748
1749 try {
1750 session = openSession();
1751
1752 if (!session.contains(resourceTypePermission)) {
1753 resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1754 resourceTypePermission.getPrimaryKeyObj());
1755 }
1756
1757 if (resourceTypePermission != null) {
1758 session.delete(resourceTypePermission);
1759 }
1760 }
1761 catch (Exception e) {
1762 throw processException(e);
1763 }
1764 finally {
1765 closeSession(session);
1766 }
1767
1768 if (resourceTypePermission != null) {
1769 clearCache(resourceTypePermission);
1770 }
1771
1772 return resourceTypePermission;
1773 }
1774
1775 @Override
1776 public ResourceTypePermission updateImpl(
1777 com.liferay.portal.model.ResourceTypePermission resourceTypePermission)
1778 throws SystemException {
1779 resourceTypePermission = toUnwrappedModel(resourceTypePermission);
1780
1781 boolean isNew = resourceTypePermission.isNew();
1782
1783 ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
1784
1785 Session session = null;
1786
1787 try {
1788 session = openSession();
1789
1790 if (resourceTypePermission.isNew()) {
1791 session.save(resourceTypePermission);
1792
1793 resourceTypePermission.setNew(false);
1794 }
1795 else {
1796 session.merge(resourceTypePermission);
1797 }
1798 }
1799 catch (Exception e) {
1800 throw processException(e);
1801 }
1802 finally {
1803 closeSession(session);
1804 }
1805
1806 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1807
1808 if (isNew || !ResourceTypePermissionModelImpl.COLUMN_BITMASK_ENABLED) {
1809 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1810 }
1811
1812 else {
1813 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1814 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1815 Object[] args = new Object[] {
1816 resourceTypePermissionModelImpl.getOriginalRoleId()
1817 };
1818
1819 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1820 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1821 args);
1822
1823 args = new Object[] { resourceTypePermissionModelImpl.getRoleId() };
1824
1825 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1826 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1827 args);
1828 }
1829
1830 if ((resourceTypePermissionModelImpl.getColumnBitmask() &
1831 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R.getColumnBitmask()) != 0) {
1832 Object[] args = new Object[] {
1833 resourceTypePermissionModelImpl.getOriginalCompanyId(),
1834 resourceTypePermissionModelImpl.getOriginalName(),
1835 resourceTypePermissionModelImpl.getOriginalRoleId()
1836 };
1837
1838 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_R, args);
1839 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R,
1840 args);
1841
1842 args = new Object[] {
1843 resourceTypePermissionModelImpl.getCompanyId(),
1844 resourceTypePermissionModelImpl.getName(),
1845 resourceTypePermissionModelImpl.getRoleId()
1846 };
1847
1848 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_R, args);
1849 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R,
1850 args);
1851 }
1852 }
1853
1854 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1855 ResourceTypePermissionImpl.class,
1856 resourceTypePermission.getPrimaryKey(), resourceTypePermission);
1857
1858 clearUniqueFindersCache(resourceTypePermission);
1859 cacheUniqueFindersCache(resourceTypePermission);
1860
1861 return resourceTypePermission;
1862 }
1863
1864 protected ResourceTypePermission toUnwrappedModel(
1865 ResourceTypePermission resourceTypePermission) {
1866 if (resourceTypePermission instanceof ResourceTypePermissionImpl) {
1867 return resourceTypePermission;
1868 }
1869
1870 ResourceTypePermissionImpl resourceTypePermissionImpl = new ResourceTypePermissionImpl();
1871
1872 resourceTypePermissionImpl.setNew(resourceTypePermission.isNew());
1873 resourceTypePermissionImpl.setPrimaryKey(resourceTypePermission.getPrimaryKey());
1874
1875 resourceTypePermissionImpl.setResourceTypePermissionId(resourceTypePermission.getResourceTypePermissionId());
1876 resourceTypePermissionImpl.setCompanyId(resourceTypePermission.getCompanyId());
1877 resourceTypePermissionImpl.setGroupId(resourceTypePermission.getGroupId());
1878 resourceTypePermissionImpl.setName(resourceTypePermission.getName());
1879 resourceTypePermissionImpl.setRoleId(resourceTypePermission.getRoleId());
1880 resourceTypePermissionImpl.setActionIds(resourceTypePermission.getActionIds());
1881
1882 return resourceTypePermissionImpl;
1883 }
1884
1885
1893 @Override
1894 public ResourceTypePermission findByPrimaryKey(Serializable primaryKey)
1895 throws NoSuchResourceTypePermissionException, SystemException {
1896 ResourceTypePermission resourceTypePermission = fetchByPrimaryKey(primaryKey);
1897
1898 if (resourceTypePermission == null) {
1899 if (_log.isWarnEnabled()) {
1900 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1901 }
1902
1903 throw new NoSuchResourceTypePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1904 primaryKey);
1905 }
1906
1907 return resourceTypePermission;
1908 }
1909
1910
1918 @Override
1919 public ResourceTypePermission findByPrimaryKey(
1920 long resourceTypePermissionId)
1921 throws NoSuchResourceTypePermissionException, SystemException {
1922 return findByPrimaryKey((Serializable)resourceTypePermissionId);
1923 }
1924
1925
1932 @Override
1933 public ResourceTypePermission fetchByPrimaryKey(Serializable primaryKey)
1934 throws SystemException {
1935 ResourceTypePermission resourceTypePermission = (ResourceTypePermission)EntityCacheUtil.getResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1936 ResourceTypePermissionImpl.class, primaryKey);
1937
1938 if (resourceTypePermission == _nullResourceTypePermission) {
1939 return null;
1940 }
1941
1942 if (resourceTypePermission == null) {
1943 Session session = null;
1944
1945 try {
1946 session = openSession();
1947
1948 resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
1949 primaryKey);
1950
1951 if (resourceTypePermission != null) {
1952 cacheResult(resourceTypePermission);
1953 }
1954 else {
1955 EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1956 ResourceTypePermissionImpl.class, primaryKey,
1957 _nullResourceTypePermission);
1958 }
1959 }
1960 catch (Exception e) {
1961 EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
1962 ResourceTypePermissionImpl.class, primaryKey);
1963
1964 throw processException(e);
1965 }
1966 finally {
1967 closeSession(session);
1968 }
1969 }
1970
1971 return resourceTypePermission;
1972 }
1973
1974
1981 @Override
1982 public ResourceTypePermission fetchByPrimaryKey(
1983 long resourceTypePermissionId) throws SystemException {
1984 return fetchByPrimaryKey((Serializable)resourceTypePermissionId);
1985 }
1986
1987
1993 @Override
1994 public List<ResourceTypePermission> findAll() throws SystemException {
1995 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1996 }
1997
1998
2010 @Override
2011 public List<ResourceTypePermission> findAll(int start, int end)
2012 throws SystemException {
2013 return findAll(start, end, null);
2014 }
2015
2016
2029 @Override
2030 public List<ResourceTypePermission> findAll(int start, int end,
2031 OrderByComparator orderByComparator) throws SystemException {
2032 boolean pagination = true;
2033 FinderPath finderPath = null;
2034 Object[] finderArgs = null;
2035
2036 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2037 (orderByComparator == null)) {
2038 pagination = false;
2039 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2040 finderArgs = FINDER_ARGS_EMPTY;
2041 }
2042 else {
2043 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2044 finderArgs = new Object[] { start, end, orderByComparator };
2045 }
2046
2047 List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
2048 finderArgs, this);
2049
2050 if (list == null) {
2051 StringBundler query = null;
2052 String sql = null;
2053
2054 if (orderByComparator != null) {
2055 query = new StringBundler(2 +
2056 (orderByComparator.getOrderByFields().length * 3));
2057
2058 query.append(_SQL_SELECT_RESOURCETYPEPERMISSION);
2059
2060 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2061 orderByComparator);
2062
2063 sql = query.toString();
2064 }
2065 else {
2066 sql = _SQL_SELECT_RESOURCETYPEPERMISSION;
2067
2068 if (pagination) {
2069 sql = sql.concat(ResourceTypePermissionModelImpl.ORDER_BY_JPQL);
2070 }
2071 }
2072
2073 Session session = null;
2074
2075 try {
2076 session = openSession();
2077
2078 Query q = session.createQuery(sql);
2079
2080 if (!pagination) {
2081 list = (List<ResourceTypePermission>)QueryUtil.list(q,
2082 getDialect(), start, end, false);
2083
2084 Collections.sort(list);
2085
2086 list = new UnmodifiableList<ResourceTypePermission>(list);
2087 }
2088 else {
2089 list = (List<ResourceTypePermission>)QueryUtil.list(q,
2090 getDialect(), start, end);
2091 }
2092
2093 cacheResult(list);
2094
2095 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2096 }
2097 catch (Exception e) {
2098 FinderCacheUtil.removeResult(finderPath, finderArgs);
2099
2100 throw processException(e);
2101 }
2102 finally {
2103 closeSession(session);
2104 }
2105 }
2106
2107 return list;
2108 }
2109
2110
2115 @Override
2116 public void removeAll() throws SystemException {
2117 for (ResourceTypePermission resourceTypePermission : findAll()) {
2118 remove(resourceTypePermission);
2119 }
2120 }
2121
2122
2128 @Override
2129 public int countAll() throws SystemException {
2130 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2131 FINDER_ARGS_EMPTY, this);
2132
2133 if (count == null) {
2134 Session session = null;
2135
2136 try {
2137 session = openSession();
2138
2139 Query q = session.createQuery(_SQL_COUNT_RESOURCETYPEPERMISSION);
2140
2141 count = (Long)q.uniqueResult();
2142
2143 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2144 FINDER_ARGS_EMPTY, count);
2145 }
2146 catch (Exception e) {
2147 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2148 FINDER_ARGS_EMPTY);
2149
2150 throw processException(e);
2151 }
2152 finally {
2153 closeSession(session);
2154 }
2155 }
2156
2157 return count.intValue();
2158 }
2159
2160
2163 public void afterPropertiesSet() {
2164 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2165 com.liferay.portal.util.PropsUtil.get(
2166 "value.object.listener.com.liferay.portal.model.ResourceTypePermission")));
2167
2168 if (listenerClassNames.length > 0) {
2169 try {
2170 List<ModelListener<ResourceTypePermission>> listenersList = new ArrayList<ModelListener<ResourceTypePermission>>();
2171
2172 for (String listenerClassName : listenerClassNames) {
2173 listenersList.add((ModelListener<ResourceTypePermission>)InstanceFactory.newInstance(
2174 getClassLoader(), listenerClassName));
2175 }
2176
2177 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2178 }
2179 catch (Exception e) {
2180 _log.error(e);
2181 }
2182 }
2183 }
2184
2185 public void destroy() {
2186 EntityCacheUtil.removeCache(ResourceTypePermissionImpl.class.getName());
2187 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2188 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2189 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2190 }
2191
2192 private static final String _SQL_SELECT_RESOURCETYPEPERMISSION = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission";
2193 private static final String _SQL_SELECT_RESOURCETYPEPERMISSION_WHERE = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission WHERE ";
2194 private static final String _SQL_COUNT_RESOURCETYPEPERMISSION = "SELECT COUNT(resourceTypePermission) FROM ResourceTypePermission resourceTypePermission";
2195 private static final String _SQL_COUNT_RESOURCETYPEPERMISSION_WHERE = "SELECT COUNT(resourceTypePermission) FROM ResourceTypePermission resourceTypePermission WHERE ";
2196 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceTypePermission.";
2197 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceTypePermission exists with the primary key ";
2198 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceTypePermission exists with the key {";
2199 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2200 private static Log _log = LogFactoryUtil.getLog(ResourceTypePermissionPersistenceImpl.class);
2201 private static ResourceTypePermission _nullResourceTypePermission = new ResourceTypePermissionImpl() {
2202 @Override
2203 public Object clone() {
2204 return this;
2205 }
2206
2207 @Override
2208 public CacheModel<ResourceTypePermission> toCacheModel() {
2209 return _nullResourceTypePermissionCacheModel;
2210 }
2211 };
2212
2213 private static CacheModel<ResourceTypePermission> _nullResourceTypePermissionCacheModel =
2214 new CacheModel<ResourceTypePermission>() {
2215 @Override
2216 public ResourceTypePermission toEntityModel() {
2217 return _nullResourceTypePermission;
2218 }
2219 };
2220 }