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