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 * 2));
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(4 +
441                                            (orderByComparator.getOrderByConditionFields().length * 3) +
442                                            (orderByComparator.getOrderByFields().length * 3));
443                    }
444                    else {
445                            query = new StringBundler(3);
446                    }
447    
448                    query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
449    
450                    boolean bindName = false;
451    
452                    if (name == null) {
453                            query.append(_FINDER_COLUMN_NAME_NAME_1);
454                    }
455                    else if (name.equals(StringPool.BLANK)) {
456                            query.append(_FINDER_COLUMN_NAME_NAME_3);
457                    }
458                    else {
459                            bindName = true;
460    
461                            query.append(_FINDER_COLUMN_NAME_NAME_2);
462                    }
463    
464                    if (orderByComparator != null) {
465                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
466    
467                            if (orderByConditionFields.length > 0) {
468                                    query.append(WHERE_AND);
469                            }
470    
471                            for (int i = 0; i < orderByConditionFields.length; i++) {
472                                    query.append(_ORDER_BY_ENTITY_ALIAS);
473                                    query.append(orderByConditionFields[i]);
474    
475                                    if ((i + 1) < orderByConditionFields.length) {
476                                            if (orderByComparator.isAscending() ^ previous) {
477                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
478                                            }
479                                            else {
480                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
481                                            }
482                                    }
483                                    else {
484                                            if (orderByComparator.isAscending() ^ previous) {
485                                                    query.append(WHERE_GREATER_THAN);
486                                            }
487                                            else {
488                                                    query.append(WHERE_LESSER_THAN);
489                                            }
490                                    }
491                            }
492    
493                            query.append(ORDER_BY_CLAUSE);
494    
495                            String[] orderByFields = orderByComparator.getOrderByFields();
496    
497                            for (int i = 0; i < orderByFields.length; i++) {
498                                    query.append(_ORDER_BY_ENTITY_ALIAS);
499                                    query.append(orderByFields[i]);
500    
501                                    if ((i + 1) < orderByFields.length) {
502                                            if (orderByComparator.isAscending() ^ previous) {
503                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
504                                            }
505                                            else {
506                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
507                                            }
508                                    }
509                                    else {
510                                            if (orderByComparator.isAscending() ^ previous) {
511                                                    query.append(ORDER_BY_ASC);
512                                            }
513                                            else {
514                                                    query.append(ORDER_BY_DESC);
515                                            }
516                                    }
517                            }
518                    }
519                    else {
520                            query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
521                    }
522    
523                    String sql = query.toString();
524    
525                    Query q = session.createQuery(sql);
526    
527                    q.setFirstResult(0);
528                    q.setMaxResults(2);
529    
530                    QueryPos qPos = QueryPos.getInstance(q);
531    
532                    if (bindName) {
533                            qPos.add(name);
534                    }
535    
536                    if (orderByComparator != null) {
537                            Object[] values = orderByComparator.getOrderByConditionValues(resourceAction);
538    
539                            for (Object value : values) {
540                                    qPos.add(value);
541                            }
542                    }
543    
544                    List<ResourceAction> list = q.list();
545    
546                    if (list.size() == 2) {
547                            return list.get(1);
548                    }
549                    else {
550                            return null;
551                    }
552            }
553    
554            /**
555             * Removes all the resource actions where name = &#63; from the database.
556             *
557             * @param name the name
558             */
559            @Override
560            public void removeByName(String name) {
561                    for (ResourceAction resourceAction : findByName(name,
562                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
563                            remove(resourceAction);
564                    }
565            }
566    
567            /**
568             * Returns the number of resource actions where name = &#63;.
569             *
570             * @param name the name
571             * @return the number of matching resource actions
572             */
573            @Override
574            public int countByName(String name) {
575                    FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
576    
577                    Object[] finderArgs = new Object[] { name };
578    
579                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
580    
581                    if (count == null) {
582                            StringBundler query = new StringBundler(2);
583    
584                            query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
585    
586                            boolean bindName = false;
587    
588                            if (name == null) {
589                                    query.append(_FINDER_COLUMN_NAME_NAME_1);
590                            }
591                            else if (name.equals(StringPool.BLANK)) {
592                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
593                            }
594                            else {
595                                    bindName = true;
596    
597                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
598                            }
599    
600                            String sql = query.toString();
601    
602                            Session session = null;
603    
604                            try {
605                                    session = openSession();
606    
607                                    Query q = session.createQuery(sql);
608    
609                                    QueryPos qPos = QueryPos.getInstance(q);
610    
611                                    if (bindName) {
612                                            qPos.add(name);
613                                    }
614    
615                                    count = (Long)q.uniqueResult();
616    
617                                    finderCache.putResult(finderPath, finderArgs, count);
618                            }
619                            catch (Exception e) {
620                                    finderCache.removeResult(finderPath, finderArgs);
621    
622                                    throw processException(e);
623                            }
624                            finally {
625                                    closeSession(session);
626                            }
627                    }
628    
629                    return count.intValue();
630            }
631    
632            private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
633            private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
634            private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = '')";
635            public static final FinderPath FINDER_PATH_FETCH_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
636                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
637                            ResourceActionImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByN_A",
638                            new String[] { String.class.getName(), String.class.getName() },
639                            ResourceActionModelImpl.NAME_COLUMN_BITMASK |
640                            ResourceActionModelImpl.ACTIONID_COLUMN_BITMASK);
641            public static final FinderPath FINDER_PATH_COUNT_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
642                            ResourceActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
643                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByN_A",
644                            new String[] { String.class.getName(), String.class.getName() });
645    
646            /**
647             * Returns the resource action where name = &#63; and actionId = &#63; or throws a {@link NoSuchResourceActionException} if it could not be found.
648             *
649             * @param name the name
650             * @param actionId the action ID
651             * @return the matching resource action
652             * @throws NoSuchResourceActionException if a matching resource action could not be found
653             */
654            @Override
655            public ResourceAction findByN_A(String name, String actionId)
656                    throws NoSuchResourceActionException {
657                    ResourceAction resourceAction = fetchByN_A(name, actionId);
658    
659                    if (resourceAction == null) {
660                            StringBundler msg = new StringBundler(6);
661    
662                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
663    
664                            msg.append("name=");
665                            msg.append(name);
666    
667                            msg.append(", actionId=");
668                            msg.append(actionId);
669    
670                            msg.append(StringPool.CLOSE_CURLY_BRACE);
671    
672                            if (_log.isWarnEnabled()) {
673                                    _log.warn(msg.toString());
674                            }
675    
676                            throw new NoSuchResourceActionException(msg.toString());
677                    }
678    
679                    return resourceAction;
680            }
681    
682            /**
683             * 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.
684             *
685             * @param name the name
686             * @param actionId the action ID
687             * @return the matching resource action, or <code>null</code> if a matching resource action could not be found
688             */
689            @Override
690            public ResourceAction fetchByN_A(String name, String actionId) {
691                    return fetchByN_A(name, actionId, true);
692            }
693    
694            /**
695             * 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.
696             *
697             * @param name the name
698             * @param actionId the action ID
699             * @param retrieveFromCache whether to retrieve from the finder cache
700             * @return the matching resource action, or <code>null</code> if a matching resource action could not be found
701             */
702            @Override
703            public ResourceAction fetchByN_A(String name, String actionId,
704                    boolean retrieveFromCache) {
705                    Object[] finderArgs = new Object[] { name, actionId };
706    
707                    Object result = null;
708    
709                    if (retrieveFromCache) {
710                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_N_A,
711                                            finderArgs, this);
712                    }
713    
714                    if (result instanceof ResourceAction) {
715                            ResourceAction resourceAction = (ResourceAction)result;
716    
717                            if (!Validator.equals(name, resourceAction.getName()) ||
718                                            !Validator.equals(actionId, resourceAction.getActionId())) {
719                                    result = null;
720                            }
721                    }
722    
723                    if (result == null) {
724                            StringBundler query = new StringBundler(4);
725    
726                            query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
727    
728                            boolean bindName = false;
729    
730                            if (name == null) {
731                                    query.append(_FINDER_COLUMN_N_A_NAME_1);
732                            }
733                            else if (name.equals(StringPool.BLANK)) {
734                                    query.append(_FINDER_COLUMN_N_A_NAME_3);
735                            }
736                            else {
737                                    bindName = true;
738    
739                                    query.append(_FINDER_COLUMN_N_A_NAME_2);
740                            }
741    
742                            boolean bindActionId = false;
743    
744                            if (actionId == null) {
745                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
746                            }
747                            else if (actionId.equals(StringPool.BLANK)) {
748                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
749                            }
750                            else {
751                                    bindActionId = true;
752    
753                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
754                            }
755    
756                            String sql = query.toString();
757    
758                            Session session = null;
759    
760                            try {
761                                    session = openSession();
762    
763                                    Query q = session.createQuery(sql);
764    
765                                    QueryPos qPos = QueryPos.getInstance(q);
766    
767                                    if (bindName) {
768                                            qPos.add(name);
769                                    }
770    
771                                    if (bindActionId) {
772                                            qPos.add(actionId);
773                                    }
774    
775                                    List<ResourceAction> list = q.list();
776    
777                                    if (list.isEmpty()) {
778                                            finderCache.putResult(FINDER_PATH_FETCH_BY_N_A, finderArgs,
779                                                    list);
780                                    }
781                                    else {
782                                            ResourceAction resourceAction = list.get(0);
783    
784                                            result = resourceAction;
785    
786                                            cacheResult(resourceAction);
787    
788                                            if ((resourceAction.getName() == null) ||
789                                                            !resourceAction.getName().equals(name) ||
790                                                            (resourceAction.getActionId() == null) ||
791                                                            !resourceAction.getActionId().equals(actionId)) {
792                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_N_A,
793                                                            finderArgs, resourceAction);
794                                            }
795                                    }
796                            }
797                            catch (Exception e) {
798                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_N_A, finderArgs);
799    
800                                    throw processException(e);
801                            }
802                            finally {
803                                    closeSession(session);
804                            }
805                    }
806    
807                    if (result instanceof List<?>) {
808                            return null;
809                    }
810                    else {
811                            return (ResourceAction)result;
812                    }
813            }
814    
815            /**
816             * Removes the resource action where name = &#63; and actionId = &#63; from the database.
817             *
818             * @param name the name
819             * @param actionId the action ID
820             * @return the resource action that was removed
821             */
822            @Override
823            public ResourceAction removeByN_A(String name, String actionId)
824                    throws NoSuchResourceActionException {
825                    ResourceAction resourceAction = findByN_A(name, actionId);
826    
827                    return remove(resourceAction);
828            }
829    
830            /**
831             * Returns the number of resource actions where name = &#63; and actionId = &#63;.
832             *
833             * @param name the name
834             * @param actionId the action ID
835             * @return the number of matching resource actions
836             */
837            @Override
838            public int countByN_A(String name, String actionId) {
839                    FinderPath finderPath = FINDER_PATH_COUNT_BY_N_A;
840    
841                    Object[] finderArgs = new Object[] { name, actionId };
842    
843                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
844    
845                    if (count == null) {
846                            StringBundler query = new StringBundler(3);
847    
848                            query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
849    
850                            boolean bindName = false;
851    
852                            if (name == null) {
853                                    query.append(_FINDER_COLUMN_N_A_NAME_1);
854                            }
855                            else if (name.equals(StringPool.BLANK)) {
856                                    query.append(_FINDER_COLUMN_N_A_NAME_3);
857                            }
858                            else {
859                                    bindName = true;
860    
861                                    query.append(_FINDER_COLUMN_N_A_NAME_2);
862                            }
863    
864                            boolean bindActionId = false;
865    
866                            if (actionId == null) {
867                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
868                            }
869                            else if (actionId.equals(StringPool.BLANK)) {
870                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
871                            }
872                            else {
873                                    bindActionId = true;
874    
875                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
876                            }
877    
878                            String sql = query.toString();
879    
880                            Session session = null;
881    
882                            try {
883                                    session = openSession();
884    
885                                    Query q = session.createQuery(sql);
886    
887                                    QueryPos qPos = QueryPos.getInstance(q);
888    
889                                    if (bindName) {
890                                            qPos.add(name);
891                                    }
892    
893                                    if (bindActionId) {
894                                            qPos.add(actionId);
895                                    }
896    
897                                    count = (Long)q.uniqueResult();
898    
899                                    finderCache.putResult(finderPath, finderArgs, count);
900                            }
901                            catch (Exception e) {
902                                    finderCache.removeResult(finderPath, finderArgs);
903    
904                                    throw processException(e);
905                            }
906                            finally {
907                                    closeSession(session);
908                            }
909                    }
910    
911                    return count.intValue();
912            }
913    
914            private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
915            private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
916            private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = '') AND ";
917            private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
918            private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
919            private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = '')";
920    
921            public ResourceActionPersistenceImpl() {
922                    setModelClass(ResourceAction.class);
923            }
924    
925            /**
926             * Caches the resource action in the entity cache if it is enabled.
927             *
928             * @param resourceAction the resource action
929             */
930            @Override
931            public void cacheResult(ResourceAction resourceAction) {
932                    entityCache.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
933                            ResourceActionImpl.class, resourceAction.getPrimaryKey(),
934                            resourceAction);
935    
936                    finderCache.putResult(FINDER_PATH_FETCH_BY_N_A,
937                            new Object[] { resourceAction.getName(), resourceAction.getActionId() },
938                            resourceAction);
939    
940                    resourceAction.resetOriginalValues();
941            }
942    
943            /**
944             * Caches the resource actions in the entity cache if it is enabled.
945             *
946             * @param resourceActions the resource actions
947             */
948            @Override
949            public void cacheResult(List<ResourceAction> resourceActions) {
950                    for (ResourceAction resourceAction : resourceActions) {
951                            if (entityCache.getResult(
952                                                    ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
953                                                    ResourceActionImpl.class, resourceAction.getPrimaryKey()) == null) {
954                                    cacheResult(resourceAction);
955                            }
956                            else {
957                                    resourceAction.resetOriginalValues();
958                            }
959                    }
960            }
961    
962            /**
963             * Clears the cache for all resource actions.
964             *
965             * <p>
966             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
967             * </p>
968             */
969            @Override
970            public void clearCache() {
971                    entityCache.clearCache(ResourceActionImpl.class);
972    
973                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
974                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
975                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
976            }
977    
978            /**
979             * Clears the cache for the resource action.
980             *
981             * <p>
982             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
983             * </p>
984             */
985            @Override
986            public void clearCache(ResourceAction resourceAction) {
987                    entityCache.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
988                            ResourceActionImpl.class, resourceAction.getPrimaryKey());
989    
990                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
991                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
992    
993                    clearUniqueFindersCache((ResourceActionModelImpl)resourceAction);
994            }
995    
996            @Override
997            public void clearCache(List<ResourceAction> resourceActions) {
998                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
999                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1000    
1001                    for (ResourceAction resourceAction : resourceActions) {
1002                            entityCache.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1003                                    ResourceActionImpl.class, resourceAction.getPrimaryKey());
1004    
1005                            clearUniqueFindersCache((ResourceActionModelImpl)resourceAction);
1006                    }
1007            }
1008    
1009            protected void cacheUniqueFindersCache(
1010                    ResourceActionModelImpl resourceActionModelImpl, boolean isNew) {
1011                    if (isNew) {
1012                            Object[] args = new Object[] {
1013                                            resourceActionModelImpl.getName(),
1014                                            resourceActionModelImpl.getActionId()
1015                                    };
1016    
1017                            finderCache.putResult(FINDER_PATH_COUNT_BY_N_A, args,
1018                                    Long.valueOf(1));
1019                            finderCache.putResult(FINDER_PATH_FETCH_BY_N_A, args,
1020                                    resourceActionModelImpl);
1021                    }
1022                    else {
1023                            if ((resourceActionModelImpl.getColumnBitmask() &
1024                                            FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
1025                                    Object[] args = new Object[] {
1026                                                    resourceActionModelImpl.getName(),
1027                                                    resourceActionModelImpl.getActionId()
1028                                            };
1029    
1030                                    finderCache.putResult(FINDER_PATH_COUNT_BY_N_A, args,
1031                                            Long.valueOf(1));
1032                                    finderCache.putResult(FINDER_PATH_FETCH_BY_N_A, args,
1033                                            resourceActionModelImpl);
1034                            }
1035                    }
1036            }
1037    
1038            protected void clearUniqueFindersCache(
1039                    ResourceActionModelImpl resourceActionModelImpl) {
1040                    Object[] args = new Object[] {
1041                                    resourceActionModelImpl.getName(),
1042                                    resourceActionModelImpl.getActionId()
1043                            };
1044    
1045                    finderCache.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
1046                    finderCache.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
1047    
1048                    if ((resourceActionModelImpl.getColumnBitmask() &
1049                                    FINDER_PATH_FETCH_BY_N_A.getColumnBitmask()) != 0) {
1050                            args = new Object[] {
1051                                            resourceActionModelImpl.getOriginalName(),
1052                                            resourceActionModelImpl.getOriginalActionId()
1053                                    };
1054    
1055                            finderCache.removeResult(FINDER_PATH_COUNT_BY_N_A, args);
1056                            finderCache.removeResult(FINDER_PATH_FETCH_BY_N_A, args);
1057                    }
1058            }
1059    
1060            /**
1061             * Creates a new resource action with the primary key. Does not add the resource action to the database.
1062             *
1063             * @param resourceActionId the primary key for the new resource action
1064             * @return the new resource action
1065             */
1066            @Override
1067            public ResourceAction create(long resourceActionId) {
1068                    ResourceAction resourceAction = new ResourceActionImpl();
1069    
1070                    resourceAction.setNew(true);
1071                    resourceAction.setPrimaryKey(resourceActionId);
1072    
1073                    return resourceAction;
1074            }
1075    
1076            /**
1077             * Removes the resource action with the primary key from the database. Also notifies the appropriate model listeners.
1078             *
1079             * @param resourceActionId the primary key of the resource action
1080             * @return the resource action that was removed
1081             * @throws NoSuchResourceActionException if a resource action with the primary key could not be found
1082             */
1083            @Override
1084            public ResourceAction remove(long resourceActionId)
1085                    throws NoSuchResourceActionException {
1086                    return remove((Serializable)resourceActionId);
1087            }
1088    
1089            /**
1090             * Removes the resource action with the primary key from the database. Also notifies the appropriate model listeners.
1091             *
1092             * @param primaryKey the primary key of the resource action
1093             * @return the resource action that was removed
1094             * @throws NoSuchResourceActionException if a resource action with the primary key could not be found
1095             */
1096            @Override
1097            public ResourceAction remove(Serializable primaryKey)
1098                    throws NoSuchResourceActionException {
1099                    Session session = null;
1100    
1101                    try {
1102                            session = openSession();
1103    
1104                            ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1105                                            primaryKey);
1106    
1107                            if (resourceAction == null) {
1108                                    if (_log.isWarnEnabled()) {
1109                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1110                                    }
1111    
1112                                    throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1113                                            primaryKey);
1114                            }
1115    
1116                            return remove(resourceAction);
1117                    }
1118                    catch (NoSuchResourceActionException nsee) {
1119                            throw nsee;
1120                    }
1121                    catch (Exception e) {
1122                            throw processException(e);
1123                    }
1124                    finally {
1125                            closeSession(session);
1126                    }
1127            }
1128    
1129            @Override
1130            protected ResourceAction removeImpl(ResourceAction resourceAction) {
1131                    resourceAction = toUnwrappedModel(resourceAction);
1132    
1133                    Session session = null;
1134    
1135                    try {
1136                            session = openSession();
1137    
1138                            if (!session.contains(resourceAction)) {
1139                                    resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1140                                                    resourceAction.getPrimaryKeyObj());
1141                            }
1142    
1143                            if (resourceAction != null) {
1144                                    session.delete(resourceAction);
1145                            }
1146                    }
1147                    catch (Exception e) {
1148                            throw processException(e);
1149                    }
1150                    finally {
1151                            closeSession(session);
1152                    }
1153    
1154                    if (resourceAction != null) {
1155                            clearCache(resourceAction);
1156                    }
1157    
1158                    return resourceAction;
1159            }
1160    
1161            @Override
1162            public ResourceAction updateImpl(ResourceAction resourceAction) {
1163                    resourceAction = toUnwrappedModel(resourceAction);
1164    
1165                    boolean isNew = resourceAction.isNew();
1166    
1167                    ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
1168    
1169                    Session session = null;
1170    
1171                    try {
1172                            session = openSession();
1173    
1174                            if (resourceAction.isNew()) {
1175                                    session.save(resourceAction);
1176    
1177                                    resourceAction.setNew(false);
1178                            }
1179                            else {
1180                                    resourceAction = (ResourceAction)session.merge(resourceAction);
1181                            }
1182                    }
1183                    catch (Exception e) {
1184                            throw processException(e);
1185                    }
1186                    finally {
1187                            closeSession(session);
1188                    }
1189    
1190                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1191    
1192                    if (isNew || !ResourceActionModelImpl.COLUMN_BITMASK_ENABLED) {
1193                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1194                    }
1195    
1196                    else {
1197                            if ((resourceActionModelImpl.getColumnBitmask() &
1198                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
1199                                    Object[] args = new Object[] {
1200                                                    resourceActionModelImpl.getOriginalName()
1201                                            };
1202    
1203                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1204                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
1205                                            args);
1206    
1207                                    args = new Object[] { resourceActionModelImpl.getName() };
1208    
1209                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
1210                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
1211                                            args);
1212                            }
1213                    }
1214    
1215                    entityCache.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1216                            ResourceActionImpl.class, resourceAction.getPrimaryKey(),
1217                            resourceAction, false);
1218    
1219                    clearUniqueFindersCache(resourceActionModelImpl);
1220                    cacheUniqueFindersCache(resourceActionModelImpl, isNew);
1221    
1222                    resourceAction.resetOriginalValues();
1223    
1224                    return resourceAction;
1225            }
1226    
1227            protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
1228                    if (resourceAction instanceof ResourceActionImpl) {
1229                            return resourceAction;
1230                    }
1231    
1232                    ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
1233    
1234                    resourceActionImpl.setNew(resourceAction.isNew());
1235                    resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
1236    
1237                    resourceActionImpl.setMvccVersion(resourceAction.getMvccVersion());
1238                    resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
1239                    resourceActionImpl.setName(resourceAction.getName());
1240                    resourceActionImpl.setActionId(resourceAction.getActionId());
1241                    resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
1242    
1243                    return resourceActionImpl;
1244            }
1245    
1246            /**
1247             * Returns the resource action with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
1248             *
1249             * @param primaryKey the primary key of the resource action
1250             * @return the resource action
1251             * @throws NoSuchResourceActionException if a resource action with the primary key could not be found
1252             */
1253            @Override
1254            public ResourceAction findByPrimaryKey(Serializable primaryKey)
1255                    throws NoSuchResourceActionException {
1256                    ResourceAction resourceAction = fetchByPrimaryKey(primaryKey);
1257    
1258                    if (resourceAction == null) {
1259                            if (_log.isWarnEnabled()) {
1260                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1261                            }
1262    
1263                            throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1264                                    primaryKey);
1265                    }
1266    
1267                    return resourceAction;
1268            }
1269    
1270            /**
1271             * Returns the resource action with the primary key or throws a {@link NoSuchResourceActionException} if it could not be found.
1272             *
1273             * @param resourceActionId the primary key of the resource action
1274             * @return the resource action
1275             * @throws NoSuchResourceActionException if a resource action with the primary key could not be found
1276             */
1277            @Override
1278            public ResourceAction findByPrimaryKey(long resourceActionId)
1279                    throws NoSuchResourceActionException {
1280                    return findByPrimaryKey((Serializable)resourceActionId);
1281            }
1282    
1283            /**
1284             * Returns the resource action with the primary key or returns <code>null</code> if it could not be found.
1285             *
1286             * @param primaryKey the primary key of the resource action
1287             * @return the resource action, or <code>null</code> if a resource action with the primary key could not be found
1288             */
1289            @Override
1290            public ResourceAction fetchByPrimaryKey(Serializable primaryKey) {
1291                    ResourceAction resourceAction = (ResourceAction)entityCache.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1292                                    ResourceActionImpl.class, primaryKey);
1293    
1294                    if (resourceAction == _nullResourceAction) {
1295                            return null;
1296                    }
1297    
1298                    if (resourceAction == null) {
1299                            Session session = null;
1300    
1301                            try {
1302                                    session = openSession();
1303    
1304                                    resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
1305                                                    primaryKey);
1306    
1307                                    if (resourceAction != null) {
1308                                            cacheResult(resourceAction);
1309                                    }
1310                                    else {
1311                                            entityCache.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1312                                                    ResourceActionImpl.class, primaryKey,
1313                                                    _nullResourceAction);
1314                                    }
1315                            }
1316                            catch (Exception e) {
1317                                    entityCache.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1318                                            ResourceActionImpl.class, primaryKey);
1319    
1320                                    throw processException(e);
1321                            }
1322                            finally {
1323                                    closeSession(session);
1324                            }
1325                    }
1326    
1327                    return resourceAction;
1328            }
1329    
1330            /**
1331             * Returns the resource action with the primary key or returns <code>null</code> if it could not be found.
1332             *
1333             * @param resourceActionId the primary key of the resource action
1334             * @return the resource action, or <code>null</code> if a resource action with the primary key could not be found
1335             */
1336            @Override
1337            public ResourceAction fetchByPrimaryKey(long resourceActionId) {
1338                    return fetchByPrimaryKey((Serializable)resourceActionId);
1339            }
1340    
1341            @Override
1342            public Map<Serializable, ResourceAction> fetchByPrimaryKeys(
1343                    Set<Serializable> primaryKeys) {
1344                    if (primaryKeys.isEmpty()) {
1345                            return Collections.emptyMap();
1346                    }
1347    
1348                    Map<Serializable, ResourceAction> map = new HashMap<Serializable, ResourceAction>();
1349    
1350                    if (primaryKeys.size() == 1) {
1351                            Iterator<Serializable> iterator = primaryKeys.iterator();
1352    
1353                            Serializable primaryKey = iterator.next();
1354    
1355                            ResourceAction resourceAction = fetchByPrimaryKey(primaryKey);
1356    
1357                            if (resourceAction != null) {
1358                                    map.put(primaryKey, resourceAction);
1359                            }
1360    
1361                            return map;
1362                    }
1363    
1364                    Set<Serializable> uncachedPrimaryKeys = null;
1365    
1366                    for (Serializable primaryKey : primaryKeys) {
1367                            ResourceAction resourceAction = (ResourceAction)entityCache.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1368                                            ResourceActionImpl.class, primaryKey);
1369    
1370                            if (resourceAction == null) {
1371                                    if (uncachedPrimaryKeys == null) {
1372                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1373                                    }
1374    
1375                                    uncachedPrimaryKeys.add(primaryKey);
1376                            }
1377                            else {
1378                                    map.put(primaryKey, resourceAction);
1379                            }
1380                    }
1381    
1382                    if (uncachedPrimaryKeys == null) {
1383                            return map;
1384                    }
1385    
1386                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1387                                    1);
1388    
1389                    query.append(_SQL_SELECT_RESOURCEACTION_WHERE_PKS_IN);
1390    
1391                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1392                            query.append(String.valueOf(primaryKey));
1393    
1394                            query.append(StringPool.COMMA);
1395                    }
1396    
1397                    query.setIndex(query.index() - 1);
1398    
1399                    query.append(StringPool.CLOSE_PARENTHESIS);
1400    
1401                    String sql = query.toString();
1402    
1403                    Session session = null;
1404    
1405                    try {
1406                            session = openSession();
1407    
1408                            Query q = session.createQuery(sql);
1409    
1410                            for (ResourceAction resourceAction : (List<ResourceAction>)q.list()) {
1411                                    map.put(resourceAction.getPrimaryKeyObj(), resourceAction);
1412    
1413                                    cacheResult(resourceAction);
1414    
1415                                    uncachedPrimaryKeys.remove(resourceAction.getPrimaryKeyObj());
1416                            }
1417    
1418                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1419                                    entityCache.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
1420                                            ResourceActionImpl.class, primaryKey, _nullResourceAction);
1421                            }
1422                    }
1423                    catch (Exception e) {
1424                            throw processException(e);
1425                    }
1426                    finally {
1427                            closeSession(session);
1428                    }
1429    
1430                    return map;
1431            }
1432    
1433            /**
1434             * Returns all the resource actions.
1435             *
1436             * @return the resource actions
1437             */
1438            @Override
1439            public List<ResourceAction> findAll() {
1440                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1441            }
1442    
1443            /**
1444             * Returns a range of all the resource actions.
1445             *
1446             * <p>
1447             * 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.
1448             * </p>
1449             *
1450             * @param start the lower bound of the range of resource actions
1451             * @param end the upper bound of the range of resource actions (not inclusive)
1452             * @return the range of resource actions
1453             */
1454            @Override
1455            public List<ResourceAction> findAll(int start, int end) {
1456                    return findAll(start, end, null);
1457            }
1458    
1459            /**
1460             * Returns an ordered range of all the resource actions.
1461             *
1462             * <p>
1463             * 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.
1464             * </p>
1465             *
1466             * @param start the lower bound of the range of resource actions
1467             * @param end the upper bound of the range of resource actions (not inclusive)
1468             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1469             * @return the ordered range of resource actions
1470             */
1471            @Override
1472            public List<ResourceAction> findAll(int start, int end,
1473                    OrderByComparator<ResourceAction> orderByComparator) {
1474                    return findAll(start, end, orderByComparator, true);
1475            }
1476    
1477            /**
1478             * Returns an ordered range of all the resource actions.
1479             *
1480             * <p>
1481             * 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.
1482             * </p>
1483             *
1484             * @param start the lower bound of the range of resource actions
1485             * @param end the upper bound of the range of resource actions (not inclusive)
1486             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1487             * @param retrieveFromCache whether to retrieve from the finder cache
1488             * @return the ordered range of resource actions
1489             */
1490            @Override
1491            public List<ResourceAction> findAll(int start, int end,
1492                    OrderByComparator<ResourceAction> orderByComparator,
1493                    boolean retrieveFromCache) {
1494                    boolean pagination = true;
1495                    FinderPath finderPath = null;
1496                    Object[] finderArgs = null;
1497    
1498                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1499                                    (orderByComparator == null)) {
1500                            pagination = false;
1501                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1502                            finderArgs = FINDER_ARGS_EMPTY;
1503                    }
1504                    else {
1505                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1506                            finderArgs = new Object[] { start, end, orderByComparator };
1507                    }
1508    
1509                    List<ResourceAction> list = null;
1510    
1511                    if (retrieveFromCache) {
1512                            list = (List<ResourceAction>)finderCache.getResult(finderPath,
1513                                            finderArgs, this);
1514                    }
1515    
1516                    if (list == null) {
1517                            StringBundler query = null;
1518                            String sql = null;
1519    
1520                            if (orderByComparator != null) {
1521                                    query = new StringBundler(2 +
1522                                                    (orderByComparator.getOrderByFields().length * 2));
1523    
1524                                    query.append(_SQL_SELECT_RESOURCEACTION);
1525    
1526                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1527                                            orderByComparator);
1528    
1529                                    sql = query.toString();
1530                            }
1531                            else {
1532                                    sql = _SQL_SELECT_RESOURCEACTION;
1533    
1534                                    if (pagination) {
1535                                            sql = sql.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
1536                                    }
1537                            }
1538    
1539                            Session session = null;
1540    
1541                            try {
1542                                    session = openSession();
1543    
1544                                    Query q = session.createQuery(sql);
1545    
1546                                    if (!pagination) {
1547                                            list = (List<ResourceAction>)QueryUtil.list(q,
1548                                                            getDialect(), start, end, false);
1549    
1550                                            Collections.sort(list);
1551    
1552                                            list = Collections.unmodifiableList(list);
1553                                    }
1554                                    else {
1555                                            list = (List<ResourceAction>)QueryUtil.list(q,
1556                                                            getDialect(), start, end);
1557                                    }
1558    
1559                                    cacheResult(list);
1560    
1561                                    finderCache.putResult(finderPath, finderArgs, list);
1562                            }
1563                            catch (Exception e) {
1564                                    finderCache.removeResult(finderPath, finderArgs);
1565    
1566                                    throw processException(e);
1567                            }
1568                            finally {
1569                                    closeSession(session);
1570                            }
1571                    }
1572    
1573                    return list;
1574            }
1575    
1576            /**
1577             * Removes all the resource actions from the database.
1578             *
1579             */
1580            @Override
1581            public void removeAll() {
1582                    for (ResourceAction resourceAction : findAll()) {
1583                            remove(resourceAction);
1584                    }
1585            }
1586    
1587            /**
1588             * Returns the number of resource actions.
1589             *
1590             * @return the number of resource actions
1591             */
1592            @Override
1593            public int countAll() {
1594                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1595                                    FINDER_ARGS_EMPTY, this);
1596    
1597                    if (count == null) {
1598                            Session session = null;
1599    
1600                            try {
1601                                    session = openSession();
1602    
1603                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1604    
1605                                    count = (Long)q.uniqueResult();
1606    
1607                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1608                                            count);
1609                            }
1610                            catch (Exception e) {
1611                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1612                                            FINDER_ARGS_EMPTY);
1613    
1614                                    throw processException(e);
1615                            }
1616                            finally {
1617                                    closeSession(session);
1618                            }
1619                    }
1620    
1621                    return count.intValue();
1622            }
1623    
1624            @Override
1625            protected Map<String, Integer> getTableColumnsMap() {
1626                    return ResourceActionModelImpl.TABLE_COLUMNS_MAP;
1627            }
1628    
1629            /**
1630             * Initializes the resource action persistence.
1631             */
1632            public void afterPropertiesSet() {
1633            }
1634    
1635            public void destroy() {
1636                    entityCache.removeCache(ResourceActionImpl.class.getName());
1637                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1638                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1639                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1640            }
1641    
1642            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1643            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1644            private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1645            private static final String _SQL_SELECT_RESOURCEACTION_WHERE_PKS_IN = "SELECT resourceAction FROM ResourceAction resourceAction WHERE resourceActionId IN (";
1646            private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1647            private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1648            private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1649            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1650            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1651            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1652            private static final Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1653            private static final ResourceAction _nullResourceAction = new ResourceActionImpl() {
1654                            @Override
1655                            public Object clone() {
1656                                    return this;
1657                            }
1658    
1659                            @Override
1660                            public CacheModel<ResourceAction> toCacheModel() {
1661                                    return _nullResourceActionCacheModel;
1662                            }
1663                    };
1664    
1665            private static final CacheModel<ResourceAction> _nullResourceActionCacheModel =
1666                    new NullCacheModel();
1667    
1668            private static class NullCacheModel implements CacheModel<ResourceAction>,
1669                    MVCCModel {
1670                    @Override
1671                    public long getMvccVersion() {
1672                            return -1;
1673                    }
1674    
1675                    @Override
1676                    public void setMvccVersion(long mvccVersion) {
1677                    }
1678    
1679                    @Override
1680                    public ResourceAction toEntityModel() {
1681                            return _nullResourceAction;
1682                    }
1683            }
1684    }