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