001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchResourceActionException;
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.ResourceAction;
040 import com.liferay.portal.model.impl.ResourceActionImpl;
041 import com.liferay.portal.model.impl.ResourceActionModelImpl;
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 ResourceActionPersistenceImpl extends BasePersistenceImpl<ResourceAction>
063 implements ResourceActionPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.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(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
075 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
076 ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
077 "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
079 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
080 ResourceActionImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
083 ResourceActionModelImpl.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_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
086 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
087 ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
088 "findByName",
089 new String[] {
090 String.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_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
096 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
097 ResourceActionImpl.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
099 new String[] { String.class.getName() },
100 ResourceActionModelImpl.NAME_COLUMN_BITMASK |
101 ResourceActionModelImpl.BITWISEVALUE_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
103 ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
105 new String[] { String.class.getName() });
106
107
114 @Override
115 public List<ResourceAction> findByName(String name)
116 throws SystemException {
117 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
133 @Override
134 public List<ResourceAction> findByName(String name, int start, int end)
135 throws SystemException {
136 return findByName(name, start, end, null);
137 }
138
139
153 @Override
154 public List<ResourceAction> findByName(String name, int start, int end,
155 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_NAME;
164 finderArgs = new Object[] { name };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
168 finderArgs = new Object[] { name, start, end, orderByComparator };
169 }
170
171 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (ResourceAction resourceAction : list) {
176 if (!Validator.equals(name, resourceAction.getName())) {
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_RESOURCEACTION_WHERE);
196
197 boolean bindName = false;
198
199 if (name == null) {
200 query.append(_FINDER_COLUMN_NAME_NAME_1);
201 }
202 else if (name.equals(StringPool.BLANK)) {
203 query.append(_FINDER_COLUMN_NAME_NAME_3);
204 }
205 else {
206 bindName = true;
207
208 query.append(_FINDER_COLUMN_NAME_NAME_2);
209 }
210
211 if (orderByComparator != null) {
212 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
213 orderByComparator);
214 }
215 else
216 if (pagination) {
217 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
218 }
219
220 String sql = query.toString();
221
222 Session session = null;
223
224 try {
225 session = openSession();
226
227 Query q = session.createQuery(sql);
228
229 QueryPos qPos = QueryPos.getInstance(q);
230
231 if (bindName) {
232 qPos.add(name);
233 }
234
235 if (!pagination) {
236 list = (List<ResourceAction>)QueryUtil.list(q,
237 getDialect(), start, end, false);
238
239 Collections.sort(list);
240
241 list = new UnmodifiableList<ResourceAction>(list);
242 }
243 else {
244 list = (List<ResourceAction>)QueryUtil.list(q,
245 getDialect(), start, end);
246 }
247
248 cacheResult(list);
249
250 FinderCacheUtil.putResult(finderPath, finderArgs, list);
251 }
252 catch (Exception e) {
253 FinderCacheUtil.removeResult(finderPath, finderArgs);
254
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260 }
261
262 return list;
263 }
264
265
274 @Override
275 public ResourceAction findByName_First(String name,
276 OrderByComparator orderByComparator)
277 throws NoSuchResourceActionException, SystemException {
278 ResourceAction resourceAction = fetchByName_First(name,
279 orderByComparator);
280
281 if (resourceAction != null) {
282 return resourceAction;
283 }
284
285 StringBundler msg = new StringBundler(4);
286
287 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288
289 msg.append("name=");
290 msg.append(name);
291
292 msg.append(StringPool.CLOSE_CURLY_BRACE);
293
294 throw new NoSuchResourceActionException(msg.toString());
295 }
296
297
305 @Override
306 public ResourceAction fetchByName_First(String name,
307 OrderByComparator orderByComparator) throws SystemException {
308 List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
309
310 if (!list.isEmpty()) {
311 return list.get(0);
312 }
313
314 return null;
315 }
316
317
326 @Override
327 public ResourceAction findByName_Last(String name,
328 OrderByComparator orderByComparator)
329 throws NoSuchResourceActionException, SystemException {
330 ResourceAction resourceAction = fetchByName_Last(name, orderByComparator);
331
332 if (resourceAction != null) {
333 return resourceAction;
334 }
335
336 StringBundler msg = new StringBundler(4);
337
338 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
339
340 msg.append("name=");
341 msg.append(name);
342
343 msg.append(StringPool.CLOSE_CURLY_BRACE);
344
345 throw new NoSuchResourceActionException(msg.toString());
346 }
347
348
356 @Override
357 public ResourceAction fetchByName_Last(String name,
358 OrderByComparator orderByComparator) throws SystemException {
359 int count = countByName(name);
360
361 if (count == 0) {
362 return null;
363 }
364
365 List<ResourceAction> list = findByName(name, count - 1, count,
366 orderByComparator);
367
368 if (!list.isEmpty()) {
369 return list.get(0);
370 }
371
372 return null;
373 }
374
375
385 @Override
386 public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
387 String name, OrderByComparator orderByComparator)
388 throws NoSuchResourceActionException, SystemException {
389 ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
390
391 Session session = null;
392
393 try {
394 session = openSession();
395
396 ResourceAction[] array = new ResourceActionImpl[3];
397
398 array[0] = getByName_PrevAndNext(session, resourceAction, name,
399 orderByComparator, true);
400
401 array[1] = resourceAction;
402
403 array[2] = getByName_PrevAndNext(session, resourceAction, name,
404 orderByComparator, false);
405
406 return array;
407 }
408 catch (Exception e) {
409 throw processException(e);
410 }
411 finally {
412 closeSession(session);
413 }
414 }
415
416 protected ResourceAction getByName_PrevAndNext(Session session,
417 ResourceAction resourceAction, String name,
418 OrderByComparator orderByComparator, boolean previous) {
419 StringBundler query = null;
420
421 if (orderByComparator != null) {
422 query = new StringBundler(6 +
423 (orderByComparator.getOrderByFields().length * 6));
424 }
425 else {
426 query = new StringBundler(3);
427 }
428
429 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
430
431 boolean bindName = false;
432
433 if (name == null) {
434 query.append(_FINDER_COLUMN_NAME_NAME_1);
435 }
436 else if (name.equals(StringPool.BLANK)) {
437 query.append(_FINDER_COLUMN_NAME_NAME_3);
438 }
439 else {
440 bindName = true;
441
442 query.append(_FINDER_COLUMN_NAME_NAME_2);
443 }
444
445 if (orderByComparator != null) {
446 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
447
448 if (orderByConditionFields.length > 0) {
449 query.append(WHERE_AND);
450 }
451
452 for (int i = 0; i < orderByConditionFields.length; i++) {
453 query.append(_ORDER_BY_ENTITY_ALIAS);
454 query.append(orderByConditionFields[i]);
455
456 if ((i + 1) < orderByConditionFields.length) {
457 if (orderByComparator.isAscending() ^ previous) {
458 query.append(WHERE_GREATER_THAN_HAS_NEXT);
459 }
460 else {
461 query.append(WHERE_LESSER_THAN_HAS_NEXT);
462 }
463 }
464 else {
465 if (orderByComparator.isAscending() ^ previous) {
466 query.append(WHERE_GREATER_THAN);
467 }
468 else {
469 query.append(WHERE_LESSER_THAN);
470 }
471 }
472 }
473
474 query.append(ORDER_BY_CLAUSE);
475
476 String[] orderByFields = orderByComparator.getOrderByFields();
477
478 for (int i = 0; i < orderByFields.length; i++) {
479 query.append(_ORDER_BY_ENTITY_ALIAS);
480 query.append(orderByFields[i]);
481
482 if ((i + 1) < orderByFields.length) {
483 if (orderByComparator.isAscending() ^ previous) {
484 query.append(ORDER_BY_ASC_HAS_NEXT);
485 }
486 else {
487 query.append(ORDER_BY_DESC_HAS_NEXT);
488 }
489 }
490 else {
491 if (orderByComparator.isAscending() ^ previous) {
492 query.append(ORDER_BY_ASC);
493 }
494 else {
495 query.append(ORDER_BY_DESC);
496 }
497 }
498 }
499 }
500 else {
501 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
502 }
503
504 String sql = query.toString();
505
506 Query q = session.createQuery(sql);
507
508 q.setFirstResult(0);
509 q.setMaxResults(2);
510
511 QueryPos qPos = QueryPos.getInstance(q);
512
513 if (bindName) {
514 qPos.add(name);
515 }
516
517 if (orderByComparator != null) {
518 Object[] values = orderByComparator.getOrderByConditionValues(resourceAction);
519
520 for (Object value : values) {
521 qPos.add(value);
522 }
523 }
524
525 List<ResourceAction> list = q.list();
526
527 if (list.size() == 2) {
528 return list.get(1);
529 }
530 else {
531 return null;
532 }
533 }
534
535
541 @Override
542 public void removeByName(String name) throws SystemException {
543 for (ResourceAction resourceAction : findByName(name,
544 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
545 remove(resourceAction);
546 }
547 }
548
549
556 @Override
557 public int countByName(String name) throws SystemException {
558 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
559
560 Object[] finderArgs = new Object[] { name };
561
562 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
563 this);
564
565 if (count == null) {
566 StringBundler query = new StringBundler(2);
567
568 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
569
570 boolean bindName = false;
571
572 if (name == null) {
573 query.append(_FINDER_COLUMN_NAME_NAME_1);
574 }
575 else if (name.equals(StringPool.BLANK)) {
576 query.append(_FINDER_COLUMN_NAME_NAME_3);
577 }
578 else {
579 bindName = true;
580
581 query.append(_FINDER_COLUMN_NAME_NAME_2);
582 }
583
584 String sql = query.toString();
585
586 Session session = null;
587
588 try {
589 session = openSession();
590
591 Query q = session.createQuery(sql);
592
593 QueryPos qPos = QueryPos.getInstance(q);
594
595 if (bindName) {
596 qPos.add(name);
597 }
598
599 count = (Long)q.uniqueResult();
600
601 FinderCacheUtil.putResult(finderPath, finderArgs, count);
602 }
603 catch (Exception e) {
604 FinderCacheUtil.removeResult(finderPath, finderArgs);
605
606 throw processException(e);
607 }
608 finally {
609 closeSession(session);
610 }
611 }
612
613 return count.intValue();
614 }
615
616 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
617 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
618 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = '')";
619 public static final FinderPath FINDER_PATH_FETCH_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
620 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
621 ResourceActionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_A",
622 new String[] { String.class.getName(), String.class.getName() },
623 ResourceActionModelImpl.NAME_COLUMN_BITMASK |
624 ResourceActionModelImpl.ACTIONID_COLUMN_BITMASK);
625 public static final FinderPath FINDER_PATH_COUNT_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
626 ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
627 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_A",
628 new String[] { String.class.getName(), String.class.getName() });
629
630
639 @Override
640 public ResourceAction findByN_A(String name, String actionId)
641 throws NoSuchResourceActionException, SystemException {
642 ResourceAction resourceAction = fetchByN_A(name, actionId);
643
644 if (resourceAction == null) {
645 StringBundler msg = new StringBundler(6);
646
647 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
648
649 msg.append("name=");
650 msg.append(name);
651
652 msg.append(", actionId=");
653 msg.append(actionId);
654
655 msg.append(StringPool.CLOSE_CURLY_BRACE);
656
657 if (_log.isWarnEnabled()) {
658 _log.warn(msg.toString());
659 }
660
661 throw new NoSuchResourceActionException(msg.toString());
662 }
663
664 return resourceAction;
665 }
666
667
675 @Override
676 public ResourceAction fetchByN_A(String name, String actionId)
677 throws SystemException {
678 return fetchByN_A(name, actionId, true);
679 }
680
681
690 @Override
691 public ResourceAction fetchByN_A(String name, String actionId,
692 boolean retrieveFromCache) throws SystemException {
693 Object[] finderArgs = new Object[] { name, actionId };
694
695 Object result = null;
696
697 if (retrieveFromCache) {
698 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
699 finderArgs, this);
700 }
701
702 if (result instanceof ResourceAction) {
703 ResourceAction resourceAction = (ResourceAction)result;
704
705 if (!Validator.equals(name, resourceAction.getName()) ||
706 !Validator.equals(actionId, resourceAction.getActionId())) {
707 result = null;
708 }
709 }
710
711 if (result == null) {
712 StringBundler query = new StringBundler(4);
713
714 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
715
716 boolean bindName = false;
717
718 if (name == null) {
719 query.append(_FINDER_COLUMN_N_A_NAME_1);
720 }
721 else if (name.equals(StringPool.BLANK)) {
722 query.append(_FINDER_COLUMN_N_A_NAME_3);
723 }
724 else {
725 bindName = true;
726
727 query.append(_FINDER_COLUMN_N_A_NAME_2);
728 }
729
730 boolean bindActionId = false;
731
732 if (actionId == null) {
733 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
734 }
735 else if (actionId.equals(StringPool.BLANK)) {
736 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
737 }
738 else {
739 bindActionId = true;
740
741 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
742 }
743
744 String sql = query.toString();
745
746 Session session = null;
747
748 try {
749 session = openSession();
750
751 Query q = session.createQuery(sql);
752
753 QueryPos qPos = QueryPos.getInstance(q);
754
755 if (bindName) {
756 qPos.add(name);
757 }
758
759 if (bindActionId) {
760 qPos.add(actionId);
761 }
762
763 List<ResourceAction> list = q.list();
764
765 if (list.isEmpty()) {
766 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
767 finderArgs, list);
768 }
769 else {
770 ResourceAction resourceAction = list.get(0);
771
772 result = resourceAction;
773
774 cacheResult(resourceAction);
775
776 if ((resourceAction.getName() == null) ||
777 !resourceAction.getName().equals(name) ||
778 (resourceAction.getActionId() == null) ||
779 !resourceAction.getActionId().equals(actionId)) {
780 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
781 finderArgs, resourceAction);
782 }
783 }
784 }
785 catch (Exception e) {
786 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
787 finderArgs);
788
789 throw processException(e);
790 }
791 finally {
792 closeSession(session);
793 }
794 }
795
796 if (result instanceof List<?>) {
797 return null;
798 }
799 else {
800 return (ResourceAction)result;
801 }
802 }
803
804
812 @Override
813 public ResourceAction removeByN_A(String name, String actionId)
814 throws NoSuchResourceActionException, SystemException {
815 ResourceAction resourceAction = findByN_A(name, actionId);
816
817 return remove(resourceAction);
818 }
819
820
828 @Override
829 public int countByN_A(String name, String actionId)
830 throws SystemException {
831 FinderPath finderPath = FINDER_PATH_COUNT_BY_N_A;
832
833 Object[] finderArgs = new Object[] { name, actionId };
834
835 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
836 this);
837
838 if (count == null) {
839 StringBundler query = new StringBundler(3);
840
841 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
842
843 boolean bindName = false;
844
845 if (name == null) {
846 query.append(_FINDER_COLUMN_N_A_NAME_1);
847 }
848 else if (name.equals(StringPool.BLANK)) {
849 query.append(_FINDER_COLUMN_N_A_NAME_3);
850 }
851 else {
852 bindName = true;
853
854 query.append(_FINDER_COLUMN_N_A_NAME_2);
855 }
856
857 boolean bindActionId = false;
858
859 if (actionId == null) {
860 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
861 }
862 else if (actionId.equals(StringPool.BLANK)) {
863 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
864 }
865 else {
866 bindActionId = true;
867
868 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
869 }
870
871 String sql = query.toString();
872
873 Session session = null;
874
875 try {
876 session = openSession();
877
878 Query q = session.createQuery(sql);
879
880 QueryPos qPos = QueryPos.getInstance(q);
881
882 if (bindName) {
883 qPos.add(name);
884 }
885
886 if (bindActionId) {
887 qPos.add(actionId);
888 }
889
890 count = (Long)q.uniqueResult();
891
892 FinderCacheUtil.putResult(finderPath, finderArgs, count);
893 }
894 catch (Exception e) {
895 FinderCacheUtil.removeResult(finderPath, finderArgs);
896
897 throw processException(e);
898 }
899 finally {
900 closeSession(session);
901 }
902 }
903
904 return count.intValue();
905 }
906
907 private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
908 private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
909 private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = '') AND ";
910 private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
911 private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
912 private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = '')";
913
914
919 @Override
920 public void cacheResult(ResourceAction resourceAction) {
921 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
922 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
923 resourceAction);
924
925 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
926 new Object[] { resourceAction.getName(), resourceAction.getActionId() },
927 resourceAction);
928
929 resourceAction.resetOriginalValues();
930 }
931
932
937 @Override
938 public void cacheResult(List<ResourceAction> resourceActions) {
939 for (ResourceAction resourceAction : resourceActions) {
940 if (EntityCacheUtil.getResult(
941 ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
942 ResourceActionImpl.class, resourceAction.getPrimaryKey()) == null) {
943 cacheResult(resourceAction);
944 }
945 else {
946 resourceAction.resetOriginalValues();
947 }
948 }
949 }
950
951
958 @Override
959 public void clearCache() {
960 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
961 CacheRegistryUtil.clear(ResourceActionImpl.class.getName());
962 }
963
964 EntityCacheUtil.clearCache(ResourceActionImpl.class.getName());
965
966 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
967 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
968 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
969 }
970
971
978 @Override
979 public void clearCache(ResourceAction resourceAction) {
980 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
981 ResourceActionImpl.class, resourceAction.getPrimaryKey());
982
983 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
984 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
985
986 clearUniqueFindersCache(resourceAction);
987 }
988
989 @Override
990 public void clearCache(List<ResourceAction> resourceActions) {
991 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
992 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
993
994 for (ResourceAction resourceAction : resourceActions) {
995 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
996 ResourceActionImpl.class, resourceAction.getPrimaryKey());
997
998 clearUniqueFindersCache(resourceAction);
999 }
1000 }
1001
1002 protected void cacheUniqueFindersCache(ResourceAction resourceAction) {
1003 if (resourceAction.isNew()) {
1004 Object[] args = new Object[] {
1005 resourceAction.getName(), resourceAction.getActionId()
1006 };
1007
1008 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, args,
1009 Long.valueOf(1));
1010 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A, args,
1011 resourceAction);
1012 }
1013 else {
1014 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
1015
1016 if ((resourceActionModelImpl.getColumnBitmask() &
1017 FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
1018 Object[] args = new Object[] {
1019 resourceAction.getName(), resourceAction.getActionId()
1020 };
1021
1022 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, args,
1023 Long.valueOf(1));
1024 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A, args,
1025 resourceAction);
1026 }
1027 }
1028 }
1029
1030 protected void clearUniqueFindersCache(ResourceAction resourceAction) {
1031 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
1032
1033 Object[] args = new Object[] {
1034 resourceAction.getName(), resourceAction.getActionId()
1035 };
1036
1037 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
1038 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
1039
1040 if ((resourceActionModelImpl.getColumnBitmask() &
1041 FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
1042 args = new Object[] {
1043 resourceActionModelImpl.getOriginalName(),
1044 resourceActionModelImpl.getOriginalActionId()
1045 };
1046
1047 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
1048 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
1049 }
1050 }
1051
1052
1058 @Override
1059 public ResourceAction create(long resourceActionId) {
1060 ResourceAction resourceAction = new ResourceActionImpl();
1061
1062 resourceAction.setNew(true);
1063 resourceAction.setPrimaryKey(resourceActionId);
1064
1065 return resourceAction;
1066 }
1067
1068
1076 @Override
1077 public ResourceAction remove(long resourceActionId)
1078 throws NoSuchResourceActionException, SystemException {
1079 return remove((Serializable)resourceActionId);
1080 }
1081
1082
1090 @Override
1091 public ResourceAction remove(Serializable primaryKey)
1092 throws NoSuchResourceActionException, SystemException {
1093 Session session = null;
1094
1095 try {
1096 session = openSession();
1097
1098 ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1099 primaryKey);
1100
1101 if (resourceAction == null) {
1102 if (_log.isWarnEnabled()) {
1103 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1104 }
1105
1106 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1107 primaryKey);
1108 }
1109
1110 return remove(resourceAction);
1111 }
1112 catch (NoSuchResourceActionException nsee) {
1113 throw nsee;
1114 }
1115 catch (Exception e) {
1116 throw processException(e);
1117 }
1118 finally {
1119 closeSession(session);
1120 }
1121 }
1122
1123 @Override
1124 protected ResourceAction removeImpl(ResourceAction resourceAction)
1125 throws SystemException {
1126 resourceAction = toUnwrappedModel(resourceAction);
1127
1128 Session session = null;
1129
1130 try {
1131 session = openSession();
1132
1133 if (!session.contains(resourceAction)) {
1134 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1135 resourceAction.getPrimaryKeyObj());
1136 }
1137
1138 if (resourceAction != null) {
1139 session.delete(resourceAction);
1140 }
1141 }
1142 catch (Exception e) {
1143 throw processException(e);
1144 }
1145 finally {
1146 closeSession(session);
1147 }
1148
1149 if (resourceAction != null) {
1150 clearCache(resourceAction);
1151 }
1152
1153 return resourceAction;
1154 }
1155
1156 @Override
1157 public ResourceAction updateImpl(
1158 com.liferay.portal.model.ResourceAction resourceAction)
1159 throws SystemException {
1160 resourceAction = toUnwrappedModel(resourceAction);
1161
1162 boolean isNew = resourceAction.isNew();
1163
1164 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
1165
1166 Session session = null;
1167
1168 try {
1169 session = openSession();
1170
1171 if (resourceAction.isNew()) {
1172 session.save(resourceAction);
1173
1174 resourceAction.setNew(false);
1175 }
1176 else {
1177 session.merge(resourceAction);
1178 }
1179 }
1180 catch (Exception e) {
1181 throw processException(e);
1182 }
1183 finally {
1184 closeSession(session);
1185 }
1186
1187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1188
1189 if (isNew || !ResourceActionModelImpl.COLUMN_BITMASK_ENABLED) {
1190 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1191 }
1192
1193 else {
1194 if ((resourceActionModelImpl.getColumnBitmask() &
1195 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
1196 Object[] args = new Object[] {
1197 resourceActionModelImpl.getOriginalName()
1198 };
1199
1200 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1201 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
1202 args);
1203
1204 args = new Object[] { resourceActionModelImpl.getName() };
1205
1206 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1207 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
1208 args);
1209 }
1210 }
1211
1212 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1213 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
1214 resourceAction);
1215
1216 clearUniqueFindersCache(resourceAction);
1217 cacheUniqueFindersCache(resourceAction);
1218
1219 return resourceAction;
1220 }
1221
1222 protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
1223 if (resourceAction instanceof ResourceActionImpl) {
1224 return resourceAction;
1225 }
1226
1227 ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
1228
1229 resourceActionImpl.setNew(resourceAction.isNew());
1230 resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
1231
1232 resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
1233 resourceActionImpl.setName(resourceAction.getName());
1234 resourceActionImpl.setActionId(resourceAction.getActionId());
1235 resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
1236
1237 return resourceActionImpl;
1238 }
1239
1240
1248 @Override
1249 public ResourceAction findByPrimaryKey(Serializable primaryKey)
1250 throws NoSuchResourceActionException, SystemException {
1251 ResourceAction resourceAction = fetchByPrimaryKey(primaryKey);
1252
1253 if (resourceAction == null) {
1254 if (_log.isWarnEnabled()) {
1255 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1256 }
1257
1258 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1259 primaryKey);
1260 }
1261
1262 return resourceAction;
1263 }
1264
1265
1273 @Override
1274 public ResourceAction findByPrimaryKey(long resourceActionId)
1275 throws NoSuchResourceActionException, SystemException {
1276 return findByPrimaryKey((Serializable)resourceActionId);
1277 }
1278
1279
1286 @Override
1287 public ResourceAction fetchByPrimaryKey(Serializable primaryKey)
1288 throws SystemException {
1289 ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1290 ResourceActionImpl.class, primaryKey);
1291
1292 if (resourceAction == _nullResourceAction) {
1293 return null;
1294 }
1295
1296 if (resourceAction == null) {
1297 Session session = null;
1298
1299 try {
1300 session = openSession();
1301
1302 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1303 primaryKey);
1304
1305 if (resourceAction != null) {
1306 cacheResult(resourceAction);
1307 }
1308 else {
1309 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1310 ResourceActionImpl.class, primaryKey,
1311 _nullResourceAction);
1312 }
1313 }
1314 catch (Exception e) {
1315 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1316 ResourceActionImpl.class, primaryKey);
1317
1318 throw processException(e);
1319 }
1320 finally {
1321 closeSession(session);
1322 }
1323 }
1324
1325 return resourceAction;
1326 }
1327
1328
1335 @Override
1336 public ResourceAction fetchByPrimaryKey(long resourceActionId)
1337 throws SystemException {
1338 return fetchByPrimaryKey((Serializable)resourceActionId);
1339 }
1340
1341
1347 @Override
1348 public List<ResourceAction> findAll() throws SystemException {
1349 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1350 }
1351
1352
1364 @Override
1365 public List<ResourceAction> findAll(int start, int end)
1366 throws SystemException {
1367 return findAll(start, end, null);
1368 }
1369
1370
1383 @Override
1384 public List<ResourceAction> findAll(int start, int end,
1385 OrderByComparator orderByComparator) throws SystemException {
1386 boolean pagination = true;
1387 FinderPath finderPath = null;
1388 Object[] finderArgs = null;
1389
1390 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1391 (orderByComparator == null)) {
1392 pagination = false;
1393 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1394 finderArgs = FINDER_ARGS_EMPTY;
1395 }
1396 else {
1397 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1398 finderArgs = new Object[] { start, end, orderByComparator };
1399 }
1400
1401 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(finderPath,
1402 finderArgs, this);
1403
1404 if (list == null) {
1405 StringBundler query = null;
1406 String sql = null;
1407
1408 if (orderByComparator != null) {
1409 query = new StringBundler(2 +
1410 (orderByComparator.getOrderByFields().length * 3));
1411
1412 query.append(_SQL_SELECT_RESOURCEACTION);
1413
1414 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1415 orderByComparator);
1416
1417 sql = query.toString();
1418 }
1419 else {
1420 sql = _SQL_SELECT_RESOURCEACTION;
1421
1422 if (pagination) {
1423 sql = sql.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
1424 }
1425 }
1426
1427 Session session = null;
1428
1429 try {
1430 session = openSession();
1431
1432 Query q = session.createQuery(sql);
1433
1434 if (!pagination) {
1435 list = (List<ResourceAction>)QueryUtil.list(q,
1436 getDialect(), start, end, false);
1437
1438 Collections.sort(list);
1439
1440 list = new UnmodifiableList<ResourceAction>(list);
1441 }
1442 else {
1443 list = (List<ResourceAction>)QueryUtil.list(q,
1444 getDialect(), start, end);
1445 }
1446
1447 cacheResult(list);
1448
1449 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1450 }
1451 catch (Exception e) {
1452 FinderCacheUtil.removeResult(finderPath, finderArgs);
1453
1454 throw processException(e);
1455 }
1456 finally {
1457 closeSession(session);
1458 }
1459 }
1460
1461 return list;
1462 }
1463
1464
1469 @Override
1470 public void removeAll() throws SystemException {
1471 for (ResourceAction resourceAction : findAll()) {
1472 remove(resourceAction);
1473 }
1474 }
1475
1476
1482 @Override
1483 public int countAll() throws SystemException {
1484 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1485 FINDER_ARGS_EMPTY, this);
1486
1487 if (count == null) {
1488 Session session = null;
1489
1490 try {
1491 session = openSession();
1492
1493 Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1494
1495 count = (Long)q.uniqueResult();
1496
1497 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1498 FINDER_ARGS_EMPTY, count);
1499 }
1500 catch (Exception e) {
1501 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1502 FINDER_ARGS_EMPTY);
1503
1504 throw processException(e);
1505 }
1506 finally {
1507 closeSession(session);
1508 }
1509 }
1510
1511 return count.intValue();
1512 }
1513
1514
1517 public void afterPropertiesSet() {
1518 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1519 com.liferay.portal.util.PropsUtil.get(
1520 "value.object.listener.com.liferay.portal.model.ResourceAction")));
1521
1522 if (listenerClassNames.length > 0) {
1523 try {
1524 List<ModelListener<ResourceAction>> listenersList = new ArrayList<ModelListener<ResourceAction>>();
1525
1526 for (String listenerClassName : listenerClassNames) {
1527 listenersList.add((ModelListener<ResourceAction>)InstanceFactory.newInstance(
1528 getClassLoader(), listenerClassName));
1529 }
1530
1531 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1532 }
1533 catch (Exception e) {
1534 _log.error(e);
1535 }
1536 }
1537 }
1538
1539 public void destroy() {
1540 EntityCacheUtil.removeCache(ResourceActionImpl.class.getName());
1541 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1542 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1543 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1544 }
1545
1546 private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1547 private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1548 private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1549 private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1550 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1551 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1552 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1553 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1554 private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1555 private static ResourceAction _nullResourceAction = new ResourceActionImpl() {
1556 @Override
1557 public Object clone() {
1558 return this;
1559 }
1560
1561 @Override
1562 public CacheModel<ResourceAction> toCacheModel() {
1563 return _nullResourceActionCacheModel;
1564 }
1565 };
1566
1567 private static CacheModel<ResourceAction> _nullResourceActionCacheModel = new CacheModel<ResourceAction>() {
1568 @Override
1569 public ResourceAction toEntityModel() {
1570 return _nullResourceAction;
1571 }
1572 };
1573 }