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.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.ResourceAction;
041 import com.liferay.portal.model.impl.ResourceActionImpl;
042 import com.liferay.portal.model.impl.ResourceActionModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class ResourceActionPersistenceImpl extends BasePersistenceImpl<ResourceAction>
064 implements ResourceActionPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
076 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
077 ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078 "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
080 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
081 ResourceActionImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
084 ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
087 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
088 ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
089 "findByName",
090 new String[] {
091 String.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
097 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
098 ResourceActionImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
100 new String[] { String.class.getName() },
101 ResourceActionModelImpl.NAME_COLUMN_BITMASK |
102 ResourceActionModelImpl.BITWISEVALUE_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
104 ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
106 new String[] { String.class.getName() });
107
108
115 public List<ResourceAction> findByName(String name)
116 throws SystemException {
117 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
133 public List<ResourceAction> findByName(String name, int start, int end)
134 throws SystemException {
135 return findByName(name, start, end, null);
136 }
137
138
152 public List<ResourceAction> findByName(String name, int start, int end,
153 OrderByComparator orderByComparator) throws SystemException {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
162 finderArgs = new Object[] { name };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
166 finderArgs = new Object[] { name, start, end, orderByComparator };
167 }
168
169 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(finderPath,
170 finderArgs, this);
171
172 if ((list != null) && !list.isEmpty()) {
173 for (ResourceAction resourceAction : list) {
174 if (!Validator.equals(name, resourceAction.getName())) {
175 list = null;
176
177 break;
178 }
179 }
180 }
181
182 if (list == null) {
183 StringBundler query = null;
184
185 if (orderByComparator != null) {
186 query = new StringBundler(3 +
187 (orderByComparator.getOrderByFields().length * 3));
188 }
189 else {
190 query = new StringBundler(3);
191 }
192
193 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
194
195 if (name == null) {
196 query.append(_FINDER_COLUMN_NAME_NAME_1);
197 }
198 else {
199 if (name.equals(StringPool.BLANK)) {
200 query.append(_FINDER_COLUMN_NAME_NAME_3);
201 }
202 else {
203 query.append(_FINDER_COLUMN_NAME_NAME_2);
204 }
205 }
206
207 if (orderByComparator != null) {
208 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209 orderByComparator);
210 }
211 else
212 if (pagination) {
213 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
214 }
215
216 String sql = query.toString();
217
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 Query q = session.createQuery(sql);
224
225 QueryPos qPos = QueryPos.getInstance(q);
226
227 if (name != null) {
228 qPos.add(name);
229 }
230
231 if (!pagination) {
232 list = (List<ResourceAction>)QueryUtil.list(q,
233 getDialect(), start, end, false);
234
235 Collections.sort(list);
236
237 list = new UnmodifiableList<ResourceAction>(list);
238 }
239 else {
240 list = (List<ResourceAction>)QueryUtil.list(q,
241 getDialect(), start, end);
242 }
243
244 cacheResult(list);
245
246 FinderCacheUtil.putResult(finderPath, finderArgs, list);
247 }
248 catch (Exception e) {
249 FinderCacheUtil.removeResult(finderPath, finderArgs);
250
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 return list;
259 }
260
261
270 public ResourceAction findByName_First(String name,
271 OrderByComparator orderByComparator)
272 throws NoSuchResourceActionException, SystemException {
273 ResourceAction resourceAction = fetchByName_First(name,
274 orderByComparator);
275
276 if (resourceAction != null) {
277 return resourceAction;
278 }
279
280 StringBundler msg = new StringBundler(4);
281
282 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283
284 msg.append("name=");
285 msg.append(name);
286
287 msg.append(StringPool.CLOSE_CURLY_BRACE);
288
289 throw new NoSuchResourceActionException(msg.toString());
290 }
291
292
300 public ResourceAction fetchByName_First(String name,
301 OrderByComparator orderByComparator) throws SystemException {
302 List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
303
304 if (!list.isEmpty()) {
305 return list.get(0);
306 }
307
308 return null;
309 }
310
311
320 public ResourceAction findByName_Last(String name,
321 OrderByComparator orderByComparator)
322 throws NoSuchResourceActionException, SystemException {
323 ResourceAction resourceAction = fetchByName_Last(name, orderByComparator);
324
325 if (resourceAction != null) {
326 return resourceAction;
327 }
328
329 StringBundler msg = new StringBundler(4);
330
331 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
332
333 msg.append("name=");
334 msg.append(name);
335
336 msg.append(StringPool.CLOSE_CURLY_BRACE);
337
338 throw new NoSuchResourceActionException(msg.toString());
339 }
340
341
349 public ResourceAction fetchByName_Last(String name,
350 OrderByComparator orderByComparator) throws SystemException {
351 int count = countByName(name);
352
353 List<ResourceAction> list = findByName(name, count - 1, count,
354 orderByComparator);
355
356 if (!list.isEmpty()) {
357 return list.get(0);
358 }
359
360 return null;
361 }
362
363
373 public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
374 String name, OrderByComparator orderByComparator)
375 throws NoSuchResourceActionException, SystemException {
376 ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
377
378 Session session = null;
379
380 try {
381 session = openSession();
382
383 ResourceAction[] array = new ResourceActionImpl[3];
384
385 array[0] = getByName_PrevAndNext(session, resourceAction, name,
386 orderByComparator, true);
387
388 array[1] = resourceAction;
389
390 array[2] = getByName_PrevAndNext(session, resourceAction, name,
391 orderByComparator, false);
392
393 return array;
394 }
395 catch (Exception e) {
396 throw processException(e);
397 }
398 finally {
399 closeSession(session);
400 }
401 }
402
403 protected ResourceAction getByName_PrevAndNext(Session session,
404 ResourceAction resourceAction, String name,
405 OrderByComparator orderByComparator, boolean previous) {
406 StringBundler query = null;
407
408 if (orderByComparator != null) {
409 query = new StringBundler(6 +
410 (orderByComparator.getOrderByFields().length * 6));
411 }
412 else {
413 query = new StringBundler(3);
414 }
415
416 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
417
418 if (name == null) {
419 query.append(_FINDER_COLUMN_NAME_NAME_1);
420 }
421 else {
422 if (name.equals(StringPool.BLANK)) {
423 query.append(_FINDER_COLUMN_NAME_NAME_3);
424 }
425 else {
426 query.append(_FINDER_COLUMN_NAME_NAME_2);
427 }
428 }
429
430 if (orderByComparator != null) {
431 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
432
433 if (orderByConditionFields.length > 0) {
434 query.append(WHERE_AND);
435 }
436
437 for (int i = 0; i < orderByConditionFields.length; i++) {
438 query.append(_ORDER_BY_ENTITY_ALIAS);
439 query.append(orderByConditionFields[i]);
440
441 if ((i + 1) < orderByConditionFields.length) {
442 if (orderByComparator.isAscending() ^ previous) {
443 query.append(WHERE_GREATER_THAN_HAS_NEXT);
444 }
445 else {
446 query.append(WHERE_LESSER_THAN_HAS_NEXT);
447 }
448 }
449 else {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(WHERE_GREATER_THAN);
452 }
453 else {
454 query.append(WHERE_LESSER_THAN);
455 }
456 }
457 }
458
459 query.append(ORDER_BY_CLAUSE);
460
461 String[] orderByFields = orderByComparator.getOrderByFields();
462
463 for (int i = 0; i < orderByFields.length; i++) {
464 query.append(_ORDER_BY_ENTITY_ALIAS);
465 query.append(orderByFields[i]);
466
467 if ((i + 1) < orderByFields.length) {
468 if (orderByComparator.isAscending() ^ previous) {
469 query.append(ORDER_BY_ASC_HAS_NEXT);
470 }
471 else {
472 query.append(ORDER_BY_DESC_HAS_NEXT);
473 }
474 }
475 else {
476 if (orderByComparator.isAscending() ^ previous) {
477 query.append(ORDER_BY_ASC);
478 }
479 else {
480 query.append(ORDER_BY_DESC);
481 }
482 }
483 }
484 }
485 else {
486 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
487 }
488
489 String sql = query.toString();
490
491 Query q = session.createQuery(sql);
492
493 q.setFirstResult(0);
494 q.setMaxResults(2);
495
496 QueryPos qPos = QueryPos.getInstance(q);
497
498 if (name != null) {
499 qPos.add(name);
500 }
501
502 if (orderByComparator != null) {
503 Object[] values = orderByComparator.getOrderByConditionValues(resourceAction);
504
505 for (Object value : values) {
506 qPos.add(value);
507 }
508 }
509
510 List<ResourceAction> list = q.list();
511
512 if (list.size() == 2) {
513 return list.get(1);
514 }
515 else {
516 return null;
517 }
518 }
519
520
526 public void removeByName(String name) throws SystemException {
527 for (ResourceAction resourceAction : findByName(name,
528 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
529 remove(resourceAction);
530 }
531 }
532
533
540 public int countByName(String name) throws SystemException {
541 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
542
543 Object[] finderArgs = new Object[] { name };
544
545 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
546 this);
547
548 if (count == null) {
549 StringBundler query = new StringBundler(2);
550
551 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
552
553 if (name == null) {
554 query.append(_FINDER_COLUMN_NAME_NAME_1);
555 }
556 else {
557 if (name.equals(StringPool.BLANK)) {
558 query.append(_FINDER_COLUMN_NAME_NAME_3);
559 }
560 else {
561 query.append(_FINDER_COLUMN_NAME_NAME_2);
562 }
563 }
564
565 String sql = query.toString();
566
567 Session session = null;
568
569 try {
570 session = openSession();
571
572 Query q = session.createQuery(sql);
573
574 QueryPos qPos = QueryPos.getInstance(q);
575
576 if (name != null) {
577 qPos.add(name);
578 }
579
580 count = (Long)q.uniqueResult();
581
582 FinderCacheUtil.putResult(finderPath, finderArgs, count);
583 }
584 catch (Exception e) {
585 FinderCacheUtil.removeResult(finderPath, finderArgs);
586
587 throw processException(e);
588 }
589 finally {
590 closeSession(session);
591 }
592 }
593
594 return count.intValue();
595 }
596
597 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
598 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
599 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?)";
600 public static final FinderPath FINDER_PATH_FETCH_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
601 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
602 ResourceActionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_A",
603 new String[] { String.class.getName(), String.class.getName() },
604 ResourceActionModelImpl.NAME_COLUMN_BITMASK |
605 ResourceActionModelImpl.ACTIONID_COLUMN_BITMASK);
606 public static final FinderPath FINDER_PATH_COUNT_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
607 ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
608 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_A",
609 new String[] { String.class.getName(), String.class.getName() });
610
611
620 public ResourceAction findByN_A(String name, String actionId)
621 throws NoSuchResourceActionException, SystemException {
622 ResourceAction resourceAction = fetchByN_A(name, actionId);
623
624 if (resourceAction == null) {
625 StringBundler msg = new StringBundler(6);
626
627 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
628
629 msg.append("name=");
630 msg.append(name);
631
632 msg.append(", actionId=");
633 msg.append(actionId);
634
635 msg.append(StringPool.CLOSE_CURLY_BRACE);
636
637 if (_log.isWarnEnabled()) {
638 _log.warn(msg.toString());
639 }
640
641 throw new NoSuchResourceActionException(msg.toString());
642 }
643
644 return resourceAction;
645 }
646
647
655 public ResourceAction fetchByN_A(String name, String actionId)
656 throws SystemException {
657 return fetchByN_A(name, actionId, true);
658 }
659
660
669 public ResourceAction fetchByN_A(String name, String actionId,
670 boolean retrieveFromCache) throws SystemException {
671 Object[] finderArgs = new Object[] { name, actionId };
672
673 Object result = null;
674
675 if (retrieveFromCache) {
676 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
677 finderArgs, this);
678 }
679
680 if (result instanceof ResourceAction) {
681 ResourceAction resourceAction = (ResourceAction)result;
682
683 if (!Validator.equals(name, resourceAction.getName()) ||
684 !Validator.equals(actionId, resourceAction.getActionId())) {
685 result = null;
686 }
687 }
688
689 if (result == null) {
690 StringBundler query = new StringBundler(4);
691
692 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
693
694 if (name == null) {
695 query.append(_FINDER_COLUMN_N_A_NAME_1);
696 }
697 else {
698 if (name.equals(StringPool.BLANK)) {
699 query.append(_FINDER_COLUMN_N_A_NAME_3);
700 }
701 else {
702 query.append(_FINDER_COLUMN_N_A_NAME_2);
703 }
704 }
705
706 if (actionId == null) {
707 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
708 }
709 else {
710 if (actionId.equals(StringPool.BLANK)) {
711 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
712 }
713 else {
714 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
715 }
716 }
717
718 String sql = query.toString();
719
720 Session session = null;
721
722 try {
723 session = openSession();
724
725 Query q = session.createQuery(sql);
726
727 QueryPos qPos = QueryPos.getInstance(q);
728
729 if (name != null) {
730 qPos.add(name);
731 }
732
733 if (actionId != null) {
734 qPos.add(actionId);
735 }
736
737 List<ResourceAction> list = q.list();
738
739 if (list.isEmpty()) {
740 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
741 finderArgs, list);
742 }
743 else {
744 ResourceAction resourceAction = list.get(0);
745
746 result = resourceAction;
747
748 cacheResult(resourceAction);
749
750 if ((resourceAction.getName() == null) ||
751 !resourceAction.getName().equals(name) ||
752 (resourceAction.getActionId() == null) ||
753 !resourceAction.getActionId().equals(actionId)) {
754 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
755 finderArgs, resourceAction);
756 }
757 }
758 }
759 catch (Exception e) {
760 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
761 finderArgs);
762
763 throw processException(e);
764 }
765 finally {
766 closeSession(session);
767 }
768 }
769
770 if (result instanceof List<?>) {
771 return null;
772 }
773 else {
774 return (ResourceAction)result;
775 }
776 }
777
778
786 public ResourceAction removeByN_A(String name, String actionId)
787 throws NoSuchResourceActionException, SystemException {
788 ResourceAction resourceAction = findByN_A(name, actionId);
789
790 return remove(resourceAction);
791 }
792
793
801 public int countByN_A(String name, String actionId)
802 throws SystemException {
803 FinderPath finderPath = FINDER_PATH_COUNT_BY_N_A;
804
805 Object[] finderArgs = new Object[] { name, actionId };
806
807 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
808 this);
809
810 if (count == null) {
811 StringBundler query = new StringBundler(3);
812
813 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
814
815 if (name == null) {
816 query.append(_FINDER_COLUMN_N_A_NAME_1);
817 }
818 else {
819 if (name.equals(StringPool.BLANK)) {
820 query.append(_FINDER_COLUMN_N_A_NAME_3);
821 }
822 else {
823 query.append(_FINDER_COLUMN_N_A_NAME_2);
824 }
825 }
826
827 if (actionId == null) {
828 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
829 }
830 else {
831 if (actionId.equals(StringPool.BLANK)) {
832 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
833 }
834 else {
835 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
836 }
837 }
838
839 String sql = query.toString();
840
841 Session session = null;
842
843 try {
844 session = openSession();
845
846 Query q = session.createQuery(sql);
847
848 QueryPos qPos = QueryPos.getInstance(q);
849
850 if (name != null) {
851 qPos.add(name);
852 }
853
854 if (actionId != null) {
855 qPos.add(actionId);
856 }
857
858 count = (Long)q.uniqueResult();
859
860 FinderCacheUtil.putResult(finderPath, finderArgs, count);
861 }
862 catch (Exception e) {
863 FinderCacheUtil.removeResult(finderPath, finderArgs);
864
865 throw processException(e);
866 }
867 finally {
868 closeSession(session);
869 }
870 }
871
872 return count.intValue();
873 }
874
875 private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
876 private static final String _FINDER_COLUMN_N_A_NAME_2 = "lower(resourceAction.name) = lower(CAST_TEXT(?)) AND ";
877 private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR lower(resourceAction.name) = lower(CAST_TEXT(?))) AND ";
878 private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
879 private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
880 private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = ?)";
881
882
887 public void cacheResult(ResourceAction resourceAction) {
888 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
889 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
890 resourceAction);
891
892 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
893 new Object[] { resourceAction.getName(), resourceAction.getActionId() },
894 resourceAction);
895
896 resourceAction.resetOriginalValues();
897 }
898
899
904 public void cacheResult(List<ResourceAction> resourceActions) {
905 for (ResourceAction resourceAction : resourceActions) {
906 if (EntityCacheUtil.getResult(
907 ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
908 ResourceActionImpl.class, resourceAction.getPrimaryKey()) == null) {
909 cacheResult(resourceAction);
910 }
911 else {
912 resourceAction.resetOriginalValues();
913 }
914 }
915 }
916
917
924 @Override
925 public void clearCache() {
926 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
927 CacheRegistryUtil.clear(ResourceActionImpl.class.getName());
928 }
929
930 EntityCacheUtil.clearCache(ResourceActionImpl.class.getName());
931
932 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
933 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
934 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
935 }
936
937
944 @Override
945 public void clearCache(ResourceAction resourceAction) {
946 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
947 ResourceActionImpl.class, resourceAction.getPrimaryKey());
948
949 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
950 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
951
952 clearUniqueFindersCache(resourceAction);
953 }
954
955 @Override
956 public void clearCache(List<ResourceAction> resourceActions) {
957 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
958 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
959
960 for (ResourceAction resourceAction : resourceActions) {
961 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
962 ResourceActionImpl.class, resourceAction.getPrimaryKey());
963
964 clearUniqueFindersCache(resourceAction);
965 }
966 }
967
968 protected void cacheUniqueFindersCache(ResourceAction resourceAction) {
969 if (resourceAction.isNew()) {
970 Object[] args = new Object[] {
971 resourceAction.getName(),
972
973 resourceAction.getActionId()
974 };
975
976 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, args,
977 Long.valueOf(1));
978 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A, args,
979 resourceAction);
980 }
981 else {
982 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
983
984 if ((resourceActionModelImpl.getColumnBitmask() &
985 FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
986 Object[] args = new Object[] {
987 resourceAction.getName(),
988
989 resourceAction.getActionId()
990 };
991
992 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, args,
993 Long.valueOf(1));
994 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A, args,
995 resourceAction);
996 }
997 }
998 }
999
1000 protected void clearUniqueFindersCache(ResourceAction resourceAction) {
1001 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
1002
1003 Object[] args = new Object[] {
1004 resourceAction.getName(),
1005
1006 resourceAction.getActionId()
1007 };
1008
1009 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
1010 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
1011
1012 if ((resourceActionModelImpl.getColumnBitmask() &
1013 FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
1014 args = new Object[] {
1015 resourceActionModelImpl.getOriginalName(),
1016
1017 resourceActionModelImpl.getOriginalActionId()
1018 };
1019
1020 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
1021 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
1022 }
1023 }
1024
1025
1031 public ResourceAction create(long resourceActionId) {
1032 ResourceAction resourceAction = new ResourceActionImpl();
1033
1034 resourceAction.setNew(true);
1035 resourceAction.setPrimaryKey(resourceActionId);
1036
1037 return resourceAction;
1038 }
1039
1040
1048 public ResourceAction remove(long resourceActionId)
1049 throws NoSuchResourceActionException, SystemException {
1050 return remove(Long.valueOf(resourceActionId));
1051 }
1052
1053
1061 @Override
1062 public ResourceAction remove(Serializable primaryKey)
1063 throws NoSuchResourceActionException, SystemException {
1064 Session session = null;
1065
1066 try {
1067 session = openSession();
1068
1069 ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1070 primaryKey);
1071
1072 if (resourceAction == null) {
1073 if (_log.isWarnEnabled()) {
1074 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1075 }
1076
1077 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1078 primaryKey);
1079 }
1080
1081 return remove(resourceAction);
1082 }
1083 catch (NoSuchResourceActionException nsee) {
1084 throw nsee;
1085 }
1086 catch (Exception e) {
1087 throw processException(e);
1088 }
1089 finally {
1090 closeSession(session);
1091 }
1092 }
1093
1094 @Override
1095 protected ResourceAction removeImpl(ResourceAction resourceAction)
1096 throws SystemException {
1097 resourceAction = toUnwrappedModel(resourceAction);
1098
1099 Session session = null;
1100
1101 try {
1102 session = openSession();
1103
1104 if (!session.contains(resourceAction)) {
1105 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1106 resourceAction.getPrimaryKeyObj());
1107 }
1108
1109 if (resourceAction != null) {
1110 session.delete(resourceAction);
1111 }
1112 }
1113 catch (Exception e) {
1114 throw processException(e);
1115 }
1116 finally {
1117 closeSession(session);
1118 }
1119
1120 if (resourceAction != null) {
1121 clearCache(resourceAction);
1122 }
1123
1124 return resourceAction;
1125 }
1126
1127 @Override
1128 public ResourceAction updateImpl(
1129 com.liferay.portal.model.ResourceAction resourceAction)
1130 throws SystemException {
1131 resourceAction = toUnwrappedModel(resourceAction);
1132
1133 boolean isNew = resourceAction.isNew();
1134
1135 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
1136
1137 Session session = null;
1138
1139 try {
1140 session = openSession();
1141
1142 if (resourceAction.isNew()) {
1143 session.save(resourceAction);
1144
1145 resourceAction.setNew(false);
1146 }
1147 else {
1148 session.merge(resourceAction);
1149 }
1150 }
1151 catch (Exception e) {
1152 throw processException(e);
1153 }
1154 finally {
1155 closeSession(session);
1156 }
1157
1158 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1159
1160 if (isNew || !ResourceActionModelImpl.COLUMN_BITMASK_ENABLED) {
1161 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1162 }
1163
1164 else {
1165 if ((resourceActionModelImpl.getColumnBitmask() &
1166 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
1167 Object[] args = new Object[] {
1168 resourceActionModelImpl.getOriginalName()
1169 };
1170
1171 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1172 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
1173 args);
1174
1175 args = new Object[] { resourceActionModelImpl.getName() };
1176
1177 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1178 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
1179 args);
1180 }
1181 }
1182
1183 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1184 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
1185 resourceAction);
1186
1187 clearUniqueFindersCache(resourceAction);
1188 cacheUniqueFindersCache(resourceAction);
1189
1190 return resourceAction;
1191 }
1192
1193 protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
1194 if (resourceAction instanceof ResourceActionImpl) {
1195 return resourceAction;
1196 }
1197
1198 ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
1199
1200 resourceActionImpl.setNew(resourceAction.isNew());
1201 resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
1202
1203 resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
1204 resourceActionImpl.setName(resourceAction.getName());
1205 resourceActionImpl.setActionId(resourceAction.getActionId());
1206 resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
1207
1208 return resourceActionImpl;
1209 }
1210
1211
1219 @Override
1220 public ResourceAction findByPrimaryKey(Serializable primaryKey)
1221 throws NoSuchModelException, SystemException {
1222 return findByPrimaryKey(((Long)primaryKey).longValue());
1223 }
1224
1225
1233 public ResourceAction findByPrimaryKey(long resourceActionId)
1234 throws NoSuchResourceActionException, SystemException {
1235 ResourceAction resourceAction = fetchByPrimaryKey(resourceActionId);
1236
1237 if (resourceAction == null) {
1238 if (_log.isWarnEnabled()) {
1239 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceActionId);
1240 }
1241
1242 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1243 resourceActionId);
1244 }
1245
1246 return resourceAction;
1247 }
1248
1249
1256 @Override
1257 public ResourceAction fetchByPrimaryKey(Serializable primaryKey)
1258 throws SystemException {
1259 return fetchByPrimaryKey(((Long)primaryKey).longValue());
1260 }
1261
1262
1269 public ResourceAction fetchByPrimaryKey(long resourceActionId)
1270 throws SystemException {
1271 ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1272 ResourceActionImpl.class, resourceActionId);
1273
1274 if (resourceAction == _nullResourceAction) {
1275 return null;
1276 }
1277
1278 if (resourceAction == null) {
1279 Session session = null;
1280
1281 try {
1282 session = openSession();
1283
1284 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1285 Long.valueOf(resourceActionId));
1286
1287 if (resourceAction != null) {
1288 cacheResult(resourceAction);
1289 }
1290 else {
1291 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1292 ResourceActionImpl.class, resourceActionId,
1293 _nullResourceAction);
1294 }
1295 }
1296 catch (Exception e) {
1297 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1298 ResourceActionImpl.class, resourceActionId);
1299
1300 throw processException(e);
1301 }
1302 finally {
1303 closeSession(session);
1304 }
1305 }
1306
1307 return resourceAction;
1308 }
1309
1310
1316 public List<ResourceAction> findAll() throws SystemException {
1317 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1318 }
1319
1320
1332 public List<ResourceAction> findAll(int start, int end)
1333 throws SystemException {
1334 return findAll(start, end, null);
1335 }
1336
1337
1350 public List<ResourceAction> findAll(int start, int end,
1351 OrderByComparator orderByComparator) throws SystemException {
1352 boolean pagination = true;
1353 FinderPath finderPath = null;
1354 Object[] finderArgs = null;
1355
1356 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1357 (orderByComparator == null)) {
1358 pagination = false;
1359 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1360 finderArgs = FINDER_ARGS_EMPTY;
1361 }
1362 else {
1363 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1364 finderArgs = new Object[] { start, end, orderByComparator };
1365 }
1366
1367 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(finderPath,
1368 finderArgs, this);
1369
1370 if (list == null) {
1371 StringBundler query = null;
1372 String sql = null;
1373
1374 if (orderByComparator != null) {
1375 query = new StringBundler(2 +
1376 (orderByComparator.getOrderByFields().length * 3));
1377
1378 query.append(_SQL_SELECT_RESOURCEACTION);
1379
1380 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1381 orderByComparator);
1382
1383 sql = query.toString();
1384 }
1385 else {
1386 sql = _SQL_SELECT_RESOURCEACTION;
1387
1388 if (pagination) {
1389 sql = sql.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
1390 }
1391 }
1392
1393 Session session = null;
1394
1395 try {
1396 session = openSession();
1397
1398 Query q = session.createQuery(sql);
1399
1400 if (!pagination) {
1401 list = (List<ResourceAction>)QueryUtil.list(q,
1402 getDialect(), start, end, false);
1403
1404 Collections.sort(list);
1405
1406 list = new UnmodifiableList<ResourceAction>(list);
1407 }
1408 else {
1409 list = (List<ResourceAction>)QueryUtil.list(q,
1410 getDialect(), start, end);
1411 }
1412
1413 cacheResult(list);
1414
1415 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1416 }
1417 catch (Exception e) {
1418 FinderCacheUtil.removeResult(finderPath, finderArgs);
1419
1420 throw processException(e);
1421 }
1422 finally {
1423 closeSession(session);
1424 }
1425 }
1426
1427 return list;
1428 }
1429
1430
1435 public void removeAll() throws SystemException {
1436 for (ResourceAction resourceAction : findAll()) {
1437 remove(resourceAction);
1438 }
1439 }
1440
1441
1447 public int countAll() throws SystemException {
1448 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1449 FINDER_ARGS_EMPTY, this);
1450
1451 if (count == null) {
1452 Session session = null;
1453
1454 try {
1455 session = openSession();
1456
1457 Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1458
1459 count = (Long)q.uniqueResult();
1460
1461 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1462 FINDER_ARGS_EMPTY, count);
1463 }
1464 catch (Exception e) {
1465 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1466 FINDER_ARGS_EMPTY);
1467
1468 throw processException(e);
1469 }
1470 finally {
1471 closeSession(session);
1472 }
1473 }
1474
1475 return count.intValue();
1476 }
1477
1478
1481 public void afterPropertiesSet() {
1482 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1483 com.liferay.portal.util.PropsUtil.get(
1484 "value.object.listener.com.liferay.portal.model.ResourceAction")));
1485
1486 if (listenerClassNames.length > 0) {
1487 try {
1488 List<ModelListener<ResourceAction>> listenersList = new ArrayList<ModelListener<ResourceAction>>();
1489
1490 for (String listenerClassName : listenerClassNames) {
1491 listenersList.add((ModelListener<ResourceAction>)InstanceFactory.newInstance(
1492 listenerClassName));
1493 }
1494
1495 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1496 }
1497 catch (Exception e) {
1498 _log.error(e);
1499 }
1500 }
1501 }
1502
1503 public void destroy() {
1504 EntityCacheUtil.removeCache(ResourceActionImpl.class.getName());
1505 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1506 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1507 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1508 }
1509
1510 private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1511 private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1512 private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1513 private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1514 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1515 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1516 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1517 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1518 private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1519 private static ResourceAction _nullResourceAction = new ResourceActionImpl() {
1520 @Override
1521 public Object clone() {
1522 return this;
1523 }
1524
1525 @Override
1526 public CacheModel<ResourceAction> toCacheModel() {
1527 return _nullResourceActionCacheModel;
1528 }
1529 };
1530
1531 private static CacheModel<ResourceAction> _nullResourceActionCacheModel = new CacheModel<ResourceAction>() {
1532 public ResourceAction toEntityModel() {
1533 return _nullResourceAction;
1534 }
1535 };
1536 }