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