001    /**
002     * Copyright (c) 2000-2010 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.NoSuchModelException;
018    import com.liferay.portal.NoSuchResourceActionException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
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     * @author    Brian Wing Shun Chan
052     * @see       ResourceActionPersistence
053     * @see       ResourceActionUtil
054     * @generated
055     */
056    public class ResourceActionPersistenceImpl extends BasePersistenceImpl<ResourceAction>
057            implements ResourceActionPersistence {
058            public static final String FINDER_CLASS_NAME_ENTITY = ResourceActionImpl.class.getName();
059            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
060                    ".List";
061            public static final FinderPath FINDER_PATH_FIND_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
062                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
063                            FINDER_CLASS_NAME_LIST, "findByName",
064                            new String[] {
065                                    String.class.getName(),
066                                    
067                            "java.lang.Integer", "java.lang.Integer",
068                                    "com.liferay.portal.kernel.util.OrderByComparator"
069                            });
070            public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
071                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
072                            FINDER_CLASS_NAME_LIST, "countByName",
073                            new String[] { String.class.getName() });
074            public static final FinderPath FINDER_PATH_FETCH_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
075                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_ENTITY, "fetchByN_A",
077                            new String[] { String.class.getName(), String.class.getName() });
078            public static final FinderPath FINDER_PATH_COUNT_BY_N_A = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
079                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
080                            FINDER_CLASS_NAME_LIST, "countByN_A",
081                            new String[] { String.class.getName(), String.class.getName() });
082            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
083                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
084                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
086                            ResourceActionModelImpl.FINDER_CACHE_ENABLED,
087                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
088    
089            public void cacheResult(ResourceAction resourceAction) {
090                    EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
091                            ResourceActionImpl.class, resourceAction.getPrimaryKey(),
092                            resourceAction);
093    
094                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
095                            new Object[] { resourceAction.getName(), resourceAction.getActionId() },
096                            resourceAction);
097            }
098    
099            public void cacheResult(List<ResourceAction> resourceActions) {
100                    for (ResourceAction resourceAction : resourceActions) {
101                            if (EntityCacheUtil.getResult(
102                                                    ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
103                                                    ResourceActionImpl.class,
104                                                    resourceAction.getPrimaryKey(), this) == null) {
105                                    cacheResult(resourceAction);
106                            }
107                    }
108            }
109    
110            public void clearCache() {
111                    CacheRegistryUtil.clear(ResourceActionImpl.class.getName());
112                    EntityCacheUtil.clearCache(ResourceActionImpl.class.getName());
113                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
114                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
115            }
116    
117            public void clearCache(ResourceAction resourceAction) {
118                    EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
119                            ResourceActionImpl.class, resourceAction.getPrimaryKey());
120    
121                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
122                            new Object[] { resourceAction.getName(), resourceAction.getActionId() });
123            }
124    
125            public ResourceAction create(long resourceActionId) {
126                    ResourceAction resourceAction = new ResourceActionImpl();
127    
128                    resourceAction.setNew(true);
129                    resourceAction.setPrimaryKey(resourceActionId);
130    
131                    return resourceAction;
132            }
133    
134            public ResourceAction remove(Serializable primaryKey)
135                    throws NoSuchModelException, SystemException {
136                    return remove(((Long)primaryKey).longValue());
137            }
138    
139            public ResourceAction remove(long resourceActionId)
140                    throws NoSuchResourceActionException, SystemException {
141                    Session session = null;
142    
143                    try {
144                            session = openSession();
145    
146                            ResourceAction resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
147                                            new Long(resourceActionId));
148    
149                            if (resourceAction == null) {
150                                    if (_log.isWarnEnabled()) {
151                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
152                                                    resourceActionId);
153                                    }
154    
155                                    throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
156                                            resourceActionId);
157                            }
158    
159                            return remove(resourceAction);
160                    }
161                    catch (NoSuchResourceActionException nsee) {
162                            throw nsee;
163                    }
164                    catch (Exception e) {
165                            throw processException(e);
166                    }
167                    finally {
168                            closeSession(session);
169                    }
170            }
171    
172            protected ResourceAction removeImpl(ResourceAction resourceAction)
173                    throws SystemException {
174                    resourceAction = toUnwrappedModel(resourceAction);
175    
176                    Session session = null;
177    
178                    try {
179                            session = openSession();
180    
181                            if (resourceAction.isCachedModel() || BatchSessionUtil.isEnabled()) {
182                                    Object staleObject = session.get(ResourceActionImpl.class,
183                                                    resourceAction.getPrimaryKeyObj());
184    
185                                    if (staleObject != null) {
186                                            session.evict(staleObject);
187                                    }
188                            }
189    
190                            session.delete(resourceAction);
191    
192                            session.flush();
193                    }
194                    catch (Exception e) {
195                            throw processException(e);
196                    }
197                    finally {
198                            closeSession(session);
199                    }
200    
201                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
202    
203                    ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
204    
205                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
206                            new Object[] {
207                                    resourceActionModelImpl.getOriginalName(),
208                                    
209                            resourceActionModelImpl.getOriginalActionId()
210                            });
211    
212                    EntityCacheUtil.removeResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
213                            ResourceActionImpl.class, resourceAction.getPrimaryKey());
214    
215                    return resourceAction;
216            }
217    
218            public ResourceAction updateImpl(
219                    com.liferay.portal.model.ResourceAction resourceAction, boolean merge)
220                    throws SystemException {
221                    resourceAction = toUnwrappedModel(resourceAction);
222    
223                    boolean isNew = resourceAction.isNew();
224    
225                    ResourceActionModelImpl resourceActionModelImpl = (ResourceActionModelImpl)resourceAction;
226    
227                    Session session = null;
228    
229                    try {
230                            session = openSession();
231    
232                            BatchSessionUtil.update(session, resourceAction, merge);
233    
234                            resourceAction.setNew(false);
235                    }
236                    catch (Exception e) {
237                            throw processException(e);
238                    }
239                    finally {
240                            closeSession(session);
241                    }
242    
243                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
244    
245                    EntityCacheUtil.putResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
246                            ResourceActionImpl.class, resourceAction.getPrimaryKey(),
247                            resourceAction);
248    
249                    if (!isNew &&
250                                    (!Validator.equals(resourceAction.getName(),
251                                            resourceActionModelImpl.getOriginalName()) ||
252                                    !Validator.equals(resourceAction.getActionId(),
253                                            resourceActionModelImpl.getOriginalActionId()))) {
254                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_N_A,
255                                    new Object[] {
256                                            resourceActionModelImpl.getOriginalName(),
257                                            
258                                    resourceActionModelImpl.getOriginalActionId()
259                                    });
260                    }
261    
262                    if (isNew ||
263                                    (!Validator.equals(resourceAction.getName(),
264                                            resourceActionModelImpl.getOriginalName()) ||
265                                    !Validator.equals(resourceAction.getActionId(),
266                                            resourceActionModelImpl.getOriginalActionId()))) {
267                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
268                                    new Object[] {
269                                            resourceAction.getName(),
270                                            
271                                    resourceAction.getActionId()
272                                    }, resourceAction);
273                    }
274    
275                    return resourceAction;
276            }
277    
278            protected ResourceAction toUnwrappedModel(ResourceAction resourceAction) {
279                    if (resourceAction instanceof ResourceActionImpl) {
280                            return resourceAction;
281                    }
282    
283                    ResourceActionImpl resourceActionImpl = new ResourceActionImpl();
284    
285                    resourceActionImpl.setNew(resourceAction.isNew());
286                    resourceActionImpl.setPrimaryKey(resourceAction.getPrimaryKey());
287    
288                    resourceActionImpl.setResourceActionId(resourceAction.getResourceActionId());
289                    resourceActionImpl.setName(resourceAction.getName());
290                    resourceActionImpl.setActionId(resourceAction.getActionId());
291                    resourceActionImpl.setBitwiseValue(resourceAction.getBitwiseValue());
292    
293                    return resourceActionImpl;
294            }
295    
296            public ResourceAction findByPrimaryKey(Serializable primaryKey)
297                    throws NoSuchModelException, SystemException {
298                    return findByPrimaryKey(((Long)primaryKey).longValue());
299            }
300    
301            public ResourceAction findByPrimaryKey(long resourceActionId)
302                    throws NoSuchResourceActionException, SystemException {
303                    ResourceAction resourceAction = fetchByPrimaryKey(resourceActionId);
304    
305                    if (resourceAction == null) {
306                            if (_log.isWarnEnabled()) {
307                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + resourceActionId);
308                            }
309    
310                            throw new NoSuchResourceActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
311                                    resourceActionId);
312                    }
313    
314                    return resourceAction;
315            }
316    
317            public ResourceAction fetchByPrimaryKey(Serializable primaryKey)
318                    throws SystemException {
319                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
320            }
321    
322            public ResourceAction fetchByPrimaryKey(long resourceActionId)
323                    throws SystemException {
324                    ResourceAction resourceAction = (ResourceAction)EntityCacheUtil.getResult(ResourceActionModelImpl.ENTITY_CACHE_ENABLED,
325                                    ResourceActionImpl.class, resourceActionId, this);
326    
327                    if (resourceAction == null) {
328                            Session session = null;
329    
330                            try {
331                                    session = openSession();
332    
333                                    resourceAction = (ResourceAction)session.get(ResourceActionImpl.class,
334                                                    new Long(resourceActionId));
335                            }
336                            catch (Exception e) {
337                                    throw processException(e);
338                            }
339                            finally {
340                                    if (resourceAction != null) {
341                                            cacheResult(resourceAction);
342                                    }
343    
344                                    closeSession(session);
345                            }
346                    }
347    
348                    return resourceAction;
349            }
350    
351            public List<ResourceAction> findByName(String name)
352                    throws SystemException {
353                    return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
354            }
355    
356            public List<ResourceAction> findByName(String name, int start, int end)
357                    throws SystemException {
358                    return findByName(name, start, end, null);
359            }
360    
361            public List<ResourceAction> findByName(String name, int start, int end,
362                    OrderByComparator orderByComparator) throws SystemException {
363                    Object[] finderArgs = new Object[] {
364                                    name,
365                                    
366                                    String.valueOf(start), String.valueOf(end),
367                                    String.valueOf(orderByComparator)
368                            };
369    
370                    List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_NAME,
371                                    finderArgs, this);
372    
373                    if (list == null) {
374                            Session session = null;
375    
376                            try {
377                                    session = openSession();
378    
379                                    StringBundler query = null;
380    
381                                    if (orderByComparator != null) {
382                                            query = new StringBundler(3 +
383                                                            (orderByComparator.getOrderByFields().length * 3));
384                                    }
385                                    else {
386                                            query = new StringBundler(3);
387                                    }
388    
389                                    query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
390    
391                                    if (name == null) {
392                                            query.append(_FINDER_COLUMN_NAME_NAME_1);
393                                    }
394                                    else {
395                                            if (name.equals(StringPool.BLANK)) {
396                                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
397                                            }
398                                            else {
399                                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
400                                            }
401                                    }
402    
403                                    if (orderByComparator != null) {
404                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
405                                                    orderByComparator);
406                                    }
407    
408                                    else {
409                                            query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
410                                    }
411    
412                                    String sql = query.toString();
413    
414                                    Query q = session.createQuery(sql);
415    
416                                    QueryPos qPos = QueryPos.getInstance(q);
417    
418                                    if (name != null) {
419                                            qPos.add(name);
420                                    }
421    
422                                    list = (List<ResourceAction>)QueryUtil.list(q, getDialect(),
423                                                    start, end);
424                            }
425                            catch (Exception e) {
426                                    throw processException(e);
427                            }
428                            finally {
429                                    if (list == null) {
430                                            list = new ArrayList<ResourceAction>();
431                                    }
432    
433                                    cacheResult(list);
434    
435                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_NAME, finderArgs,
436                                            list);
437    
438                                    closeSession(session);
439                            }
440                    }
441    
442                    return list;
443            }
444    
445            public ResourceAction findByName_First(String name,
446                    OrderByComparator orderByComparator)
447                    throws NoSuchResourceActionException, SystemException {
448                    List<ResourceAction> list = findByName(name, 0, 1, orderByComparator);
449    
450                    if (list.isEmpty()) {
451                            StringBundler msg = new StringBundler(4);
452    
453                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
454    
455                            msg.append("name=");
456                            msg.append(name);
457    
458                            msg.append(StringPool.CLOSE_CURLY_BRACE);
459    
460                            throw new NoSuchResourceActionException(msg.toString());
461                    }
462                    else {
463                            return list.get(0);
464                    }
465            }
466    
467            public ResourceAction findByName_Last(String name,
468                    OrderByComparator orderByComparator)
469                    throws NoSuchResourceActionException, SystemException {
470                    int count = countByName(name);
471    
472                    List<ResourceAction> list = findByName(name, count - 1, count,
473                                    orderByComparator);
474    
475                    if (list.isEmpty()) {
476                            StringBundler msg = new StringBundler(4);
477    
478                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
479    
480                            msg.append("name=");
481                            msg.append(name);
482    
483                            msg.append(StringPool.CLOSE_CURLY_BRACE);
484    
485                            throw new NoSuchResourceActionException(msg.toString());
486                    }
487                    else {
488                            return list.get(0);
489                    }
490            }
491    
492            public ResourceAction[] findByName_PrevAndNext(long resourceActionId,
493                    String name, OrderByComparator orderByComparator)
494                    throws NoSuchResourceActionException, SystemException {
495                    ResourceAction resourceAction = findByPrimaryKey(resourceActionId);
496    
497                    Session session = null;
498    
499                    try {
500                            session = openSession();
501    
502                            ResourceAction[] array = new ResourceActionImpl[3];
503    
504                            array[0] = getByName_PrevAndNext(session, resourceAction, name,
505                                            orderByComparator, true);
506    
507                            array[1] = resourceAction;
508    
509                            array[2] = getByName_PrevAndNext(session, resourceAction, name,
510                                            orderByComparator, false);
511    
512                            return array;
513                    }
514                    catch (Exception e) {
515                            throw processException(e);
516                    }
517                    finally {
518                            closeSession(session);
519                    }
520            }
521    
522            protected ResourceAction getByName_PrevAndNext(Session session,
523                    ResourceAction resourceAction, String name,
524                    OrderByComparator orderByComparator, boolean previous) {
525                    StringBundler query = null;
526    
527                    if (orderByComparator != null) {
528                            query = new StringBundler(6 +
529                                            (orderByComparator.getOrderByFields().length * 6));
530                    }
531                    else {
532                            query = new StringBundler(3);
533                    }
534    
535                    query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
536    
537                    if (name == null) {
538                            query.append(_FINDER_COLUMN_NAME_NAME_1);
539                    }
540                    else {
541                            if (name.equals(StringPool.BLANK)) {
542                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
543                            }
544                            else {
545                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
546                            }
547                    }
548    
549                    if (orderByComparator != null) {
550                            String[] orderByFields = orderByComparator.getOrderByFields();
551    
552                            if (orderByFields.length > 0) {
553                                    query.append(WHERE_AND);
554                            }
555    
556                            for (int i = 0; i < orderByFields.length; i++) {
557                                    query.append(_ORDER_BY_ENTITY_ALIAS);
558                                    query.append(orderByFields[i]);
559    
560                                    if ((i + 1) < orderByFields.length) {
561                                            if (orderByComparator.isAscending() ^ previous) {
562                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
563                                            }
564                                            else {
565                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
566                                            }
567                                    }
568                                    else {
569                                            if (orderByComparator.isAscending() ^ previous) {
570                                                    query.append(WHERE_GREATER_THAN);
571                                            }
572                                            else {
573                                                    query.append(WHERE_LESSER_THAN);
574                                            }
575                                    }
576                            }
577    
578                            query.append(ORDER_BY_CLAUSE);
579    
580                            for (int i = 0; i < orderByFields.length; i++) {
581                                    query.append(_ORDER_BY_ENTITY_ALIAS);
582                                    query.append(orderByFields[i]);
583    
584                                    if ((i + 1) < orderByFields.length) {
585                                            if (orderByComparator.isAscending() ^ previous) {
586                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
587                                            }
588                                            else {
589                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
590                                            }
591                                    }
592                                    else {
593                                            if (orderByComparator.isAscending() ^ previous) {
594                                                    query.append(ORDER_BY_ASC);
595                                            }
596                                            else {
597                                                    query.append(ORDER_BY_DESC);
598                                            }
599                                    }
600                            }
601                    }
602    
603                    else {
604                            query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
605                    }
606    
607                    String sql = query.toString();
608    
609                    Query q = session.createQuery(sql);
610    
611                    q.setFirstResult(0);
612                    q.setMaxResults(2);
613    
614                    QueryPos qPos = QueryPos.getInstance(q);
615    
616                    if (name != null) {
617                            qPos.add(name);
618                    }
619    
620                    if (orderByComparator != null) {
621                            Object[] values = orderByComparator.getOrderByValues(resourceAction);
622    
623                            for (Object value : values) {
624                                    qPos.add(value);
625                            }
626                    }
627    
628                    List<ResourceAction> list = q.list();
629    
630                    if (list.size() == 2) {
631                            return list.get(1);
632                    }
633                    else {
634                            return null;
635                    }
636            }
637    
638            public ResourceAction findByN_A(String name, String actionId)
639                    throws NoSuchResourceActionException, SystemException {
640                    ResourceAction resourceAction = fetchByN_A(name, actionId);
641    
642                    if (resourceAction == null) {
643                            StringBundler msg = new StringBundler(6);
644    
645                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
646    
647                            msg.append("name=");
648                            msg.append(name);
649    
650                            msg.append(", actionId=");
651                            msg.append(actionId);
652    
653                            msg.append(StringPool.CLOSE_CURLY_BRACE);
654    
655                            if (_log.isWarnEnabled()) {
656                                    _log.warn(msg.toString());
657                            }
658    
659                            throw new NoSuchResourceActionException(msg.toString());
660                    }
661    
662                    return resourceAction;
663            }
664    
665            public ResourceAction fetchByN_A(String name, String actionId)
666                    throws SystemException {
667                    return fetchByN_A(name, actionId, true);
668            }
669    
670            public ResourceAction fetchByN_A(String name, String actionId,
671                    boolean retrieveFromCache) throws SystemException {
672                    Object[] finderArgs = new Object[] { name, actionId };
673    
674                    Object result = null;
675    
676                    if (retrieveFromCache) {
677                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_N_A,
678                                            finderArgs, this);
679                    }
680    
681                    if (result == null) {
682                            Session session = null;
683    
684                            try {
685                                    session = openSession();
686    
687                                    StringBundler query = new StringBundler(4);
688    
689                                    query.append(_SQL_SELECT_RESOURCEACTION_WHERE);
690    
691                                    if (name == null) {
692                                            query.append(_FINDER_COLUMN_N_A_NAME_1);
693                                    }
694                                    else {
695                                            if (name.equals(StringPool.BLANK)) {
696                                                    query.append(_FINDER_COLUMN_N_A_NAME_3);
697                                            }
698                                            else {
699                                                    query.append(_FINDER_COLUMN_N_A_NAME_2);
700                                            }
701                                    }
702    
703                                    if (actionId == null) {
704                                            query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
705                                    }
706                                    else {
707                                            if (actionId.equals(StringPool.BLANK)) {
708                                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
709                                            }
710                                            else {
711                                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
712                                            }
713                                    }
714    
715                                    query.append(ResourceActionModelImpl.ORDER_BY_JPQL);
716    
717                                    String sql = query.toString();
718    
719                                    Query q = session.createQuery(sql);
720    
721                                    QueryPos qPos = QueryPos.getInstance(q);
722    
723                                    if (name != null) {
724                                            qPos.add(name);
725                                    }
726    
727                                    if (actionId != null) {
728                                            qPos.add(actionId);
729                                    }
730    
731                                    List<ResourceAction> list = q.list();
732    
733                                    result = list;
734    
735                                    ResourceAction resourceAction = null;
736    
737                                    if (list.isEmpty()) {
738                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
739                                                    finderArgs, list);
740                                    }
741                                    else {
742                                            resourceAction = list.get(0);
743    
744                                            cacheResult(resourceAction);
745    
746                                            if ((resourceAction.getName() == null) ||
747                                                            !resourceAction.getName().equals(name) ||
748                                                            (resourceAction.getActionId() == null) ||
749                                                            !resourceAction.getActionId().equals(actionId)) {
750                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
751                                                            finderArgs, resourceAction);
752                                            }
753                                    }
754    
755                                    return resourceAction;
756                            }
757                            catch (Exception e) {
758                                    throw processException(e);
759                            }
760                            finally {
761                                    if (result == null) {
762                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_N_A,
763                                                    finderArgs, new ArrayList<ResourceAction>());
764                                    }
765    
766                                    closeSession(session);
767                            }
768                    }
769                    else {
770                            if (result instanceof List<?>) {
771                                    return null;
772                            }
773                            else {
774                                    return (ResourceAction)result;
775                            }
776                    }
777            }
778    
779            public List<ResourceAction> findAll() throws SystemException {
780                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
781            }
782    
783            public List<ResourceAction> findAll(int start, int end)
784                    throws SystemException {
785                    return findAll(start, end, null);
786            }
787    
788            public List<ResourceAction> findAll(int start, int end,
789                    OrderByComparator orderByComparator) throws SystemException {
790                    Object[] finderArgs = new Object[] {
791                                    String.valueOf(start), String.valueOf(end),
792                                    String.valueOf(orderByComparator)
793                            };
794    
795                    List<ResourceAction> list = (List<ResourceAction>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
796                                    finderArgs, this);
797    
798                    if (list == null) {
799                            Session session = null;
800    
801                            try {
802                                    session = openSession();
803    
804                                    StringBundler query = null;
805                                    String sql = null;
806    
807                                    if (orderByComparator != null) {
808                                            query = new StringBundler(2 +
809                                                            (orderByComparator.getOrderByFields().length * 3));
810    
811                                            query.append(_SQL_SELECT_RESOURCEACTION);
812    
813                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
814                                                    orderByComparator);
815    
816                                            sql = query.toString();
817                                    }
818                                    else {
819                                            sql = _SQL_SELECT_RESOURCEACTION.concat(ResourceActionModelImpl.ORDER_BY_JPQL);
820                                    }
821    
822                                    Query q = session.createQuery(sql);
823    
824                                    if (orderByComparator == null) {
825                                            list = (List<ResourceAction>)QueryUtil.list(q,
826                                                            getDialect(), start, end, false);
827    
828                                            Collections.sort(list);
829                                    }
830                                    else {
831                                            list = (List<ResourceAction>)QueryUtil.list(q,
832                                                            getDialect(), start, end);
833                                    }
834                            }
835                            catch (Exception e) {
836                                    throw processException(e);
837                            }
838                            finally {
839                                    if (list == null) {
840                                            list = new ArrayList<ResourceAction>();
841                                    }
842    
843                                    cacheResult(list);
844    
845                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
846    
847                                    closeSession(session);
848                            }
849                    }
850    
851                    return list;
852            }
853    
854            public void removeByName(String name) throws SystemException {
855                    for (ResourceAction resourceAction : findByName(name)) {
856                            remove(resourceAction);
857                    }
858            }
859    
860            public void removeByN_A(String name, String actionId)
861                    throws NoSuchResourceActionException, SystemException {
862                    ResourceAction resourceAction = findByN_A(name, actionId);
863    
864                    remove(resourceAction);
865            }
866    
867            public void removeAll() throws SystemException {
868                    for (ResourceAction resourceAction : findAll()) {
869                            remove(resourceAction);
870                    }
871            }
872    
873            public int countByName(String name) throws SystemException {
874                    Object[] finderArgs = new Object[] { name };
875    
876                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_NAME,
877                                    finderArgs, this);
878    
879                    if (count == null) {
880                            Session session = null;
881    
882                            try {
883                                    session = openSession();
884    
885                                    StringBundler query = new StringBundler(2);
886    
887                                    query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
888    
889                                    if (name == null) {
890                                            query.append(_FINDER_COLUMN_NAME_NAME_1);
891                                    }
892                                    else {
893                                            if (name.equals(StringPool.BLANK)) {
894                                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
895                                            }
896                                            else {
897                                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
898                                            }
899                                    }
900    
901                                    String sql = query.toString();
902    
903                                    Query q = session.createQuery(sql);
904    
905                                    QueryPos qPos = QueryPos.getInstance(q);
906    
907                                    if (name != null) {
908                                            qPos.add(name);
909                                    }
910    
911                                    count = (Long)q.uniqueResult();
912                            }
913                            catch (Exception e) {
914                                    throw processException(e);
915                            }
916                            finally {
917                                    if (count == null) {
918                                            count = Long.valueOf(0);
919                                    }
920    
921                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_NAME,
922                                            finderArgs, count);
923    
924                                    closeSession(session);
925                            }
926                    }
927    
928                    return count.intValue();
929            }
930    
931            public int countByN_A(String name, String actionId)
932                    throws SystemException {
933                    Object[] finderArgs = new Object[] { name, actionId };
934    
935                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_N_A,
936                                    finderArgs, this);
937    
938                    if (count == null) {
939                            Session session = null;
940    
941                            try {
942                                    session = openSession();
943    
944                                    StringBundler query = new StringBundler(3);
945    
946                                    query.append(_SQL_COUNT_RESOURCEACTION_WHERE);
947    
948                                    if (name == null) {
949                                            query.append(_FINDER_COLUMN_N_A_NAME_1);
950                                    }
951                                    else {
952                                            if (name.equals(StringPool.BLANK)) {
953                                                    query.append(_FINDER_COLUMN_N_A_NAME_3);
954                                            }
955                                            else {
956                                                    query.append(_FINDER_COLUMN_N_A_NAME_2);
957                                            }
958                                    }
959    
960                                    if (actionId == null) {
961                                            query.append(_FINDER_COLUMN_N_A_ACTIONID_1);
962                                    }
963                                    else {
964                                            if (actionId.equals(StringPool.BLANK)) {
965                                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_3);
966                                            }
967                                            else {
968                                                    query.append(_FINDER_COLUMN_N_A_ACTIONID_2);
969                                            }
970                                    }
971    
972                                    String sql = query.toString();
973    
974                                    Query q = session.createQuery(sql);
975    
976                                    QueryPos qPos = QueryPos.getInstance(q);
977    
978                                    if (name != null) {
979                                            qPos.add(name);
980                                    }
981    
982                                    if (actionId != null) {
983                                            qPos.add(actionId);
984                                    }
985    
986                                    count = (Long)q.uniqueResult();
987                            }
988                            catch (Exception e) {
989                                    throw processException(e);
990                            }
991                            finally {
992                                    if (count == null) {
993                                            count = Long.valueOf(0);
994                                    }
995    
996                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_N_A, finderArgs,
997                                            count);
998    
999                                    closeSession(session);
1000                            }
1001                    }
1002    
1003                    return count.intValue();
1004            }
1005    
1006            public int countAll() throws SystemException {
1007                    Object[] finderArgs = new Object[0];
1008    
1009                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1010                                    finderArgs, this);
1011    
1012                    if (count == null) {
1013                            Session session = null;
1014    
1015                            try {
1016                                    session = openSession();
1017    
1018                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEACTION);
1019    
1020                                    count = (Long)q.uniqueResult();
1021                            }
1022                            catch (Exception e) {
1023                                    throw processException(e);
1024                            }
1025                            finally {
1026                                    if (count == null) {
1027                                            count = Long.valueOf(0);
1028                                    }
1029    
1030                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1031                                            count);
1032    
1033                                    closeSession(session);
1034                            }
1035                    }
1036    
1037                    return count.intValue();
1038            }
1039    
1040            public void afterPropertiesSet() {
1041                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1042                                            com.liferay.portal.util.PropsUtil.get(
1043                                                    "value.object.listener.com.liferay.portal.model.ResourceAction")));
1044    
1045                    if (listenerClassNames.length > 0) {
1046                            try {
1047                                    List<ModelListener<ResourceAction>> listenersList = new ArrayList<ModelListener<ResourceAction>>();
1048    
1049                                    for (String listenerClassName : listenerClassNames) {
1050                                            listenersList.add((ModelListener<ResourceAction>)InstanceFactory.newInstance(
1051                                                            listenerClassName));
1052                                    }
1053    
1054                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1055                            }
1056                            catch (Exception e) {
1057                                    _log.error(e);
1058                            }
1059                    }
1060            }
1061    
1062            @BeanReference(type = AccountPersistence.class)
1063            protected AccountPersistence accountPersistence;
1064            @BeanReference(type = AddressPersistence.class)
1065            protected AddressPersistence addressPersistence;
1066            @BeanReference(type = BrowserTrackerPersistence.class)
1067            protected BrowserTrackerPersistence browserTrackerPersistence;
1068            @BeanReference(type = ClassNamePersistence.class)
1069            protected ClassNamePersistence classNamePersistence;
1070            @BeanReference(type = CompanyPersistence.class)
1071            protected CompanyPersistence companyPersistence;
1072            @BeanReference(type = ContactPersistence.class)
1073            protected ContactPersistence contactPersistence;
1074            @BeanReference(type = CountryPersistence.class)
1075            protected CountryPersistence countryPersistence;
1076            @BeanReference(type = EmailAddressPersistence.class)
1077            protected EmailAddressPersistence emailAddressPersistence;
1078            @BeanReference(type = GroupPersistence.class)
1079            protected GroupPersistence groupPersistence;
1080            @BeanReference(type = ImagePersistence.class)
1081            protected ImagePersistence imagePersistence;
1082            @BeanReference(type = LayoutPersistence.class)
1083            protected LayoutPersistence layoutPersistence;
1084            @BeanReference(type = LayoutPrototypePersistence.class)
1085            protected LayoutPrototypePersistence layoutPrototypePersistence;
1086            @BeanReference(type = LayoutSetPersistence.class)
1087            protected LayoutSetPersistence layoutSetPersistence;
1088            @BeanReference(type = LayoutSetPrototypePersistence.class)
1089            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1090            @BeanReference(type = ListTypePersistence.class)
1091            protected ListTypePersistence listTypePersistence;
1092            @BeanReference(type = LockPersistence.class)
1093            protected LockPersistence lockPersistence;
1094            @BeanReference(type = MembershipRequestPersistence.class)
1095            protected MembershipRequestPersistence membershipRequestPersistence;
1096            @BeanReference(type = OrganizationPersistence.class)
1097            protected OrganizationPersistence organizationPersistence;
1098            @BeanReference(type = OrgGroupPermissionPersistence.class)
1099            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1100            @BeanReference(type = OrgGroupRolePersistence.class)
1101            protected OrgGroupRolePersistence orgGroupRolePersistence;
1102            @BeanReference(type = OrgLaborPersistence.class)
1103            protected OrgLaborPersistence orgLaborPersistence;
1104            @BeanReference(type = PasswordPolicyPersistence.class)
1105            protected PasswordPolicyPersistence passwordPolicyPersistence;
1106            @BeanReference(type = PasswordPolicyRelPersistence.class)
1107            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1108            @BeanReference(type = PasswordTrackerPersistence.class)
1109            protected PasswordTrackerPersistence passwordTrackerPersistence;
1110            @BeanReference(type = PermissionPersistence.class)
1111            protected PermissionPersistence permissionPersistence;
1112            @BeanReference(type = PhonePersistence.class)
1113            protected PhonePersistence phonePersistence;
1114            @BeanReference(type = PluginSettingPersistence.class)
1115            protected PluginSettingPersistence pluginSettingPersistence;
1116            @BeanReference(type = PortletPersistence.class)
1117            protected PortletPersistence portletPersistence;
1118            @BeanReference(type = PortletItemPersistence.class)
1119            protected PortletItemPersistence portletItemPersistence;
1120            @BeanReference(type = PortletPreferencesPersistence.class)
1121            protected PortletPreferencesPersistence portletPreferencesPersistence;
1122            @BeanReference(type = RegionPersistence.class)
1123            protected RegionPersistence regionPersistence;
1124            @BeanReference(type = ReleasePersistence.class)
1125            protected ReleasePersistence releasePersistence;
1126            @BeanReference(type = ResourcePersistence.class)
1127            protected ResourcePersistence resourcePersistence;
1128            @BeanReference(type = ResourceActionPersistence.class)
1129            protected ResourceActionPersistence resourceActionPersistence;
1130            @BeanReference(type = ResourceCodePersistence.class)
1131            protected ResourceCodePersistence resourceCodePersistence;
1132            @BeanReference(type = ResourcePermissionPersistence.class)
1133            protected ResourcePermissionPersistence resourcePermissionPersistence;
1134            @BeanReference(type = RolePersistence.class)
1135            protected RolePersistence rolePersistence;
1136            @BeanReference(type = ServiceComponentPersistence.class)
1137            protected ServiceComponentPersistence serviceComponentPersistence;
1138            @BeanReference(type = ShardPersistence.class)
1139            protected ShardPersistence shardPersistence;
1140            @BeanReference(type = SubscriptionPersistence.class)
1141            protected SubscriptionPersistence subscriptionPersistence;
1142            @BeanReference(type = TicketPersistence.class)
1143            protected TicketPersistence ticketPersistence;
1144            @BeanReference(type = TeamPersistence.class)
1145            protected TeamPersistence teamPersistence;
1146            @BeanReference(type = UserPersistence.class)
1147            protected UserPersistence userPersistence;
1148            @BeanReference(type = UserGroupPersistence.class)
1149            protected UserGroupPersistence userGroupPersistence;
1150            @BeanReference(type = UserGroupGroupRolePersistence.class)
1151            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1152            @BeanReference(type = UserGroupRolePersistence.class)
1153            protected UserGroupRolePersistence userGroupRolePersistence;
1154            @BeanReference(type = UserIdMapperPersistence.class)
1155            protected UserIdMapperPersistence userIdMapperPersistence;
1156            @BeanReference(type = UserTrackerPersistence.class)
1157            protected UserTrackerPersistence userTrackerPersistence;
1158            @BeanReference(type = UserTrackerPathPersistence.class)
1159            protected UserTrackerPathPersistence userTrackerPathPersistence;
1160            @BeanReference(type = WebDAVPropsPersistence.class)
1161            protected WebDAVPropsPersistence webDAVPropsPersistence;
1162            @BeanReference(type = WebsitePersistence.class)
1163            protected WebsitePersistence websitePersistence;
1164            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1165            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1166            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1167            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1168            private static final String _SQL_SELECT_RESOURCEACTION = "SELECT resourceAction FROM ResourceAction resourceAction";
1169            private static final String _SQL_SELECT_RESOURCEACTION_WHERE = "SELECT resourceAction FROM ResourceAction resourceAction WHERE ";
1170            private static final String _SQL_COUNT_RESOURCEACTION = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction";
1171            private static final String _SQL_COUNT_RESOURCEACTION_WHERE = "SELECT COUNT(resourceAction) FROM ResourceAction resourceAction WHERE ";
1172            private static final String _FINDER_COLUMN_NAME_NAME_1 = "resourceAction.name IS NULL";
1173            private static final String _FINDER_COLUMN_NAME_NAME_2 = "resourceAction.name = ?";
1174            private static final String _FINDER_COLUMN_NAME_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?)";
1175            private static final String _FINDER_COLUMN_N_A_NAME_1 = "resourceAction.name IS NULL AND ";
1176            private static final String _FINDER_COLUMN_N_A_NAME_2 = "resourceAction.name = ? AND ";
1177            private static final String _FINDER_COLUMN_N_A_NAME_3 = "(resourceAction.name IS NULL OR resourceAction.name = ?) AND ";
1178            private static final String _FINDER_COLUMN_N_A_ACTIONID_1 = "resourceAction.actionId IS NULL";
1179            private static final String _FINDER_COLUMN_N_A_ACTIONID_2 = "resourceAction.actionId = ?";
1180            private static final String _FINDER_COLUMN_N_A_ACTIONID_3 = "(resourceAction.actionId IS NULL OR resourceAction.actionId = ?)";
1181            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceAction.";
1182            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceAction exists with the primary key ";
1183            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceAction exists with the key {";
1184            private static Log _log = LogFactoryUtil.getLog(ResourceActionPersistenceImpl.class);
1185    }