001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchResourceActionException;
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.ResourceAction;
036 import com.liferay.portal.model.impl.ResourceActionImpl;
037 import com.liferay.portal.model.impl.ResourceActionModelImpl;
038 import com.liferay.portal.service.persistence.ResourceActionPersistence;
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 ResourceActionPersistenceImpl extends BasePersistenceImpl<ResourceAction>
064 implements ResourceActionPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.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(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
076 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
077 ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078 "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
080 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
081 ResourceActionImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
084 ResourceActionModelImpl.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_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
087 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
088 ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
089 "findByName",
090 new String[] {
091 String.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_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
097 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
098 ResourceActionImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
100 new String[] { String.class.getName() },
101 ResourceActionModelImpl.NAME_COLUMN_BITMASK |
102 ResourceActionModelImpl.BITWISEVALUE_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
104 ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
106 new String[] { String.class.getName() });
107
108
114 @Override
115 public List<ResourceAction> findByName(String name) {
116 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
117 }
118
119
131 @Override
132 public List<ResourceAction> findByName(String name, int start, int end) {
133 return findByName(name, start, end, null);
134 }
135
136
149 @Override
150 public List<ResourceAction> findByName(String name, int start, int end,
151 OrderByComparator<ResourceAction> orderByComparator) {
152 boolean pagination = true;
153 FinderPath finderPath = null;
154 Object[] finderArgs = null;
155
156 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
157 (orderByComparator == null)) {
158 pagination = false;
159 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
160 finderArgs = new Object[] { name };
161 }
162 else {
163 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
164 finderArgs = new Object[] { name, start, end, orderByComparator };
165 }
166
167 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(finderPath,
168 finderArgs, this);
169
170 if ((list != null) && !list.isEmpty()) {
171 for (ResourceAction resourceAction : list) {
172 if (!Validator.equals(name, resourceAction.getName())) {
173 list = null;
174
175 break;
176 }
177 }
178 }
179
180 if (list == null) {
181 StringBundler query = null;
182
183 if (orderByComparator != null) {
184 query = new StringBundler(3 +
185 (orderByComparator.getOrderByFields().length * 3));
186 }
187 else {
188 query = new StringBundler(3);
189 }
190
191 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
192
193 boolean bindName = false;
194
195 if (name == null) {
196 query.append(_FINDER_COLUMN_NAME_NAME_1);
197 }
198 else if (name.equals(StringPool.BLANK)) {
199 query.append(_FINDER_COLUMN_NAME_NAME_3);
200 }
201 else {
202 bindName = true;
203
204 query.append(_FINDER_COLUMN_NAME_NAME_2);
205 }
206
207 if (orderByComparator != null) {
208 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209 orderByComparator);
210 }
211 else
212 if (pagination) {
213 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
214 }
215
216 String sql = query.toString();
217
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 Query q = session.createQuery(sql);
224
225 QueryPos qPos = QueryPos.getInstance(q);
226
227 if (bindName) {
228 qPos.add(name);
229 }
230
231 if (!pagination) {
232 list = (List<ResourceAction>)QueryUtil.list(q,
233 getDialect(), start, end, false);
234
235 Collections.sort(list);
236
237 list = Collections.unmodifiableList(list);
238 }
239 else {
240 list = (List<ResourceAction>)QueryUtil.list(q,
241 getDialect(), start, end);
242 }
243
244 cacheResult(list);
245
246 FinderCacheUtil.putResult(finderPath, finderArgs, list);
247 }
248 catch (Exception e) {
249 FinderCacheUtil.removeResult(finderPath, finderArgs);
250
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 return list;
259 }
260
261
269 @Override
270 public ResourceAction findByName_First(String name,
271 OrderByComparator<ResourceAction> orderByComparator)
272 throws NoSuchResourceActionException {
273 ResourceAction resourceAction = fetchByName_First(name,
274 orderByComparator);
275
276 if (resourceAction != null) {
277 return resourceAction;
278 }
279
280 StringBundler msg = new StringBundler(4);
281
282 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283
284 msg.append("name=");
285 msg.append(name);
286
287 msg.append(StringPool.CLOSE_CURLY_BRACE);
288
289 throw new NoSuchResourceActionException(msg.toString());
290 }
291
292
299 @Override
300 public ResourceAction fetchByName_First(String name,
301 OrderByComparator<ResourceAction> orderByComparator) {
302 List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
303
304 if (!list.isEmpty()) {
305 return list.get(0);
306 }
307
308 return null;
309 }
310
311
319 @Override
320 public ResourceAction findByName_Last(String name,
321 OrderByComparator<ResourceAction> orderByComparator)
322 throws NoSuchResourceActionException {
323 ResourceAction resourceAction = fetchByName_Last(name, orderByComparator);
324
325 if (resourceAction != null) {
326 return resourceAction;
327 }
328
329 StringBundler msg = new StringBundler(4);
330
331 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
332
333 msg.append("name=");
334 msg.append(name);
335
336 msg.append(StringPool.CLOSE_CURLY_BRACE);
337
338 throw new NoSuchResourceActionException(msg.toString());
339 }
340
341
348 @Override
349 public ResourceAction fetchByName_Last(String name,
350 OrderByComparator<ResourceAction> orderByComparator) {
351 int count = countByName(name);
352
353 if (count == 0) {
354 return null;
355 }
356
357 List<ResourceAction> list = findByName(name, count - 1, count,
358 orderByComparator);
359
360 if (!list.isEmpty()) {
361 return list.get(0);
362 }
363
364 return null;
365 }
366
367
376 @Override
377 public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
378 String name, OrderByComparator<ResourceAction> orderByComparator)
379 throws NoSuchResourceActionException {
380 ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
381
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 ResourceAction[] array = new ResourceActionImpl[3];
388
389 array[0] = getByName_PrevAndNext(session, resourceAction, name,
390 orderByComparator, true);
391
392 array[1] = resourceAction;
393
394 array[2] = getByName_PrevAndNext(session, resourceAction, name,
395 orderByComparator, false);
396
397 return array;
398 }
399 catch (Exception e) {
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 protected ResourceAction getByName_PrevAndNext(Session session,
408 ResourceAction resourceAction, String name,
409 OrderByComparator<ResourceAction> orderByComparator, boolean previous) {
410 StringBundler query = null;
411
412 if (orderByComparator != null) {
413 query = new StringBundler(6 +
414 (orderByComparator.getOrderByFields().length * 6));
415 }
416 else {
417 query = new StringBundler(3);
418 }
419
420 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
421
422 boolean bindName = false;
423
424 if (name == null) {
425 query.append(_FINDER_COLUMN_NAME_NAME_1);
426 }
427 else if (name.equals(StringPool.BLANK)) {
428 query.append(_FINDER_COLUMN_NAME_NAME_3);
429 }
430 else {
431 bindName = true;
432
433 query.append(_FINDER_COLUMN_NAME_NAME_2);
434 }
435
436 if (orderByComparator != null) {
437 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438
439 if (orderByConditionFields.length > 0) {
440 query.append(WHERE_AND);
441 }
442
443 for (int i = 0; i < orderByConditionFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByConditionFields[i]);
446
447 if ((i + 1) < orderByConditionFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(WHERE_GREATER_THAN_HAS_NEXT);
450 }
451 else {
452 query.append(WHERE_LESSER_THAN_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN);
461 }
462 }
463 }
464
465 query.append(ORDER_BY_CLAUSE);
466
467 String[] orderByFields = orderByComparator.getOrderByFields();
468
469 for (int i = 0; i < orderByFields.length; i++) {
470 query.append(_ORDER_BY_ENTITY_ALIAS);
471 query.append(orderByFields[i]);
472
473 if ((i + 1) < orderByFields.length) {
474 if (orderByComparator.isAscending() ^ previous) {
475 query.append(ORDER_BY_ASC_HAS_NEXT);
476 }
477 else {
478 query.append(ORDER_BY_DESC_HAS_NEXT);
479 }
480 }
481 else {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC);
484 }
485 else {
486 query.append(ORDER_BY_DESC);
487 }
488 }
489 }
490 }
491 else {
492 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
493 }
494
495 String sql = query.toString();
496
497 Query q = session.createQuery(sql);
498
499 q.setFirstResult(0);
500 q.setMaxResults(2);
501
502 QueryPos qPos = QueryPos.getInstance(q);
503
504 if (bindName) {
505 qPos.add(name);
506 }
507
508 if (orderByComparator != null) {
509 Object[] values = orderByComparator.getOrderByConditionValues(resourceAction);
510
511 for (Object value : values) {
512 qPos.add(value);
513 }
514 }
515
516 List<ResourceAction> list = q.list();
517
518 if (list.size() == 2) {
519 return list.get(1);
520 }
521 else {
522 return null;
523 }
524 }
525
526
531 @Override
532 public void removeByName(String name) {
533 for (ResourceAction resourceAction : findByName(name,
534 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
535 remove(resourceAction);
536 }
537 }
538
539
545 @Override
546 public int countByName(String name) {
547 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
548
549 Object[] finderArgs = new Object[] { name };
550
551 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
552 this);
553
554 if (count == null) {
555 StringBundler query = new StringBundler(2);
556
557 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
558
559 boolean bindName = false;
560
561 if (name == null) {
562 query.append(_FINDER_COLUMN_NAME_NAME_1);
563 }
564 else if (name.equals(StringPool.BLANK)) {
565 query.append(_FINDER_COLUMN_NAME_NAME_3);
566 }
567 else {
568 bindName = true;
569
570 query.append(_FINDER_COLUMN_NAME_NAME_2);
571 }
572
573 String sql = query.toString();
574
575 Session session = null;
576
577 try {
578 session = openSession();
579
580 Query q = session.createQuery(sql);
581
582 QueryPos qPos = QueryPos.getInstance(q);
583
584 if (bindName) {
585 qPos.add(name);
586 }
587
588 count = (Long)q.uniqueResult();
589
590 FinderCacheUtil.putResult(finderPath, finderArgs, count);
591 }
592 catch (Exception e) {
593 FinderCacheUtil.removeResult(finderPath, finderArgs);
594
595 throw processException(e);
596 }
597 finally {
598 closeSession(session);
599 }
600 }
601
602 return count.intValue();
603 }
604
605 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
606 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
607 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = '')";
608 public static final FinderPath FINDER_PATH_FETCH_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
609 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
610 ResourceActionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_A",
611 new String[] { String.class.getName(), String.class.getName() },
612 ResourceActionModelImpl.NAME_COLUMN_BITMASK |
613 ResourceActionModelImpl.ACTIONID_COLUMN_BITMASK);
614 public static final FinderPath FINDER_PATH_COUNT_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
615 ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
616 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_A",
617 new String[] { String.class.getName(), String.class.getName() });
618
619
627 @Override
628 public ResourceAction findByN_A(String name, String actionId)
629 throws NoSuchResourceActionException {
630 ResourceAction resourceAction = fetchByN_A(name, actionId);
631
632 if (resourceAction == null) {
633 StringBundler msg = new StringBundler(6);
634
635 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
636
637 msg.append("name=");
638 msg.append(name);
639
640 msg.append(", actionId=");
641 msg.append(actionId);
642
643 msg.append(StringPool.CLOSE_CURLY_BRACE);
644
645 if (_log.isWarnEnabled()) {
646 _log.warn(msg.toString());
647 }
648
649 throw new NoSuchResourceActionException(msg.toString());
650 }
651
652 return resourceAction;
653 }
654
655
662 @Override
663 public ResourceAction fetchByN_A(String name, String actionId) {
664 return fetchByN_A(name, actionId, true);
665 }
666
667
675 @Override
676 public ResourceAction fetchByN_A(String name, String actionId,
677 boolean retrieveFromCache) {
678 Object[] finderArgs = new Object[] { name, actionId };
679
680 Object result = null;
681
682 if (retrieveFromCache) {
683 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
684 finderArgs, this);
685 }
686
687 if (result instanceof ResourceAction) {
688 ResourceAction resourceAction = (ResourceAction)result;
689
690 if (!Validator.equals(name, resourceAction.getName()) ||
691 !Validator.equals(actionId, resourceAction.getActionId())) {
692 result = null;
693 }
694 }
695
696 if (result == null) {
697 StringBundler query = new StringBundler(4);
698
699 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
700
701 boolean bindName = false;
702
703 if (name == null) {
704 query.append(_FINDER_COLUMN_N_A_NAME_1);
705 }
706 else if (name.equals(StringPool.BLANK)) {
707 query.append(_FINDER_COLUMN_N_A_NAME_3);
708 }
709 else {
710 bindName = true;
711
712 query.append(_FINDER_COLUMN_N_A_NAME_2);
713 }
714
715 boolean bindActionId = false;
716
717 if (actionId == null) {
718 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
719 }
720 else if (actionId.equals(StringPool.BLANK)) {
721 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
722 }
723 else {
724 bindActionId = true;
725
726 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
727 }
728
729 String sql = query.toString();
730
731 Session session = null;
732
733 try {
734 session = openSession();
735
736 Query q = session.createQuery(sql);
737
738 QueryPos qPos = QueryPos.getInstance(q);
739
740 if (bindName) {
741 qPos.add(name);
742 }
743
744 if (bindActionId) {
745 qPos.add(actionId);
746 }
747
748 List<ResourceAction> list = q.list();
749
750 if (list.isEmpty()) {
751 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
752 finderArgs, list);
753 }
754 else {
755 ResourceAction resourceAction = list.get(0);
756
757 result = resourceAction;
758
759 cacheResult(resourceAction);
760
761 if ((resourceAction.getName() == null) ||
762 !resourceAction.getName().equals(name) ||
763 (resourceAction.getActionId() == null) ||
764 !resourceAction.getActionId().equals(actionId)) {
765 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
766 finderArgs, resourceAction);
767 }
768 }
769 }
770 catch (Exception e) {
771 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
772 finderArgs);
773
774 throw processException(e);
775 }
776 finally {
777 closeSession(session);
778 }
779 }
780
781 if (result instanceof List<?>) {
782 return null;
783 }
784 else {
785 return (ResourceAction)result;
786 }
787 }
788
789
796 @Override
797 public ResourceAction removeByN_A(String name, String actionId)
798 throws NoSuchResourceActionException {
799 ResourceAction resourceAction = findByN_A(name, actionId);
800
801 return remove(resourceAction);
802 }
803
804
811 @Override
812 public int countByN_A(String name, String actionId) {
813 FinderPath finderPath = FINDER_PATH_COUNT_BY_N_A;
814
815 Object[] finderArgs = new Object[] { name, actionId };
816
817 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
818 this);
819
820 if (count == null) {
821 StringBundler query = new StringBundler(3);
822
823 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
824
825 boolean bindName = false;
826
827 if (name == null) {
828 query.append(_FINDER_COLUMN_N_A_NAME_1);
829 }
830 else if (name.equals(StringPool.BLANK)) {
831 query.append(_FINDER_COLUMN_N_A_NAME_3);
832 }
833 else {
834 bindName = true;
835
836 query.append(_FINDER_COLUMN_N_A_NAME_2);
837 }
838
839 boolean bindActionId = false;
840
841 if (actionId == null) {
842 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
843 }
844 else if (actionId.equals(StringPool.BLANK)) {
845 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
846 }
847 else {
848 bindActionId = true;
849
850 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
851 }
852
853 String sql = query.toString();
854
855 Session session = null;
856
857 try {
858 session = openSession();
859
860 Query q = session.createQuery(sql);
861
862 QueryPos qPos = QueryPos.getInstance(q);
863
864 if (bindName) {
865 qPos.add(name);
866 }
867
868 if (bindActionId) {
869 qPos.add(actionId);
870 }
871
872 count = (Long)q.uniqueResult();
873
874 FinderCacheUtil.putResult(finderPath, finderArgs, count);
875 }
876 catch (Exception e) {
877 FinderCacheUtil.removeResult(finderPath, finderArgs);
878
879 throw processException(e);
880 }
881 finally {
882 closeSession(session);
883 }
884 }
885
886 return count.intValue();
887 }
888
889 private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
890 private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
891 private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = '') AND ";
892 private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
893 private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
894 private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = '')";
895
896 public ResourceActionPersistenceImpl() {
897 setModelClass(ResourceAction.class);
898 }
899
900
905 @Override
906 public void cacheResult(ResourceAction resourceAction) {
907 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
908 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
909 resourceAction);
910
911 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
912 new Object[] { resourceAction.getName(), resourceAction.getActionId() },
913 resourceAction);
914
915 resourceAction.resetOriginalValues();
916 }
917
918
923 @Override
924 public void cacheResult(List<ResourceAction> resourceActions) {
925 for (ResourceAction resourceAction : resourceActions) {
926 if (EntityCacheUtil.getResult(
927 ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
928 ResourceActionImpl.class, resourceAction.getPrimaryKey()) == null) {
929 cacheResult(resourceAction);
930 }
931 else {
932 resourceAction.resetOriginalValues();
933 }
934 }
935 }
936
937
944 @Override
945 public void clearCache() {
946 EntityCacheUtil.clearCache(ResourceActionImpl.class);
947
948 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
949 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
950 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
951 }
952
953
960 @Override
961 public void clearCache(ResourceAction resourceAction) {
962 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
963 ResourceActionImpl.class, resourceAction.getPrimaryKey());
964
965 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
966 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
967
968 clearUniqueFindersCache(resourceAction);
969 }
970
971 @Override
972 public void clearCache(List<ResourceAction> resourceActions) {
973 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
974 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
975
976 for (ResourceAction resourceAction : resourceActions) {
977 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
978 ResourceActionImpl.class, resourceAction.getPrimaryKey());
979
980 clearUniqueFindersCache(resourceAction);
981 }
982 }
983
984 protected void cacheUniqueFindersCache(ResourceAction resourceAction) {
985 if (resourceAction.isNew()) {
986 Object[] args = new Object[] {
987 resourceAction.getName(), resourceAction.getActionId()
988 };
989
990 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, args,
991 Long.valueOf(1));
992 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A, args,
993 resourceAction);
994 }
995 else {
996 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
997
998 if ((resourceActionModelImpl.getColumnBitmask() &
999 FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
1000 Object[] args = new Object[] {
1001 resourceAction.getName(), resourceAction.getActionId()
1002 };
1003
1004 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, args,
1005 Long.valueOf(1));
1006 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A, args,
1007 resourceAction);
1008 }
1009 }
1010 }
1011
1012 protected void clearUniqueFindersCache(ResourceAction resourceAction) {
1013 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
1014
1015 Object[] args = new Object[] {
1016 resourceAction.getName(), resourceAction.getActionId()
1017 };
1018
1019 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
1020 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
1021
1022 if ((resourceActionModelImpl.getColumnBitmask() &
1023 FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
1024 args = new Object[] {
1025 resourceActionModelImpl.getOriginalName(),
1026 resourceActionModelImpl.getOriginalActionId()
1027 };
1028
1029 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
1030 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
1031 }
1032 }
1033
1034
1040 @Override
1041 public ResourceAction create(long resourceActionId) {
1042 ResourceAction resourceAction = new ResourceActionImpl();
1043
1044 resourceAction.setNew(true);
1045 resourceAction.setPrimaryKey(resourceActionId);
1046
1047 return resourceAction;
1048 }
1049
1050
1057 @Override
1058 public ResourceAction remove(long resourceActionId)
1059 throws NoSuchResourceActionException {
1060 return remove((Serializable)resourceActionId);
1061 }
1062
1063
1070 @Override
1071 public ResourceAction remove(Serializable primaryKey)
1072 throws NoSuchResourceActionException {
1073 Session session = null;
1074
1075 try {
1076 session = openSession();
1077
1078 ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1079 primaryKey);
1080
1081 if (resourceAction == null) {
1082 if (_log.isWarnEnabled()) {
1083 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1084 }
1085
1086 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1087 primaryKey);
1088 }
1089
1090 return remove(resourceAction);
1091 }
1092 catch (NoSuchResourceActionException nsee) {
1093 throw nsee;
1094 }
1095 catch (Exception e) {
1096 throw processException(e);
1097 }
1098 finally {
1099 closeSession(session);
1100 }
1101 }
1102
1103 @Override
1104 protected ResourceAction removeImpl(ResourceAction resourceAction) {
1105 resourceAction = toUnwrappedModel(resourceAction);
1106
1107 Session session = null;
1108
1109 try {
1110 session = openSession();
1111
1112 if (!session.contains(resourceAction)) {
1113 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1114 resourceAction.getPrimaryKeyObj());
1115 }
1116
1117 if (resourceAction != null) {
1118 session.delete(resourceAction);
1119 }
1120 }
1121 catch (Exception e) {
1122 throw processException(e);
1123 }
1124 finally {
1125 closeSession(session);
1126 }
1127
1128 if (resourceAction != null) {
1129 clearCache(resourceAction);
1130 }
1131
1132 return resourceAction;
1133 }
1134
1135 @Override
1136 public ResourceAction updateImpl(ResourceAction resourceAction) {
1137 resourceAction = toUnwrappedModel(resourceAction);
1138
1139 boolean isNew = resourceAction.isNew();
1140
1141 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
1142
1143 Session session = null;
1144
1145 try {
1146 session = openSession();
1147
1148 if (resourceAction.isNew()) {
1149 session.save(resourceAction);
1150
1151 resourceAction.setNew(false);
1152 }
1153 else {
1154 session.merge(resourceAction);
1155 }
1156 }
1157 catch (Exception e) {
1158 throw processException(e);
1159 }
1160 finally {
1161 closeSession(session);
1162 }
1163
1164 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1165
1166 if (isNew || !ResourceActionModelImpl.COLUMN_BITMASK_ENABLED) {
1167 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1168 }
1169
1170 else {
1171 if ((resourceActionModelImpl.getColumnBitmask() &
1172 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
1173 Object[] args = new Object[] {
1174 resourceActionModelImpl.getOriginalName()
1175 };
1176
1177 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1178 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
1179 args);
1180
1181 args = new Object[] { resourceActionModelImpl.getName() };
1182
1183 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1184 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
1185 args);
1186 }
1187 }
1188
1189 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1190 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
1191 resourceAction, false);
1192
1193 clearUniqueFindersCache(resourceAction);
1194 cacheUniqueFindersCache(resourceAction);
1195
1196 resourceAction.resetOriginalValues();
1197
1198 return resourceAction;
1199 }
1200
1201 protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
1202 if (resourceAction instanceof ResourceActionImpl) {
1203 return resourceAction;
1204 }
1205
1206 ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
1207
1208 resourceActionImpl.setNew(resourceAction.isNew());
1209 resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
1210
1211 resourceActionImpl.setMvccVersion(resourceAction.getMvccVersion());
1212 resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
1213 resourceActionImpl.setName(resourceAction.getName());
1214 resourceActionImpl.setActionId(resourceAction.getActionId());
1215 resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
1216
1217 return resourceActionImpl;
1218 }
1219
1220
1227 @Override
1228 public ResourceAction findByPrimaryKey(Serializable primaryKey)
1229 throws NoSuchResourceActionException {
1230 ResourceAction resourceAction = fetchByPrimaryKey(primaryKey);
1231
1232 if (resourceAction == null) {
1233 if (_log.isWarnEnabled()) {
1234 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1235 }
1236
1237 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1238 primaryKey);
1239 }
1240
1241 return resourceAction;
1242 }
1243
1244
1251 @Override
1252 public ResourceAction findByPrimaryKey(long resourceActionId)
1253 throws NoSuchResourceActionException {
1254 return findByPrimaryKey((Serializable)resourceActionId);
1255 }
1256
1257
1263 @Override
1264 public ResourceAction fetchByPrimaryKey(Serializable primaryKey) {
1265 ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1266 ResourceActionImpl.class, primaryKey);
1267
1268 if (resourceAction == _nullResourceAction) {
1269 return null;
1270 }
1271
1272 if (resourceAction == null) {
1273 Session session = null;
1274
1275 try {
1276 session = openSession();
1277
1278 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1279 primaryKey);
1280
1281 if (resourceAction != null) {
1282 cacheResult(resourceAction);
1283 }
1284 else {
1285 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1286 ResourceActionImpl.class, primaryKey,
1287 _nullResourceAction);
1288 }
1289 }
1290 catch (Exception e) {
1291 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1292 ResourceActionImpl.class, primaryKey);
1293
1294 throw processException(e);
1295 }
1296 finally {
1297 closeSession(session);
1298 }
1299 }
1300
1301 return resourceAction;
1302 }
1303
1304
1310 @Override
1311 public ResourceAction fetchByPrimaryKey(long resourceActionId) {
1312 return fetchByPrimaryKey((Serializable)resourceActionId);
1313 }
1314
1315 @Override
1316 public Map<Serializable, ResourceAction> fetchByPrimaryKeys(
1317 Set<Serializable> primaryKeys) {
1318 if (primaryKeys.isEmpty()) {
1319 return Collections.emptyMap();
1320 }
1321
1322 Map<Serializable, ResourceAction> map = new HashMap<Serializable, ResourceAction>();
1323
1324 if (primaryKeys.size() == 1) {
1325 Iterator<Serializable> iterator = primaryKeys.iterator();
1326
1327 Serializable primaryKey = iterator.next();
1328
1329 ResourceAction resourceAction = fetchByPrimaryKey(primaryKey);
1330
1331 if (resourceAction != null) {
1332 map.put(primaryKey, resourceAction);
1333 }
1334
1335 return map;
1336 }
1337
1338 Set<Serializable> uncachedPrimaryKeys = null;
1339
1340 for (Serializable primaryKey : primaryKeys) {
1341 ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1342 ResourceActionImpl.class, primaryKey);
1343
1344 if (resourceAction == null) {
1345 if (uncachedPrimaryKeys == null) {
1346 uncachedPrimaryKeys = new HashSet<Serializable>();
1347 }
1348
1349 uncachedPrimaryKeys.add(primaryKey);
1350 }
1351 else {
1352 map.put(primaryKey, resourceAction);
1353 }
1354 }
1355
1356 if (uncachedPrimaryKeys == null) {
1357 return map;
1358 }
1359
1360 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1361 1);
1362
1363 query.append(_SQL_SELECT_RESOURCEACTION_WHERE_PKS_IN);
1364
1365 for (Serializable primaryKey : uncachedPrimaryKeys) {
1366 query.append(String.valueOf(primaryKey));
1367
1368 query.append(StringPool.COMMA);
1369 }
1370
1371 query.setIndex(query.index() - 1);
1372
1373 query.append(StringPool.CLOSE_PARENTHESIS);
1374
1375 String sql = query.toString();
1376
1377 Session session = null;
1378
1379 try {
1380 session = openSession();
1381
1382 Query q = session.createQuery(sql);
1383
1384 for (ResourceAction resourceAction : (List<ResourceAction>)q.list()) {
1385 map.put(resourceAction.getPrimaryKeyObj(), resourceAction);
1386
1387 cacheResult(resourceAction);
1388
1389 uncachedPrimaryKeys.remove(resourceAction.getPrimaryKeyObj());
1390 }
1391
1392 for (Serializable primaryKey : uncachedPrimaryKeys) {
1393 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1394 ResourceActionImpl.class, primaryKey, _nullResourceAction);
1395 }
1396 }
1397 catch (Exception e) {
1398 throw processException(e);
1399 }
1400 finally {
1401 closeSession(session);
1402 }
1403
1404 return map;
1405 }
1406
1407
1412 @Override
1413 public List<ResourceAction> findAll() {
1414 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1415 }
1416
1417
1428 @Override
1429 public List<ResourceAction> findAll(int start, int end) {
1430 return findAll(start, end, null);
1431 }
1432
1433
1445 @Override
1446 public List<ResourceAction> findAll(int start, int end,
1447 OrderByComparator<ResourceAction> orderByComparator) {
1448 boolean pagination = true;
1449 FinderPath finderPath = null;
1450 Object[] finderArgs = null;
1451
1452 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1453 (orderByComparator == null)) {
1454 pagination = false;
1455 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1456 finderArgs = FINDER_ARGS_EMPTY;
1457 }
1458 else {
1459 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1460 finderArgs = new Object[] { start, end, orderByComparator };
1461 }
1462
1463 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(finderPath,
1464 finderArgs, this);
1465
1466 if (list == null) {
1467 StringBundler query = null;
1468 String sql = null;
1469
1470 if (orderByComparator != null) {
1471 query = new StringBundler(2 +
1472 (orderByComparator.getOrderByFields().length * 3));
1473
1474 query.append(_SQL_SELECT_RESOURCEACTION);
1475
1476 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1477 orderByComparator);
1478
1479 sql = query.toString();
1480 }
1481 else {
1482 sql = _SQL_SELECT_RESOURCEACTION;
1483
1484 if (pagination) {
1485 sql = sql.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
1486 }
1487 }
1488
1489 Session session = null;
1490
1491 try {
1492 session = openSession();
1493
1494 Query q = session.createQuery(sql);
1495
1496 if (!pagination) {
1497 list = (List<ResourceAction>)QueryUtil.list(q,
1498 getDialect(), start, end, false);
1499
1500 Collections.sort(list);
1501
1502 list = Collections.unmodifiableList(list);
1503 }
1504 else {
1505 list = (List<ResourceAction>)QueryUtil.list(q,
1506 getDialect(), start, end);
1507 }
1508
1509 cacheResult(list);
1510
1511 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1512 }
1513 catch (Exception e) {
1514 FinderCacheUtil.removeResult(finderPath, finderArgs);
1515
1516 throw processException(e);
1517 }
1518 finally {
1519 closeSession(session);
1520 }
1521 }
1522
1523 return list;
1524 }
1525
1526
1530 @Override
1531 public void removeAll() {
1532 for (ResourceAction resourceAction : findAll()) {
1533 remove(resourceAction);
1534 }
1535 }
1536
1537
1542 @Override
1543 public int countAll() {
1544 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1545 FINDER_ARGS_EMPTY, this);
1546
1547 if (count == null) {
1548 Session session = null;
1549
1550 try {
1551 session = openSession();
1552
1553 Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1554
1555 count = (Long)q.uniqueResult();
1556
1557 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1558 FINDER_ARGS_EMPTY, count);
1559 }
1560 catch (Exception e) {
1561 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1562 FINDER_ARGS_EMPTY);
1563
1564 throw processException(e);
1565 }
1566 finally {
1567 closeSession(session);
1568 }
1569 }
1570
1571 return count.intValue();
1572 }
1573
1574
1577 public void afterPropertiesSet() {
1578 }
1579
1580 public void destroy() {
1581 EntityCacheUtil.removeCache(ResourceActionImpl.class.getName());
1582 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1583 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1584 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1585 }
1586
1587 private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1588 private static final String _SQL_SELECT_RESOURCEACTION_WHERE_PKS_IN = "SELECT resourceAction FROM ResourceAction resourceAction WHERE resourceActionId IN (";
1589 private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1590 private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1591 private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1592 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1593 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1594 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1595 private static final Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1596 private static final ResourceAction _nullResourceAction = new ResourceActionImpl() {
1597 @Override
1598 public Object clone() {
1599 return this;
1600 }
1601
1602 @Override
1603 public CacheModel<ResourceAction> toCacheModel() {
1604 return _nullResourceActionCacheModel;
1605 }
1606 };
1607
1608 private static final CacheModel<ResourceAction> _nullResourceActionCacheModel =
1609 new NullCacheModel();
1610
1611 private static class NullCacheModel implements CacheModel<ResourceAction>,
1612 MVCCModel {
1613 @Override
1614 public long getMvccVersion() {
1615 return -1;
1616 }
1617
1618 @Override
1619 public void setMvccVersion(long mvccVersion) {
1620 }
1621
1622 @Override
1623 public ResourceAction toEntityModel() {
1624 return _nullResourceAction;
1625 }
1626 }
1627 }