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