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