001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchResourceActionException;
019 import com.liferay.portal.kernel.annotation.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
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
066 public class ResourceActionPersistenceImpl extends BasePersistenceImpl<ResourceAction>
067 implements ResourceActionPersistence {
068 public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.class.getName();
069 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070 ".List";
071 public static final FinderPath FINDER_PATH_FIND_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
072 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
073 FINDER_CLASS_NAME_LIST, "findByName",
074 new String[] {
075 String.class.getName(),
076
077 "java.lang.Integer", "java.lang.Integer",
078 "com.liferay.portal.kernel.util.OrderByComparator"
079 });
080 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
081 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
082 FINDER_CLASS_NAME_LIST, "countByName",
083 new String[] { String.class.getName() });
084 public static final FinderPath FINDER_PATH_FETCH_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
085 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
086 FINDER_CLASS_NAME_ENTITY, "fetchByN_A",
087 new String[] { String.class.getName(), String.class.getName() });
088 public static final FinderPath FINDER_PATH_COUNT_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
089 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
090 FINDER_CLASS_NAME_LIST, "countByN_A",
091 new String[] { String.class.getName(), String.class.getName() });
092 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
093 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
094 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
095 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
096 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
097 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
098
099
104 public void cacheResult(ResourceAction resourceAction) {
105 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
106 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
107 resourceAction);
108
109 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
110 new Object[] { resourceAction.getName(), resourceAction.getActionId() },
111 resourceAction);
112 }
113
114
119 public void cacheResult(List<ResourceAction> resourceActions) {
120 for (ResourceAction resourceAction : resourceActions) {
121 if (EntityCacheUtil.getResult(
122 ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
123 ResourceActionImpl.class,
124 resourceAction.getPrimaryKey(), this) == null) {
125 cacheResult(resourceAction);
126 }
127 }
128 }
129
130
137 public void clearCache() {
138 CacheRegistryUtil.clear(ResourceActionImpl.class.getName());
139 EntityCacheUtil.clearCache(ResourceActionImpl.class.getName());
140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
141 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
142 }
143
144
151 public void clearCache(ResourceAction resourceAction) {
152 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
153 ResourceActionImpl.class, resourceAction.getPrimaryKey());
154
155 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
156 new Object[] { resourceAction.getName(), resourceAction.getActionId() });
157 }
158
159
165 public ResourceAction create(long resourceActionId) {
166 ResourceAction resourceAction = new ResourceActionImpl();
167
168 resourceAction.setNew(true);
169 resourceAction.setPrimaryKey(resourceActionId);
170
171 return resourceAction;
172 }
173
174
182 public ResourceAction remove(Serializable primaryKey)
183 throws NoSuchModelException, SystemException {
184 return remove(((Long)primaryKey).longValue());
185 }
186
187
195 public ResourceAction remove(long resourceActionId)
196 throws NoSuchResourceActionException, SystemException {
197 Session session = null;
198
199 try {
200 session = openSession();
201
202 ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
203 new Long(resourceActionId));
204
205 if (resourceAction == null) {
206 if (_log.isWarnEnabled()) {
207 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
208 resourceActionId);
209 }
210
211 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
212 resourceActionId);
213 }
214
215 return remove(resourceAction);
216 }
217 catch (NoSuchResourceActionException nsee) {
218 throw nsee;
219 }
220 catch (Exception e) {
221 throw processException(e);
222 }
223 finally {
224 closeSession(session);
225 }
226 }
227
228 protected ResourceAction removeImpl(ResourceAction resourceAction)
229 throws SystemException {
230 resourceAction = toUnwrappedModel(resourceAction);
231
232 Session session = null;
233
234 try {
235 session = openSession();
236
237 if (resourceAction.isCachedModel() || BatchSessionUtil.isEnabled()) {
238 Object staleObject = session.get(ResourceActionImpl.class,
239 resourceAction.getPrimaryKeyObj());
240
241 if (staleObject != null) {
242 session.evict(staleObject);
243 }
244 }
245
246 session.delete(resourceAction);
247
248 session.flush();
249 }
250 catch (Exception e) {
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256
257 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
258
259 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
260
261 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
262 new Object[] {
263 resourceActionModelImpl.getOriginalName(),
264
265 resourceActionModelImpl.getOriginalActionId()
266 });
267
268 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
269 ResourceActionImpl.class, resourceAction.getPrimaryKey());
270
271 return resourceAction;
272 }
273
274 public ResourceAction updateImpl(
275 com.liferay.portal.model.ResourceAction resourceAction, boolean merge)
276 throws SystemException {
277 resourceAction = toUnwrappedModel(resourceAction);
278
279 boolean isNew = resourceAction.isNew();
280
281 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
282
283 Session session = null;
284
285 try {
286 session = openSession();
287
288 BatchSessionUtil.update(session, resourceAction, merge);
289
290 resourceAction.setNew(false);
291 }
292 catch (Exception e) {
293 throw processException(e);
294 }
295 finally {
296 closeSession(session);
297 }
298
299 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
300
301 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
302 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
303 resourceAction);
304
305 if (!isNew &&
306 (!Validator.equals(resourceAction.getName(),
307 resourceActionModelImpl.getOriginalName()) ||
308 !Validator.equals(resourceAction.getActionId(),
309 resourceActionModelImpl.getOriginalActionId()))) {
310 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
311 new Object[] {
312 resourceActionModelImpl.getOriginalName(),
313
314 resourceActionModelImpl.getOriginalActionId()
315 });
316 }
317
318 if (isNew ||
319 (!Validator.equals(resourceAction.getName(),
320 resourceActionModelImpl.getOriginalName()) ||
321 !Validator.equals(resourceAction.getActionId(),
322 resourceActionModelImpl.getOriginalActionId()))) {
323 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
324 new Object[] {
325 resourceAction.getName(),
326
327 resourceAction.getActionId()
328 }, resourceAction);
329 }
330
331 return resourceAction;
332 }
333
334 protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
335 if (resourceAction instanceof ResourceActionImpl) {
336 return resourceAction;
337 }
338
339 ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
340
341 resourceActionImpl.setNew(resourceAction.isNew());
342 resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
343
344 resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
345 resourceActionImpl.setName(resourceAction.getName());
346 resourceActionImpl.setActionId(resourceAction.getActionId());
347 resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
348
349 return resourceActionImpl;
350 }
351
352
360 public ResourceAction findByPrimaryKey(Serializable primaryKey)
361 throws NoSuchModelException, SystemException {
362 return findByPrimaryKey(((Long)primaryKey).longValue());
363 }
364
365
373 public ResourceAction findByPrimaryKey(long resourceActionId)
374 throws NoSuchResourceActionException, SystemException {
375 ResourceAction resourceAction = fetchByPrimaryKey(resourceActionId);
376
377 if (resourceAction == null) {
378 if (_log.isWarnEnabled()) {
379 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceActionId);
380 }
381
382 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
383 resourceActionId);
384 }
385
386 return resourceAction;
387 }
388
389
396 public ResourceAction fetchByPrimaryKey(Serializable primaryKey)
397 throws SystemException {
398 return fetchByPrimaryKey(((Long)primaryKey).longValue());
399 }
400
401
408 public ResourceAction fetchByPrimaryKey(long resourceActionId)
409 throws SystemException {
410 ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
411 ResourceActionImpl.class, resourceActionId, this);
412
413 if (resourceAction == null) {
414 Session session = null;
415
416 try {
417 session = openSession();
418
419 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
420 new Long(resourceActionId));
421 }
422 catch (Exception e) {
423 throw processException(e);
424 }
425 finally {
426 if (resourceAction != null) {
427 cacheResult(resourceAction);
428 }
429
430 closeSession(session);
431 }
432 }
433
434 return resourceAction;
435 }
436
437
444 public List<ResourceAction> findByName(String name)
445 throws SystemException {
446 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
447 }
448
449
462 public List<ResourceAction> findByName(String name, int start, int end)
463 throws SystemException {
464 return findByName(name, start, end, null);
465 }
466
467
481 public List<ResourceAction> findByName(String name, int start, int end,
482 OrderByComparator orderByComparator) throws SystemException {
483 Object[] finderArgs = new Object[] {
484 name,
485
486 String.valueOf(start), String.valueOf(end),
487 String.valueOf(orderByComparator)
488 };
489
490 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NAME,
491 finderArgs, this);
492
493 if (list == null) {
494 Session session = null;
495
496 try {
497 session = openSession();
498
499 StringBundler query = null;
500
501 if (orderByComparator != null) {
502 query = new StringBundler(3 +
503 (orderByComparator.getOrderByFields().length * 3));
504 }
505 else {
506 query = new StringBundler(3);
507 }
508
509 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
510
511 if (name == null) {
512 query.append(_FINDER_COLUMN_NAME_NAME_1);
513 }
514 else {
515 if (name.equals(StringPool.BLANK)) {
516 query.append(_FINDER_COLUMN_NAME_NAME_3);
517 }
518 else {
519 query.append(_FINDER_COLUMN_NAME_NAME_2);
520 }
521 }
522
523 if (orderByComparator != null) {
524 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
525 orderByComparator);
526 }
527
528 else {
529 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
530 }
531
532 String sql = query.toString();
533
534 Query q = session.createQuery(sql);
535
536 QueryPos qPos = QueryPos.getInstance(q);
537
538 if (name != null) {
539 qPos.add(name);
540 }
541
542 list = (List<ResourceAction>)QueryUtil.list(q, getDialect(),
543 start, end);
544 }
545 catch (Exception e) {
546 throw processException(e);
547 }
548 finally {
549 if (list == null) {
550 list = new ArrayList<ResourceAction>();
551 }
552
553 cacheResult(list);
554
555 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NAME, finderArgs,
556 list);
557
558 closeSession(session);
559 }
560 }
561
562 return list;
563 }
564
565
578 public ResourceAction findByName_First(String name,
579 OrderByComparator orderByComparator)
580 throws NoSuchResourceActionException, SystemException {
581 List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
582
583 if (list.isEmpty()) {
584 StringBundler msg = new StringBundler(4);
585
586 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
587
588 msg.append("name=");
589 msg.append(name);
590
591 msg.append(StringPool.CLOSE_CURLY_BRACE);
592
593 throw new NoSuchResourceActionException(msg.toString());
594 }
595 else {
596 return list.get(0);
597 }
598 }
599
600
613 public ResourceAction findByName_Last(String name,
614 OrderByComparator orderByComparator)
615 throws NoSuchResourceActionException, SystemException {
616 int count = countByName(name);
617
618 List<ResourceAction> list = findByName(name, count - 1, count,
619 orderByComparator);
620
621 if (list.isEmpty()) {
622 StringBundler msg = new StringBundler(4);
623
624 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
625
626 msg.append("name=");
627 msg.append(name);
628
629 msg.append(StringPool.CLOSE_CURLY_BRACE);
630
631 throw new NoSuchResourceActionException(msg.toString());
632 }
633 else {
634 return list.get(0);
635 }
636 }
637
638
652 public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
653 String name, OrderByComparator orderByComparator)
654 throws NoSuchResourceActionException, SystemException {
655 ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
656
657 Session session = null;
658
659 try {
660 session = openSession();
661
662 ResourceAction[] array = new ResourceActionImpl[3];
663
664 array[0] = getByName_PrevAndNext(session, resourceAction, name,
665 orderByComparator, true);
666
667 array[1] = resourceAction;
668
669 array[2] = getByName_PrevAndNext(session, resourceAction, name,
670 orderByComparator, false);
671
672 return array;
673 }
674 catch (Exception e) {
675 throw processException(e);
676 }
677 finally {
678 closeSession(session);
679 }
680 }
681
682 protected ResourceAction getByName_PrevAndNext(Session session,
683 ResourceAction resourceAction, String name,
684 OrderByComparator orderByComparator, boolean previous) {
685 StringBundler query = null;
686
687 if (orderByComparator != null) {
688 query = new StringBundler(6 +
689 (orderByComparator.getOrderByFields().length * 6));
690 }
691 else {
692 query = new StringBundler(3);
693 }
694
695 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
696
697 if (name == null) {
698 query.append(_FINDER_COLUMN_NAME_NAME_1);
699 }
700 else {
701 if (name.equals(StringPool.BLANK)) {
702 query.append(_FINDER_COLUMN_NAME_NAME_3);
703 }
704 else {
705 query.append(_FINDER_COLUMN_NAME_NAME_2);
706 }
707 }
708
709 if (orderByComparator != null) {
710 String[] orderByFields = orderByComparator.getOrderByFields();
711
712 if (orderByFields.length > 0) {
713 query.append(WHERE_AND);
714 }
715
716 for (int i = 0; i < orderByFields.length; i++) {
717 query.append(_ORDER_BY_ENTITY_ALIAS);
718 query.append(orderByFields[i]);
719
720 if ((i + 1) < orderByFields.length) {
721 if (orderByComparator.isAscending() ^ previous) {
722 query.append(WHERE_GREATER_THAN_HAS_NEXT);
723 }
724 else {
725 query.append(WHERE_LESSER_THAN_HAS_NEXT);
726 }
727 }
728 else {
729 if (orderByComparator.isAscending() ^ previous) {
730 query.append(WHERE_GREATER_THAN);
731 }
732 else {
733 query.append(WHERE_LESSER_THAN);
734 }
735 }
736 }
737
738 query.append(ORDER_BY_CLAUSE);
739
740 for (int i = 0; i < orderByFields.length; i++) {
741 query.append(_ORDER_BY_ENTITY_ALIAS);
742 query.append(orderByFields[i]);
743
744 if ((i + 1) < orderByFields.length) {
745 if (orderByComparator.isAscending() ^ previous) {
746 query.append(ORDER_BY_ASC_HAS_NEXT);
747 }
748 else {
749 query.append(ORDER_BY_DESC_HAS_NEXT);
750 }
751 }
752 else {
753 if (orderByComparator.isAscending() ^ previous) {
754 query.append(ORDER_BY_ASC);
755 }
756 else {
757 query.append(ORDER_BY_DESC);
758 }
759 }
760 }
761 }
762
763 else {
764 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
765 }
766
767 String sql = query.toString();
768
769 Query q = session.createQuery(sql);
770
771 q.setFirstResult(0);
772 q.setMaxResults(2);
773
774 QueryPos qPos = QueryPos.getInstance(q);
775
776 if (name != null) {
777 qPos.add(name);
778 }
779
780 if (orderByComparator != null) {
781 Object[] values = orderByComparator.getOrderByValues(resourceAction);
782
783 for (Object value : values) {
784 qPos.add(value);
785 }
786 }
787
788 List<ResourceAction> list = q.list();
789
790 if (list.size() == 2) {
791 return list.get(1);
792 }
793 else {
794 return null;
795 }
796 }
797
798
807 public ResourceAction findByN_A(String name, String actionId)
808 throws NoSuchResourceActionException, SystemException {
809 ResourceAction resourceAction = fetchByN_A(name, actionId);
810
811 if (resourceAction == null) {
812 StringBundler msg = new StringBundler(6);
813
814 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
815
816 msg.append("name=");
817 msg.append(name);
818
819 msg.append(", actionId=");
820 msg.append(actionId);
821
822 msg.append(StringPool.CLOSE_CURLY_BRACE);
823
824 if (_log.isWarnEnabled()) {
825 _log.warn(msg.toString());
826 }
827
828 throw new NoSuchResourceActionException(msg.toString());
829 }
830
831 return resourceAction;
832 }
833
834
842 public ResourceAction fetchByN_A(String name, String actionId)
843 throws SystemException {
844 return fetchByN_A(name, actionId, true);
845 }
846
847
855 public ResourceAction fetchByN_A(String name, String actionId,
856 boolean retrieveFromCache) throws SystemException {
857 Object[] finderArgs = new Object[] { name, actionId };
858
859 Object result = null;
860
861 if (retrieveFromCache) {
862 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
863 finderArgs, this);
864 }
865
866 if (result == null) {
867 Session session = null;
868
869 try {
870 session = openSession();
871
872 StringBundler query = new StringBundler(4);
873
874 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
875
876 if (name == null) {
877 query.append(_FINDER_COLUMN_N_A_NAME_1);
878 }
879 else {
880 if (name.equals(StringPool.BLANK)) {
881 query.append(_FINDER_COLUMN_N_A_NAME_3);
882 }
883 else {
884 query.append(_FINDER_COLUMN_N_A_NAME_2);
885 }
886 }
887
888 if (actionId == null) {
889 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
890 }
891 else {
892 if (actionId.equals(StringPool.BLANK)) {
893 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
894 }
895 else {
896 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
897 }
898 }
899
900 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
901
902 String sql = query.toString();
903
904 Query q = session.createQuery(sql);
905
906 QueryPos qPos = QueryPos.getInstance(q);
907
908 if (name != null) {
909 qPos.add(name);
910 }
911
912 if (actionId != null) {
913 qPos.add(actionId);
914 }
915
916 List<ResourceAction> list = q.list();
917
918 result = list;
919
920 ResourceAction resourceAction = null;
921
922 if (list.isEmpty()) {
923 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
924 finderArgs, list);
925 }
926 else {
927 resourceAction = list.get(0);
928
929 cacheResult(resourceAction);
930
931 if ((resourceAction.getName() == null) ||
932 !resourceAction.getName().equals(name) ||
933 (resourceAction.getActionId() == null) ||
934 !resourceAction.getActionId().equals(actionId)) {
935 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
936 finderArgs, resourceAction);
937 }
938 }
939
940 return resourceAction;
941 }
942 catch (Exception e) {
943 throw processException(e);
944 }
945 finally {
946 if (result == null) {
947 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
948 finderArgs, new ArrayList<ResourceAction>());
949 }
950
951 closeSession(session);
952 }
953 }
954 else {
955 if (result instanceof List<?>) {
956 return null;
957 }
958 else {
959 return (ResourceAction)result;
960 }
961 }
962 }
963
964
970 public List<ResourceAction> findAll() throws SystemException {
971 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
972 }
973
974
986 public List<ResourceAction> findAll(int start, int end)
987 throws SystemException {
988 return findAll(start, end, null);
989 }
990
991
1004 public List<ResourceAction> findAll(int start, int end,
1005 OrderByComparator orderByComparator) throws SystemException {
1006 Object[] finderArgs = new Object[] {
1007 String.valueOf(start), String.valueOf(end),
1008 String.valueOf(orderByComparator)
1009 };
1010
1011 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1012 finderArgs, this);
1013
1014 if (list == null) {
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 StringBundler query = null;
1021 String sql = null;
1022
1023 if (orderByComparator != null) {
1024 query = new StringBundler(2 +
1025 (orderByComparator.getOrderByFields().length * 3));
1026
1027 query.append(_SQL_SELECT_RESOURCEACTION);
1028
1029 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1030 orderByComparator);
1031
1032 sql = query.toString();
1033 }
1034 else {
1035 sql = _SQL_SELECT_RESOURCEACTION.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
1036 }
1037
1038 Query q = session.createQuery(sql);
1039
1040 if (orderByComparator == null) {
1041 list = (List<ResourceAction>)QueryUtil.list(q,
1042 getDialect(), start, end, false);
1043
1044 Collections.sort(list);
1045 }
1046 else {
1047 list = (List<ResourceAction>)QueryUtil.list(q,
1048 getDialect(), start, end);
1049 }
1050 }
1051 catch (Exception e) {
1052 throw processException(e);
1053 }
1054 finally {
1055 if (list == null) {
1056 list = new ArrayList<ResourceAction>();
1057 }
1058
1059 cacheResult(list);
1060
1061 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1062
1063 closeSession(session);
1064 }
1065 }
1066
1067 return list;
1068 }
1069
1070
1076 public void removeByName(String name) throws SystemException {
1077 for (ResourceAction resourceAction : findByName(name)) {
1078 remove(resourceAction);
1079 }
1080 }
1081
1082
1089 public void removeByN_A(String name, String actionId)
1090 throws NoSuchResourceActionException, SystemException {
1091 ResourceAction resourceAction = findByN_A(name, actionId);
1092
1093 remove(resourceAction);
1094 }
1095
1096
1101 public void removeAll() throws SystemException {
1102 for (ResourceAction resourceAction : findAll()) {
1103 remove(resourceAction);
1104 }
1105 }
1106
1107
1114 public int countByName(String name) throws SystemException {
1115 Object[] finderArgs = new Object[] { name };
1116
1117 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1118 finderArgs, this);
1119
1120 if (count == null) {
1121 Session session = null;
1122
1123 try {
1124 session = openSession();
1125
1126 StringBundler query = new StringBundler(2);
1127
1128 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
1129
1130 if (name == null) {
1131 query.append(_FINDER_COLUMN_NAME_NAME_1);
1132 }
1133 else {
1134 if (name.equals(StringPool.BLANK)) {
1135 query.append(_FINDER_COLUMN_NAME_NAME_3);
1136 }
1137 else {
1138 query.append(_FINDER_COLUMN_NAME_NAME_2);
1139 }
1140 }
1141
1142 String sql = query.toString();
1143
1144 Query q = session.createQuery(sql);
1145
1146 QueryPos qPos = QueryPos.getInstance(q);
1147
1148 if (name != null) {
1149 qPos.add(name);
1150 }
1151
1152 count = (Long)q.uniqueResult();
1153 }
1154 catch (Exception e) {
1155 throw processException(e);
1156 }
1157 finally {
1158 if (count == null) {
1159 count = Long.valueOf(0);
1160 }
1161
1162 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1163 finderArgs, count);
1164
1165 closeSession(session);
1166 }
1167 }
1168
1169 return count.intValue();
1170 }
1171
1172
1180 public int countByN_A(String name, String actionId)
1181 throws SystemException {
1182 Object[] finderArgs = new Object[] { name, actionId };
1183
1184 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_A,
1185 finderArgs, this);
1186
1187 if (count == null) {
1188 Session session = null;
1189
1190 try {
1191 session = openSession();
1192
1193 StringBundler query = new StringBundler(3);
1194
1195 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
1196
1197 if (name == null) {
1198 query.append(_FINDER_COLUMN_N_A_NAME_1);
1199 }
1200 else {
1201 if (name.equals(StringPool.BLANK)) {
1202 query.append(_FINDER_COLUMN_N_A_NAME_3);
1203 }
1204 else {
1205 query.append(_FINDER_COLUMN_N_A_NAME_2);
1206 }
1207 }
1208
1209 if (actionId == null) {
1210 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
1211 }
1212 else {
1213 if (actionId.equals(StringPool.BLANK)) {
1214 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
1215 }
1216 else {
1217 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
1218 }
1219 }
1220
1221 String sql = query.toString();
1222
1223 Query q = session.createQuery(sql);
1224
1225 QueryPos qPos = QueryPos.getInstance(q);
1226
1227 if (name != null) {
1228 qPos.add(name);
1229 }
1230
1231 if (actionId != null) {
1232 qPos.add(actionId);
1233 }
1234
1235 count = (Long)q.uniqueResult();
1236 }
1237 catch (Exception e) {
1238 throw processException(e);
1239 }
1240 finally {
1241 if (count == null) {
1242 count = Long.valueOf(0);
1243 }
1244
1245 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, finderArgs,
1246 count);
1247
1248 closeSession(session);
1249 }
1250 }
1251
1252 return count.intValue();
1253 }
1254
1255
1261 public int countAll() throws SystemException {
1262 Object[] finderArgs = new Object[0];
1263
1264 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1265 finderArgs, this);
1266
1267 if (count == null) {
1268 Session session = null;
1269
1270 try {
1271 session = openSession();
1272
1273 Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1274
1275 count = (Long)q.uniqueResult();
1276 }
1277 catch (Exception e) {
1278 throw processException(e);
1279 }
1280 finally {
1281 if (count == null) {
1282 count = Long.valueOf(0);
1283 }
1284
1285 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1286 count);
1287
1288 closeSession(session);
1289 }
1290 }
1291
1292 return count.intValue();
1293 }
1294
1295
1298 public void afterPropertiesSet() {
1299 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1300 com.liferay.portal.util.PropsUtil.get(
1301 "value.object.listener.com.liferay.portal.model.ResourceAction")));
1302
1303 if (listenerClassNames.length > 0) {
1304 try {
1305 List<ModelListener<ResourceAction>> listenersList = new ArrayList<ModelListener<ResourceAction>>();
1306
1307 for (String listenerClassName : listenerClassNames) {
1308 listenersList.add((ModelListener<ResourceAction>)InstanceFactory.newInstance(
1309 listenerClassName));
1310 }
1311
1312 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1313 }
1314 catch (Exception e) {
1315 _log.error(e);
1316 }
1317 }
1318 }
1319
1320 @BeanReference(type = AccountPersistence.class)
1321 protected AccountPersistence accountPersistence;
1322 @BeanReference(type = AddressPersistence.class)
1323 protected AddressPersistence addressPersistence;
1324 @BeanReference(type = BrowserTrackerPersistence.class)
1325 protected BrowserTrackerPersistence browserTrackerPersistence;
1326 @BeanReference(type = ClassNamePersistence.class)
1327 protected ClassNamePersistence classNamePersistence;
1328 @BeanReference(type = CompanyPersistence.class)
1329 protected CompanyPersistence companyPersistence;
1330 @BeanReference(type = ContactPersistence.class)
1331 protected ContactPersistence contactPersistence;
1332 @BeanReference(type = CountryPersistence.class)
1333 protected CountryPersistence countryPersistence;
1334 @BeanReference(type = EmailAddressPersistence.class)
1335 protected EmailAddressPersistence emailAddressPersistence;
1336 @BeanReference(type = GroupPersistence.class)
1337 protected GroupPersistence groupPersistence;
1338 @BeanReference(type = ImagePersistence.class)
1339 protected ImagePersistence imagePersistence;
1340 @BeanReference(type = LayoutPersistence.class)
1341 protected LayoutPersistence layoutPersistence;
1342 @BeanReference(type = LayoutPrototypePersistence.class)
1343 protected LayoutPrototypePersistence layoutPrototypePersistence;
1344 @BeanReference(type = LayoutSetPersistence.class)
1345 protected LayoutSetPersistence layoutSetPersistence;
1346 @BeanReference(type = LayoutSetPrototypePersistence.class)
1347 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1348 @BeanReference(type = ListTypePersistence.class)
1349 protected ListTypePersistence listTypePersistence;
1350 @BeanReference(type = LockPersistence.class)
1351 protected LockPersistence lockPersistence;
1352 @BeanReference(type = MembershipRequestPersistence.class)
1353 protected MembershipRequestPersistence membershipRequestPersistence;
1354 @BeanReference(type = OrganizationPersistence.class)
1355 protected OrganizationPersistence organizationPersistence;
1356 @BeanReference(type = OrgGroupPermissionPersistence.class)
1357 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1358 @BeanReference(type = OrgGroupRolePersistence.class)
1359 protected OrgGroupRolePersistence orgGroupRolePersistence;
1360 @BeanReference(type = OrgLaborPersistence.class)
1361 protected OrgLaborPersistence orgLaborPersistence;
1362 @BeanReference(type = PasswordPolicyPersistence.class)
1363 protected PasswordPolicyPersistence passwordPolicyPersistence;
1364 @BeanReference(type = PasswordPolicyRelPersistence.class)
1365 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1366 @BeanReference(type = PasswordTrackerPersistence.class)
1367 protected PasswordTrackerPersistence passwordTrackerPersistence;
1368 @BeanReference(type = PermissionPersistence.class)
1369 protected PermissionPersistence permissionPersistence;
1370 @BeanReference(type = PhonePersistence.class)
1371 protected PhonePersistence phonePersistence;
1372 @BeanReference(type = PluginSettingPersistence.class)
1373 protected PluginSettingPersistence pluginSettingPersistence;
1374 @BeanReference(type = PortletPersistence.class)
1375 protected PortletPersistence portletPersistence;
1376 @BeanReference(type = PortletItemPersistence.class)
1377 protected PortletItemPersistence portletItemPersistence;
1378 @BeanReference(type = PortletPreferencesPersistence.class)
1379 protected PortletPreferencesPersistence portletPreferencesPersistence;
1380 @BeanReference(type = RegionPersistence.class)
1381 protected RegionPersistence regionPersistence;
1382 @BeanReference(type = ReleasePersistence.class)
1383 protected ReleasePersistence releasePersistence;
1384 @BeanReference(type = ResourcePersistence.class)
1385 protected ResourcePersistence resourcePersistence;
1386 @BeanReference(type = ResourceActionPersistence.class)
1387 protected ResourceActionPersistence resourceActionPersistence;
1388 @BeanReference(type = ResourceCodePersistence.class)
1389 protected ResourceCodePersistence resourceCodePersistence;
1390 @BeanReference(type = ResourcePermissionPersistence.class)
1391 protected ResourcePermissionPersistence resourcePermissionPersistence;
1392 @BeanReference(type = RolePersistence.class)
1393 protected RolePersistence rolePersistence;
1394 @BeanReference(type = ServiceComponentPersistence.class)
1395 protected ServiceComponentPersistence serviceComponentPersistence;
1396 @BeanReference(type = ShardPersistence.class)
1397 protected ShardPersistence shardPersistence;
1398 @BeanReference(type = SubscriptionPersistence.class)
1399 protected SubscriptionPersistence subscriptionPersistence;
1400 @BeanReference(type = TicketPersistence.class)
1401 protected TicketPersistence ticketPersistence;
1402 @BeanReference(type = TeamPersistence.class)
1403 protected TeamPersistence teamPersistence;
1404 @BeanReference(type = UserPersistence.class)
1405 protected UserPersistence userPersistence;
1406 @BeanReference(type = UserGroupPersistence.class)
1407 protected UserGroupPersistence userGroupPersistence;
1408 @BeanReference(type = UserGroupGroupRolePersistence.class)
1409 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1410 @BeanReference(type = UserGroupRolePersistence.class)
1411 protected UserGroupRolePersistence userGroupRolePersistence;
1412 @BeanReference(type = UserIdMapperPersistence.class)
1413 protected UserIdMapperPersistence userIdMapperPersistence;
1414 @BeanReference(type = UserTrackerPersistence.class)
1415 protected UserTrackerPersistence userTrackerPersistence;
1416 @BeanReference(type = UserTrackerPathPersistence.class)
1417 protected UserTrackerPathPersistence userTrackerPathPersistence;
1418 @BeanReference(type = WebDAVPropsPersistence.class)
1419 protected WebDAVPropsPersistence webDAVPropsPersistence;
1420 @BeanReference(type = WebsitePersistence.class)
1421 protected WebsitePersistence websitePersistence;
1422 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1423 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1424 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1425 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1426 private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1427 private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1428 private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1429 private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1430 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
1431 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
1432 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?)";
1433 private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
1434 private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
1435 private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?) AND ";
1436 private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
1437 private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
1438 private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = ?)";
1439 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1440 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1441 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1442 private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1443 }