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