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