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