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