001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchResourceActionException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.ResourceAction;
040    import com.liferay.portal.model.impl.ResourceActionImpl;
041    import com.liferay.portal.model.impl.ResourceActionModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the resource action service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see ResourceActionPersistence
059     * @see ResourceActionUtil
060     * @generated
061     */
062    public class ResourceActionPersistenceImpl extends BasePersistenceImpl<ResourceAction>
063            implements ResourceActionPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link ResourceActionUtil} to access the resource action persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
075                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
076                            ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
077                            "findByName",
078                            new String[] {
079                                    String.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
085                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
086                            ResourceActionImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
088                            new String[] { String.class.getName() },
089                            ResourceActionModelImpl.NAME_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
091                            ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
093                            new String[] { String.class.getName() });
094            public static final FinderPath FINDER_PATH_FETCH_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
095                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
096                            ResourceActionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_A",
097                            new String[] { String.class.getName(), String.class.getName() },
098                            ResourceActionModelImpl.NAME_COLUMN_BITMASK |
099                            ResourceActionModelImpl.ACTIONID_COLUMN_BITMASK);
100            public static final FinderPath FINDER_PATH_COUNT_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
101                            ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_A",
103                            new String[] { String.class.getName(), String.class.getName() });
104            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
105                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
106                            ResourceActionImpl.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
108            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
109                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
110                            ResourceActionImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
111                            "findAll", new String[0]);
112            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
113                            ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
115    
116            /**
117             * Caches the resource action in the entity cache if it is enabled.
118             *
119             * @param resourceAction the resource action
120             */
121            public void cacheResult(ResourceAction resourceAction) {
122                    EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
123                            ResourceActionImpl.class, resourceAction.getPrimaryKey(),
124                            resourceAction);
125    
126                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
127                            new Object[] { resourceAction.getName(), resourceAction.getActionId() },
128                            resourceAction);
129    
130                    resourceAction.resetOriginalValues();
131            }
132    
133            /**
134             * Caches the resource actions in the entity cache if it is enabled.
135             *
136             * @param resourceActions the resource actions
137             */
138            public void cacheResult(List<ResourceAction> resourceActions) {
139                    for (ResourceAction resourceAction : resourceActions) {
140                            if (EntityCacheUtil.getResult(
141                                                    ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
142                                                    ResourceActionImpl.class, resourceAction.getPrimaryKey()) == null) {
143                                    cacheResult(resourceAction);
144                            }
145                            else {
146                                    resourceAction.resetOriginalValues();
147                            }
148                    }
149            }
150    
151            /**
152             * Clears the cache for all resource actions.
153             *
154             * <p>
155             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
156             * </p>
157             */
158            @Override
159            public void clearCache() {
160                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
161                            CacheRegistryUtil.clear(ResourceActionImpl.class.getName());
162                    }
163    
164                    EntityCacheUtil.clearCache(ResourceActionImpl.class.getName());
165    
166                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
169            }
170    
171            /**
172             * Clears the cache for the resource action.
173             *
174             * <p>
175             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
176             * </p>
177             */
178            @Override
179            public void clearCache(ResourceAction resourceAction) {
180                    EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
181                            ResourceActionImpl.class, resourceAction.getPrimaryKey());
182    
183                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
184                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
185    
186                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
187                            new Object[] { resourceAction.getName(), resourceAction.getActionId() });
188            }
189    
190            /**
191             * Creates a new resource action with the primary key. Does not add the resource action to the database.
192             *
193             * @param resourceActionId the primary key for the new resource action
194             * @return the new resource action
195             */
196            public ResourceAction create(long resourceActionId) {
197                    ResourceAction resourceAction = new ResourceActionImpl();
198    
199                    resourceAction.setNew(true);
200                    resourceAction.setPrimaryKey(resourceActionId);
201    
202                    return resourceAction;
203            }
204    
205            /**
206             * Removes the resource action with the primary key from the database. Also notifies the appropriate model listeners.
207             *
208             * @param primaryKey the primary key of the resource action
209             * @return the resource action that was removed
210             * @throws com.liferay.portal.NoSuchModelException if a resource action with the primary key could not be found
211             * @throws SystemException if a system exception occurred
212             */
213            @Override
214            public ResourceAction remove(Serializable primaryKey)
215                    throws NoSuchModelException, SystemException {
216                    return remove(((Long)primaryKey).longValue());
217            }
218    
219            /**
220             * Removes the resource action with the primary key from the database. Also notifies the appropriate model listeners.
221             *
222             * @param resourceActionId the primary key of the resource action
223             * @return the resource action that was removed
224             * @throws com.liferay.portal.NoSuchResourceActionException if a resource action with the primary key could not be found
225             * @throws SystemException if a system exception occurred
226             */
227            public ResourceAction remove(long resourceActionId)
228                    throws NoSuchResourceActionException, SystemException {
229                    Session session = null;
230    
231                    try {
232                            session = openSession();
233    
234                            ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
235                                            Long.valueOf(resourceActionId));
236    
237                            if (resourceAction == null) {
238                                    if (_log.isWarnEnabled()) {
239                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
240                                                    resourceActionId);
241                                    }
242    
243                                    throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
244                                            resourceActionId);
245                            }
246    
247                            return resourceActionPersistence.remove(resourceAction);
248                    }
249                    catch (NoSuchResourceActionException nsee) {
250                            throw nsee;
251                    }
252                    catch (Exception e) {
253                            throw processException(e);
254                    }
255                    finally {
256                            closeSession(session);
257                    }
258            }
259    
260            /**
261             * Removes the resource action from the database. Also notifies the appropriate model listeners.
262             *
263             * @param resourceAction the resource action
264             * @return the resource action that was removed
265             * @throws SystemException if a system exception occurred
266             */
267            @Override
268            public ResourceAction remove(ResourceAction resourceAction)
269                    throws SystemException {
270                    return super.remove(resourceAction);
271            }
272    
273            @Override
274            protected ResourceAction removeImpl(ResourceAction resourceAction)
275                    throws SystemException {
276                    resourceAction = toUnwrappedModel(resourceAction);
277    
278                    Session session = null;
279    
280                    try {
281                            session = openSession();
282    
283                            BatchSessionUtil.delete(session, resourceAction);
284                    }
285                    catch (Exception e) {
286                            throw processException(e);
287                    }
288                    finally {
289                            closeSession(session);
290                    }
291    
292                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
293                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
294    
295                    ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
296    
297                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
298                            new Object[] {
299                                    resourceActionModelImpl.getName(),
300                                    
301                            resourceActionModelImpl.getActionId()
302                            });
303    
304                    EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
305                            ResourceActionImpl.class, resourceAction.getPrimaryKey());
306    
307                    return resourceAction;
308            }
309    
310            @Override
311            public ResourceAction updateImpl(
312                    com.liferay.portal.model.ResourceAction resourceAction, boolean merge)
313                    throws SystemException {
314                    resourceAction = toUnwrappedModel(resourceAction);
315    
316                    boolean isNew = resourceAction.isNew();
317    
318                    ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
319    
320                    Session session = null;
321    
322                    try {
323                            session = openSession();
324    
325                            BatchSessionUtil.update(session, resourceAction, merge);
326    
327                            resourceAction.setNew(false);
328                    }
329                    catch (Exception e) {
330                            throw processException(e);
331                    }
332                    finally {
333                            closeSession(session);
334                    }
335    
336                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
337    
338                    if (isNew || !ResourceActionModelImpl.COLUMN_BITMASK_ENABLED) {
339                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
340                    }
341    
342                    else {
343                            if ((resourceActionModelImpl.getColumnBitmask() &
344                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
345                                    Object[] args = new Object[] {
346                                                    resourceActionModelImpl.getOriginalName()
347                                            };
348    
349                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
350                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
351                                            args);
352    
353                                    args = new Object[] { resourceActionModelImpl.getName() };
354    
355                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
356                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
357                                            args);
358                            }
359                    }
360    
361                    EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
362                            ResourceActionImpl.class, resourceAction.getPrimaryKey(),
363                            resourceAction);
364    
365                    if (isNew) {
366                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
367                                    new Object[] {
368                                            resourceAction.getName(),
369                                            
370                                    resourceAction.getActionId()
371                                    }, resourceAction);
372                    }
373                    else {
374                            if ((resourceActionModelImpl.getColumnBitmask() &
375                                            FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
376                                    Object[] args = new Object[] {
377                                                    resourceActionModelImpl.getOriginalName(),
378                                                    
379                                                    resourceActionModelImpl.getOriginalActionId()
380                                            };
381    
382                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
383                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
384    
385                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
386                                            new Object[] {
387                                                    resourceAction.getName(),
388                                                    
389                                            resourceAction.getActionId()
390                                            }, resourceAction);
391                            }
392                    }
393    
394                    return resourceAction;
395            }
396    
397            protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
398                    if (resourceAction instanceof ResourceActionImpl) {
399                            return resourceAction;
400                    }
401    
402                    ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
403    
404                    resourceActionImpl.setNew(resourceAction.isNew());
405                    resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
406    
407                    resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
408                    resourceActionImpl.setName(resourceAction.getName());
409                    resourceActionImpl.setActionId(resourceAction.getActionId());
410                    resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
411    
412                    return resourceActionImpl;
413            }
414    
415            /**
416             * Returns the resource action with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
417             *
418             * @param primaryKey the primary key of the resource action
419             * @return the resource action
420             * @throws com.liferay.portal.NoSuchModelException if a resource action with the primary key could not be found
421             * @throws SystemException if a system exception occurred
422             */
423            @Override
424            public ResourceAction findByPrimaryKey(Serializable primaryKey)
425                    throws NoSuchModelException, SystemException {
426                    return findByPrimaryKey(((Long)primaryKey).longValue());
427            }
428    
429            /**
430             * Returns the resource action with the primary key or throws a {@link com.liferay.portal.NoSuchResourceActionException} if it could not be found.
431             *
432             * @param resourceActionId the primary key of the resource action
433             * @return the resource action
434             * @throws com.liferay.portal.NoSuchResourceActionException if a resource action with the primary key could not be found
435             * @throws SystemException if a system exception occurred
436             */
437            public ResourceAction findByPrimaryKey(long resourceActionId)
438                    throws NoSuchResourceActionException, SystemException {
439                    ResourceAction resourceAction = fetchByPrimaryKey(resourceActionId);
440    
441                    if (resourceAction == null) {
442                            if (_log.isWarnEnabled()) {
443                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceActionId);
444                            }
445    
446                            throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
447                                    resourceActionId);
448                    }
449    
450                    return resourceAction;
451            }
452    
453            /**
454             * Returns the resource action with the primary key or returns <code>null</code> if it could not be found.
455             *
456             * @param primaryKey the primary key of the resource action
457             * @return the resource action, or <code>null</code> if a resource action with the primary key could not be found
458             * @throws SystemException if a system exception occurred
459             */
460            @Override
461            public ResourceAction fetchByPrimaryKey(Serializable primaryKey)
462                    throws SystemException {
463                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
464            }
465    
466            /**
467             * Returns the resource action with the primary key or returns <code>null</code> if it could not be found.
468             *
469             * @param resourceActionId the primary key of the resource action
470             * @return the resource action, or <code>null</code> if a resource action with the primary key could not be found
471             * @throws SystemException if a system exception occurred
472             */
473            public ResourceAction fetchByPrimaryKey(long resourceActionId)
474                    throws SystemException {
475                    ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
476                                    ResourceActionImpl.class, resourceActionId);
477    
478                    if (resourceAction == _nullResourceAction) {
479                            return null;
480                    }
481    
482                    if (resourceAction == null) {
483                            Session session = null;
484    
485                            boolean hasException = false;
486    
487                            try {
488                                    session = openSession();
489    
490                                    resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
491                                                    Long.valueOf(resourceActionId));
492                            }
493                            catch (Exception e) {
494                                    hasException = true;
495    
496                                    throw processException(e);
497                            }
498                            finally {
499                                    if (resourceAction != null) {
500                                            cacheResult(resourceAction);
501                                    }
502                                    else if (!hasException) {
503                                            EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
504                                                    ResourceActionImpl.class, resourceActionId,
505                                                    _nullResourceAction);
506                                    }
507    
508                                    closeSession(session);
509                            }
510                    }
511    
512                    return resourceAction;
513            }
514    
515            /**
516             * Returns all the resource actions where name = &#63;.
517             *
518             * @param name the name
519             * @return the matching resource actions
520             * @throws SystemException if a system exception occurred
521             */
522            public List<ResourceAction> findByName(String name)
523                    throws SystemException {
524                    return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
525            }
526    
527            /**
528             * Returns a range of all the resource actions where name = &#63;.
529             *
530             * <p>
531             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
532             * </p>
533             *
534             * @param name the name
535             * @param start the lower bound of the range of resource actions
536             * @param end the upper bound of the range of resource actions (not inclusive)
537             * @return the range of matching resource actions
538             * @throws SystemException if a system exception occurred
539             */
540            public List<ResourceAction> findByName(String name, int start, int end)
541                    throws SystemException {
542                    return findByName(name, start, end, null);
543            }
544    
545            /**
546             * Returns an ordered range of all the resource actions where name = &#63;.
547             *
548             * <p>
549             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
550             * </p>
551             *
552             * @param name the name
553             * @param start the lower bound of the range of resource actions
554             * @param end the upper bound of the range of resource actions (not inclusive)
555             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
556             * @return the ordered range of matching resource actions
557             * @throws SystemException if a system exception occurred
558             */
559            public List<ResourceAction> findByName(String name, int start, int end,
560                    OrderByComparator orderByComparator) throws SystemException {
561                    FinderPath finderPath = null;
562                    Object[] finderArgs = null;
563    
564                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
565                                    (orderByComparator == null)) {
566                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
567                            finderArgs = new Object[] { name };
568                    }
569                    else {
570                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
571                            finderArgs = new Object[] { name, start, end, orderByComparator };
572                    }
573    
574                    List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(finderPath,
575                                    finderArgs, this);
576    
577                    if (list == null) {
578                            StringBundler query = null;
579    
580                            if (orderByComparator != null) {
581                                    query = new StringBundler(3 +
582                                                    (orderByComparator.getOrderByFields().length * 3));
583                            }
584                            else {
585                                    query = new StringBundler(3);
586                            }
587    
588                            query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
589    
590                            if (name == null) {
591                                    query.append(_FINDER_COLUMN_NAME_NAME_1);
592                            }
593                            else {
594                                    if (name.equals(StringPool.BLANK)) {
595                                            query.append(_FINDER_COLUMN_NAME_NAME_3);
596                                    }
597                                    else {
598                                            query.append(_FINDER_COLUMN_NAME_NAME_2);
599                                    }
600                            }
601    
602                            if (orderByComparator != null) {
603                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
604                                            orderByComparator);
605                            }
606    
607                            else {
608                                    query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
609                            }
610    
611                            String sql = query.toString();
612    
613                            Session session = null;
614    
615                            try {
616                                    session = openSession();
617    
618                                    Query q = session.createQuery(sql);
619    
620                                    QueryPos qPos = QueryPos.getInstance(q);
621    
622                                    if (name != null) {
623                                            qPos.add(name);
624                                    }
625    
626                                    list = (List<ResourceAction>)QueryUtil.list(q, getDialect(),
627                                                    start, end);
628                            }
629                            catch (Exception e) {
630                                    throw processException(e);
631                            }
632                            finally {
633                                    if (list == null) {
634                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
635                                    }
636                                    else {
637                                            cacheResult(list);
638    
639                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
640                                    }
641    
642                                    closeSession(session);
643                            }
644                    }
645    
646                    return list;
647            }
648    
649            /**
650             * Returns the first resource action in the ordered set where name = &#63;.
651             *
652             * <p>
653             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
654             * </p>
655             *
656             * @param name the name
657             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
658             * @return the first matching resource action
659             * @throws com.liferay.portal.NoSuchResourceActionException if a matching resource action could not be found
660             * @throws SystemException if a system exception occurred
661             */
662            public ResourceAction findByName_First(String name,
663                    OrderByComparator orderByComparator)
664                    throws NoSuchResourceActionException, SystemException {
665                    List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
666    
667                    if (list.isEmpty()) {
668                            StringBundler msg = new StringBundler(4);
669    
670                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
671    
672                            msg.append("name=");
673                            msg.append(name);
674    
675                            msg.append(StringPool.CLOSE_CURLY_BRACE);
676    
677                            throw new NoSuchResourceActionException(msg.toString());
678                    }
679                    else {
680                            return list.get(0);
681                    }
682            }
683    
684            /**
685             * Returns the last resource action in the ordered set where name = &#63;.
686             *
687             * <p>
688             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
689             * </p>
690             *
691             * @param name the name
692             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
693             * @return the last matching resource action
694             * @throws com.liferay.portal.NoSuchResourceActionException if a matching resource action could not be found
695             * @throws SystemException if a system exception occurred
696             */
697            public ResourceAction findByName_Last(String name,
698                    OrderByComparator orderByComparator)
699                    throws NoSuchResourceActionException, SystemException {
700                    int count = countByName(name);
701    
702                    List<ResourceAction> list = findByName(name, count - 1, count,
703                                    orderByComparator);
704    
705                    if (list.isEmpty()) {
706                            StringBundler msg = new StringBundler(4);
707    
708                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
709    
710                            msg.append("name=");
711                            msg.append(name);
712    
713                            msg.append(StringPool.CLOSE_CURLY_BRACE);
714    
715                            throw new NoSuchResourceActionException(msg.toString());
716                    }
717                    else {
718                            return list.get(0);
719                    }
720            }
721    
722            /**
723             * Returns the resource actions before and after the current resource action in the ordered set where name = &#63;.
724             *
725             * <p>
726             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
727             * </p>
728             *
729             * @param resourceActionId the primary key of the current resource action
730             * @param name the name
731             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
732             * @return the previous, current, and next resource action
733             * @throws com.liferay.portal.NoSuchResourceActionException if a resource action with the primary key could not be found
734             * @throws SystemException if a system exception occurred
735             */
736            public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
737                    String name, OrderByComparator orderByComparator)
738                    throws NoSuchResourceActionException, SystemException {
739                    ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
740    
741                    Session session = null;
742    
743                    try {
744                            session = openSession();
745    
746                            ResourceAction[] array = new ResourceActionImpl[3];
747    
748                            array[0] = getByName_PrevAndNext(session, resourceAction, name,
749                                            orderByComparator, true);
750    
751                            array[1] = resourceAction;
752    
753                            array[2] = getByName_PrevAndNext(session, resourceAction, name,
754                                            orderByComparator, false);
755    
756                            return array;
757                    }
758                    catch (Exception e) {
759                            throw processException(e);
760                    }
761                    finally {
762                            closeSession(session);
763                    }
764            }
765    
766            protected ResourceAction getByName_PrevAndNext(Session session,
767                    ResourceAction resourceAction, String name,
768                    OrderByComparator orderByComparator, boolean previous) {
769                    StringBundler query = null;
770    
771                    if (orderByComparator != null) {
772                            query = new StringBundler(6 +
773                                            (orderByComparator.getOrderByFields().length * 6));
774                    }
775                    else {
776                            query = new StringBundler(3);
777                    }
778    
779                    query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
780    
781                    if (name == null) {
782                            query.append(_FINDER_COLUMN_NAME_NAME_1);
783                    }
784                    else {
785                            if (name.equals(StringPool.BLANK)) {
786                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
787                            }
788                            else {
789                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
790                            }
791                    }
792    
793                    if (orderByComparator != null) {
794                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
795    
796                            if (orderByConditionFields.length > 0) {
797                                    query.append(WHERE_AND);
798                            }
799    
800                            for (int i = 0; i < orderByConditionFields.length; i++) {
801                                    query.append(_ORDER_BY_ENTITY_ALIAS);
802                                    query.append(orderByConditionFields[i]);
803    
804                                    if ((i + 1) < orderByConditionFields.length) {
805                                            if (orderByComparator.isAscending() ^ previous) {
806                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
807                                            }
808                                            else {
809                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
810                                            }
811                                    }
812                                    else {
813                                            if (orderByComparator.isAscending() ^ previous) {
814                                                    query.append(WHERE_GREATER_THAN);
815                                            }
816                                            else {
817                                                    query.append(WHERE_LESSER_THAN);
818                                            }
819                                    }
820                            }
821    
822                            query.append(ORDER_BY_CLAUSE);
823    
824                            String[] orderByFields = orderByComparator.getOrderByFields();
825    
826                            for (int i = 0; i < orderByFields.length; i++) {
827                                    query.append(_ORDER_BY_ENTITY_ALIAS);
828                                    query.append(orderByFields[i]);
829    
830                                    if ((i + 1) < orderByFields.length) {
831                                            if (orderByComparator.isAscending() ^ previous) {
832                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
833                                            }
834                                            else {
835                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
836                                            }
837                                    }
838                                    else {
839                                            if (orderByComparator.isAscending() ^ previous) {
840                                                    query.append(ORDER_BY_ASC);
841                                            }
842                                            else {
843                                                    query.append(ORDER_BY_DESC);
844                                            }
845                                    }
846                            }
847                    }
848    
849                    else {
850                            query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
851                    }
852    
853                    String sql = query.toString();
854    
855                    Query q = session.createQuery(sql);
856    
857                    q.setFirstResult(0);
858                    q.setMaxResults(2);
859    
860                    QueryPos qPos = QueryPos.getInstance(q);
861    
862                    if (name != null) {
863                            qPos.add(name);
864                    }
865    
866                    if (orderByComparator != null) {
867                            Object[] values = orderByComparator.getOrderByConditionValues(resourceAction);
868    
869                            for (Object value : values) {
870                                    qPos.add(value);
871                            }
872                    }
873    
874                    List<ResourceAction> list = q.list();
875    
876                    if (list.size() == 2) {
877                            return list.get(1);
878                    }
879                    else {
880                            return null;
881                    }
882            }
883    
884            /**
885             * Returns the resource action where name = &#63; and actionId = &#63; or throws a {@link com.liferay.portal.NoSuchResourceActionException} if it could not be found.
886             *
887             * @param name the name
888             * @param actionId the action ID
889             * @return the matching resource action
890             * @throws com.liferay.portal.NoSuchResourceActionException if a matching resource action could not be found
891             * @throws SystemException if a system exception occurred
892             */
893            public ResourceAction findByN_A(String name, String actionId)
894                    throws NoSuchResourceActionException, SystemException {
895                    ResourceAction resourceAction = fetchByN_A(name, actionId);
896    
897                    if (resourceAction == null) {
898                            StringBundler msg = new StringBundler(6);
899    
900                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
901    
902                            msg.append("name=");
903                            msg.append(name);
904    
905                            msg.append(", actionId=");
906                            msg.append(actionId);
907    
908                            msg.append(StringPool.CLOSE_CURLY_BRACE);
909    
910                            if (_log.isWarnEnabled()) {
911                                    _log.warn(msg.toString());
912                            }
913    
914                            throw new NoSuchResourceActionException(msg.toString());
915                    }
916    
917                    return resourceAction;
918            }
919    
920            /**
921             * Returns the resource action where name = &#63; and actionId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
922             *
923             * @param name the name
924             * @param actionId the action ID
925             * @return the matching resource action, or <code>null</code> if a matching resource action could not be found
926             * @throws SystemException if a system exception occurred
927             */
928            public ResourceAction fetchByN_A(String name, String actionId)
929                    throws SystemException {
930                    return fetchByN_A(name, actionId, true);
931            }
932    
933            /**
934             * Returns the resource action where name = &#63; and actionId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
935             *
936             * @param name the name
937             * @param actionId the action ID
938             * @param retrieveFromCache whether to use the finder cache
939             * @return the matching resource action, or <code>null</code> if a matching resource action could not be found
940             * @throws SystemException if a system exception occurred
941             */
942            public ResourceAction fetchByN_A(String name, String actionId,
943                    boolean retrieveFromCache) throws SystemException {
944                    Object[] finderArgs = new Object[] { name, actionId };
945    
946                    Object result = null;
947    
948                    if (retrieveFromCache) {
949                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
950                                            finderArgs, this);
951                    }
952    
953                    if (result == null) {
954                            StringBundler query = new StringBundler(4);
955    
956                            query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
957    
958                            if (name == null) {
959                                    query.append(_FINDER_COLUMN_N_A_NAME_1);
960                            }
961                            else {
962                                    if (name.equals(StringPool.BLANK)) {
963                                            query.append(_FINDER_COLUMN_N_A_NAME_3);
964                                    }
965                                    else {
966                                            query.append(_FINDER_COLUMN_N_A_NAME_2);
967                                    }
968                            }
969    
970                            if (actionId == null) {
971                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
972                            }
973                            else {
974                                    if (actionId.equals(StringPool.BLANK)) {
975                                            query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
976                                    }
977                                    else {
978                                            query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
979                                    }
980                            }
981    
982                            query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
983    
984                            String sql = query.toString();
985    
986                            Session session = null;
987    
988                            try {
989                                    session = openSession();
990    
991                                    Query q = session.createQuery(sql);
992    
993                                    QueryPos qPos = QueryPos.getInstance(q);
994    
995                                    if (name != null) {
996                                            qPos.add(name);
997                                    }
998    
999                                    if (actionId != null) {
1000                                            qPos.add(actionId);
1001                                    }
1002    
1003                                    List<ResourceAction> list = q.list();
1004    
1005                                    result = list;
1006    
1007                                    ResourceAction resourceAction = null;
1008    
1009                                    if (list.isEmpty()) {
1010                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
1011                                                    finderArgs, list);
1012                                    }
1013                                    else {
1014                                            resourceAction = list.get(0);
1015    
1016                                            cacheResult(resourceAction);
1017    
1018                                            if ((resourceAction.getName() == null) ||
1019                                                            !resourceAction.getName().equals(name) ||
1020                                                            (resourceAction.getActionId() == null) ||
1021                                                            !resourceAction.getActionId().equals(actionId)) {
1022                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
1023                                                            finderArgs, resourceAction);
1024                                            }
1025                                    }
1026    
1027                                    return resourceAction;
1028                            }
1029                            catch (Exception e) {
1030                                    throw processException(e);
1031                            }
1032                            finally {
1033                                    if (result == null) {
1034                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
1035                                                    finderArgs);
1036                                    }
1037    
1038                                    closeSession(session);
1039                            }
1040                    }
1041                    else {
1042                            if (result instanceof List<?>) {
1043                                    return null;
1044                            }
1045                            else {
1046                                    return (ResourceAction)result;
1047                            }
1048                    }
1049            }
1050    
1051            /**
1052             * Returns all the resource actions.
1053             *
1054             * @return the resource actions
1055             * @throws SystemException if a system exception occurred
1056             */
1057            public List<ResourceAction> findAll() throws SystemException {
1058                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1059            }
1060    
1061            /**
1062             * Returns a range of all the resource actions.
1063             *
1064             * <p>
1065             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1066             * </p>
1067             *
1068             * @param start the lower bound of the range of resource actions
1069             * @param end the upper bound of the range of resource actions (not inclusive)
1070             * @return the range of resource actions
1071             * @throws SystemException if a system exception occurred
1072             */
1073            public List<ResourceAction> findAll(int start, int end)
1074                    throws SystemException {
1075                    return findAll(start, end, null);
1076            }
1077    
1078            /**
1079             * Returns an ordered range of all the resource actions.
1080             *
1081             * <p>
1082             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1083             * </p>
1084             *
1085             * @param start the lower bound of the range of resource actions
1086             * @param end the upper bound of the range of resource actions (not inclusive)
1087             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1088             * @return the ordered range of resource actions
1089             * @throws SystemException if a system exception occurred
1090             */
1091            public List<ResourceAction> findAll(int start, int end,
1092                    OrderByComparator orderByComparator) throws SystemException {
1093                    FinderPath finderPath = null;
1094                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1095    
1096                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1097                                    (orderByComparator == null)) {
1098                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1099                            finderArgs = FINDER_ARGS_EMPTY;
1100                    }
1101                    else {
1102                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1103                            finderArgs = new Object[] { start, end, orderByComparator };
1104                    }
1105    
1106                    List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(finderPath,
1107                                    finderArgs, this);
1108    
1109                    if (list == null) {
1110                            StringBundler query = null;
1111                            String sql = null;
1112    
1113                            if (orderByComparator != null) {
1114                                    query = new StringBundler(2 +
1115                                                    (orderByComparator.getOrderByFields().length * 3));
1116    
1117                                    query.append(_SQL_SELECT_RESOURCEACTION);
1118    
1119                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1120                                            orderByComparator);
1121    
1122                                    sql = query.toString();
1123                            }
1124                            else {
1125                                    sql = _SQL_SELECT_RESOURCEACTION.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
1126                            }
1127    
1128                            Session session = null;
1129    
1130                            try {
1131                                    session = openSession();
1132    
1133                                    Query q = session.createQuery(sql);
1134    
1135                                    if (orderByComparator == null) {
1136                                            list = (List<ResourceAction>)QueryUtil.list(q,
1137                                                            getDialect(), start, end, false);
1138    
1139                                            Collections.sort(list);
1140                                    }
1141                                    else {
1142                                            list = (List<ResourceAction>)QueryUtil.list(q,
1143                                                            getDialect(), start, end);
1144                                    }
1145                            }
1146                            catch (Exception e) {
1147                                    throw processException(e);
1148                            }
1149                            finally {
1150                                    if (list == null) {
1151                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1152                                    }
1153                                    else {
1154                                            cacheResult(list);
1155    
1156                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1157                                    }
1158    
1159                                    closeSession(session);
1160                            }
1161                    }
1162    
1163                    return list;
1164            }
1165    
1166            /**
1167             * Removes all the resource actions where name = &#63; from the database.
1168             *
1169             * @param name the name
1170             * @throws SystemException if a system exception occurred
1171             */
1172            public void removeByName(String name) throws SystemException {
1173                    for (ResourceAction resourceAction : findByName(name)) {
1174                            resourceActionPersistence.remove(resourceAction);
1175                    }
1176            }
1177    
1178            /**
1179             * Removes the resource action where name = &#63; and actionId = &#63; from the database.
1180             *
1181             * @param name the name
1182             * @param actionId the action ID
1183             * @throws SystemException if a system exception occurred
1184             */
1185            public void removeByN_A(String name, String actionId)
1186                    throws NoSuchResourceActionException, SystemException {
1187                    ResourceAction resourceAction = findByN_A(name, actionId);
1188    
1189                    resourceActionPersistence.remove(resourceAction);
1190            }
1191    
1192            /**
1193             * Removes all the resource actions from the database.
1194             *
1195             * @throws SystemException if a system exception occurred
1196             */
1197            public void removeAll() throws SystemException {
1198                    for (ResourceAction resourceAction : findAll()) {
1199                            resourceActionPersistence.remove(resourceAction);
1200                    }
1201            }
1202    
1203            /**
1204             * Returns the number of resource actions where name = &#63;.
1205             *
1206             * @param name the name
1207             * @return the number of matching resource actions
1208             * @throws SystemException if a system exception occurred
1209             */
1210            public int countByName(String name) throws SystemException {
1211                    Object[] finderArgs = new Object[] { name };
1212    
1213                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
1214                                    finderArgs, this);
1215    
1216                    if (count == null) {
1217                            StringBundler query = new StringBundler(2);
1218    
1219                            query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
1220    
1221                            if (name == null) {
1222                                    query.append(_FINDER_COLUMN_NAME_NAME_1);
1223                            }
1224                            else {
1225                                    if (name.equals(StringPool.BLANK)) {
1226                                            query.append(_FINDER_COLUMN_NAME_NAME_3);
1227                                    }
1228                                    else {
1229                                            query.append(_FINDER_COLUMN_NAME_NAME_2);
1230                                    }
1231                            }
1232    
1233                            String sql = query.toString();
1234    
1235                            Session session = null;
1236    
1237                            try {
1238                                    session = openSession();
1239    
1240                                    Query q = session.createQuery(sql);
1241    
1242                                    QueryPos qPos = QueryPos.getInstance(q);
1243    
1244                                    if (name != null) {
1245                                            qPos.add(name);
1246                                    }
1247    
1248                                    count = (Long)q.uniqueResult();
1249                            }
1250                            catch (Exception e) {
1251                                    throw processException(e);
1252                            }
1253                            finally {
1254                                    if (count == null) {
1255                                            count = Long.valueOf(0);
1256                                    }
1257    
1258                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
1259                                            finderArgs, count);
1260    
1261                                    closeSession(session);
1262                            }
1263                    }
1264    
1265                    return count.intValue();
1266            }
1267    
1268            /**
1269             * Returns the number of resource actions where name = &#63; and actionId = &#63;.
1270             *
1271             * @param name the name
1272             * @param actionId the action ID
1273             * @return the number of matching resource actions
1274             * @throws SystemException if a system exception occurred
1275             */
1276            public int countByN_A(String name, String actionId)
1277                    throws SystemException {
1278                    Object[] finderArgs = new Object[] { name, actionId };
1279    
1280                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_A,
1281                                    finderArgs, this);
1282    
1283                    if (count == null) {
1284                            StringBundler query = new StringBundler(3);
1285    
1286                            query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
1287    
1288                            if (name == null) {
1289                                    query.append(_FINDER_COLUMN_N_A_NAME_1);
1290                            }
1291                            else {
1292                                    if (name.equals(StringPool.BLANK)) {
1293                                            query.append(_FINDER_COLUMN_N_A_NAME_3);
1294                                    }
1295                                    else {
1296                                            query.append(_FINDER_COLUMN_N_A_NAME_2);
1297                                    }
1298                            }
1299    
1300                            if (actionId == null) {
1301                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
1302                            }
1303                            else {
1304                                    if (actionId.equals(StringPool.BLANK)) {
1305                                            query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
1306                                    }
1307                                    else {
1308                                            query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
1309                                    }
1310                            }
1311    
1312                            String sql = query.toString();
1313    
1314                            Session session = null;
1315    
1316                            try {
1317                                    session = openSession();
1318    
1319                                    Query q = session.createQuery(sql);
1320    
1321                                    QueryPos qPos = QueryPos.getInstance(q);
1322    
1323                                    if (name != null) {
1324                                            qPos.add(name);
1325                                    }
1326    
1327                                    if (actionId != null) {
1328                                            qPos.add(actionId);
1329                                    }
1330    
1331                                    count = (Long)q.uniqueResult();
1332                            }
1333                            catch (Exception e) {
1334                                    throw processException(e);
1335                            }
1336                            finally {
1337                                    if (count == null) {
1338                                            count = Long.valueOf(0);
1339                                    }
1340    
1341                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, finderArgs,
1342                                            count);
1343    
1344                                    closeSession(session);
1345                            }
1346                    }
1347    
1348                    return count.intValue();
1349            }
1350    
1351            /**
1352             * Returns the number of resource actions.
1353             *
1354             * @return the number of resource actions
1355             * @throws SystemException if a system exception occurred
1356             */
1357            public int countAll() throws SystemException {
1358                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1359                                    FINDER_ARGS_EMPTY, this);
1360    
1361                    if (count == null) {
1362                            Session session = null;
1363    
1364                            try {
1365                                    session = openSession();
1366    
1367                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1368    
1369                                    count = (Long)q.uniqueResult();
1370                            }
1371                            catch (Exception e) {
1372                                    throw processException(e);
1373                            }
1374                            finally {
1375                                    if (count == null) {
1376                                            count = Long.valueOf(0);
1377                                    }
1378    
1379                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1380                                            FINDER_ARGS_EMPTY, count);
1381    
1382                                    closeSession(session);
1383                            }
1384                    }
1385    
1386                    return count.intValue();
1387            }
1388    
1389            /**
1390             * Initializes the resource action persistence.
1391             */
1392            public void afterPropertiesSet() {
1393                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1394                                            com.liferay.portal.util.PropsUtil.get(
1395                                                    "value.object.listener.com.liferay.portal.model.ResourceAction")));
1396    
1397                    if (listenerClassNames.length > 0) {
1398                            try {
1399                                    List<ModelListener<ResourceAction>> listenersList = new ArrayList<ModelListener<ResourceAction>>();
1400    
1401                                    for (String listenerClassName : listenerClassNames) {
1402                                            listenersList.add((ModelListener<ResourceAction>)InstanceFactory.newInstance(
1403                                                            listenerClassName));
1404                                    }
1405    
1406                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1407                            }
1408                            catch (Exception e) {
1409                                    _log.error(e);
1410                            }
1411                    }
1412            }
1413    
1414            public void destroy() {
1415                    EntityCacheUtil.removeCache(ResourceActionImpl.class.getName());
1416                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1417                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1418            }
1419    
1420            @BeanReference(type = AccountPersistence.class)
1421            protected AccountPersistence accountPersistence;
1422            @BeanReference(type = AddressPersistence.class)
1423            protected AddressPersistence addressPersistence;
1424            @BeanReference(type = BrowserTrackerPersistence.class)
1425            protected BrowserTrackerPersistence browserTrackerPersistence;
1426            @BeanReference(type = ClassNamePersistence.class)
1427            protected ClassNamePersistence classNamePersistence;
1428            @BeanReference(type = ClusterGroupPersistence.class)
1429            protected ClusterGroupPersistence clusterGroupPersistence;
1430            @BeanReference(type = CompanyPersistence.class)
1431            protected CompanyPersistence companyPersistence;
1432            @BeanReference(type = ContactPersistence.class)
1433            protected ContactPersistence contactPersistence;
1434            @BeanReference(type = CountryPersistence.class)
1435            protected CountryPersistence countryPersistence;
1436            @BeanReference(type = EmailAddressPersistence.class)
1437            protected EmailAddressPersistence emailAddressPersistence;
1438            @BeanReference(type = GroupPersistence.class)
1439            protected GroupPersistence groupPersistence;
1440            @BeanReference(type = ImagePersistence.class)
1441            protected ImagePersistence imagePersistence;
1442            @BeanReference(type = LayoutPersistence.class)
1443            protected LayoutPersistence layoutPersistence;
1444            @BeanReference(type = LayoutBranchPersistence.class)
1445            protected LayoutBranchPersistence layoutBranchPersistence;
1446            @BeanReference(type = LayoutPrototypePersistence.class)
1447            protected LayoutPrototypePersistence layoutPrototypePersistence;
1448            @BeanReference(type = LayoutRevisionPersistence.class)
1449            protected LayoutRevisionPersistence layoutRevisionPersistence;
1450            @BeanReference(type = LayoutSetPersistence.class)
1451            protected LayoutSetPersistence layoutSetPersistence;
1452            @BeanReference(type = LayoutSetBranchPersistence.class)
1453            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1454            @BeanReference(type = LayoutSetPrototypePersistence.class)
1455            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1456            @BeanReference(type = ListTypePersistence.class)
1457            protected ListTypePersistence listTypePersistence;
1458            @BeanReference(type = LockPersistence.class)
1459            protected LockPersistence lockPersistence;
1460            @BeanReference(type = MembershipRequestPersistence.class)
1461            protected MembershipRequestPersistence membershipRequestPersistence;
1462            @BeanReference(type = OrganizationPersistence.class)
1463            protected OrganizationPersistence organizationPersistence;
1464            @BeanReference(type = OrgGroupPermissionPersistence.class)
1465            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1466            @BeanReference(type = OrgGroupRolePersistence.class)
1467            protected OrgGroupRolePersistence orgGroupRolePersistence;
1468            @BeanReference(type = OrgLaborPersistence.class)
1469            protected OrgLaborPersistence orgLaborPersistence;
1470            @BeanReference(type = PasswordPolicyPersistence.class)
1471            protected PasswordPolicyPersistence passwordPolicyPersistence;
1472            @BeanReference(type = PasswordPolicyRelPersistence.class)
1473            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1474            @BeanReference(type = PasswordTrackerPersistence.class)
1475            protected PasswordTrackerPersistence passwordTrackerPersistence;
1476            @BeanReference(type = PermissionPersistence.class)
1477            protected PermissionPersistence permissionPersistence;
1478            @BeanReference(type = PhonePersistence.class)
1479            protected PhonePersistence phonePersistence;
1480            @BeanReference(type = PluginSettingPersistence.class)
1481            protected PluginSettingPersistence pluginSettingPersistence;
1482            @BeanReference(type = PortalPreferencesPersistence.class)
1483            protected PortalPreferencesPersistence portalPreferencesPersistence;
1484            @BeanReference(type = PortletPersistence.class)
1485            protected PortletPersistence portletPersistence;
1486            @BeanReference(type = PortletItemPersistence.class)
1487            protected PortletItemPersistence portletItemPersistence;
1488            @BeanReference(type = PortletPreferencesPersistence.class)
1489            protected PortletPreferencesPersistence portletPreferencesPersistence;
1490            @BeanReference(type = RegionPersistence.class)
1491            protected RegionPersistence regionPersistence;
1492            @BeanReference(type = ReleasePersistence.class)
1493            protected ReleasePersistence releasePersistence;
1494            @BeanReference(type = RepositoryPersistence.class)
1495            protected RepositoryPersistence repositoryPersistence;
1496            @BeanReference(type = RepositoryEntryPersistence.class)
1497            protected RepositoryEntryPersistence repositoryEntryPersistence;
1498            @BeanReference(type = ResourcePersistence.class)
1499            protected ResourcePersistence resourcePersistence;
1500            @BeanReference(type = ResourceActionPersistence.class)
1501            protected ResourceActionPersistence resourceActionPersistence;
1502            @BeanReference(type = ResourceBlockPersistence.class)
1503            protected ResourceBlockPersistence resourceBlockPersistence;
1504            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1505            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1506            @BeanReference(type = ResourceCodePersistence.class)
1507            protected ResourceCodePersistence resourceCodePersistence;
1508            @BeanReference(type = ResourcePermissionPersistence.class)
1509            protected ResourcePermissionPersistence resourcePermissionPersistence;
1510            @BeanReference(type = ResourceTypePermissionPersistence.class)
1511            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1512            @BeanReference(type = RolePersistence.class)
1513            protected RolePersistence rolePersistence;
1514            @BeanReference(type = ServiceComponentPersistence.class)
1515            protected ServiceComponentPersistence serviceComponentPersistence;
1516            @BeanReference(type = ShardPersistence.class)
1517            protected ShardPersistence shardPersistence;
1518            @BeanReference(type = SubscriptionPersistence.class)
1519            protected SubscriptionPersistence subscriptionPersistence;
1520            @BeanReference(type = TeamPersistence.class)
1521            protected TeamPersistence teamPersistence;
1522            @BeanReference(type = TicketPersistence.class)
1523            protected TicketPersistence ticketPersistence;
1524            @BeanReference(type = UserPersistence.class)
1525            protected UserPersistence userPersistence;
1526            @BeanReference(type = UserGroupPersistence.class)
1527            protected UserGroupPersistence userGroupPersistence;
1528            @BeanReference(type = UserGroupGroupRolePersistence.class)
1529            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1530            @BeanReference(type = UserGroupRolePersistence.class)
1531            protected UserGroupRolePersistence userGroupRolePersistence;
1532            @BeanReference(type = UserIdMapperPersistence.class)
1533            protected UserIdMapperPersistence userIdMapperPersistence;
1534            @BeanReference(type = UserNotificationEventPersistence.class)
1535            protected UserNotificationEventPersistence userNotificationEventPersistence;
1536            @BeanReference(type = UserTrackerPersistence.class)
1537            protected UserTrackerPersistence userTrackerPersistence;
1538            @BeanReference(type = UserTrackerPathPersistence.class)
1539            protected UserTrackerPathPersistence userTrackerPathPersistence;
1540            @BeanReference(type = VirtualHostPersistence.class)
1541            protected VirtualHostPersistence virtualHostPersistence;
1542            @BeanReference(type = WebDAVPropsPersistence.class)
1543            protected WebDAVPropsPersistence webDAVPropsPersistence;
1544            @BeanReference(type = WebsitePersistence.class)
1545            protected WebsitePersistence websitePersistence;
1546            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1547            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1548            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1549            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1550            private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1551            private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1552            private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1553            private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1554            private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
1555            private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
1556            private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?)";
1557            private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
1558            private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
1559            private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?) AND ";
1560            private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
1561            private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
1562            private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = ?)";
1563            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1564            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1565            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1566            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1567            private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1568            private static ResourceAction _nullResourceAction = new ResourceActionImpl() {
1569                            @Override
1570                            public Object clone() {
1571                                    return this;
1572                            }
1573    
1574                            @Override
1575                            public CacheModel<ResourceAction> toCacheModel() {
1576                                    return _nullResourceActionCacheModel;
1577                            }
1578                    };
1579    
1580            private static CacheModel<ResourceAction> _nullResourceActionCacheModel = new CacheModel<ResourceAction>() {
1581                            public ResourceAction toEntityModel() {
1582                                    return _nullResourceAction;
1583                            }
1584                    };
1585    }