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