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.getName(),
253
254 resourceActionModelImpl.getActionId()
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 StringBundler query = null;
484
485 if (orderByComparator != null) {
486 query = new StringBundler(3 +
487 (orderByComparator.getOrderByFields().length * 3));
488 }
489 else {
490 query = new StringBundler(3);
491 }
492
493 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
494
495 if (name == null) {
496 query.append(_FINDER_COLUMN_NAME_NAME_1);
497 }
498 else {
499 if (name.equals(StringPool.BLANK)) {
500 query.append(_FINDER_COLUMN_NAME_NAME_3);
501 }
502 else {
503 query.append(_FINDER_COLUMN_NAME_NAME_2);
504 }
505 }
506
507 if (orderByComparator != null) {
508 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
509 orderByComparator);
510 }
511
512 else {
513 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
514 }
515
516 String sql = query.toString();
517
518 Session session = null;
519
520 try {
521 session = openSession();
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 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_NAME,
540 finderArgs);
541 }
542 else {
543 cacheResult(list);
544
545 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NAME,
546 finderArgs, list);
547 }
548
549 closeSession(session);
550 }
551 }
552
553 return list;
554 }
555
556
569 public ResourceAction findByName_First(String name,
570 OrderByComparator orderByComparator)
571 throws NoSuchResourceActionException, SystemException {
572 List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
573
574 if (list.isEmpty()) {
575 StringBundler msg = new StringBundler(4);
576
577 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
578
579 msg.append("name=");
580 msg.append(name);
581
582 msg.append(StringPool.CLOSE_CURLY_BRACE);
583
584 throw new NoSuchResourceActionException(msg.toString());
585 }
586 else {
587 return list.get(0);
588 }
589 }
590
591
604 public ResourceAction findByName_Last(String name,
605 OrderByComparator orderByComparator)
606 throws NoSuchResourceActionException, SystemException {
607 int count = countByName(name);
608
609 List<ResourceAction> list = findByName(name, count - 1, count,
610 orderByComparator);
611
612 if (list.isEmpty()) {
613 StringBundler msg = new StringBundler(4);
614
615 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
616
617 msg.append("name=");
618 msg.append(name);
619
620 msg.append(StringPool.CLOSE_CURLY_BRACE);
621
622 throw new NoSuchResourceActionException(msg.toString());
623 }
624 else {
625 return list.get(0);
626 }
627 }
628
629
643 public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
644 String name, OrderByComparator orderByComparator)
645 throws NoSuchResourceActionException, SystemException {
646 ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
647
648 Session session = null;
649
650 try {
651 session = openSession();
652
653 ResourceAction[] array = new ResourceActionImpl[3];
654
655 array[0] = getByName_PrevAndNext(session, resourceAction, name,
656 orderByComparator, true);
657
658 array[1] = resourceAction;
659
660 array[2] = getByName_PrevAndNext(session, resourceAction, name,
661 orderByComparator, false);
662
663 return array;
664 }
665 catch (Exception e) {
666 throw processException(e);
667 }
668 finally {
669 closeSession(session);
670 }
671 }
672
673 protected ResourceAction getByName_PrevAndNext(Session session,
674 ResourceAction resourceAction, String name,
675 OrderByComparator orderByComparator, boolean previous) {
676 StringBundler query = null;
677
678 if (orderByComparator != null) {
679 query = new StringBundler(6 +
680 (orderByComparator.getOrderByFields().length * 6));
681 }
682 else {
683 query = new StringBundler(3);
684 }
685
686 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
687
688 if (name == null) {
689 query.append(_FINDER_COLUMN_NAME_NAME_1);
690 }
691 else {
692 if (name.equals(StringPool.BLANK)) {
693 query.append(_FINDER_COLUMN_NAME_NAME_3);
694 }
695 else {
696 query.append(_FINDER_COLUMN_NAME_NAME_2);
697 }
698 }
699
700 if (orderByComparator != null) {
701 String[] orderByFields = orderByComparator.getOrderByFields();
702
703 if (orderByFields.length > 0) {
704 query.append(WHERE_AND);
705 }
706
707 for (int i = 0; i < orderByFields.length; i++) {
708 query.append(_ORDER_BY_ENTITY_ALIAS);
709 query.append(orderByFields[i]);
710
711 if ((i + 1) < orderByFields.length) {
712 if (orderByComparator.isAscending() ^ previous) {
713 query.append(WHERE_GREATER_THAN_HAS_NEXT);
714 }
715 else {
716 query.append(WHERE_LESSER_THAN_HAS_NEXT);
717 }
718 }
719 else {
720 if (orderByComparator.isAscending() ^ previous) {
721 query.append(WHERE_GREATER_THAN);
722 }
723 else {
724 query.append(WHERE_LESSER_THAN);
725 }
726 }
727 }
728
729 query.append(ORDER_BY_CLAUSE);
730
731 for (int i = 0; i < orderByFields.length; i++) {
732 query.append(_ORDER_BY_ENTITY_ALIAS);
733 query.append(orderByFields[i]);
734
735 if ((i + 1) < orderByFields.length) {
736 if (orderByComparator.isAscending() ^ previous) {
737 query.append(ORDER_BY_ASC_HAS_NEXT);
738 }
739 else {
740 query.append(ORDER_BY_DESC_HAS_NEXT);
741 }
742 }
743 else {
744 if (orderByComparator.isAscending() ^ previous) {
745 query.append(ORDER_BY_ASC);
746 }
747 else {
748 query.append(ORDER_BY_DESC);
749 }
750 }
751 }
752 }
753
754 else {
755 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
756 }
757
758 String sql = query.toString();
759
760 Query q = session.createQuery(sql);
761
762 q.setFirstResult(0);
763 q.setMaxResults(2);
764
765 QueryPos qPos = QueryPos.getInstance(q);
766
767 if (name != null) {
768 qPos.add(name);
769 }
770
771 if (orderByComparator != null) {
772 Object[] values = orderByComparator.getOrderByValues(resourceAction);
773
774 for (Object value : values) {
775 qPos.add(value);
776 }
777 }
778
779 List<ResourceAction> list = q.list();
780
781 if (list.size() == 2) {
782 return list.get(1);
783 }
784 else {
785 return null;
786 }
787 }
788
789
798 public ResourceAction findByN_A(String name, String actionId)
799 throws NoSuchResourceActionException, SystemException {
800 ResourceAction resourceAction = fetchByN_A(name, actionId);
801
802 if (resourceAction == null) {
803 StringBundler msg = new StringBundler(6);
804
805 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
806
807 msg.append("name=");
808 msg.append(name);
809
810 msg.append(", actionId=");
811 msg.append(actionId);
812
813 msg.append(StringPool.CLOSE_CURLY_BRACE);
814
815 if (_log.isWarnEnabled()) {
816 _log.warn(msg.toString());
817 }
818
819 throw new NoSuchResourceActionException(msg.toString());
820 }
821
822 return resourceAction;
823 }
824
825
833 public ResourceAction fetchByN_A(String name, String actionId)
834 throws SystemException {
835 return fetchByN_A(name, actionId, true);
836 }
837
838
846 public ResourceAction fetchByN_A(String name, String actionId,
847 boolean retrieveFromCache) throws SystemException {
848 Object[] finderArgs = new Object[] { name, actionId };
849
850 Object result = null;
851
852 if (retrieveFromCache) {
853 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
854 finderArgs, this);
855 }
856
857 if (result == null) {
858 StringBundler query = new StringBundler(4);
859
860 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
861
862 if (name == null) {
863 query.append(_FINDER_COLUMN_N_A_NAME_1);
864 }
865 else {
866 if (name.equals(StringPool.BLANK)) {
867 query.append(_FINDER_COLUMN_N_A_NAME_3);
868 }
869 else {
870 query.append(_FINDER_COLUMN_N_A_NAME_2);
871 }
872 }
873
874 if (actionId == null) {
875 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
876 }
877 else {
878 if (actionId.equals(StringPool.BLANK)) {
879 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
880 }
881 else {
882 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
883 }
884 }
885
886 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
887
888 String sql = query.toString();
889
890 Session session = null;
891
892 try {
893 session = openSession();
894
895 Query q = session.createQuery(sql);
896
897 QueryPos qPos = QueryPos.getInstance(q);
898
899 if (name != null) {
900 qPos.add(name);
901 }
902
903 if (actionId != null) {
904 qPos.add(actionId);
905 }
906
907 List<ResourceAction> list = q.list();
908
909 result = list;
910
911 ResourceAction resourceAction = null;
912
913 if (list.isEmpty()) {
914 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
915 finderArgs, list);
916 }
917 else {
918 resourceAction = list.get(0);
919
920 cacheResult(resourceAction);
921
922 if ((resourceAction.getName() == null) ||
923 !resourceAction.getName().equals(name) ||
924 (resourceAction.getActionId() == null) ||
925 !resourceAction.getActionId().equals(actionId)) {
926 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
927 finderArgs, resourceAction);
928 }
929 }
930
931 return resourceAction;
932 }
933 catch (Exception e) {
934 throw processException(e);
935 }
936 finally {
937 if (result == null) {
938 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
939 finderArgs);
940 }
941
942 closeSession(session);
943 }
944 }
945 else {
946 if (result instanceof List<?>) {
947 return null;
948 }
949 else {
950 return (ResourceAction)result;
951 }
952 }
953 }
954
955
961 public List<ResourceAction> findAll() throws SystemException {
962 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
963 }
964
965
977 public List<ResourceAction> findAll(int start, int end)
978 throws SystemException {
979 return findAll(start, end, null);
980 }
981
982
995 public List<ResourceAction> findAll(int start, int end,
996 OrderByComparator orderByComparator) throws SystemException {
997 Object[] finderArgs = new Object[] {
998 String.valueOf(start), String.valueOf(end),
999 String.valueOf(orderByComparator)
1000 };
1001
1002 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1003 finderArgs, this);
1004
1005 if (list == null) {
1006 StringBundler query = null;
1007 String sql = null;
1008
1009 if (orderByComparator != null) {
1010 query = new StringBundler(2 +
1011 (orderByComparator.getOrderByFields().length * 3));
1012
1013 query.append(_SQL_SELECT_RESOURCEACTION);
1014
1015 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1016 orderByComparator);
1017
1018 sql = query.toString();
1019 }
1020 else {
1021 sql = _SQL_SELECT_RESOURCEACTION.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
1022 }
1023
1024 Session session = null;
1025
1026 try {
1027 session = openSession();
1028
1029 Query q = session.createQuery(sql);
1030
1031 if (orderByComparator == null) {
1032 list = (List<ResourceAction>)QueryUtil.list(q,
1033 getDialect(), start, end, false);
1034
1035 Collections.sort(list);
1036 }
1037 else {
1038 list = (List<ResourceAction>)QueryUtil.list(q,
1039 getDialect(), start, end);
1040 }
1041 }
1042 catch (Exception e) {
1043 throw processException(e);
1044 }
1045 finally {
1046 if (list == null) {
1047 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1048 finderArgs);
1049 }
1050 else {
1051 cacheResult(list);
1052
1053 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1054 list);
1055 }
1056
1057 closeSession(session);
1058 }
1059 }
1060
1061 return list;
1062 }
1063
1064
1070 public void removeByName(String name) throws SystemException {
1071 for (ResourceAction resourceAction : findByName(name)) {
1072 remove(resourceAction);
1073 }
1074 }
1075
1076
1083 public void removeByN_A(String name, String actionId)
1084 throws NoSuchResourceActionException, SystemException {
1085 ResourceAction resourceAction = findByN_A(name, actionId);
1086
1087 remove(resourceAction);
1088 }
1089
1090
1095 public void removeAll() throws SystemException {
1096 for (ResourceAction resourceAction : findAll()) {
1097 remove(resourceAction);
1098 }
1099 }
1100
1101
1108 public int countByName(String name) throws SystemException {
1109 Object[] finderArgs = new Object[] { name };
1110
1111 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1112 finderArgs, this);
1113
1114 if (count == null) {
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 Session session = null;
1134
1135 try {
1136 session = openSession();
1137
1138 Query q = session.createQuery(sql);
1139
1140 QueryPos qPos = QueryPos.getInstance(q);
1141
1142 if (name != null) {
1143 qPos.add(name);
1144 }
1145
1146 count = (Long)q.uniqueResult();
1147 }
1148 catch (Exception e) {
1149 throw processException(e);
1150 }
1151 finally {
1152 if (count == null) {
1153 count = Long.valueOf(0);
1154 }
1155
1156 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1157 finderArgs, count);
1158
1159 closeSession(session);
1160 }
1161 }
1162
1163 return count.intValue();
1164 }
1165
1166
1174 public int countByN_A(String name, String actionId)
1175 throws SystemException {
1176 Object[] finderArgs = new Object[] { name, actionId };
1177
1178 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_A,
1179 finderArgs, this);
1180
1181 if (count == null) {
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 Session session = null;
1213
1214 try {
1215 session = openSession();
1216
1217 Query q = session.createQuery(sql);
1218
1219 QueryPos qPos = QueryPos.getInstance(q);
1220
1221 if (name != null) {
1222 qPos.add(name);
1223 }
1224
1225 if (actionId != null) {
1226 qPos.add(actionId);
1227 }
1228
1229 count = (Long)q.uniqueResult();
1230 }
1231 catch (Exception e) {
1232 throw processException(e);
1233 }
1234 finally {
1235 if (count == null) {
1236 count = Long.valueOf(0);
1237 }
1238
1239 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, finderArgs,
1240 count);
1241
1242 closeSession(session);
1243 }
1244 }
1245
1246 return count.intValue();
1247 }
1248
1249
1255 public int countAll() throws SystemException {
1256 Object[] finderArgs = new Object[0];
1257
1258 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1259 finderArgs, this);
1260
1261 if (count == null) {
1262 Session session = null;
1263
1264 try {
1265 session = openSession();
1266
1267 Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1268
1269 count = (Long)q.uniqueResult();
1270 }
1271 catch (Exception e) {
1272 throw processException(e);
1273 }
1274 finally {
1275 if (count == null) {
1276 count = Long.valueOf(0);
1277 }
1278
1279 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1280 count);
1281
1282 closeSession(session);
1283 }
1284 }
1285
1286 return count.intValue();
1287 }
1288
1289
1292 public void afterPropertiesSet() {
1293 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1294 com.liferay.portal.util.PropsUtil.get(
1295 "value.object.listener.com.liferay.portal.model.ResourceAction")));
1296
1297 if (listenerClassNames.length > 0) {
1298 try {
1299 List<ModelListener<ResourceAction>> listenersList = new ArrayList<ModelListener<ResourceAction>>();
1300
1301 for (String listenerClassName : listenerClassNames) {
1302 listenersList.add((ModelListener<ResourceAction>)InstanceFactory.newInstance(
1303 listenerClassName));
1304 }
1305
1306 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1307 }
1308 catch (Exception e) {
1309 _log.error(e);
1310 }
1311 }
1312 }
1313
1314 public void destroy() {
1315 EntityCacheUtil.removeCache(ResourceActionImpl.class.getName());
1316 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1317 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
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 = ClusterGroupPersistence.class)
1329 protected ClusterGroupPersistence clusterGroupPersistence;
1330 @BeanReference(type = CompanyPersistence.class)
1331 protected CompanyPersistence companyPersistence;
1332 @BeanReference(type = ContactPersistence.class)
1333 protected ContactPersistence contactPersistence;
1334 @BeanReference(type = CountryPersistence.class)
1335 protected CountryPersistence countryPersistence;
1336 @BeanReference(type = EmailAddressPersistence.class)
1337 protected EmailAddressPersistence emailAddressPersistence;
1338 @BeanReference(type = GroupPersistence.class)
1339 protected GroupPersistence groupPersistence;
1340 @BeanReference(type = ImagePersistence.class)
1341 protected ImagePersistence imagePersistence;
1342 @BeanReference(type = LayoutPersistence.class)
1343 protected LayoutPersistence layoutPersistence;
1344 @BeanReference(type = LayoutPrototypePersistence.class)
1345 protected LayoutPrototypePersistence layoutPrototypePersistence;
1346 @BeanReference(type = LayoutSetPersistence.class)
1347 protected LayoutSetPersistence layoutSetPersistence;
1348 @BeanReference(type = LayoutSetPrototypePersistence.class)
1349 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1350 @BeanReference(type = ListTypePersistence.class)
1351 protected ListTypePersistence listTypePersistence;
1352 @BeanReference(type = LockPersistence.class)
1353 protected LockPersistence lockPersistence;
1354 @BeanReference(type = MembershipRequestPersistence.class)
1355 protected MembershipRequestPersistence membershipRequestPersistence;
1356 @BeanReference(type = OrganizationPersistence.class)
1357 protected OrganizationPersistence organizationPersistence;
1358 @BeanReference(type = OrgGroupPermissionPersistence.class)
1359 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1360 @BeanReference(type = OrgGroupRolePersistence.class)
1361 protected OrgGroupRolePersistence orgGroupRolePersistence;
1362 @BeanReference(type = OrgLaborPersistence.class)
1363 protected OrgLaborPersistence orgLaborPersistence;
1364 @BeanReference(type = PasswordPolicyPersistence.class)
1365 protected PasswordPolicyPersistence passwordPolicyPersistence;
1366 @BeanReference(type = PasswordPolicyRelPersistence.class)
1367 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1368 @BeanReference(type = PasswordTrackerPersistence.class)
1369 protected PasswordTrackerPersistence passwordTrackerPersistence;
1370 @BeanReference(type = PermissionPersistence.class)
1371 protected PermissionPersistence permissionPersistence;
1372 @BeanReference(type = PhonePersistence.class)
1373 protected PhonePersistence phonePersistence;
1374 @BeanReference(type = PluginSettingPersistence.class)
1375 protected PluginSettingPersistence pluginSettingPersistence;
1376 @BeanReference(type = PortletPersistence.class)
1377 protected PortletPersistence portletPersistence;
1378 @BeanReference(type = PortletItemPersistence.class)
1379 protected PortletItemPersistence portletItemPersistence;
1380 @BeanReference(type = PortletPreferencesPersistence.class)
1381 protected PortletPreferencesPersistence portletPreferencesPersistence;
1382 @BeanReference(type = RegionPersistence.class)
1383 protected RegionPersistence regionPersistence;
1384 @BeanReference(type = ReleasePersistence.class)
1385 protected ReleasePersistence releasePersistence;
1386 @BeanReference(type = ResourcePersistence.class)
1387 protected ResourcePersistence resourcePersistence;
1388 @BeanReference(type = ResourceActionPersistence.class)
1389 protected ResourceActionPersistence resourceActionPersistence;
1390 @BeanReference(type = ResourceCodePersistence.class)
1391 protected ResourceCodePersistence resourceCodePersistence;
1392 @BeanReference(type = ResourcePermissionPersistence.class)
1393 protected ResourcePermissionPersistence resourcePermissionPersistence;
1394 @BeanReference(type = RolePersistence.class)
1395 protected RolePersistence rolePersistence;
1396 @BeanReference(type = ServiceComponentPersistence.class)
1397 protected ServiceComponentPersistence serviceComponentPersistence;
1398 @BeanReference(type = ShardPersistence.class)
1399 protected ShardPersistence shardPersistence;
1400 @BeanReference(type = SubscriptionPersistence.class)
1401 protected SubscriptionPersistence subscriptionPersistence;
1402 @BeanReference(type = TicketPersistence.class)
1403 protected TicketPersistence ticketPersistence;
1404 @BeanReference(type = TeamPersistence.class)
1405 protected TeamPersistence teamPersistence;
1406 @BeanReference(type = UserPersistence.class)
1407 protected UserPersistence userPersistence;
1408 @BeanReference(type = UserGroupPersistence.class)
1409 protected UserGroupPersistence userGroupPersistence;
1410 @BeanReference(type = UserGroupGroupRolePersistence.class)
1411 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1412 @BeanReference(type = UserGroupRolePersistence.class)
1413 protected UserGroupRolePersistence userGroupRolePersistence;
1414 @BeanReference(type = UserIdMapperPersistence.class)
1415 protected UserIdMapperPersistence userIdMapperPersistence;
1416 @BeanReference(type = UserTrackerPersistence.class)
1417 protected UserTrackerPersistence userTrackerPersistence;
1418 @BeanReference(type = UserTrackerPathPersistence.class)
1419 protected UserTrackerPathPersistence userTrackerPathPersistence;
1420 @BeanReference(type = WebDAVPropsPersistence.class)
1421 protected WebDAVPropsPersistence webDAVPropsPersistence;
1422 @BeanReference(type = WebsitePersistence.class)
1423 protected WebsitePersistence websitePersistence;
1424 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1425 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1426 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1427 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1428 private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1429 private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1430 private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1431 private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1432 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
1433 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
1434 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?)";
1435 private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
1436 private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
1437 private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?) AND ";
1438 private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
1439 private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
1440 private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = ?)";
1441 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1442 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1443 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1444 private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1445 }