1
14
15 package com.liferay.portal.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.NoSuchResourceActionException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderPath;
24 import com.liferay.portal.kernel.dao.orm.Query;
25 import com.liferay.portal.kernel.dao.orm.QueryPos;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.dao.orm.Session;
28 import com.liferay.portal.kernel.exception.SystemException;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.kernel.util.GetterUtil;
32 import com.liferay.portal.kernel.util.InstanceFactory;
33 import com.liferay.portal.kernel.util.OrderByComparator;
34 import com.liferay.portal.kernel.util.StringBundler;
35 import com.liferay.portal.kernel.util.StringPool;
36 import com.liferay.portal.kernel.util.StringUtil;
37 import com.liferay.portal.kernel.util.Validator;
38 import com.liferay.portal.model.ModelListener;
39 import com.liferay.portal.model.ResourceAction;
40 import com.liferay.portal.model.impl.ResourceActionImpl;
41 import com.liferay.portal.model.impl.ResourceActionModelImpl;
42 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43
44 import java.io.Serializable;
45
46 import java.util.ArrayList;
47 import java.util.Collections;
48 import java.util.List;
49
50
63 public class ResourceActionPersistenceImpl extends BasePersistenceImpl<ResourceAction>
64 implements ResourceActionPersistence {
65 public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.class.getName();
66 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
67 ".List";
68 public static final FinderPath FINDER_PATH_FIND_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
69 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
70 FINDER_CLASS_NAME_LIST, "findByName",
71 new String[] {
72 String.class.getName(),
73
74 "java.lang.Integer", "java.lang.Integer",
75 "com.liferay.portal.kernel.util.OrderByComparator"
76 });
77 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
78 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
79 FINDER_CLASS_NAME_LIST, "countByName",
80 new String[] { String.class.getName() });
81 public static final FinderPath FINDER_PATH_FETCH_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
82 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
83 FINDER_CLASS_NAME_ENTITY, "fetchByN_A",
84 new String[] { String.class.getName(), String.class.getName() });
85 public static final FinderPath FINDER_PATH_COUNT_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
86 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
87 FINDER_CLASS_NAME_LIST, "countByN_A",
88 new String[] { String.class.getName(), String.class.getName() });
89 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
90 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
91 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
92 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
93 ResourceActionModelImpl.FINDER_CACHE_ENABLED,
94 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
95
96 public void cacheResult(ResourceAction resourceAction) {
97 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
98 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
99 resourceAction);
100
101 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
102 new Object[] { resourceAction.getName(), resourceAction.getActionId() },
103 resourceAction);
104 }
105
106 public void cacheResult(List<ResourceAction> resourceActions) {
107 for (ResourceAction resourceAction : resourceActions) {
108 if (EntityCacheUtil.getResult(
109 ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
110 ResourceActionImpl.class,
111 resourceAction.getPrimaryKey(), this) == null) {
112 cacheResult(resourceAction);
113 }
114 }
115 }
116
117 public void clearCache() {
118 CacheRegistry.clear(ResourceActionImpl.class.getName());
119 EntityCacheUtil.clearCache(ResourceActionImpl.class.getName());
120 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
121 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
122 }
123
124 public void clearCache(ResourceAction resourceAction) {
125 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
126 ResourceActionImpl.class, resourceAction.getPrimaryKey());
127
128 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
129 new Object[] { resourceAction.getName(), resourceAction.getActionId() });
130 }
131
132 public ResourceAction create(long resourceActionId) {
133 ResourceAction resourceAction = new ResourceActionImpl();
134
135 resourceAction.setNew(true);
136 resourceAction.setPrimaryKey(resourceActionId);
137
138 return resourceAction;
139 }
140
141 public ResourceAction remove(Serializable primaryKey)
142 throws NoSuchModelException, SystemException {
143 return remove(((Long)primaryKey).longValue());
144 }
145
146 public ResourceAction remove(long resourceActionId)
147 throws NoSuchResourceActionException, SystemException {
148 Session session = null;
149
150 try {
151 session = openSession();
152
153 ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
154 new Long(resourceActionId));
155
156 if (resourceAction == null) {
157 if (_log.isWarnEnabled()) {
158 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
159 resourceActionId);
160 }
161
162 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
163 resourceActionId);
164 }
165
166 return remove(resourceAction);
167 }
168 catch (NoSuchResourceActionException nsee) {
169 throw nsee;
170 }
171 catch (Exception e) {
172 throw processException(e);
173 }
174 finally {
175 closeSession(session);
176 }
177 }
178
179 public ResourceAction remove(ResourceAction resourceAction)
180 throws SystemException {
181 for (ModelListener<ResourceAction> listener : listeners) {
182 listener.onBeforeRemove(resourceAction);
183 }
184
185 resourceAction = removeImpl(resourceAction);
186
187 for (ModelListener<ResourceAction> listener : listeners) {
188 listener.onAfterRemove(resourceAction);
189 }
190
191 return resourceAction;
192 }
193
194 protected ResourceAction removeImpl(ResourceAction resourceAction)
195 throws SystemException {
196 resourceAction = toUnwrappedModel(resourceAction);
197
198 Session session = null;
199
200 try {
201 session = openSession();
202
203 if (resourceAction.isCachedModel() || BatchSessionUtil.isEnabled()) {
204 Object staleObject = session.get(ResourceActionImpl.class,
205 resourceAction.getPrimaryKeyObj());
206
207 if (staleObject != null) {
208 session.evict(staleObject);
209 }
210 }
211
212 session.delete(resourceAction);
213
214 session.flush();
215 }
216 catch (Exception e) {
217 throw processException(e);
218 }
219 finally {
220 closeSession(session);
221 }
222
223 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
224
225 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
226
227 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
228 new Object[] {
229 resourceActionModelImpl.getOriginalName(),
230
231 resourceActionModelImpl.getOriginalActionId()
232 });
233
234 EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
235 ResourceActionImpl.class, resourceAction.getPrimaryKey());
236
237 return resourceAction;
238 }
239
240 public ResourceAction updateImpl(
241 com.liferay.portal.model.ResourceAction resourceAction, boolean merge)
242 throws SystemException {
243 resourceAction = toUnwrappedModel(resourceAction);
244
245 boolean isNew = resourceAction.isNew();
246
247 ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
248
249 Session session = null;
250
251 try {
252 session = openSession();
253
254 BatchSessionUtil.update(session, resourceAction, merge);
255
256 resourceAction.setNew(false);
257 }
258 catch (Exception e) {
259 throw processException(e);
260 }
261 finally {
262 closeSession(session);
263 }
264
265 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
266
267 EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
268 ResourceActionImpl.class, resourceAction.getPrimaryKey(),
269 resourceAction);
270
271 if (!isNew &&
272 (!Validator.equals(resourceAction.getName(),
273 resourceActionModelImpl.getOriginalName()) ||
274 !Validator.equals(resourceAction.getActionId(),
275 resourceActionModelImpl.getOriginalActionId()))) {
276 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
277 new Object[] {
278 resourceActionModelImpl.getOriginalName(),
279
280 resourceActionModelImpl.getOriginalActionId()
281 });
282 }
283
284 if (isNew ||
285 (!Validator.equals(resourceAction.getName(),
286 resourceActionModelImpl.getOriginalName()) ||
287 !Validator.equals(resourceAction.getActionId(),
288 resourceActionModelImpl.getOriginalActionId()))) {
289 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
290 new Object[] {
291 resourceAction.getName(),
292
293 resourceAction.getActionId()
294 }, resourceAction);
295 }
296
297 return resourceAction;
298 }
299
300 protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
301 if (resourceAction instanceof ResourceActionImpl) {
302 return resourceAction;
303 }
304
305 ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
306
307 resourceActionImpl.setNew(resourceAction.isNew());
308 resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
309
310 resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
311 resourceActionImpl.setName(resourceAction.getName());
312 resourceActionImpl.setActionId(resourceAction.getActionId());
313 resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
314
315 return resourceActionImpl;
316 }
317
318 public ResourceAction findByPrimaryKey(Serializable primaryKey)
319 throws NoSuchModelException, SystemException {
320 return findByPrimaryKey(((Long)primaryKey).longValue());
321 }
322
323 public ResourceAction findByPrimaryKey(long resourceActionId)
324 throws NoSuchResourceActionException, SystemException {
325 ResourceAction resourceAction = fetchByPrimaryKey(resourceActionId);
326
327 if (resourceAction == null) {
328 if (_log.isWarnEnabled()) {
329 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceActionId);
330 }
331
332 throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
333 resourceActionId);
334 }
335
336 return resourceAction;
337 }
338
339 public ResourceAction fetchByPrimaryKey(Serializable primaryKey)
340 throws SystemException {
341 return fetchByPrimaryKey(((Long)primaryKey).longValue());
342 }
343
344 public ResourceAction fetchByPrimaryKey(long resourceActionId)
345 throws SystemException {
346 ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
347 ResourceActionImpl.class, resourceActionId, this);
348
349 if (resourceAction == null) {
350 Session session = null;
351
352 try {
353 session = openSession();
354
355 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
356 new Long(resourceActionId));
357 }
358 catch (Exception e) {
359 throw processException(e);
360 }
361 finally {
362 if (resourceAction != null) {
363 cacheResult(resourceAction);
364 }
365
366 closeSession(session);
367 }
368 }
369
370 return resourceAction;
371 }
372
373 public List<ResourceAction> findByName(String name)
374 throws SystemException {
375 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
376 }
377
378 public List<ResourceAction> findByName(String name, int start, int end)
379 throws SystemException {
380 return findByName(name, start, end, null);
381 }
382
383 public List<ResourceAction> findByName(String name, int start, int end,
384 OrderByComparator orderByComparator) throws SystemException {
385 Object[] finderArgs = new Object[] {
386 name,
387
388 String.valueOf(start), String.valueOf(end),
389 String.valueOf(orderByComparator)
390 };
391
392 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NAME,
393 finderArgs, this);
394
395 if (list == null) {
396 Session session = null;
397
398 try {
399 session = openSession();
400
401 StringBundler query = null;
402
403 if (orderByComparator != null) {
404 query = new StringBundler(3 +
405 (orderByComparator.getOrderByFields().length * 3));
406 }
407 else {
408 query = new StringBundler(3);
409 }
410
411 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
412
413 if (name == null) {
414 query.append(_FINDER_COLUMN_NAME_NAME_1);
415 }
416 else {
417 if (name.equals(StringPool.BLANK)) {
418 query.append(_FINDER_COLUMN_NAME_NAME_3);
419 }
420 else {
421 query.append(_FINDER_COLUMN_NAME_NAME_2);
422 }
423 }
424
425 if (orderByComparator != null) {
426 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
427 orderByComparator);
428 }
429
430 else {
431 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
432 }
433
434 String sql = query.toString();
435
436 Query q = session.createQuery(sql);
437
438 QueryPos qPos = QueryPos.getInstance(q);
439
440 if (name != null) {
441 qPos.add(name);
442 }
443
444 list = (List<ResourceAction>)QueryUtil.list(q, getDialect(),
445 start, end);
446 }
447 catch (Exception e) {
448 throw processException(e);
449 }
450 finally {
451 if (list == null) {
452 list = new ArrayList<ResourceAction>();
453 }
454
455 cacheResult(list);
456
457 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NAME, finderArgs,
458 list);
459
460 closeSession(session);
461 }
462 }
463
464 return list;
465 }
466
467 public ResourceAction findByName_First(String name,
468 OrderByComparator orderByComparator)
469 throws NoSuchResourceActionException, SystemException {
470 List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
471
472 if (list.isEmpty()) {
473 StringBundler msg = new StringBundler(4);
474
475 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
476
477 msg.append("name=");
478 msg.append(name);
479
480 msg.append(StringPool.CLOSE_CURLY_BRACE);
481
482 throw new NoSuchResourceActionException(msg.toString());
483 }
484 else {
485 return list.get(0);
486 }
487 }
488
489 public ResourceAction findByName_Last(String name,
490 OrderByComparator orderByComparator)
491 throws NoSuchResourceActionException, SystemException {
492 int count = countByName(name);
493
494 List<ResourceAction> list = findByName(name, count - 1, count,
495 orderByComparator);
496
497 if (list.isEmpty()) {
498 StringBundler msg = new StringBundler(4);
499
500 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
501
502 msg.append("name=");
503 msg.append(name);
504
505 msg.append(StringPool.CLOSE_CURLY_BRACE);
506
507 throw new NoSuchResourceActionException(msg.toString());
508 }
509 else {
510 return list.get(0);
511 }
512 }
513
514 public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
515 String name, OrderByComparator orderByComparator)
516 throws NoSuchResourceActionException, SystemException {
517 ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
518
519 Session session = null;
520
521 try {
522 session = openSession();
523
524 ResourceAction[] array = new ResourceActionImpl[3];
525
526 array[0] = getByName_PrevAndNext(session, resourceAction, name,
527 orderByComparator, true);
528
529 array[1] = resourceAction;
530
531 array[2] = getByName_PrevAndNext(session, resourceAction, name,
532 orderByComparator, false);
533
534 return array;
535 }
536 catch (Exception e) {
537 throw processException(e);
538 }
539 finally {
540 closeSession(session);
541 }
542 }
543
544 protected ResourceAction getByName_PrevAndNext(Session session,
545 ResourceAction resourceAction, String name,
546 OrderByComparator orderByComparator, boolean previous) {
547 StringBundler query = null;
548
549 if (orderByComparator != null) {
550 query = new StringBundler(6 +
551 (orderByComparator.getOrderByFields().length * 6));
552 }
553 else {
554 query = new StringBundler(3);
555 }
556
557 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
558
559 if (name == null) {
560 query.append(_FINDER_COLUMN_NAME_NAME_1);
561 }
562 else {
563 if (name.equals(StringPool.BLANK)) {
564 query.append(_FINDER_COLUMN_NAME_NAME_3);
565 }
566 else {
567 query.append(_FINDER_COLUMN_NAME_NAME_2);
568 }
569 }
570
571 if (orderByComparator != null) {
572 String[] orderByFields = orderByComparator.getOrderByFields();
573
574 if (orderByFields.length > 0) {
575 query.append(WHERE_AND);
576 }
577
578 for (int i = 0; i < orderByFields.length; i++) {
579 query.append(_ORDER_BY_ENTITY_ALIAS);
580 query.append(orderByFields[i]);
581
582 if ((i + 1) < orderByFields.length) {
583 if (orderByComparator.isAscending() ^ previous) {
584 query.append(WHERE_GREATER_THAN_HAS_NEXT);
585 }
586 else {
587 query.append(WHERE_LESSER_THAN_HAS_NEXT);
588 }
589 }
590 else {
591 if (orderByComparator.isAscending() ^ previous) {
592 query.append(WHERE_GREATER_THAN);
593 }
594 else {
595 query.append(WHERE_LESSER_THAN);
596 }
597 }
598 }
599
600 query.append(ORDER_BY_CLAUSE);
601
602 for (int i = 0; i < orderByFields.length; i++) {
603 query.append(_ORDER_BY_ENTITY_ALIAS);
604 query.append(orderByFields[i]);
605
606 if ((i + 1) < orderByFields.length) {
607 if (orderByComparator.isAscending() ^ previous) {
608 query.append(ORDER_BY_ASC_HAS_NEXT);
609 }
610 else {
611 query.append(ORDER_BY_DESC_HAS_NEXT);
612 }
613 }
614 else {
615 if (orderByComparator.isAscending() ^ previous) {
616 query.append(ORDER_BY_ASC);
617 }
618 else {
619 query.append(ORDER_BY_DESC);
620 }
621 }
622 }
623 }
624
625 else {
626 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
627 }
628
629 String sql = query.toString();
630
631 Query q = session.createQuery(sql);
632
633 q.setFirstResult(0);
634 q.setMaxResults(2);
635
636 QueryPos qPos = QueryPos.getInstance(q);
637
638 if (name != null) {
639 qPos.add(name);
640 }
641
642 if (orderByComparator != null) {
643 Object[] values = orderByComparator.getOrderByValues(resourceAction);
644
645 for (Object value : values) {
646 qPos.add(value);
647 }
648 }
649
650 List<ResourceAction> list = q.list();
651
652 if (list.size() == 2) {
653 return list.get(1);
654 }
655 else {
656 return null;
657 }
658 }
659
660 public ResourceAction findByN_A(String name, String actionId)
661 throws NoSuchResourceActionException, SystemException {
662 ResourceAction resourceAction = fetchByN_A(name, actionId);
663
664 if (resourceAction == null) {
665 StringBundler msg = new StringBundler(6);
666
667 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
668
669 msg.append("name=");
670 msg.append(name);
671
672 msg.append(", actionId=");
673 msg.append(actionId);
674
675 msg.append(StringPool.CLOSE_CURLY_BRACE);
676
677 if (_log.isWarnEnabled()) {
678 _log.warn(msg.toString());
679 }
680
681 throw new NoSuchResourceActionException(msg.toString());
682 }
683
684 return resourceAction;
685 }
686
687 public ResourceAction fetchByN_A(String name, String actionId)
688 throws SystemException {
689 return fetchByN_A(name, actionId, true);
690 }
691
692 public ResourceAction fetchByN_A(String name, String actionId,
693 boolean retrieveFromCache) throws SystemException {
694 Object[] finderArgs = new Object[] { name, actionId };
695
696 Object result = null;
697
698 if (retrieveFromCache) {
699 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
700 finderArgs, this);
701 }
702
703 if (result == null) {
704 Session session = null;
705
706 try {
707 session = openSession();
708
709 StringBundler query = new StringBundler(4);
710
711 query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
712
713 if (name == null) {
714 query.append(_FINDER_COLUMN_N_A_NAME_1);
715 }
716 else {
717 if (name.equals(StringPool.BLANK)) {
718 query.append(_FINDER_COLUMN_N_A_NAME_3);
719 }
720 else {
721 query.append(_FINDER_COLUMN_N_A_NAME_2);
722 }
723 }
724
725 if (actionId == null) {
726 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
727 }
728 else {
729 if (actionId.equals(StringPool.BLANK)) {
730 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
731 }
732 else {
733 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
734 }
735 }
736
737 query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
738
739 String sql = query.toString();
740
741 Query q = session.createQuery(sql);
742
743 QueryPos qPos = QueryPos.getInstance(q);
744
745 if (name != null) {
746 qPos.add(name);
747 }
748
749 if (actionId != null) {
750 qPos.add(actionId);
751 }
752
753 List<ResourceAction> list = q.list();
754
755 result = list;
756
757 ResourceAction resourceAction = null;
758
759 if (list.isEmpty()) {
760 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
761 finderArgs, list);
762 }
763 else {
764 resourceAction = list.get(0);
765
766 cacheResult(resourceAction);
767
768 if ((resourceAction.getName() == null) ||
769 !resourceAction.getName().equals(name) ||
770 (resourceAction.getActionId() == null) ||
771 !resourceAction.getActionId().equals(actionId)) {
772 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
773 finderArgs, resourceAction);
774 }
775 }
776
777 return resourceAction;
778 }
779 catch (Exception e) {
780 throw processException(e);
781 }
782 finally {
783 if (result == null) {
784 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
785 finderArgs, new ArrayList<ResourceAction>());
786 }
787
788 closeSession(session);
789 }
790 }
791 else {
792 if (result instanceof List<?>) {
793 return null;
794 }
795 else {
796 return (ResourceAction)result;
797 }
798 }
799 }
800
801 public List<ResourceAction> findAll() throws SystemException {
802 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
803 }
804
805 public List<ResourceAction> findAll(int start, int end)
806 throws SystemException {
807 return findAll(start, end, null);
808 }
809
810 public List<ResourceAction> findAll(int start, int end,
811 OrderByComparator orderByComparator) throws SystemException {
812 Object[] finderArgs = new Object[] {
813 String.valueOf(start), String.valueOf(end),
814 String.valueOf(orderByComparator)
815 };
816
817 List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
818 finderArgs, this);
819
820 if (list == null) {
821 Session session = null;
822
823 try {
824 session = openSession();
825
826 StringBundler query = null;
827 String sql = null;
828
829 if (orderByComparator != null) {
830 query = new StringBundler(2 +
831 (orderByComparator.getOrderByFields().length * 3));
832
833 query.append(_SQL_SELECT_RESOURCEACTION);
834
835 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
836 orderByComparator);
837
838 sql = query.toString();
839 }
840
841 else {
842 sql = _SQL_SELECT_RESOURCEACTION.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
843 }
844
845 Query q = session.createQuery(sql);
846
847 if (orderByComparator == null) {
848 list = (List<ResourceAction>)QueryUtil.list(q,
849 getDialect(), start, end, false);
850
851 Collections.sort(list);
852 }
853 else {
854 list = (List<ResourceAction>)QueryUtil.list(q,
855 getDialect(), start, end);
856 }
857 }
858 catch (Exception e) {
859 throw processException(e);
860 }
861 finally {
862 if (list == null) {
863 list = new ArrayList<ResourceAction>();
864 }
865
866 cacheResult(list);
867
868 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
869
870 closeSession(session);
871 }
872 }
873
874 return list;
875 }
876
877 public void removeByName(String name) throws SystemException {
878 for (ResourceAction resourceAction : findByName(name)) {
879 remove(resourceAction);
880 }
881 }
882
883 public void removeByN_A(String name, String actionId)
884 throws NoSuchResourceActionException, SystemException {
885 ResourceAction resourceAction = findByN_A(name, actionId);
886
887 remove(resourceAction);
888 }
889
890 public void removeAll() throws SystemException {
891 for (ResourceAction resourceAction : findAll()) {
892 remove(resourceAction);
893 }
894 }
895
896 public int countByName(String name) throws SystemException {
897 Object[] finderArgs = new Object[] { name };
898
899 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
900 finderArgs, this);
901
902 if (count == null) {
903 Session session = null;
904
905 try {
906 session = openSession();
907
908 StringBundler query = new StringBundler(2);
909
910 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
911
912 if (name == null) {
913 query.append(_FINDER_COLUMN_NAME_NAME_1);
914 }
915 else {
916 if (name.equals(StringPool.BLANK)) {
917 query.append(_FINDER_COLUMN_NAME_NAME_3);
918 }
919 else {
920 query.append(_FINDER_COLUMN_NAME_NAME_2);
921 }
922 }
923
924 String sql = query.toString();
925
926 Query q = session.createQuery(sql);
927
928 QueryPos qPos = QueryPos.getInstance(q);
929
930 if (name != null) {
931 qPos.add(name);
932 }
933
934 count = (Long)q.uniqueResult();
935 }
936 catch (Exception e) {
937 throw processException(e);
938 }
939 finally {
940 if (count == null) {
941 count = Long.valueOf(0);
942 }
943
944 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
945 finderArgs, count);
946
947 closeSession(session);
948 }
949 }
950
951 return count.intValue();
952 }
953
954 public int countByN_A(String name, String actionId)
955 throws SystemException {
956 Object[] finderArgs = new Object[] { name, actionId };
957
958 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_A,
959 finderArgs, this);
960
961 if (count == null) {
962 Session session = null;
963
964 try {
965 session = openSession();
966
967 StringBundler query = new StringBundler(3);
968
969 query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
970
971 if (name == null) {
972 query.append(_FINDER_COLUMN_N_A_NAME_1);
973 }
974 else {
975 if (name.equals(StringPool.BLANK)) {
976 query.append(_FINDER_COLUMN_N_A_NAME_3);
977 }
978 else {
979 query.append(_FINDER_COLUMN_N_A_NAME_2);
980 }
981 }
982
983 if (actionId == null) {
984 query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
985 }
986 else {
987 if (actionId.equals(StringPool.BLANK)) {
988 query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
989 }
990 else {
991 query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
992 }
993 }
994
995 String sql = query.toString();
996
997 Query q = session.createQuery(sql);
998
999 QueryPos qPos = QueryPos.getInstance(q);
1000
1001 if (name != null) {
1002 qPos.add(name);
1003 }
1004
1005 if (actionId != null) {
1006 qPos.add(actionId);
1007 }
1008
1009 count = (Long)q.uniqueResult();
1010 }
1011 catch (Exception e) {
1012 throw processException(e);
1013 }
1014 finally {
1015 if (count == null) {
1016 count = Long.valueOf(0);
1017 }
1018
1019 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, finderArgs,
1020 count);
1021
1022 closeSession(session);
1023 }
1024 }
1025
1026 return count.intValue();
1027 }
1028
1029 public int countAll() throws SystemException {
1030 Object[] finderArgs = new Object[0];
1031
1032 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1033 finderArgs, this);
1034
1035 if (count == null) {
1036 Session session = null;
1037
1038 try {
1039 session = openSession();
1040
1041 Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1042
1043 count = (Long)q.uniqueResult();
1044 }
1045 catch (Exception e) {
1046 throw processException(e);
1047 }
1048 finally {
1049 if (count == null) {
1050 count = Long.valueOf(0);
1051 }
1052
1053 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1054 count);
1055
1056 closeSession(session);
1057 }
1058 }
1059
1060 return count.intValue();
1061 }
1062
1063 public void afterPropertiesSet() {
1064 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1065 com.liferay.portal.util.PropsUtil.get(
1066 "value.object.listener.com.liferay.portal.model.ResourceAction")));
1067
1068 if (listenerClassNames.length > 0) {
1069 try {
1070 List<ModelListener<ResourceAction>> listenersList = new ArrayList<ModelListener<ResourceAction>>();
1071
1072 for (String listenerClassName : listenerClassNames) {
1073 listenersList.add((ModelListener<ResourceAction>)InstanceFactory.newInstance(
1074 listenerClassName));
1075 }
1076
1077 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1078 }
1079 catch (Exception e) {
1080 _log.error(e);
1081 }
1082 }
1083 }
1084
1085 @BeanReference(type = AccountPersistence.class)
1086 protected AccountPersistence accountPersistence;
1087 @BeanReference(type = AddressPersistence.class)
1088 protected AddressPersistence addressPersistence;
1089 @BeanReference(type = BrowserTrackerPersistence.class)
1090 protected BrowserTrackerPersistence browserTrackerPersistence;
1091 @BeanReference(type = ClassNamePersistence.class)
1092 protected ClassNamePersistence classNamePersistence;
1093 @BeanReference(type = CompanyPersistence.class)
1094 protected CompanyPersistence companyPersistence;
1095 @BeanReference(type = ContactPersistence.class)
1096 protected ContactPersistence contactPersistence;
1097 @BeanReference(type = CountryPersistence.class)
1098 protected CountryPersistence countryPersistence;
1099 @BeanReference(type = EmailAddressPersistence.class)
1100 protected EmailAddressPersistence emailAddressPersistence;
1101 @BeanReference(type = GroupPersistence.class)
1102 protected GroupPersistence groupPersistence;
1103 @BeanReference(type = ImagePersistence.class)
1104 protected ImagePersistence imagePersistence;
1105 @BeanReference(type = LayoutPersistence.class)
1106 protected LayoutPersistence layoutPersistence;
1107 @BeanReference(type = LayoutPrototypePersistence.class)
1108 protected LayoutPrototypePersistence layoutPrototypePersistence;
1109 @BeanReference(type = LayoutSetPersistence.class)
1110 protected LayoutSetPersistence layoutSetPersistence;
1111 @BeanReference(type = LayoutSetPrototypePersistence.class)
1112 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1113 @BeanReference(type = ListTypePersistence.class)
1114 protected ListTypePersistence listTypePersistence;
1115 @BeanReference(type = LockPersistence.class)
1116 protected LockPersistence lockPersistence;
1117 @BeanReference(type = MembershipRequestPersistence.class)
1118 protected MembershipRequestPersistence membershipRequestPersistence;
1119 @BeanReference(type = OrganizationPersistence.class)
1120 protected OrganizationPersistence organizationPersistence;
1121 @BeanReference(type = OrgGroupPermissionPersistence.class)
1122 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1123 @BeanReference(type = OrgGroupRolePersistence.class)
1124 protected OrgGroupRolePersistence orgGroupRolePersistence;
1125 @BeanReference(type = OrgLaborPersistence.class)
1126 protected OrgLaborPersistence orgLaborPersistence;
1127 @BeanReference(type = PasswordPolicyPersistence.class)
1128 protected PasswordPolicyPersistence passwordPolicyPersistence;
1129 @BeanReference(type = PasswordPolicyRelPersistence.class)
1130 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1131 @BeanReference(type = PasswordTrackerPersistence.class)
1132 protected PasswordTrackerPersistence passwordTrackerPersistence;
1133 @BeanReference(type = PermissionPersistence.class)
1134 protected PermissionPersistence permissionPersistence;
1135 @BeanReference(type = PhonePersistence.class)
1136 protected PhonePersistence phonePersistence;
1137 @BeanReference(type = PluginSettingPersistence.class)
1138 protected PluginSettingPersistence pluginSettingPersistence;
1139 @BeanReference(type = PortletPersistence.class)
1140 protected PortletPersistence portletPersistence;
1141 @BeanReference(type = PortletItemPersistence.class)
1142 protected PortletItemPersistence portletItemPersistence;
1143 @BeanReference(type = PortletPreferencesPersistence.class)
1144 protected PortletPreferencesPersistence portletPreferencesPersistence;
1145 @BeanReference(type = RegionPersistence.class)
1146 protected RegionPersistence regionPersistence;
1147 @BeanReference(type = ReleasePersistence.class)
1148 protected ReleasePersistence releasePersistence;
1149 @BeanReference(type = ResourcePersistence.class)
1150 protected ResourcePersistence resourcePersistence;
1151 @BeanReference(type = ResourceActionPersistence.class)
1152 protected ResourceActionPersistence resourceActionPersistence;
1153 @BeanReference(type = ResourceCodePersistence.class)
1154 protected ResourceCodePersistence resourceCodePersistence;
1155 @BeanReference(type = ResourcePermissionPersistence.class)
1156 protected ResourcePermissionPersistence resourcePermissionPersistence;
1157 @BeanReference(type = RolePersistence.class)
1158 protected RolePersistence rolePersistence;
1159 @BeanReference(type = ServiceComponentPersistence.class)
1160 protected ServiceComponentPersistence serviceComponentPersistence;
1161 @BeanReference(type = ShardPersistence.class)
1162 protected ShardPersistence shardPersistence;
1163 @BeanReference(type = SubscriptionPersistence.class)
1164 protected SubscriptionPersistence subscriptionPersistence;
1165 @BeanReference(type = TicketPersistence.class)
1166 protected TicketPersistence ticketPersistence;
1167 @BeanReference(type = TeamPersistence.class)
1168 protected TeamPersistence teamPersistence;
1169 @BeanReference(type = UserPersistence.class)
1170 protected UserPersistence userPersistence;
1171 @BeanReference(type = UserGroupPersistence.class)
1172 protected UserGroupPersistence userGroupPersistence;
1173 @BeanReference(type = UserGroupGroupRolePersistence.class)
1174 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1175 @BeanReference(type = UserGroupRolePersistence.class)
1176 protected UserGroupRolePersistence userGroupRolePersistence;
1177 @BeanReference(type = UserIdMapperPersistence.class)
1178 protected UserIdMapperPersistence userIdMapperPersistence;
1179 @BeanReference(type = UserTrackerPersistence.class)
1180 protected UserTrackerPersistence userTrackerPersistence;
1181 @BeanReference(type = UserTrackerPathPersistence.class)
1182 protected UserTrackerPathPersistence userTrackerPathPersistence;
1183 @BeanReference(type = WebDAVPropsPersistence.class)
1184 protected WebDAVPropsPersistence webDAVPropsPersistence;
1185 @BeanReference(type = WebsitePersistence.class)
1186 protected WebsitePersistence websitePersistence;
1187 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1188 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1189 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1190 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1191 private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1192 private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1193 private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1194 private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1195 private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
1196 private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
1197 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?)";
1198 private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
1199 private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
1200 private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?) AND ";
1201 private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
1202 private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
1203 private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = ?)";
1204 private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1205 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1206 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1207 private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1208}