1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchResourceActionException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.annotation.BeanReference;
28  import com.liferay.portal.kernel.cache.CacheRegistry;
29  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32  import com.liferay.portal.kernel.dao.orm.FinderPath;
33  import com.liferay.portal.kernel.dao.orm.Query;
34  import com.liferay.portal.kernel.dao.orm.QueryPos;
35  import com.liferay.portal.kernel.dao.orm.QueryUtil;
36  import com.liferay.portal.kernel.dao.orm.Session;
37  import com.liferay.portal.kernel.log.Log;
38  import com.liferay.portal.kernel.log.LogFactoryUtil;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.OrderByComparator;
41  import com.liferay.portal.kernel.util.StringPool;
42  import com.liferay.portal.kernel.util.StringUtil;
43  import com.liferay.portal.model.ModelListener;
44  import com.liferay.portal.model.ResourceAction;
45  import com.liferay.portal.model.impl.ResourceActionImpl;
46  import com.liferay.portal.model.impl.ResourceActionModelImpl;
47  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
48  
49  import java.util.ArrayList;
50  import java.util.Collections;
51  import java.util.List;
52  
53  /**
54   * <a href="ResourceActionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   */
59  public class ResourceActionPersistenceImpl extends BasePersistenceImpl
60      implements ResourceActionPersistence {
61      public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.class.getName();
62      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
63          ".List";
64      public static final FinderPath FINDER_PATH_FIND_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
65              ResourceActionModelImpl.FINDER_CACHE_ENABLED,
66              FINDER_CLASS_NAME_LIST, "findByName",
67              new String[] { String.class.getName() });
68      public static final FinderPath FINDER_PATH_FIND_BY_OBC_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 ResourceAction create(long resourceActionId) {
125         ResourceAction resourceAction = new ResourceActionImpl();
126 
127         resourceAction.setNew(true);
128         resourceAction.setPrimaryKey(resourceActionId);
129 
130         return resourceAction;
131     }
132 
133     public ResourceAction remove(long resourceActionId)
134         throws NoSuchResourceActionException, SystemException {
135         Session session = null;
136 
137         try {
138             session = openSession();
139 
140             ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
141                     new Long(resourceActionId));
142 
143             if (resourceAction == null) {
144                 if (_log.isWarnEnabled()) {
145                     _log.warn("No ResourceAction exists with the primary key " +
146                         resourceActionId);
147                 }
148 
149                 throw new NoSuchResourceActionException(
150                     "No ResourceAction exists with the primary key " +
151                     resourceActionId);
152             }
153 
154             return remove(resourceAction);
155         }
156         catch (NoSuchResourceActionException nsee) {
157             throw nsee;
158         }
159         catch (Exception e) {
160             throw processException(e);
161         }
162         finally {
163             closeSession(session);
164         }
165     }
166 
167     public ResourceAction remove(ResourceAction resourceAction)
168         throws SystemException {
169         for (ModelListener<ResourceAction> listener : listeners) {
170             listener.onBeforeRemove(resourceAction);
171         }
172 
173         resourceAction = removeImpl(resourceAction);
174 
175         for (ModelListener<ResourceAction> listener : listeners) {
176             listener.onAfterRemove(resourceAction);
177         }
178 
179         return resourceAction;
180     }
181 
182     protected ResourceAction removeImpl(ResourceAction resourceAction)
183         throws SystemException {
184         Session session = null;
185 
186         try {
187             session = openSession();
188 
189             if (resourceAction.isCachedModel() || BatchSessionUtil.isEnabled()) {
190                 Object staleObject = session.get(ResourceActionImpl.class,
191                         resourceAction.getPrimaryKeyObj());
192 
193                 if (staleObject != null) {
194                     session.evict(staleObject);
195                 }
196             }
197 
198             session.delete(resourceAction);
199 
200             session.flush();
201         }
202         catch (Exception e) {
203             throw processException(e);
204         }
205         finally {
206             closeSession(session);
207         }
208 
209         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
210 
211         ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
212 
213         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
214             new Object[] {
215                 resourceActionModelImpl.getOriginalName(),
216                 
217             resourceActionModelImpl.getOriginalActionId()
218             });
219 
220         EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
221             ResourceActionImpl.class, resourceAction.getPrimaryKey());
222 
223         return resourceAction;
224     }
225 
226     /**
227      * @deprecated Use <code>update(ResourceAction resourceAction, boolean merge)</code>.
228      */
229     public ResourceAction update(ResourceAction resourceAction)
230         throws SystemException {
231         if (_log.isWarnEnabled()) {
232             _log.warn(
233                 "Using the deprecated update(ResourceAction resourceAction) method. Use update(ResourceAction resourceAction, boolean merge) instead.");
234         }
235 
236         return update(resourceAction, false);
237     }
238 
239     /**
240      * Add, update, or merge, the entity. This method also calls the model
241      * listeners to trigger the proper events associated with adding, deleting,
242      * or updating an entity.
243      *
244      * @param        resourceAction the entity to add, update, or merge
245      * @param        merge boolean value for whether to merge the entity. The
246      *                default value is false. Setting merge to true is more
247      *                expensive and should only be true when resourceAction is
248      *                transient. See LEP-5473 for a detailed discussion of this
249      *                method.
250      * @return        true if the portlet can be displayed via Ajax
251      */
252     public ResourceAction update(ResourceAction resourceAction, boolean merge)
253         throws SystemException {
254         boolean isNew = resourceAction.isNew();
255 
256         for (ModelListener<ResourceAction> listener : listeners) {
257             if (isNew) {
258                 listener.onBeforeCreate(resourceAction);
259             }
260             else {
261                 listener.onBeforeUpdate(resourceAction);
262             }
263         }
264 
265         resourceAction = updateImpl(resourceAction, merge);
266 
267         for (ModelListener<ResourceAction> listener : listeners) {
268             if (isNew) {
269                 listener.onAfterCreate(resourceAction);
270             }
271             else {
272                 listener.onAfterUpdate(resourceAction);
273             }
274         }
275 
276         return resourceAction;
277     }
278 
279     public ResourceAction updateImpl(
280         com.liferay.portal.model.ResourceAction resourceAction, boolean merge)
281         throws SystemException {
282         boolean isNew = resourceAction.isNew();
283 
284         ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
285 
286         Session session = null;
287 
288         try {
289             session = openSession();
290 
291             BatchSessionUtil.update(session, resourceAction, merge);
292 
293             resourceAction.setNew(false);
294         }
295         catch (Exception e) {
296             throw processException(e);
297         }
298         finally {
299             closeSession(session);
300         }
301 
302         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
303 
304         EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
305             ResourceActionImpl.class, resourceAction.getPrimaryKey(),
306             resourceAction);
307 
308         if (!isNew &&
309                 (!resourceAction.getName()
310                                     .equals(resourceActionModelImpl.getOriginalName()) ||
311                 !resourceAction.getActionId()
312                                    .equals(resourceActionModelImpl.getOriginalActionId()))) {
313             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
314                 new Object[] {
315                     resourceActionModelImpl.getOriginalName(),
316                     
317                 resourceActionModelImpl.getOriginalActionId()
318                 });
319         }
320 
321         if (isNew ||
322                 (!resourceAction.getName()
323                                     .equals(resourceActionModelImpl.getOriginalName()) ||
324                 !resourceAction.getActionId()
325                                    .equals(resourceActionModelImpl.getOriginalActionId()))) {
326             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
327                 new Object[] {
328                     resourceAction.getName(),
329                     
330                 resourceAction.getActionId()
331                 }, resourceAction);
332         }
333 
334         return resourceAction;
335     }
336 
337     public ResourceAction findByPrimaryKey(long resourceActionId)
338         throws NoSuchResourceActionException, SystemException {
339         ResourceAction resourceAction = fetchByPrimaryKey(resourceActionId);
340 
341         if (resourceAction == null) {
342             if (_log.isWarnEnabled()) {
343                 _log.warn("No ResourceAction exists with the primary key " +
344                     resourceActionId);
345             }
346 
347             throw new NoSuchResourceActionException(
348                 "No ResourceAction exists with the primary key " +
349                 resourceActionId);
350         }
351 
352         return resourceAction;
353     }
354 
355     public ResourceAction fetchByPrimaryKey(long resourceActionId)
356         throws SystemException {
357         ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
358                 ResourceActionImpl.class, resourceActionId, this);
359 
360         if (resourceAction == null) {
361             Session session = null;
362 
363             try {
364                 session = openSession();
365 
366                 resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
367                         new Long(resourceActionId));
368             }
369             catch (Exception e) {
370                 throw processException(e);
371             }
372             finally {
373                 if (resourceAction != null) {
374                     cacheResult(resourceAction);
375                 }
376 
377                 closeSession(session);
378             }
379         }
380 
381         return resourceAction;
382     }
383 
384     public List<ResourceAction> findByName(String name)
385         throws SystemException {
386         Object[] finderArgs = new Object[] { name };
387 
388         List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NAME,
389                 finderArgs, this);
390 
391         if (list == null) {
392             Session session = null;
393 
394             try {
395                 session = openSession();
396 
397                 StringBuilder query = new StringBuilder();
398 
399                 query.append(
400                     "FROM com.liferay.portal.model.ResourceAction WHERE ");
401 
402                 if (name == null) {
403                     query.append("name IS NULL");
404                 }
405                 else {
406                     query.append("name = ?");
407                 }
408 
409                 query.append(" ");
410 
411                 query.append("ORDER BY ");
412 
413                 query.append("name ASC, ");
414                 query.append("bitwiseValue ASC");
415 
416                 Query q = session.createQuery(query.toString());
417 
418                 QueryPos qPos = QueryPos.getInstance(q);
419 
420                 if (name != null) {
421                     qPos.add(name);
422                 }
423 
424                 list = q.list();
425             }
426             catch (Exception e) {
427                 throw processException(e);
428             }
429             finally {
430                 if (list == null) {
431                     list = new ArrayList<ResourceAction>();
432                 }
433 
434                 cacheResult(list);
435 
436                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NAME, finderArgs,
437                     list);
438 
439                 closeSession(session);
440             }
441         }
442 
443         return list;
444     }
445 
446     public List<ResourceAction> findByName(String name, int start, int end)
447         throws SystemException {
448         return findByName(name, start, end, null);
449     }
450 
451     public List<ResourceAction> findByName(String name, int start, int end,
452         OrderByComparator obc) throws SystemException {
453         Object[] finderArgs = new Object[] {
454                 name,
455                 
456                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
457             };
458 
459         List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_NAME,
460                 finderArgs, this);
461 
462         if (list == null) {
463             Session session = null;
464 
465             try {
466                 session = openSession();
467 
468                 StringBuilder query = new StringBuilder();
469 
470                 query.append(
471                     "FROM com.liferay.portal.model.ResourceAction WHERE ");
472 
473                 if (name == null) {
474                     query.append("name IS NULL");
475                 }
476                 else {
477                     query.append("name = ?");
478                 }
479 
480                 query.append(" ");
481 
482                 if (obc != null) {
483                     query.append("ORDER BY ");
484                     query.append(obc.getOrderBy());
485                 }
486 
487                 else {
488                     query.append("ORDER BY ");
489 
490                     query.append("name ASC, ");
491                     query.append("bitwiseValue ASC");
492                 }
493 
494                 Query q = session.createQuery(query.toString());
495 
496                 QueryPos qPos = QueryPos.getInstance(q);
497 
498                 if (name != null) {
499                     qPos.add(name);
500                 }
501 
502                 list = (List<ResourceAction>)QueryUtil.list(q, getDialect(),
503                         start, end);
504             }
505             catch (Exception e) {
506                 throw processException(e);
507             }
508             finally {
509                 if (list == null) {
510                     list = new ArrayList<ResourceAction>();
511                 }
512 
513                 cacheResult(list);
514 
515                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_NAME,
516                     finderArgs, list);
517 
518                 closeSession(session);
519             }
520         }
521 
522         return list;
523     }
524 
525     public ResourceAction findByName_First(String name, OrderByComparator obc)
526         throws NoSuchResourceActionException, SystemException {
527         List<ResourceAction> list = findByName(name, 0, 1, obc);
528 
529         if (list.isEmpty()) {
530             StringBuilder msg = new StringBuilder();
531 
532             msg.append("No ResourceAction exists with the key {");
533 
534             msg.append("name=" + name);
535 
536             msg.append(StringPool.CLOSE_CURLY_BRACE);
537 
538             throw new NoSuchResourceActionException(msg.toString());
539         }
540         else {
541             return list.get(0);
542         }
543     }
544 
545     public ResourceAction findByName_Last(String name, OrderByComparator obc)
546         throws NoSuchResourceActionException, SystemException {
547         int count = countByName(name);
548 
549         List<ResourceAction> list = findByName(name, count - 1, count, obc);
550 
551         if (list.isEmpty()) {
552             StringBuilder msg = new StringBuilder();
553 
554             msg.append("No ResourceAction exists with the key {");
555 
556             msg.append("name=" + 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 obc)
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             StringBuilder query = new StringBuilder();
580 
581             query.append("FROM com.liferay.portal.model.ResourceAction WHERE ");
582 
583             if (name == null) {
584                 query.append("name IS NULL");
585             }
586             else {
587                 query.append("name = ?");
588             }
589 
590             query.append(" ");
591 
592             if (obc != null) {
593                 query.append("ORDER BY ");
594                 query.append(obc.getOrderBy());
595             }
596 
597             else {
598                 query.append("ORDER BY ");
599 
600                 query.append("name ASC, ");
601                 query.append("bitwiseValue ASC");
602             }
603 
604             Query q = session.createQuery(query.toString());
605 
606             QueryPos qPos = QueryPos.getInstance(q);
607 
608             if (name != null) {
609                 qPos.add(name);
610             }
611 
612             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
613                     resourceAction);
614 
615             ResourceAction[] array = new ResourceActionImpl[3];
616 
617             array[0] = (ResourceAction)objArray[0];
618             array[1] = (ResourceAction)objArray[1];
619             array[2] = (ResourceAction)objArray[2];
620 
621             return array;
622         }
623         catch (Exception e) {
624             throw processException(e);
625         }
626         finally {
627             closeSession(session);
628         }
629     }
630 
631     public ResourceAction findByN_A(String name, String actionId)
632         throws NoSuchResourceActionException, SystemException {
633         ResourceAction resourceAction = fetchByN_A(name, actionId);
634 
635         if (resourceAction == null) {
636             StringBuilder msg = new StringBuilder();
637 
638             msg.append("No ResourceAction exists with the key {");
639 
640             msg.append("name=" + name);
641 
642             msg.append(", ");
643             msg.append("actionId=" + actionId);
644 
645             msg.append(StringPool.CLOSE_CURLY_BRACE);
646 
647             if (_log.isWarnEnabled()) {
648                 _log.warn(msg.toString());
649             }
650 
651             throw new NoSuchResourceActionException(msg.toString());
652         }
653 
654         return resourceAction;
655     }
656 
657     public ResourceAction fetchByN_A(String name, String actionId)
658         throws SystemException {
659         return fetchByN_A(name, actionId, true);
660     }
661 
662     public ResourceAction fetchByN_A(String name, String actionId,
663         boolean retrieveFromCache) throws SystemException {
664         Object[] finderArgs = new Object[] { name, actionId };
665 
666         Object result = null;
667 
668         if (retrieveFromCache) {
669             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
670                     finderArgs, this);
671         }
672 
673         if (result == null) {
674             Session session = null;
675 
676             try {
677                 session = openSession();
678 
679                 StringBuilder query = new StringBuilder();
680 
681                 query.append(
682                     "FROM com.liferay.portal.model.ResourceAction WHERE ");
683 
684                 if (name == null) {
685                     query.append("name IS NULL");
686                 }
687                 else {
688                     query.append("name = ?");
689                 }
690 
691                 query.append(" AND ");
692 
693                 if (actionId == null) {
694                     query.append("actionId IS NULL");
695                 }
696                 else {
697                     query.append("actionId = ?");
698                 }
699 
700                 query.append(" ");
701 
702                 query.append("ORDER BY ");
703 
704                 query.append("name ASC, ");
705                 query.append("bitwiseValue ASC");
706 
707                 Query q = session.createQuery(query.toString());
708 
709                 QueryPos qPos = QueryPos.getInstance(q);
710 
711                 if (name != null) {
712                     qPos.add(name);
713                 }
714 
715                 if (actionId != null) {
716                     qPos.add(actionId);
717                 }
718 
719                 List<ResourceAction> list = q.list();
720 
721                 result = list;
722 
723                 ResourceAction resourceAction = null;
724 
725                 if (list.isEmpty()) {
726                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
727                         finderArgs, list);
728                 }
729                 else {
730                     resourceAction = list.get(0);
731 
732                     cacheResult(resourceAction);
733 
734                     if ((resourceAction.getName() == null) ||
735                             !resourceAction.getName().equals(name) ||
736                             (resourceAction.getActionId() == null) ||
737                             !resourceAction.getActionId().equals(actionId)) {
738                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
739                             finderArgs, list);
740                     }
741                 }
742 
743                 return resourceAction;
744             }
745             catch (Exception e) {
746                 throw processException(e);
747             }
748             finally {
749                 if (result == null) {
750                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
751                         finderArgs, new ArrayList<ResourceAction>());
752                 }
753 
754                 closeSession(session);
755             }
756         }
757         else {
758             if (result instanceof List) {
759                 return null;
760             }
761             else {
762                 return (ResourceAction)result;
763             }
764         }
765     }
766 
767     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
768         throws SystemException {
769         Session session = null;
770 
771         try {
772             session = openSession();
773 
774             dynamicQuery.compile(session);
775 
776             return dynamicQuery.list();
777         }
778         catch (Exception e) {
779             throw processException(e);
780         }
781         finally {
782             closeSession(session);
783         }
784     }
785 
786     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
787         int start, int end) throws SystemException {
788         Session session = null;
789 
790         try {
791             session = openSession();
792 
793             dynamicQuery.setLimit(start, end);
794 
795             dynamicQuery.compile(session);
796 
797             return dynamicQuery.list();
798         }
799         catch (Exception e) {
800             throw processException(e);
801         }
802         finally {
803             closeSession(session);
804         }
805     }
806 
807     public List<ResourceAction> findAll() throws SystemException {
808         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
809     }
810 
811     public List<ResourceAction> findAll(int start, int end)
812         throws SystemException {
813         return findAll(start, end, null);
814     }
815 
816     public List<ResourceAction> findAll(int start, int end,
817         OrderByComparator obc) throws SystemException {
818         Object[] finderArgs = new Object[] {
819                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
820             };
821 
822         List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
823                 finderArgs, this);
824 
825         if (list == null) {
826             Session session = null;
827 
828             try {
829                 session = openSession();
830 
831                 StringBuilder query = new StringBuilder();
832 
833                 query.append("FROM com.liferay.portal.model.ResourceAction ");
834 
835                 if (obc != null) {
836                     query.append("ORDER BY ");
837                     query.append(obc.getOrderBy());
838                 }
839 
840                 else {
841                     query.append("ORDER BY ");
842 
843                     query.append("name ASC, ");
844                     query.append("bitwiseValue ASC");
845                 }
846 
847                 Query q = session.createQuery(query.toString());
848 
849                 if (obc == null) {
850                     list = (List<ResourceAction>)QueryUtil.list(q,
851                             getDialect(), start, end, false);
852 
853                     Collections.sort(list);
854                 }
855                 else {
856                     list = (List<ResourceAction>)QueryUtil.list(q,
857                             getDialect(), start, end);
858                 }
859             }
860             catch (Exception e) {
861                 throw processException(e);
862             }
863             finally {
864                 if (list == null) {
865                     list = new ArrayList<ResourceAction>();
866                 }
867 
868                 cacheResult(list);
869 
870                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
871 
872                 closeSession(session);
873             }
874         }
875 
876         return list;
877     }
878 
879     public void removeByName(String name) throws SystemException {
880         for (ResourceAction resourceAction : findByName(name)) {
881             remove(resourceAction);
882         }
883     }
884 
885     public void removeByN_A(String name, String actionId)
886         throws NoSuchResourceActionException, SystemException {
887         ResourceAction resourceAction = findByN_A(name, actionId);
888 
889         remove(resourceAction);
890     }
891 
892     public void removeAll() throws SystemException {
893         for (ResourceAction resourceAction : findAll()) {
894             remove(resourceAction);
895         }
896     }
897 
898     public int countByName(String name) throws SystemException {
899         Object[] finderArgs = new Object[] { name };
900 
901         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
902                 finderArgs, this);
903 
904         if (count == null) {
905             Session session = null;
906 
907             try {
908                 session = openSession();
909 
910                 StringBuilder query = new StringBuilder();
911 
912                 query.append("SELECT COUNT(*) ");
913                 query.append(
914                     "FROM com.liferay.portal.model.ResourceAction WHERE ");
915 
916                 if (name == null) {
917                     query.append("name IS NULL");
918                 }
919                 else {
920                     query.append("name = ?");
921                 }
922 
923                 query.append(" ");
924 
925                 Query q = session.createQuery(query.toString());
926 
927                 QueryPos qPos = QueryPos.getInstance(q);
928 
929                 if (name != null) {
930                     qPos.add(name);
931                 }
932 
933                 count = (Long)q.uniqueResult();
934             }
935             catch (Exception e) {
936                 throw processException(e);
937             }
938             finally {
939                 if (count == null) {
940                     count = Long.valueOf(0);
941                 }
942 
943                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
944                     finderArgs, count);
945 
946                 closeSession(session);
947             }
948         }
949 
950         return count.intValue();
951     }
952 
953     public int countByN_A(String name, String actionId)
954         throws SystemException {
955         Object[] finderArgs = new Object[] { name, actionId };
956 
957         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_A,
958                 finderArgs, this);
959 
960         if (count == null) {
961             Session session = null;
962 
963             try {
964                 session = openSession();
965 
966                 StringBuilder query = new StringBuilder();
967 
968                 query.append("SELECT COUNT(*) ");
969                 query.append(
970                     "FROM com.liferay.portal.model.ResourceAction WHERE ");
971 
972                 if (name == null) {
973                     query.append("name IS NULL");
974                 }
975                 else {
976                     query.append("name = ?");
977                 }
978 
979                 query.append(" AND ");
980 
981                 if (actionId == null) {
982                     query.append("actionId IS NULL");
983                 }
984                 else {
985                     query.append("actionId = ?");
986                 }
987 
988                 query.append(" ");
989 
990                 Query q = session.createQuery(query.toString());
991 
992                 QueryPos qPos = QueryPos.getInstance(q);
993 
994                 if (name != null) {
995                     qPos.add(name);
996                 }
997 
998                 if (actionId != null) {
999                     qPos.add(actionId);
1000                }
1001
1002                count = (Long)q.uniqueResult();
1003            }
1004            catch (Exception e) {
1005                throw processException(e);
1006            }
1007            finally {
1008                if (count == null) {
1009                    count = Long.valueOf(0);
1010                }
1011
1012                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, finderArgs,
1013                    count);
1014
1015                closeSession(session);
1016            }
1017        }
1018
1019        return count.intValue();
1020    }
1021
1022    public int countAll() throws SystemException {
1023        Object[] finderArgs = new Object[0];
1024
1025        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1026                finderArgs, this);
1027
1028        if (count == null) {
1029            Session session = null;
1030
1031            try {
1032                session = openSession();
1033
1034                Query q = session.createQuery(
1035                        "SELECT COUNT(*) FROM com.liferay.portal.model.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(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1080    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1081    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1082    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1083    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1084    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1085    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1086    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1087    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1088    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1089    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1090    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1091    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1092    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1093    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1094    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1095    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1096    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1097    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1098    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1099    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1100    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1101    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
1102    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1103    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
1104    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1105    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
1106    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1107    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
1108    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1109    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
1110    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1111    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
1112    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1113    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
1114    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1115    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
1116    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1117    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
1118    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1119    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
1120    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1121    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
1122    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1123    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
1124    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1125    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
1126    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1127    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
1128    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1129    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
1130    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1131    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
1132    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1133    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
1134    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1135    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
1136    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1137    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1138    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1139    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
1140    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1141    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
1142    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1143    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
1144    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1145    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
1146    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1147    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
1148    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1149    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
1150    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1151    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
1152    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1153    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1154    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1155    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
1156    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1157    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
1158    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1159    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
1160    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1161    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
1162    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1163    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
1164    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1165    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
1166    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1167    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
1168    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1169    private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1170}