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 BatchSessionUtil.delete(session, resourceAction);
238 }
239 catch (Exception e) {
240 throw processException(e);
241 }
242 finally {
243 closeSession(session);
244 }
245
246 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
247
248 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
249
250 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
251 new Object[] {
252 resourceActionModelImpl.getOriginalName(),
253
254 resourceActionModelImpl.getOriginalActionId()
255 });
256
257 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
258 ResourceActionImpl.class, resourceAction.getPrimaryKey());
259
260 return resourceAction;
261 }
262
263 public ResourceAction updateImpl(
264 com.liferay.portal.model.ResourceAction resourceAction, boolean merge)
265 throws SystemException {
266 resourceAction = toUnwrappedModel(resourceAction);
267
268 boolean isNew = resourceAction.isNew();
269
270 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
271
272 Session session = null;
273
274 try {
275 session = openSession();
276
277 BatchSessionUtil.update(session, resourceAction, merge);
278
279 resourceAction.setNew(false);
280 }
281 catch (Exception e) {
282 throw processException(e);
283 }
284 finally {
285 closeSession(session);
286 }
287
288 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
289
290 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
291 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
292 resourceAction);
293
294 if (!isNew &&
295 (!Validator.equals(resourceAction.getName(),
296 resourceActionModelImpl.getOriginalName()) ||
297 !Validator.equals(resourceAction.getActionId(),
298 resourceActionModelImpl.getOriginalActionId()))) {
299 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
300 new Object[] {
301 resourceActionModelImpl.getOriginalName(),
302
303 resourceActionModelImpl.getOriginalActionId()
304 });
305 }
306
307 if (isNew ||
308 (!Validator.equals(resourceAction.getName(),
309 resourceActionModelImpl.getOriginalName()) ||
310 !Validator.equals(resourceAction.getActionId(),
311 resourceActionModelImpl.getOriginalActionId()))) {
312 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
313 new Object[] {
314 resourceAction.getName(),
315
316 resourceAction.getActionId()
317 }, resourceAction);
318 }
319
320 return resourceAction;
321 }
322
323 protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
324 if (resourceAction instanceof ResourceActionImpl) {
325 return resourceAction;
326 }
327
328 ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
329
330 resourceActionImpl.setNew(resourceAction.isNew());
331 resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
332
333 resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
334 resourceActionImpl.setName(resourceAction.getName());
335 resourceActionImpl.setActionId(resourceAction.getActionId());
336 resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
337
338 return resourceActionImpl;
339 }
340
341
349 public ResourceAction findByPrimaryKey(Serializable primaryKey)
350 throws NoSuchModelException, SystemException {
351 return findByPrimaryKey(((Long)primaryKey).longValue());
352 }
353
354
362 public ResourceAction findByPrimaryKey(long resourceActionId)
363 throws NoSuchResourceActionException, SystemException {
364 ResourceAction resourceAction = fetchByPrimaryKey(resourceActionId);
365
366 if (resourceAction == null) {
367 if (_log.isWarnEnabled()) {
368 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceActionId);
369 }
370
371 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
372 resourceActionId);
373 }
374
375 return resourceAction;
376 }
377
378
385 public ResourceAction fetchByPrimaryKey(Serializable primaryKey)
386 throws SystemException {
387 return fetchByPrimaryKey(((Long)primaryKey).longValue());
388 }
389
390
397 public ResourceAction fetchByPrimaryKey(long resourceActionId)
398 throws SystemException {
399 ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
400 ResourceActionImpl.class, resourceActionId, this);
401
402 if (resourceAction == null) {
403 Session session = null;
404
405 try {
406 session = openSession();
407
408 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
409 new Long(resourceActionId));
410 }
411 catch (Exception e) {
412 throw processException(e);
413 }
414 finally {
415 if (resourceAction != null) {
416 cacheResult(resourceAction);
417 }
418
419 closeSession(session);
420 }
421 }
422
423 return resourceAction;
424 }
425
426
433 public List<ResourceAction> findByName(String name)
434 throws SystemException {
435 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
436 }
437
438
451 public List<ResourceAction> findByName(String name, int start, int end)
452 throws SystemException {
453 return findByName(name, start, end, null);
454 }
455
456
470 public List<ResourceAction> findByName(String name, int start, int end,
471 OrderByComparator orderByComparator) throws SystemException {
472 Object[] finderArgs = new Object[] {
473 name,
474
475 String.valueOf(start), String.valueOf(end),
476 String.valueOf(orderByComparator)
477 };
478
479 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NAME,
480 finderArgs, this);
481
482 if (list == null) {
483 Session session = null;
484
485 try {
486 session = openSession();
487
488 StringBundler query = null;
489
490 if (orderByComparator != null) {
491 query = new StringBundler(3 +
492 (orderByComparator.getOrderByFields().length * 3));
493 }
494 else {
495 query = new StringBundler(3);
496 }
497
498 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
499
500 if (name == null) {
501 query.append(_FINDER_COLUMN_NAME_NAME_1);
502 }
503 else {
504 if (name.equals(StringPool.BLANK)) {
505 query.append(_FINDER_COLUMN_NAME_NAME_3);
506 }
507 else {
508 query.append(_FINDER_COLUMN_NAME_NAME_2);
509 }
510 }
511
512 if (orderByComparator != null) {
513 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
514 orderByComparator);
515 }
516
517 else {
518 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
519 }
520
521 String sql = query.toString();
522
523 Query q = session.createQuery(sql);
524
525 QueryPos qPos = QueryPos.getInstance(q);
526
527 if (name != null) {
528 qPos.add(name);
529 }
530
531 list = (List<ResourceAction>)QueryUtil.list(q, getDialect(),
532 start, end);
533 }
534 catch (Exception e) {
535 throw processException(e);
536 }
537 finally {
538 if (list == null) {
539 list = new ArrayList<ResourceAction>();
540 }
541
542 cacheResult(list);
543
544 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NAME, finderArgs,
545 list);
546
547 closeSession(session);
548 }
549 }
550
551 return list;
552 }
553
554
567 public ResourceAction findByName_First(String name,
568 OrderByComparator orderByComparator)
569 throws NoSuchResourceActionException, SystemException {
570 List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
571
572 if (list.isEmpty()) {
573 StringBundler msg = new StringBundler(4);
574
575 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
576
577 msg.append("name=");
578 msg.append(name);
579
580 msg.append(StringPool.CLOSE_CURLY_BRACE);
581
582 throw new NoSuchResourceActionException(msg.toString());
583 }
584 else {
585 return list.get(0);
586 }
587 }
588
589
602 public ResourceAction findByName_Last(String name,
603 OrderByComparator orderByComparator)
604 throws NoSuchResourceActionException, SystemException {
605 int count = countByName(name);
606
607 List<ResourceAction> list = findByName(name, count - 1, count,
608 orderByComparator);
609
610 if (list.isEmpty()) {
611 StringBundler msg = new StringBundler(4);
612
613 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
614
615 msg.append("name=");
616 msg.append(name);
617
618 msg.append(StringPool.CLOSE_CURLY_BRACE);
619
620 throw new NoSuchResourceActionException(msg.toString());
621 }
622 else {
623 return list.get(0);
624 }
625 }
626
627
641 public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
642 String name, OrderByComparator orderByComparator)
643 throws NoSuchResourceActionException, SystemException {
644 ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
645
646 Session session = null;
647
648 try {
649 session = openSession();
650
651 ResourceAction[] array = new ResourceActionImpl[3];
652
653 array[0] = getByName_PrevAndNext(session, resourceAction, name,
654 orderByComparator, true);
655
656 array[1] = resourceAction;
657
658 array[2] = getByName_PrevAndNext(session, resourceAction, name,
659 orderByComparator, false);
660
661 return array;
662 }
663 catch (Exception e) {
664 throw processException(e);
665 }
666 finally {
667 closeSession(session);
668 }
669 }
670
671 protected ResourceAction getByName_PrevAndNext(Session session,
672 ResourceAction resourceAction, String name,
673 OrderByComparator orderByComparator, boolean previous) {
674 StringBundler query = null;
675
676 if (orderByComparator != null) {
677 query = new StringBundler(6 +
678 (orderByComparator.getOrderByFields().length * 6));
679 }
680 else {
681 query = new StringBundler(3);
682 }
683
684 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
685
686 if (name == null) {
687 query.append(_FINDER_COLUMN_NAME_NAME_1);
688 }
689 else {
690 if (name.equals(StringPool.BLANK)) {
691 query.append(_FINDER_COLUMN_NAME_NAME_3);
692 }
693 else {
694 query.append(_FINDER_COLUMN_NAME_NAME_2);
695 }
696 }
697
698 if (orderByComparator != null) {
699 String[] orderByFields = orderByComparator.getOrderByFields();
700
701 if (orderByFields.length > 0) {
702 query.append(WHERE_AND);
703 }
704
705 for (int i = 0; i < orderByFields.length; i++) {
706 query.append(_ORDER_BY_ENTITY_ALIAS);
707 query.append(orderByFields[i]);
708
709 if ((i + 1) < orderByFields.length) {
710 if (orderByComparator.isAscending() ^ previous) {
711 query.append(WHERE_GREATER_THAN_HAS_NEXT);
712 }
713 else {
714 query.append(WHERE_LESSER_THAN_HAS_NEXT);
715 }
716 }
717 else {
718 if (orderByComparator.isAscending() ^ previous) {
719 query.append(WHERE_GREATER_THAN);
720 }
721 else {
722 query.append(WHERE_LESSER_THAN);
723 }
724 }
725 }
726
727 query.append(ORDER_BY_CLAUSE);
728
729 for (int i = 0; i < orderByFields.length; i++) {
730 query.append(_ORDER_BY_ENTITY_ALIAS);
731 query.append(orderByFields[i]);
732
733 if ((i + 1) < orderByFields.length) {
734 if (orderByComparator.isAscending() ^ previous) {
735 query.append(ORDER_BY_ASC_HAS_NEXT);
736 }
737 else {
738 query.append(ORDER_BY_DESC_HAS_NEXT);
739 }
740 }
741 else {
742 if (orderByComparator.isAscending() ^ previous) {
743 query.append(ORDER_BY_ASC);
744 }
745 else {
746 query.append(ORDER_BY_DESC);
747 }
748 }
749 }
750 }
751
752 else {
753 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
754 }
755
756 String sql = query.toString();
757
758 Query q = session.createQuery(sql);
759
760 q.setFirstResult(0);
761 q.setMaxResults(2);
762
763 QueryPos qPos = QueryPos.getInstance(q);
764
765 if (name != null) {
766 qPos.add(name);
767 }
768
769 if (orderByComparator != null) {
770 Object[] values = orderByComparator.getOrderByValues(resourceAction);
771
772 for (Object value : values) {
773 qPos.add(value);
774 }
775 }
776
777 List<ResourceAction> list = q.list();
778
779 if (list.size() == 2) {
780 return list.get(1);
781 }
782 else {
783 return null;
784 }
785 }
786
787
796 public ResourceAction findByN_A(String name, String actionId)
797 throws NoSuchResourceActionException, SystemException {
798 ResourceAction resourceAction = fetchByN_A(name, actionId);
799
800 if (resourceAction == null) {
801 StringBundler msg = new StringBundler(6);
802
803 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
804
805 msg.append("name=");
806 msg.append(name);
807
808 msg.append(", actionId=");
809 msg.append(actionId);
810
811 msg.append(StringPool.CLOSE_CURLY_BRACE);
812
813 if (_log.isWarnEnabled()) {
814 _log.warn(msg.toString());
815 }
816
817 throw new NoSuchResourceActionException(msg.toString());
818 }
819
820 return resourceAction;
821 }
822
823
831 public ResourceAction fetchByN_A(String name, String actionId)
832 throws SystemException {
833 return fetchByN_A(name, actionId, true);
834 }
835
836
844 public ResourceAction fetchByN_A(String name, String actionId,
845 boolean retrieveFromCache) throws SystemException {
846 Object[] finderArgs = new Object[] { name, actionId };
847
848 Object result = null;
849
850 if (retrieveFromCache) {
851 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
852 finderArgs, this);
853 }
854
855 if (result == null) {
856 Session session = null;
857
858 try {
859 session = openSession();
860
861 StringBundler query = new StringBundler(4);
862
863 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
864
865 if (name == null) {
866 query.append(_FINDER_COLUMN_N_A_NAME_1);
867 }
868 else {
869 if (name.equals(StringPool.BLANK)) {
870 query.append(_FINDER_COLUMN_N_A_NAME_3);
871 }
872 else {
873 query.append(_FINDER_COLUMN_N_A_NAME_2);
874 }
875 }
876
877 if (actionId == null) {
878 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
879 }
880 else {
881 if (actionId.equals(StringPool.BLANK)) {
882 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
883 }
884 else {
885 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
886 }
887 }
888
889 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
890
891 String sql = query.toString();
892
893 Query q = session.createQuery(sql);
894
895 QueryPos qPos = QueryPos.getInstance(q);
896
897 if (name != null) {
898 qPos.add(name);
899 }
900
901 if (actionId != null) {
902 qPos.add(actionId);
903 }
904
905 List<ResourceAction> list = q.list();
906
907 result = list;
908
909 ResourceAction resourceAction = null;
910
911 if (list.isEmpty()) {
912 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
913 finderArgs, list);
914 }
915 else {
916 resourceAction = list.get(0);
917
918 cacheResult(resourceAction);
919
920 if ((resourceAction.getName() == null) ||
921 !resourceAction.getName().equals(name) ||
922 (resourceAction.getActionId() == null) ||
923 !resourceAction.getActionId().equals(actionId)) {
924 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
925 finderArgs, resourceAction);
926 }
927 }
928
929 return resourceAction;
930 }
931 catch (Exception e) {
932 throw processException(e);
933 }
934 finally {
935 if (result == null) {
936 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
937 finderArgs, new ArrayList<ResourceAction>());
938 }
939
940 closeSession(session);
941 }
942 }
943 else {
944 if (result instanceof List<?>) {
945 return null;
946 }
947 else {
948 return (ResourceAction)result;
949 }
950 }
951 }
952
953
959 public List<ResourceAction> findAll() throws SystemException {
960 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
961 }
962
963
975 public List<ResourceAction> findAll(int start, int end)
976 throws SystemException {
977 return findAll(start, end, null);
978 }
979
980
993 public List<ResourceAction> findAll(int start, int end,
994 OrderByComparator orderByComparator) throws SystemException {
995 Object[] finderArgs = new Object[] {
996 String.valueOf(start), String.valueOf(end),
997 String.valueOf(orderByComparator)
998 };
999
1000 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1001 finderArgs, this);
1002
1003 if (list == null) {
1004 Session session = null;
1005
1006 try {
1007 session = openSession();
1008
1009 StringBundler query = null;
1010 String sql = null;
1011
1012 if (orderByComparator != null) {
1013 query = new StringBundler(2 +
1014 (orderByComparator.getOrderByFields().length * 3));
1015
1016 query.append(_SQL_SELECT_RESOURCEACTION);
1017
1018 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1019 orderByComparator);
1020
1021 sql = query.toString();
1022 }
1023 else {
1024 sql = _SQL_SELECT_RESOURCEACTION.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
1025 }
1026
1027 Query q = session.createQuery(sql);
1028
1029 if (orderByComparator == null) {
1030 list = (List<ResourceAction>)QueryUtil.list(q,
1031 getDialect(), start, end, false);
1032
1033 Collections.sort(list);
1034 }
1035 else {
1036 list = (List<ResourceAction>)QueryUtil.list(q,
1037 getDialect(), start, end);
1038 }
1039 }
1040 catch (Exception e) {
1041 throw processException(e);
1042 }
1043 finally {
1044 if (list == null) {
1045 list = new ArrayList<ResourceAction>();
1046 }
1047
1048 cacheResult(list);
1049
1050 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1051
1052 closeSession(session);
1053 }
1054 }
1055
1056 return list;
1057 }
1058
1059
1065 public void removeByName(String name) throws SystemException {
1066 for (ResourceAction resourceAction : findByName(name)) {
1067 remove(resourceAction);
1068 }
1069 }
1070
1071
1078 public void removeByN_A(String name, String actionId)
1079 throws NoSuchResourceActionException, SystemException {
1080 ResourceAction resourceAction = findByN_A(name, actionId);
1081
1082 remove(resourceAction);
1083 }
1084
1085
1090 public void removeAll() throws SystemException {
1091 for (ResourceAction resourceAction : findAll()) {
1092 remove(resourceAction);
1093 }
1094 }
1095
1096
1103 public int countByName(String name) throws SystemException {
1104 Object[] finderArgs = new Object[] { name };
1105
1106 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1107 finderArgs, this);
1108
1109 if (count == null) {
1110 Session session = null;
1111
1112 try {
1113 session = openSession();
1114
1115 StringBundler query = new StringBundler(2);
1116
1117 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
1118
1119 if (name == null) {
1120 query.append(_FINDER_COLUMN_NAME_NAME_1);
1121 }
1122 else {
1123 if (name.equals(StringPool.BLANK)) {
1124 query.append(_FINDER_COLUMN_NAME_NAME_3);
1125 }
1126 else {
1127 query.append(_FINDER_COLUMN_NAME_NAME_2);
1128 }
1129 }
1130
1131 String sql = query.toString();
1132
1133 Query q = session.createQuery(sql);
1134
1135 QueryPos qPos = QueryPos.getInstance(q);
1136
1137 if (name != null) {
1138 qPos.add(name);
1139 }
1140
1141 count = (Long)q.uniqueResult();
1142 }
1143 catch (Exception e) {
1144 throw processException(e);
1145 }
1146 finally {
1147 if (count == null) {
1148 count = Long.valueOf(0);
1149 }
1150
1151 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1152 finderArgs, count);
1153
1154 closeSession(session);
1155 }
1156 }
1157
1158 return count.intValue();
1159 }
1160
1161
1169 public int countByN_A(String name, String actionId)
1170 throws SystemException {
1171 Object[] finderArgs = new Object[] { name, actionId };
1172
1173 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_A,
1174 finderArgs, this);
1175
1176 if (count == null) {
1177 Session session = null;
1178
1179 try {
1180 session = openSession();
1181
1182 StringBundler query = new StringBundler(3);
1183
1184 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
1185
1186 if (name == null) {
1187 query.append(_FINDER_COLUMN_N_A_NAME_1);
1188 }
1189 else {
1190 if (name.equals(StringPool.BLANK)) {
1191 query.append(_FINDER_COLUMN_N_A_NAME_3);
1192 }
1193 else {
1194 query.append(_FINDER_COLUMN_N_A_NAME_2);
1195 }
1196 }
1197
1198 if (actionId == null) {
1199 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
1200 }
1201 else {
1202 if (actionId.equals(StringPool.BLANK)) {
1203 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
1204 }
1205 else {
1206 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
1207 }
1208 }
1209
1210 String sql = query.toString();
1211
1212 Query q = session.createQuery(sql);
1213
1214 QueryPos qPos = QueryPos.getInstance(q);
1215
1216 if (name != null) {
1217 qPos.add(name);
1218 }
1219
1220 if (actionId != null) {
1221 qPos.add(actionId);
1222 }
1223
1224 count = (Long)q.uniqueResult();
1225 }
1226 catch (Exception e) {
1227 throw processException(e);
1228 }
1229 finally {
1230 if (count == null) {
1231 count = Long.valueOf(0);
1232 }
1233
1234 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, finderArgs,
1235 count);
1236
1237 closeSession(session);
1238 }
1239 }
1240
1241 return count.intValue();
1242 }
1243
1244
1250 public int countAll() throws SystemException {
1251 Object[] finderArgs = new Object[0];
1252
1253 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1254 finderArgs, this);
1255
1256 if (count == null) {
1257 Session session = null;
1258
1259 try {
1260 session = openSession();
1261
1262 Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1263
1264 count = (Long)q.uniqueResult();
1265 }
1266 catch (Exception e) {
1267 throw processException(e);
1268 }
1269 finally {
1270 if (count == null) {
1271 count = Long.valueOf(0);
1272 }
1273
1274 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1275 count);
1276
1277 closeSession(session);
1278 }
1279 }
1280
1281 return count.intValue();
1282 }
1283
1284
1287 public void afterPropertiesSet() {
1288 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1289 com.liferay.portal.util.PropsUtil.get(
1290 "value.object.listener.com.liferay.portal.model.ResourceAction")));
1291
1292 if (listenerClassNames.length > 0) {
1293 try {
1294 List<ModelListener<ResourceAction>> listenersList = new ArrayList<ModelListener<ResourceAction>>();
1295
1296 for (String listenerClassName : listenerClassNames) {
1297 listenersList.add((ModelListener<ResourceAction>)InstanceFactory.newInstance(
1298 listenerClassName));
1299 }
1300
1301 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1302 }
1303 catch (Exception e) {
1304 _log.error(e);
1305 }
1306 }
1307 }
1308
1309 public void destroy() {
1310 EntityCacheUtil.removeCache(ResourceActionImpl.class.getName());
1311 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1312 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1313 }
1314
1315 @BeanReference(type = AccountPersistence.class)
1316 protected AccountPersistence accountPersistence;
1317 @BeanReference(type = AddressPersistence.class)
1318 protected AddressPersistence addressPersistence;
1319 @BeanReference(type = BrowserTrackerPersistence.class)
1320 protected BrowserTrackerPersistence browserTrackerPersistence;
1321 @BeanReference(type = ClassNamePersistence.class)
1322 protected ClassNamePersistence classNamePersistence;
1323 @BeanReference(type = ClusterGroupPersistence.class)
1324 protected ClusterGroupPersistence clusterGroupPersistence;
1325 @BeanReference(type = CompanyPersistence.class)
1326 protected CompanyPersistence companyPersistence;
1327 @BeanReference(type = ContactPersistence.class)
1328 protected ContactPersistence contactPersistence;
1329 @BeanReference(type = CountryPersistence.class)
1330 protected CountryPersistence countryPersistence;
1331 @BeanReference(type = EmailAddressPersistence.class)
1332 protected EmailAddressPersistence emailAddressPersistence;
1333 @BeanReference(type = GroupPersistence.class)
1334 protected GroupPersistence groupPersistence;
1335 @BeanReference(type = ImagePersistence.class)
1336 protected ImagePersistence imagePersistence;
1337 @BeanReference(type = LayoutPersistence.class)
1338 protected LayoutPersistence layoutPersistence;
1339 @BeanReference(type = LayoutPrototypePersistence.class)
1340 protected LayoutPrototypePersistence layoutPrototypePersistence;
1341 @BeanReference(type = LayoutSetPersistence.class)
1342 protected LayoutSetPersistence layoutSetPersistence;
1343 @BeanReference(type = LayoutSetPrototypePersistence.class)
1344 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1345 @BeanReference(type = ListTypePersistence.class)
1346 protected ListTypePersistence listTypePersistence;
1347 @BeanReference(type = LockPersistence.class)
1348 protected LockPersistence lockPersistence;
1349 @BeanReference(type = MembershipRequestPersistence.class)
1350 protected MembershipRequestPersistence membershipRequestPersistence;
1351 @BeanReference(type = OrganizationPersistence.class)
1352 protected OrganizationPersistence organizationPersistence;
1353 @BeanReference(type = OrgGroupPermissionPersistence.class)
1354 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1355 @BeanReference(type = OrgGroupRolePersistence.class)
1356 protected OrgGroupRolePersistence orgGroupRolePersistence;
1357 @BeanReference(type = OrgLaborPersistence.class)
1358 protected OrgLaborPersistence orgLaborPersistence;
1359 @BeanReference(type = PasswordPolicyPersistence.class)
1360 protected PasswordPolicyPersistence passwordPolicyPersistence;
1361 @BeanReference(type = PasswordPolicyRelPersistence.class)
1362 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1363 @BeanReference(type = PasswordTrackerPersistence.class)
1364 protected PasswordTrackerPersistence passwordTrackerPersistence;
1365 @BeanReference(type = PermissionPersistence.class)
1366 protected PermissionPersistence permissionPersistence;
1367 @BeanReference(type = PhonePersistence.class)
1368 protected PhonePersistence phonePersistence;
1369 @BeanReference(type = PluginSettingPersistence.class)
1370 protected PluginSettingPersistence pluginSettingPersistence;
1371 @BeanReference(type = PortletPersistence.class)
1372 protected PortletPersistence portletPersistence;
1373 @BeanReference(type = PortletItemPersistence.class)
1374 protected PortletItemPersistence portletItemPersistence;
1375 @BeanReference(type = PortletPreferencesPersistence.class)
1376 protected PortletPreferencesPersistence portletPreferencesPersistence;
1377 @BeanReference(type = RegionPersistence.class)
1378 protected RegionPersistence regionPersistence;
1379 @BeanReference(type = ReleasePersistence.class)
1380 protected ReleasePersistence releasePersistence;
1381 @BeanReference(type = ResourcePersistence.class)
1382 protected ResourcePersistence resourcePersistence;
1383 @BeanReference(type = ResourceActionPersistence.class)
1384 protected ResourceActionPersistence resourceActionPersistence;
1385 @BeanReference(type = ResourceCodePersistence.class)
1386 protected ResourceCodePersistence resourceCodePersistence;
1387 @BeanReference(type = ResourcePermissionPersistence.class)
1388 protected ResourcePermissionPersistence resourcePermissionPersistence;
1389 @BeanReference(type = RolePersistence.class)
1390 protected RolePersistence rolePersistence;
1391 @BeanReference(type = ServiceComponentPersistence.class)
1392 protected ServiceComponentPersistence serviceComponentPersistence;
1393 @BeanReference(type = ShardPersistence.class)
1394 protected ShardPersistence shardPersistence;
1395 @BeanReference(type = SubscriptionPersistence.class)
1396 protected SubscriptionPersistence subscriptionPersistence;
1397 @BeanReference(type = TicketPersistence.class)
1398 protected TicketPersistence ticketPersistence;
1399 @BeanReference(type = TeamPersistence.class)
1400 protected TeamPersistence teamPersistence;
1401 @BeanReference(type = UserPersistence.class)
1402 protected UserPersistence userPersistence;
1403 @BeanReference(type = UserGroupPersistence.class)
1404 protected UserGroupPersistence userGroupPersistence;
1405 @BeanReference(type = UserGroupGroupRolePersistence.class)
1406 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1407 @BeanReference(type = UserGroupRolePersistence.class)
1408 protected UserGroupRolePersistence userGroupRolePersistence;
1409 @BeanReference(type = UserIdMapperPersistence.class)
1410 protected UserIdMapperPersistence userIdMapperPersistence;
1411 @BeanReference(type = UserTrackerPersistence.class)
1412 protected UserTrackerPersistence userTrackerPersistence;
1413 @BeanReference(type = UserTrackerPathPersistence.class)
1414 protected UserTrackerPathPersistence userTrackerPathPersistence;
1415 @BeanReference(type = WebDAVPropsPersistence.class)
1416 protected WebDAVPropsPersistence webDAVPropsPersistence;
1417 @BeanReference(type = WebsitePersistence.class)
1418 protected WebsitePersistence websitePersistence;
1419 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1420 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1421 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1422 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1423 private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1424 private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1425 private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1426 private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1427 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
1428 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
1429 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?)";
1430 private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
1431 private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
1432 private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?) AND ";
1433 private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
1434 private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
1435 private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = ?)";
1436 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1437 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1438 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1439 private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1440 }