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