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