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