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