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.portlet.mobiledevicerules.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.BatchSessionUtil;
041    import com.liferay.portal.service.persistence.ResourcePersistence;
042    import com.liferay.portal.service.persistence.UserPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.mobiledevicerules.NoSuchActionException;
046    import com.liferay.portlet.mobiledevicerules.model.MDRAction;
047    import com.liferay.portlet.mobiledevicerules.model.impl.MDRActionImpl;
048    import com.liferay.portlet.mobiledevicerules.model.impl.MDRActionModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    
056    /**
057     * The persistence implementation for the m d r action service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Edward C. Han
064     * @see MDRActionPersistence
065     * @see MDRActionUtil
066     * @generated
067     */
068    public class MDRActionPersistenceImpl extends BasePersistenceImpl<MDRAction>
069            implements MDRActionPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * Never modify or reference this class directly. Always use {@link MDRActionUtil} to access the m d r action persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = MDRActionImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
081                            MDRActionModelImpl.FINDER_CACHE_ENABLED, MDRActionImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
083                            new String[] {
084                                    String.class.getName(),
085                                    
086                            "java.lang.Integer", "java.lang.Integer",
087                                    "com.liferay.portal.kernel.util.OrderByComparator"
088                            });
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
090                            MDRActionModelImpl.FINDER_CACHE_ENABLED, MDRActionImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
092                            new String[] { String.class.getName() },
093                            MDRActionModelImpl.UUID_COLUMN_BITMASK);
094            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
095                            MDRActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
097                            new String[] { String.class.getName() });
098            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
099                            MDRActionModelImpl.FINDER_CACHE_ENABLED, MDRActionImpl.class,
100                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
101                            new String[] { String.class.getName(), Long.class.getName() },
102                            MDRActionModelImpl.UUID_COLUMN_BITMASK |
103                            MDRActionModelImpl.GROUPID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
105                            MDRActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
107                            new String[] { String.class.getName(), Long.class.getName() });
108            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPINSTANCEID =
109                    new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
110                            MDRActionModelImpl.FINDER_CACHE_ENABLED, MDRActionImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
112                            "findByRuleGroupInstanceId",
113                            new String[] {
114                                    Long.class.getName(),
115                                    
116                            "java.lang.Integer", "java.lang.Integer",
117                                    "com.liferay.portal.kernel.util.OrderByComparator"
118                            });
119            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPINSTANCEID =
120                    new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
121                            MDRActionModelImpl.FINDER_CACHE_ENABLED, MDRActionImpl.class,
122                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
123                            "findByRuleGroupInstanceId", new String[] { Long.class.getName() },
124                            MDRActionModelImpl.RULEGROUPINSTANCEID_COLUMN_BITMASK);
125            public static final FinderPath FINDER_PATH_COUNT_BY_RULEGROUPINSTANCEID = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
126                            MDRActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
128                            "countByRuleGroupInstanceId", new String[] { Long.class.getName() });
129            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
130                            MDRActionModelImpl.FINDER_CACHE_ENABLED, MDRActionImpl.class,
131                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
132            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
133                            MDRActionModelImpl.FINDER_CACHE_ENABLED, MDRActionImpl.class,
134                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
135            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
136                            MDRActionModelImpl.FINDER_CACHE_ENABLED, Long.class,
137                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
138    
139            /**
140             * Caches the m d r action in the entity cache if it is enabled.
141             *
142             * @param mdrAction the m d r action
143             */
144            public void cacheResult(MDRAction mdrAction) {
145                    EntityCacheUtil.putResult(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
146                            MDRActionImpl.class, mdrAction.getPrimaryKey(), mdrAction);
147    
148                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
149                            new Object[] {
150                                    mdrAction.getUuid(), Long.valueOf(mdrAction.getGroupId())
151                            }, mdrAction);
152    
153                    mdrAction.resetOriginalValues();
154            }
155    
156            /**
157             * Caches the m d r actions in the entity cache if it is enabled.
158             *
159             * @param mdrActions the m d r actions
160             */
161            public void cacheResult(List<MDRAction> mdrActions) {
162                    for (MDRAction mdrAction : mdrActions) {
163                            if (EntityCacheUtil.getResult(
164                                                    MDRActionModelImpl.ENTITY_CACHE_ENABLED,
165                                                    MDRActionImpl.class, mdrAction.getPrimaryKey()) == null) {
166                                    cacheResult(mdrAction);
167                            }
168                            else {
169                                    mdrAction.resetOriginalValues();
170                            }
171                    }
172            }
173    
174            /**
175             * Clears the cache for all m d r actions.
176             *
177             * <p>
178             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
179             * </p>
180             */
181            @Override
182            public void clearCache() {
183                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
184                            CacheRegistryUtil.clear(MDRActionImpl.class.getName());
185                    }
186    
187                    EntityCacheUtil.clearCache(MDRActionImpl.class.getName());
188    
189                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
190                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
192            }
193    
194            /**
195             * Clears the cache for the m d r action.
196             *
197             * <p>
198             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
199             * </p>
200             */
201            @Override
202            public void clearCache(MDRAction mdrAction) {
203                    EntityCacheUtil.removeResult(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
204                            MDRActionImpl.class, mdrAction.getPrimaryKey());
205    
206                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
207                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
208    
209                    clearUniqueFindersCache(mdrAction);
210            }
211    
212            @Override
213            public void clearCache(List<MDRAction> mdrActions) {
214                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
215                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
216    
217                    for (MDRAction mdrAction : mdrActions) {
218                            EntityCacheUtil.removeResult(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
219                                    MDRActionImpl.class, mdrAction.getPrimaryKey());
220    
221                            clearUniqueFindersCache(mdrAction);
222                    }
223            }
224    
225            protected void cacheUniqueFindersCache(MDRAction mdrAction) {
226                    if (mdrAction.isNew()) {
227                            Object[] args = new Object[] {
228                                            mdrAction.getUuid(), Long.valueOf(mdrAction.getGroupId())
229                                    };
230    
231                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
232                                    Long.valueOf(1));
233                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
234                                    mdrAction);
235                    }
236                    else {
237                            MDRActionModelImpl mdrActionModelImpl = (MDRActionModelImpl)mdrAction;
238    
239                            if ((mdrActionModelImpl.getColumnBitmask() &
240                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
241                                    Object[] args = new Object[] {
242                                                    mdrAction.getUuid(),
243                                                    Long.valueOf(mdrAction.getGroupId())
244                                            };
245    
246                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
247                                            Long.valueOf(1));
248                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
249                                            mdrAction);
250                            }
251                    }
252            }
253    
254            protected void clearUniqueFindersCache(MDRAction mdrAction) {
255                    MDRActionModelImpl mdrActionModelImpl = (MDRActionModelImpl)mdrAction;
256    
257                    Object[] args = new Object[] {
258                                    mdrAction.getUuid(), Long.valueOf(mdrAction.getGroupId())
259                            };
260    
261                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
262                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
263    
264                    if ((mdrActionModelImpl.getColumnBitmask() &
265                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
266                            args = new Object[] {
267                                            mdrActionModelImpl.getOriginalUuid(),
268                                            Long.valueOf(mdrActionModelImpl.getOriginalGroupId())
269                                    };
270    
271                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
272                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
273                    }
274            }
275    
276            /**
277             * Creates a new m d r action with the primary key. Does not add the m d r action to the database.
278             *
279             * @param actionId the primary key for the new m d r action
280             * @return the new m d r action
281             */
282            public MDRAction create(long actionId) {
283                    MDRAction mdrAction = new MDRActionImpl();
284    
285                    mdrAction.setNew(true);
286                    mdrAction.setPrimaryKey(actionId);
287    
288                    String uuid = PortalUUIDUtil.generate();
289    
290                    mdrAction.setUuid(uuid);
291    
292                    return mdrAction;
293            }
294    
295            /**
296             * Removes the m d r action with the primary key from the database. Also notifies the appropriate model listeners.
297             *
298             * @param actionId the primary key of the m d r action
299             * @return the m d r action that was removed
300             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a m d r action with the primary key could not be found
301             * @throws SystemException if a system exception occurred
302             */
303            public MDRAction remove(long actionId)
304                    throws NoSuchActionException, SystemException {
305                    return remove(Long.valueOf(actionId));
306            }
307    
308            /**
309             * Removes the m d r action with the primary key from the database. Also notifies the appropriate model listeners.
310             *
311             * @param primaryKey the primary key of the m d r action
312             * @return the m d r action that was removed
313             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a m d r action with the primary key could not be found
314             * @throws SystemException if a system exception occurred
315             */
316            @Override
317            public MDRAction remove(Serializable primaryKey)
318                    throws NoSuchActionException, SystemException {
319                    Session session = null;
320    
321                    try {
322                            session = openSession();
323    
324                            MDRAction mdrAction = (MDRAction)session.get(MDRActionImpl.class,
325                                            primaryKey);
326    
327                            if (mdrAction == null) {
328                                    if (_log.isWarnEnabled()) {
329                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
330                                    }
331    
332                                    throw new NoSuchActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
333                                            primaryKey);
334                            }
335    
336                            return remove(mdrAction);
337                    }
338                    catch (NoSuchActionException nsee) {
339                            throw nsee;
340                    }
341                    catch (Exception e) {
342                            throw processException(e);
343                    }
344                    finally {
345                            closeSession(session);
346                    }
347            }
348    
349            @Override
350            protected MDRAction removeImpl(MDRAction mdrAction)
351                    throws SystemException {
352                    mdrAction = toUnwrappedModel(mdrAction);
353    
354                    Session session = null;
355    
356                    try {
357                            session = openSession();
358    
359                            BatchSessionUtil.delete(session, mdrAction);
360                    }
361                    catch (Exception e) {
362                            throw processException(e);
363                    }
364                    finally {
365                            closeSession(session);
366                    }
367    
368                    clearCache(mdrAction);
369    
370                    return mdrAction;
371            }
372    
373            @Override
374            public MDRAction updateImpl(
375                    com.liferay.portlet.mobiledevicerules.model.MDRAction mdrAction,
376                    boolean merge) throws SystemException {
377                    mdrAction = toUnwrappedModel(mdrAction);
378    
379                    boolean isNew = mdrAction.isNew();
380    
381                    MDRActionModelImpl mdrActionModelImpl = (MDRActionModelImpl)mdrAction;
382    
383                    if (Validator.isNull(mdrAction.getUuid())) {
384                            String uuid = PortalUUIDUtil.generate();
385    
386                            mdrAction.setUuid(uuid);
387                    }
388    
389                    Session session = null;
390    
391                    try {
392                            session = openSession();
393    
394                            BatchSessionUtil.update(session, mdrAction, merge);
395    
396                            mdrAction.setNew(false);
397                    }
398                    catch (Exception e) {
399                            throw processException(e);
400                    }
401                    finally {
402                            closeSession(session);
403                    }
404    
405                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
406    
407                    if (isNew || !MDRActionModelImpl.COLUMN_BITMASK_ENABLED) {
408                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
409                    }
410    
411                    else {
412                            if ((mdrActionModelImpl.getColumnBitmask() &
413                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
414                                    Object[] args = new Object[] {
415                                                    mdrActionModelImpl.getOriginalUuid()
416                                            };
417    
418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
419                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
420                                            args);
421    
422                                    args = new Object[] { mdrActionModelImpl.getUuid() };
423    
424                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
425                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
426                                            args);
427                            }
428    
429                            if ((mdrActionModelImpl.getColumnBitmask() &
430                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPINSTANCEID.getColumnBitmask()) != 0) {
431                                    Object[] args = new Object[] {
432                                                    Long.valueOf(mdrActionModelImpl.getOriginalRuleGroupInstanceId())
433                                            };
434    
435                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPINSTANCEID,
436                                            args);
437                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPINSTANCEID,
438                                            args);
439    
440                                    args = new Object[] {
441                                                    Long.valueOf(mdrActionModelImpl.getRuleGroupInstanceId())
442                                            };
443    
444                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPINSTANCEID,
445                                            args);
446                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPINSTANCEID,
447                                            args);
448                            }
449                    }
450    
451                    EntityCacheUtil.putResult(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
452                            MDRActionImpl.class, mdrAction.getPrimaryKey(), mdrAction);
453    
454                    clearUniqueFindersCache(mdrAction);
455                    cacheUniqueFindersCache(mdrAction);
456    
457                    return mdrAction;
458            }
459    
460            protected MDRAction toUnwrappedModel(MDRAction mdrAction) {
461                    if (mdrAction instanceof MDRActionImpl) {
462                            return mdrAction;
463                    }
464    
465                    MDRActionImpl mdrActionImpl = new MDRActionImpl();
466    
467                    mdrActionImpl.setNew(mdrAction.isNew());
468                    mdrActionImpl.setPrimaryKey(mdrAction.getPrimaryKey());
469    
470                    mdrActionImpl.setUuid(mdrAction.getUuid());
471                    mdrActionImpl.setActionId(mdrAction.getActionId());
472                    mdrActionImpl.setGroupId(mdrAction.getGroupId());
473                    mdrActionImpl.setCompanyId(mdrAction.getCompanyId());
474                    mdrActionImpl.setUserId(mdrAction.getUserId());
475                    mdrActionImpl.setUserName(mdrAction.getUserName());
476                    mdrActionImpl.setCreateDate(mdrAction.getCreateDate());
477                    mdrActionImpl.setModifiedDate(mdrAction.getModifiedDate());
478                    mdrActionImpl.setClassNameId(mdrAction.getClassNameId());
479                    mdrActionImpl.setClassPK(mdrAction.getClassPK());
480                    mdrActionImpl.setRuleGroupInstanceId(mdrAction.getRuleGroupInstanceId());
481                    mdrActionImpl.setName(mdrAction.getName());
482                    mdrActionImpl.setDescription(mdrAction.getDescription());
483                    mdrActionImpl.setType(mdrAction.getType());
484                    mdrActionImpl.setTypeSettings(mdrAction.getTypeSettings());
485    
486                    return mdrActionImpl;
487            }
488    
489            /**
490             * Returns the m d r action with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
491             *
492             * @param primaryKey the primary key of the m d r action
493             * @return the m d r action
494             * @throws com.liferay.portal.NoSuchModelException if a m d r action with the primary key could not be found
495             * @throws SystemException if a system exception occurred
496             */
497            @Override
498            public MDRAction findByPrimaryKey(Serializable primaryKey)
499                    throws NoSuchModelException, SystemException {
500                    return findByPrimaryKey(((Long)primaryKey).longValue());
501            }
502    
503            /**
504             * Returns the m d r action with the primary key or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchActionException} if it could not be found.
505             *
506             * @param actionId the primary key of the m d r action
507             * @return the m d r action
508             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a m d r action with the primary key could not be found
509             * @throws SystemException if a system exception occurred
510             */
511            public MDRAction findByPrimaryKey(long actionId)
512                    throws NoSuchActionException, SystemException {
513                    MDRAction mdrAction = fetchByPrimaryKey(actionId);
514    
515                    if (mdrAction == null) {
516                            if (_log.isWarnEnabled()) {
517                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + actionId);
518                            }
519    
520                            throw new NoSuchActionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
521                                    actionId);
522                    }
523    
524                    return mdrAction;
525            }
526    
527            /**
528             * Returns the m d r action with the primary key or returns <code>null</code> if it could not be found.
529             *
530             * @param primaryKey the primary key of the m d r action
531             * @return the m d r action, or <code>null</code> if a m d r action with the primary key could not be found
532             * @throws SystemException if a system exception occurred
533             */
534            @Override
535            public MDRAction fetchByPrimaryKey(Serializable primaryKey)
536                    throws SystemException {
537                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
538            }
539    
540            /**
541             * Returns the m d r action with the primary key or returns <code>null</code> if it could not be found.
542             *
543             * @param actionId the primary key of the m d r action
544             * @return the m d r action, or <code>null</code> if a m d r action with the primary key could not be found
545             * @throws SystemException if a system exception occurred
546             */
547            public MDRAction fetchByPrimaryKey(long actionId) throws SystemException {
548                    MDRAction mdrAction = (MDRAction)EntityCacheUtil.getResult(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
549                                    MDRActionImpl.class, actionId);
550    
551                    if (mdrAction == _nullMDRAction) {
552                            return null;
553                    }
554    
555                    if (mdrAction == null) {
556                            Session session = null;
557    
558                            boolean hasException = false;
559    
560                            try {
561                                    session = openSession();
562    
563                                    mdrAction = (MDRAction)session.get(MDRActionImpl.class,
564                                                    Long.valueOf(actionId));
565                            }
566                            catch (Exception e) {
567                                    hasException = true;
568    
569                                    throw processException(e);
570                            }
571                            finally {
572                                    if (mdrAction != null) {
573                                            cacheResult(mdrAction);
574                                    }
575                                    else if (!hasException) {
576                                            EntityCacheUtil.putResult(MDRActionModelImpl.ENTITY_CACHE_ENABLED,
577                                                    MDRActionImpl.class, actionId, _nullMDRAction);
578                                    }
579    
580                                    closeSession(session);
581                            }
582                    }
583    
584                    return mdrAction;
585            }
586    
587            /**
588             * Returns all the m d r actions where uuid = &#63;.
589             *
590             * @param uuid the uuid
591             * @return the matching m d r actions
592             * @throws SystemException if a system exception occurred
593             */
594            public List<MDRAction> findByUuid(String uuid) throws SystemException {
595                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
596            }
597    
598            /**
599             * Returns a range of all the m d r actions where uuid = &#63;.
600             *
601             * <p>
602             * 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.
603             * </p>
604             *
605             * @param uuid the uuid
606             * @param start the lower bound of the range of m d r actions
607             * @param end the upper bound of the range of m d r actions (not inclusive)
608             * @return the range of matching m d r actions
609             * @throws SystemException if a system exception occurred
610             */
611            public List<MDRAction> findByUuid(String uuid, int start, int end)
612                    throws SystemException {
613                    return findByUuid(uuid, start, end, null);
614            }
615    
616            /**
617             * Returns an ordered range of all the m d r actions where uuid = &#63;.
618             *
619             * <p>
620             * 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.
621             * </p>
622             *
623             * @param uuid the uuid
624             * @param start the lower bound of the range of m d r actions
625             * @param end the upper bound of the range of m d r actions (not inclusive)
626             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
627             * @return the ordered range of matching m d r actions
628             * @throws SystemException if a system exception occurred
629             */
630            public List<MDRAction> findByUuid(String uuid, int start, int end,
631                    OrderByComparator orderByComparator) throws SystemException {
632                    FinderPath finderPath = null;
633                    Object[] finderArgs = null;
634    
635                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
636                                    (orderByComparator == null)) {
637                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
638                            finderArgs = new Object[] { uuid };
639                    }
640                    else {
641                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
642                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
643                    }
644    
645                    List<MDRAction> list = (List<MDRAction>)FinderCacheUtil.getResult(finderPath,
646                                    finderArgs, this);
647    
648                    if ((list != null) && !list.isEmpty()) {
649                            for (MDRAction mdrAction : list) {
650                                    if (!Validator.equals(uuid, mdrAction.getUuid())) {
651                                            list = null;
652    
653                                            break;
654                                    }
655                            }
656                    }
657    
658                    if (list == null) {
659                            StringBundler query = null;
660    
661                            if (orderByComparator != null) {
662                                    query = new StringBundler(3 +
663                                                    (orderByComparator.getOrderByFields().length * 3));
664                            }
665                            else {
666                                    query = new StringBundler(2);
667                            }
668    
669                            query.append(_SQL_SELECT_MDRACTION_WHERE);
670    
671                            if (uuid == null) {
672                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
673                            }
674                            else {
675                                    if (uuid.equals(StringPool.BLANK)) {
676                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
677                                    }
678                                    else {
679                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
680                                    }
681                            }
682    
683                            if (orderByComparator != null) {
684                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
685                                            orderByComparator);
686                            }
687    
688                            String sql = query.toString();
689    
690                            Session session = null;
691    
692                            try {
693                                    session = openSession();
694    
695                                    Query q = session.createQuery(sql);
696    
697                                    QueryPos qPos = QueryPos.getInstance(q);
698    
699                                    if (uuid != null) {
700                                            qPos.add(uuid);
701                                    }
702    
703                                    list = (List<MDRAction>)QueryUtil.list(q, getDialect(), start,
704                                                    end);
705                            }
706                            catch (Exception e) {
707                                    throw processException(e);
708                            }
709                            finally {
710                                    if (list == null) {
711                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
712                                    }
713                                    else {
714                                            cacheResult(list);
715    
716                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
717                                    }
718    
719                                    closeSession(session);
720                            }
721                    }
722    
723                    return list;
724            }
725    
726            /**
727             * Returns the first m d r action in the ordered set where uuid = &#63;.
728             *
729             * @param uuid the uuid
730             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
731             * @return the first matching m d r action
732             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a matching m d r action could not be found
733             * @throws SystemException if a system exception occurred
734             */
735            public MDRAction findByUuid_First(String uuid,
736                    OrderByComparator orderByComparator)
737                    throws NoSuchActionException, SystemException {
738                    MDRAction mdrAction = fetchByUuid_First(uuid, orderByComparator);
739    
740                    if (mdrAction != null) {
741                            return mdrAction;
742                    }
743    
744                    StringBundler msg = new StringBundler(4);
745    
746                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
747    
748                    msg.append("uuid=");
749                    msg.append(uuid);
750    
751                    msg.append(StringPool.CLOSE_CURLY_BRACE);
752    
753                    throw new NoSuchActionException(msg.toString());
754            }
755    
756            /**
757             * Returns the first m d r action in the ordered set where uuid = &#63;.
758             *
759             * @param uuid the uuid
760             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
761             * @return the first matching m d r action, or <code>null</code> if a matching m d r action could not be found
762             * @throws SystemException if a system exception occurred
763             */
764            public MDRAction fetchByUuid_First(String uuid,
765                    OrderByComparator orderByComparator) throws SystemException {
766                    List<MDRAction> list = findByUuid(uuid, 0, 1, orderByComparator);
767    
768                    if (!list.isEmpty()) {
769                            return list.get(0);
770                    }
771    
772                    return null;
773            }
774    
775            /**
776             * Returns the last m d r action in the ordered set where uuid = &#63;.
777             *
778             * @param uuid the uuid
779             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
780             * @return the last matching m d r action
781             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a matching m d r action could not be found
782             * @throws SystemException if a system exception occurred
783             */
784            public MDRAction findByUuid_Last(String uuid,
785                    OrderByComparator orderByComparator)
786                    throws NoSuchActionException, SystemException {
787                    MDRAction mdrAction = fetchByUuid_Last(uuid, orderByComparator);
788    
789                    if (mdrAction != null) {
790                            return mdrAction;
791                    }
792    
793                    StringBundler msg = new StringBundler(4);
794    
795                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
796    
797                    msg.append("uuid=");
798                    msg.append(uuid);
799    
800                    msg.append(StringPool.CLOSE_CURLY_BRACE);
801    
802                    throw new NoSuchActionException(msg.toString());
803            }
804    
805            /**
806             * Returns the last m d r action in the ordered set where uuid = &#63;.
807             *
808             * @param uuid the uuid
809             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
810             * @return the last matching m d r action, or <code>null</code> if a matching m d r action could not be found
811             * @throws SystemException if a system exception occurred
812             */
813            public MDRAction fetchByUuid_Last(String uuid,
814                    OrderByComparator orderByComparator) throws SystemException {
815                    int count = countByUuid(uuid);
816    
817                    List<MDRAction> list = findByUuid(uuid, count - 1, count,
818                                    orderByComparator);
819    
820                    if (!list.isEmpty()) {
821                            return list.get(0);
822                    }
823    
824                    return null;
825            }
826    
827            /**
828             * Returns the m d r actions before and after the current m d r action in the ordered set where uuid = &#63;.
829             *
830             * @param actionId the primary key of the current m d r action
831             * @param uuid the uuid
832             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
833             * @return the previous, current, and next m d r action
834             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a m d r action with the primary key could not be found
835             * @throws SystemException if a system exception occurred
836             */
837            public MDRAction[] findByUuid_PrevAndNext(long actionId, String uuid,
838                    OrderByComparator orderByComparator)
839                    throws NoSuchActionException, SystemException {
840                    MDRAction mdrAction = findByPrimaryKey(actionId);
841    
842                    Session session = null;
843    
844                    try {
845                            session = openSession();
846    
847                            MDRAction[] array = new MDRActionImpl[3];
848    
849                            array[0] = getByUuid_PrevAndNext(session, mdrAction, uuid,
850                                            orderByComparator, true);
851    
852                            array[1] = mdrAction;
853    
854                            array[2] = getByUuid_PrevAndNext(session, mdrAction, uuid,
855                                            orderByComparator, false);
856    
857                            return array;
858                    }
859                    catch (Exception e) {
860                            throw processException(e);
861                    }
862                    finally {
863                            closeSession(session);
864                    }
865            }
866    
867            protected MDRAction getByUuid_PrevAndNext(Session session,
868                    MDRAction mdrAction, String uuid, OrderByComparator orderByComparator,
869                    boolean previous) {
870                    StringBundler query = null;
871    
872                    if (orderByComparator != null) {
873                            query = new StringBundler(6 +
874                                            (orderByComparator.getOrderByFields().length * 6));
875                    }
876                    else {
877                            query = new StringBundler(3);
878                    }
879    
880                    query.append(_SQL_SELECT_MDRACTION_WHERE);
881    
882                    if (uuid == null) {
883                            query.append(_FINDER_COLUMN_UUID_UUID_1);
884                    }
885                    else {
886                            if (uuid.equals(StringPool.BLANK)) {
887                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
888                            }
889                            else {
890                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
891                            }
892                    }
893    
894                    if (orderByComparator != null) {
895                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
896    
897                            if (orderByConditionFields.length > 0) {
898                                    query.append(WHERE_AND);
899                            }
900    
901                            for (int i = 0; i < orderByConditionFields.length; i++) {
902                                    query.append(_ORDER_BY_ENTITY_ALIAS);
903                                    query.append(orderByConditionFields[i]);
904    
905                                    if ((i + 1) < orderByConditionFields.length) {
906                                            if (orderByComparator.isAscending() ^ previous) {
907                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
908                                            }
909                                            else {
910                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
911                                            }
912                                    }
913                                    else {
914                                            if (orderByComparator.isAscending() ^ previous) {
915                                                    query.append(WHERE_GREATER_THAN);
916                                            }
917                                            else {
918                                                    query.append(WHERE_LESSER_THAN);
919                                            }
920                                    }
921                            }
922    
923                            query.append(ORDER_BY_CLAUSE);
924    
925                            String[] orderByFields = orderByComparator.getOrderByFields();
926    
927                            for (int i = 0; i < orderByFields.length; i++) {
928                                    query.append(_ORDER_BY_ENTITY_ALIAS);
929                                    query.append(orderByFields[i]);
930    
931                                    if ((i + 1) < orderByFields.length) {
932                                            if (orderByComparator.isAscending() ^ previous) {
933                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
934                                            }
935                                            else {
936                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
937                                            }
938                                    }
939                                    else {
940                                            if (orderByComparator.isAscending() ^ previous) {
941                                                    query.append(ORDER_BY_ASC);
942                                            }
943                                            else {
944                                                    query.append(ORDER_BY_DESC);
945                                            }
946                                    }
947                            }
948                    }
949    
950                    String sql = query.toString();
951    
952                    Query q = session.createQuery(sql);
953    
954                    q.setFirstResult(0);
955                    q.setMaxResults(2);
956    
957                    QueryPos qPos = QueryPos.getInstance(q);
958    
959                    if (uuid != null) {
960                            qPos.add(uuid);
961                    }
962    
963                    if (orderByComparator != null) {
964                            Object[] values = orderByComparator.getOrderByConditionValues(mdrAction);
965    
966                            for (Object value : values) {
967                                    qPos.add(value);
968                            }
969                    }
970    
971                    List<MDRAction> list = q.list();
972    
973                    if (list.size() == 2) {
974                            return list.get(1);
975                    }
976                    else {
977                            return null;
978                    }
979            }
980    
981            /**
982             * Returns the m d r action where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchActionException} if it could not be found.
983             *
984             * @param uuid the uuid
985             * @param groupId the group ID
986             * @return the matching m d r action
987             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a matching m d r action could not be found
988             * @throws SystemException if a system exception occurred
989             */
990            public MDRAction findByUUID_G(String uuid, long groupId)
991                    throws NoSuchActionException, SystemException {
992                    MDRAction mdrAction = fetchByUUID_G(uuid, groupId);
993    
994                    if (mdrAction == null) {
995                            StringBundler msg = new StringBundler(6);
996    
997                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
998    
999                            msg.append("uuid=");
1000                            msg.append(uuid);
1001    
1002                            msg.append(", groupId=");
1003                            msg.append(groupId);
1004    
1005                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1006    
1007                            if (_log.isWarnEnabled()) {
1008                                    _log.warn(msg.toString());
1009                            }
1010    
1011                            throw new NoSuchActionException(msg.toString());
1012                    }
1013    
1014                    return mdrAction;
1015            }
1016    
1017            /**
1018             * Returns the m d r action where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1019             *
1020             * @param uuid the uuid
1021             * @param groupId the group ID
1022             * @return the matching m d r action, or <code>null</code> if a matching m d r action could not be found
1023             * @throws SystemException if a system exception occurred
1024             */
1025            public MDRAction fetchByUUID_G(String uuid, long groupId)
1026                    throws SystemException {
1027                    return fetchByUUID_G(uuid, groupId, true);
1028            }
1029    
1030            /**
1031             * Returns the m d r action where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1032             *
1033             * @param uuid the uuid
1034             * @param groupId the group ID
1035             * @param retrieveFromCache whether to use the finder cache
1036             * @return the matching m d r action, or <code>null</code> if a matching m d r action could not be found
1037             * @throws SystemException if a system exception occurred
1038             */
1039            public MDRAction fetchByUUID_G(String uuid, long groupId,
1040                    boolean retrieveFromCache) throws SystemException {
1041                    Object[] finderArgs = new Object[] { uuid, groupId };
1042    
1043                    Object result = null;
1044    
1045                    if (retrieveFromCache) {
1046                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1047                                            finderArgs, this);
1048                    }
1049    
1050                    if (result instanceof MDRAction) {
1051                            MDRAction mdrAction = (MDRAction)result;
1052    
1053                            if (!Validator.equals(uuid, mdrAction.getUuid()) ||
1054                                            (groupId != mdrAction.getGroupId())) {
1055                                    result = null;
1056                            }
1057                    }
1058    
1059                    if (result == null) {
1060                            StringBundler query = new StringBundler(3);
1061    
1062                            query.append(_SQL_SELECT_MDRACTION_WHERE);
1063    
1064                            if (uuid == null) {
1065                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1066                            }
1067                            else {
1068                                    if (uuid.equals(StringPool.BLANK)) {
1069                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1070                                    }
1071                                    else {
1072                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1073                                    }
1074                            }
1075    
1076                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1077    
1078                            String sql = query.toString();
1079    
1080                            Session session = null;
1081    
1082                            try {
1083                                    session = openSession();
1084    
1085                                    Query q = session.createQuery(sql);
1086    
1087                                    QueryPos qPos = QueryPos.getInstance(q);
1088    
1089                                    if (uuid != null) {
1090                                            qPos.add(uuid);
1091                                    }
1092    
1093                                    qPos.add(groupId);
1094    
1095                                    List<MDRAction> list = q.list();
1096    
1097                                    result = list;
1098    
1099                                    MDRAction mdrAction = null;
1100    
1101                                    if (list.isEmpty()) {
1102                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1103                                                    finderArgs, list);
1104                                    }
1105                                    else {
1106                                            mdrAction = list.get(0);
1107    
1108                                            cacheResult(mdrAction);
1109    
1110                                            if ((mdrAction.getUuid() == null) ||
1111                                                            !mdrAction.getUuid().equals(uuid) ||
1112                                                            (mdrAction.getGroupId() != groupId)) {
1113                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1114                                                            finderArgs, mdrAction);
1115                                            }
1116                                    }
1117    
1118                                    return mdrAction;
1119                            }
1120                            catch (Exception e) {
1121                                    throw processException(e);
1122                            }
1123                            finally {
1124                                    if (result == null) {
1125                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1126                                                    finderArgs);
1127                                    }
1128    
1129                                    closeSession(session);
1130                            }
1131                    }
1132                    else {
1133                            if (result instanceof List<?>) {
1134                                    return null;
1135                            }
1136                            else {
1137                                    return (MDRAction)result;
1138                            }
1139                    }
1140            }
1141    
1142            /**
1143             * Returns all the m d r actions where ruleGroupInstanceId = &#63;.
1144             *
1145             * @param ruleGroupInstanceId the rule group instance ID
1146             * @return the matching m d r actions
1147             * @throws SystemException if a system exception occurred
1148             */
1149            public List<MDRAction> findByRuleGroupInstanceId(long ruleGroupInstanceId)
1150                    throws SystemException {
1151                    return findByRuleGroupInstanceId(ruleGroupInstanceId,
1152                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1153            }
1154    
1155            /**
1156             * Returns a range of all the m d r actions where ruleGroupInstanceId = &#63;.
1157             *
1158             * <p>
1159             * 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.
1160             * </p>
1161             *
1162             * @param ruleGroupInstanceId the rule group instance ID
1163             * @param start the lower bound of the range of m d r actions
1164             * @param end the upper bound of the range of m d r actions (not inclusive)
1165             * @return the range of matching m d r actions
1166             * @throws SystemException if a system exception occurred
1167             */
1168            public List<MDRAction> findByRuleGroupInstanceId(long ruleGroupInstanceId,
1169                    int start, int end) throws SystemException {
1170                    return findByRuleGroupInstanceId(ruleGroupInstanceId, start, end, null);
1171            }
1172    
1173            /**
1174             * Returns an ordered range of all the m d r actions where ruleGroupInstanceId = &#63;.
1175             *
1176             * <p>
1177             * 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.
1178             * </p>
1179             *
1180             * @param ruleGroupInstanceId the rule group instance ID
1181             * @param start the lower bound of the range of m d r actions
1182             * @param end the upper bound of the range of m d r actions (not inclusive)
1183             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1184             * @return the ordered range of matching m d r actions
1185             * @throws SystemException if a system exception occurred
1186             */
1187            public List<MDRAction> findByRuleGroupInstanceId(long ruleGroupInstanceId,
1188                    int start, int end, OrderByComparator orderByComparator)
1189                    throws SystemException {
1190                    FinderPath finderPath = null;
1191                    Object[] finderArgs = null;
1192    
1193                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1194                                    (orderByComparator == null)) {
1195                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPINSTANCEID;
1196                            finderArgs = new Object[] { ruleGroupInstanceId };
1197                    }
1198                    else {
1199                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPINSTANCEID;
1200                            finderArgs = new Object[] {
1201                                            ruleGroupInstanceId,
1202                                            
1203                                            start, end, orderByComparator
1204                                    };
1205                    }
1206    
1207                    List<MDRAction> list = (List<MDRAction>)FinderCacheUtil.getResult(finderPath,
1208                                    finderArgs, this);
1209    
1210                    if ((list != null) && !list.isEmpty()) {
1211                            for (MDRAction mdrAction : list) {
1212                                    if ((ruleGroupInstanceId != mdrAction.getRuleGroupInstanceId())) {
1213                                            list = null;
1214    
1215                                            break;
1216                                    }
1217                            }
1218                    }
1219    
1220                    if (list == null) {
1221                            StringBundler query = null;
1222    
1223                            if (orderByComparator != null) {
1224                                    query = new StringBundler(3 +
1225                                                    (orderByComparator.getOrderByFields().length * 3));
1226                            }
1227                            else {
1228                                    query = new StringBundler(2);
1229                            }
1230    
1231                            query.append(_SQL_SELECT_MDRACTION_WHERE);
1232    
1233                            query.append(_FINDER_COLUMN_RULEGROUPINSTANCEID_RULEGROUPINSTANCEID_2);
1234    
1235                            if (orderByComparator != null) {
1236                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1237                                            orderByComparator);
1238                            }
1239    
1240                            String sql = query.toString();
1241    
1242                            Session session = null;
1243    
1244                            try {
1245                                    session = openSession();
1246    
1247                                    Query q = session.createQuery(sql);
1248    
1249                                    QueryPos qPos = QueryPos.getInstance(q);
1250    
1251                                    qPos.add(ruleGroupInstanceId);
1252    
1253                                    list = (List<MDRAction>)QueryUtil.list(q, getDialect(), start,
1254                                                    end);
1255                            }
1256                            catch (Exception e) {
1257                                    throw processException(e);
1258                            }
1259                            finally {
1260                                    if (list == null) {
1261                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1262                                    }
1263                                    else {
1264                                            cacheResult(list);
1265    
1266                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1267                                    }
1268    
1269                                    closeSession(session);
1270                            }
1271                    }
1272    
1273                    return list;
1274            }
1275    
1276            /**
1277             * Returns the first m d r action in the ordered set where ruleGroupInstanceId = &#63;.
1278             *
1279             * @param ruleGroupInstanceId the rule group instance ID
1280             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1281             * @return the first matching m d r action
1282             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a matching m d r action could not be found
1283             * @throws SystemException if a system exception occurred
1284             */
1285            public MDRAction findByRuleGroupInstanceId_First(long ruleGroupInstanceId,
1286                    OrderByComparator orderByComparator)
1287                    throws NoSuchActionException, SystemException {
1288                    MDRAction mdrAction = fetchByRuleGroupInstanceId_First(ruleGroupInstanceId,
1289                                    orderByComparator);
1290    
1291                    if (mdrAction != null) {
1292                            return mdrAction;
1293                    }
1294    
1295                    StringBundler msg = new StringBundler(4);
1296    
1297                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1298    
1299                    msg.append("ruleGroupInstanceId=");
1300                    msg.append(ruleGroupInstanceId);
1301    
1302                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1303    
1304                    throw new NoSuchActionException(msg.toString());
1305            }
1306    
1307            /**
1308             * Returns the first m d r action in the ordered set where ruleGroupInstanceId = &#63;.
1309             *
1310             * @param ruleGroupInstanceId the rule group instance ID
1311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1312             * @return the first matching m d r action, or <code>null</code> if a matching m d r action could not be found
1313             * @throws SystemException if a system exception occurred
1314             */
1315            public MDRAction fetchByRuleGroupInstanceId_First(
1316                    long ruleGroupInstanceId, OrderByComparator orderByComparator)
1317                    throws SystemException {
1318                    List<MDRAction> list = findByRuleGroupInstanceId(ruleGroupInstanceId,
1319                                    0, 1, orderByComparator);
1320    
1321                    if (!list.isEmpty()) {
1322                            return list.get(0);
1323                    }
1324    
1325                    return null;
1326            }
1327    
1328            /**
1329             * Returns the last m d r action in the ordered set where ruleGroupInstanceId = &#63;.
1330             *
1331             * @param ruleGroupInstanceId the rule group instance ID
1332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1333             * @return the last matching m d r action
1334             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a matching m d r action could not be found
1335             * @throws SystemException if a system exception occurred
1336             */
1337            public MDRAction findByRuleGroupInstanceId_Last(long ruleGroupInstanceId,
1338                    OrderByComparator orderByComparator)
1339                    throws NoSuchActionException, SystemException {
1340                    MDRAction mdrAction = fetchByRuleGroupInstanceId_Last(ruleGroupInstanceId,
1341                                    orderByComparator);
1342    
1343                    if (mdrAction != null) {
1344                            return mdrAction;
1345                    }
1346    
1347                    StringBundler msg = new StringBundler(4);
1348    
1349                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1350    
1351                    msg.append("ruleGroupInstanceId=");
1352                    msg.append(ruleGroupInstanceId);
1353    
1354                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1355    
1356                    throw new NoSuchActionException(msg.toString());
1357            }
1358    
1359            /**
1360             * Returns the last m d r action in the ordered set where ruleGroupInstanceId = &#63;.
1361             *
1362             * @param ruleGroupInstanceId the rule group instance ID
1363             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1364             * @return the last matching m d r action, or <code>null</code> if a matching m d r action could not be found
1365             * @throws SystemException if a system exception occurred
1366             */
1367            public MDRAction fetchByRuleGroupInstanceId_Last(long ruleGroupInstanceId,
1368                    OrderByComparator orderByComparator) throws SystemException {
1369                    int count = countByRuleGroupInstanceId(ruleGroupInstanceId);
1370    
1371                    List<MDRAction> list = findByRuleGroupInstanceId(ruleGroupInstanceId,
1372                                    count - 1, count, orderByComparator);
1373    
1374                    if (!list.isEmpty()) {
1375                            return list.get(0);
1376                    }
1377    
1378                    return null;
1379            }
1380    
1381            /**
1382             * Returns the m d r actions before and after the current m d r action in the ordered set where ruleGroupInstanceId = &#63;.
1383             *
1384             * @param actionId the primary key of the current m d r action
1385             * @param ruleGroupInstanceId the rule group instance ID
1386             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1387             * @return the previous, current, and next m d r action
1388             * @throws com.liferay.portlet.mobiledevicerules.NoSuchActionException if a m d r action with the primary key could not be found
1389             * @throws SystemException if a system exception occurred
1390             */
1391            public MDRAction[] findByRuleGroupInstanceId_PrevAndNext(long actionId,
1392                    long ruleGroupInstanceId, OrderByComparator orderByComparator)
1393                    throws NoSuchActionException, SystemException {
1394                    MDRAction mdrAction = findByPrimaryKey(actionId);
1395    
1396                    Session session = null;
1397    
1398                    try {
1399                            session = openSession();
1400    
1401                            MDRAction[] array = new MDRActionImpl[3];
1402    
1403                            array[0] = getByRuleGroupInstanceId_PrevAndNext(session, mdrAction,
1404                                            ruleGroupInstanceId, orderByComparator, true);
1405    
1406                            array[1] = mdrAction;
1407    
1408                            array[2] = getByRuleGroupInstanceId_PrevAndNext(session, mdrAction,
1409                                            ruleGroupInstanceId, orderByComparator, false);
1410    
1411                            return array;
1412                    }
1413                    catch (Exception e) {
1414                            throw processException(e);
1415                    }
1416                    finally {
1417                            closeSession(session);
1418                    }
1419            }
1420    
1421            protected MDRAction getByRuleGroupInstanceId_PrevAndNext(Session session,
1422                    MDRAction mdrAction, long ruleGroupInstanceId,
1423                    OrderByComparator orderByComparator, boolean previous) {
1424                    StringBundler query = null;
1425    
1426                    if (orderByComparator != null) {
1427                            query = new StringBundler(6 +
1428                                            (orderByComparator.getOrderByFields().length * 6));
1429                    }
1430                    else {
1431                            query = new StringBundler(3);
1432                    }
1433    
1434                    query.append(_SQL_SELECT_MDRACTION_WHERE);
1435    
1436                    query.append(_FINDER_COLUMN_RULEGROUPINSTANCEID_RULEGROUPINSTANCEID_2);
1437    
1438                    if (orderByComparator != null) {
1439                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1440    
1441                            if (orderByConditionFields.length > 0) {
1442                                    query.append(WHERE_AND);
1443                            }
1444    
1445                            for (int i = 0; i < orderByConditionFields.length; i++) {
1446                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1447                                    query.append(orderByConditionFields[i]);
1448    
1449                                    if ((i + 1) < orderByConditionFields.length) {
1450                                            if (orderByComparator.isAscending() ^ previous) {
1451                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1452                                            }
1453                                            else {
1454                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1455                                            }
1456                                    }
1457                                    else {
1458                                            if (orderByComparator.isAscending() ^ previous) {
1459                                                    query.append(WHERE_GREATER_THAN);
1460                                            }
1461                                            else {
1462                                                    query.append(WHERE_LESSER_THAN);
1463                                            }
1464                                    }
1465                            }
1466    
1467                            query.append(ORDER_BY_CLAUSE);
1468    
1469                            String[] orderByFields = orderByComparator.getOrderByFields();
1470    
1471                            for (int i = 0; i < orderByFields.length; i++) {
1472                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1473                                    query.append(orderByFields[i]);
1474    
1475                                    if ((i + 1) < orderByFields.length) {
1476                                            if (orderByComparator.isAscending() ^ previous) {
1477                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1478                                            }
1479                                            else {
1480                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1481                                            }
1482                                    }
1483                                    else {
1484                                            if (orderByComparator.isAscending() ^ previous) {
1485                                                    query.append(ORDER_BY_ASC);
1486                                            }
1487                                            else {
1488                                                    query.append(ORDER_BY_DESC);
1489                                            }
1490                                    }
1491                            }
1492                    }
1493    
1494                    String sql = query.toString();
1495    
1496                    Query q = session.createQuery(sql);
1497    
1498                    q.setFirstResult(0);
1499                    q.setMaxResults(2);
1500    
1501                    QueryPos qPos = QueryPos.getInstance(q);
1502    
1503                    qPos.add(ruleGroupInstanceId);
1504    
1505                    if (orderByComparator != null) {
1506                            Object[] values = orderByComparator.getOrderByConditionValues(mdrAction);
1507    
1508                            for (Object value : values) {
1509                                    qPos.add(value);
1510                            }
1511                    }
1512    
1513                    List<MDRAction> list = q.list();
1514    
1515                    if (list.size() == 2) {
1516                            return list.get(1);
1517                    }
1518                    else {
1519                            return null;
1520                    }
1521            }
1522    
1523            /**
1524             * Returns all the m d r actions.
1525             *
1526             * @return the m d r actions
1527             * @throws SystemException if a system exception occurred
1528             */
1529            public List<MDRAction> findAll() throws SystemException {
1530                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1531            }
1532    
1533            /**
1534             * Returns a range of all the m d r actions.
1535             *
1536             * <p>
1537             * 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.
1538             * </p>
1539             *
1540             * @param start the lower bound of the range of m d r actions
1541             * @param end the upper bound of the range of m d r actions (not inclusive)
1542             * @return the range of m d r actions
1543             * @throws SystemException if a system exception occurred
1544             */
1545            public List<MDRAction> findAll(int start, int end)
1546                    throws SystemException {
1547                    return findAll(start, end, null);
1548            }
1549    
1550            /**
1551             * Returns an ordered range of all the m d r actions.
1552             *
1553             * <p>
1554             * 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.
1555             * </p>
1556             *
1557             * @param start the lower bound of the range of m d r actions
1558             * @param end the upper bound of the range of m d r actions (not inclusive)
1559             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1560             * @return the ordered range of m d r actions
1561             * @throws SystemException if a system exception occurred
1562             */
1563            public List<MDRAction> findAll(int start, int end,
1564                    OrderByComparator orderByComparator) throws SystemException {
1565                    FinderPath finderPath = null;
1566                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1567    
1568                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1569                                    (orderByComparator == null)) {
1570                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1571                            finderArgs = FINDER_ARGS_EMPTY;
1572                    }
1573                    else {
1574                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1575                            finderArgs = new Object[] { start, end, orderByComparator };
1576                    }
1577    
1578                    List<MDRAction> list = (List<MDRAction>)FinderCacheUtil.getResult(finderPath,
1579                                    finderArgs, this);
1580    
1581                    if (list == null) {
1582                            StringBundler query = null;
1583                            String sql = null;
1584    
1585                            if (orderByComparator != null) {
1586                                    query = new StringBundler(2 +
1587                                                    (orderByComparator.getOrderByFields().length * 3));
1588    
1589                                    query.append(_SQL_SELECT_MDRACTION);
1590    
1591                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1592                                            orderByComparator);
1593    
1594                                    sql = query.toString();
1595                            }
1596                            else {
1597                                    sql = _SQL_SELECT_MDRACTION;
1598                            }
1599    
1600                            Session session = null;
1601    
1602                            try {
1603                                    session = openSession();
1604    
1605                                    Query q = session.createQuery(sql);
1606    
1607                                    if (orderByComparator == null) {
1608                                            list = (List<MDRAction>)QueryUtil.list(q, getDialect(),
1609                                                            start, end, false);
1610    
1611                                            Collections.sort(list);
1612                                    }
1613                                    else {
1614                                            list = (List<MDRAction>)QueryUtil.list(q, getDialect(),
1615                                                            start, end);
1616                                    }
1617                            }
1618                            catch (Exception e) {
1619                                    throw processException(e);
1620                            }
1621                            finally {
1622                                    if (list == null) {
1623                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1624                                    }
1625                                    else {
1626                                            cacheResult(list);
1627    
1628                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1629                                    }
1630    
1631                                    closeSession(session);
1632                            }
1633                    }
1634    
1635                    return list;
1636            }
1637    
1638            /**
1639             * Removes all the m d r actions where uuid = &#63; from the database.
1640             *
1641             * @param uuid the uuid
1642             * @throws SystemException if a system exception occurred
1643             */
1644            public void removeByUuid(String uuid) throws SystemException {
1645                    for (MDRAction mdrAction : findByUuid(uuid)) {
1646                            remove(mdrAction);
1647                    }
1648            }
1649    
1650            /**
1651             * Removes the m d r action where uuid = &#63; and groupId = &#63; from the database.
1652             *
1653             * @param uuid the uuid
1654             * @param groupId the group ID
1655             * @return the m d r action that was removed
1656             * @throws SystemException if a system exception occurred
1657             */
1658            public MDRAction removeByUUID_G(String uuid, long groupId)
1659                    throws NoSuchActionException, SystemException {
1660                    MDRAction mdrAction = findByUUID_G(uuid, groupId);
1661    
1662                    return remove(mdrAction);
1663            }
1664    
1665            /**
1666             * Removes all the m d r actions where ruleGroupInstanceId = &#63; from the database.
1667             *
1668             * @param ruleGroupInstanceId the rule group instance ID
1669             * @throws SystemException if a system exception occurred
1670             */
1671            public void removeByRuleGroupInstanceId(long ruleGroupInstanceId)
1672                    throws SystemException {
1673                    for (MDRAction mdrAction : findByRuleGroupInstanceId(
1674                                    ruleGroupInstanceId)) {
1675                            remove(mdrAction);
1676                    }
1677            }
1678    
1679            /**
1680             * Removes all the m d r actions from the database.
1681             *
1682             * @throws SystemException if a system exception occurred
1683             */
1684            public void removeAll() throws SystemException {
1685                    for (MDRAction mdrAction : findAll()) {
1686                            remove(mdrAction);
1687                    }
1688            }
1689    
1690            /**
1691             * Returns the number of m d r actions where uuid = &#63;.
1692             *
1693             * @param uuid the uuid
1694             * @return the number of matching m d r actions
1695             * @throws SystemException if a system exception occurred
1696             */
1697            public int countByUuid(String uuid) throws SystemException {
1698                    Object[] finderArgs = new Object[] { uuid };
1699    
1700                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
1701                                    finderArgs, this);
1702    
1703                    if (count == null) {
1704                            StringBundler query = new StringBundler(2);
1705    
1706                            query.append(_SQL_COUNT_MDRACTION_WHERE);
1707    
1708                            if (uuid == null) {
1709                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
1710                            }
1711                            else {
1712                                    if (uuid.equals(StringPool.BLANK)) {
1713                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
1714                                    }
1715                                    else {
1716                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
1717                                    }
1718                            }
1719    
1720                            String sql = query.toString();
1721    
1722                            Session session = null;
1723    
1724                            try {
1725                                    session = openSession();
1726    
1727                                    Query q = session.createQuery(sql);
1728    
1729                                    QueryPos qPos = QueryPos.getInstance(q);
1730    
1731                                    if (uuid != null) {
1732                                            qPos.add(uuid);
1733                                    }
1734    
1735                                    count = (Long)q.uniqueResult();
1736                            }
1737                            catch (Exception e) {
1738                                    throw processException(e);
1739                            }
1740                            finally {
1741                                    if (count == null) {
1742                                            count = Long.valueOf(0);
1743                                    }
1744    
1745                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
1746                                            finderArgs, count);
1747    
1748                                    closeSession(session);
1749                            }
1750                    }
1751    
1752                    return count.intValue();
1753            }
1754    
1755            /**
1756             * Returns the number of m d r actions where uuid = &#63; and groupId = &#63;.
1757             *
1758             * @param uuid the uuid
1759             * @param groupId the group ID
1760             * @return the number of matching m d r actions
1761             * @throws SystemException if a system exception occurred
1762             */
1763            public int countByUUID_G(String uuid, long groupId)
1764                    throws SystemException {
1765                    Object[] finderArgs = new Object[] { uuid, groupId };
1766    
1767                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
1768                                    finderArgs, this);
1769    
1770                    if (count == null) {
1771                            StringBundler query = new StringBundler(3);
1772    
1773                            query.append(_SQL_COUNT_MDRACTION_WHERE);
1774    
1775                            if (uuid == null) {
1776                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1777                            }
1778                            else {
1779                                    if (uuid.equals(StringPool.BLANK)) {
1780                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1781                                    }
1782                                    else {
1783                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1784                                    }
1785                            }
1786    
1787                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1788    
1789                            String sql = query.toString();
1790    
1791                            Session session = null;
1792    
1793                            try {
1794                                    session = openSession();
1795    
1796                                    Query q = session.createQuery(sql);
1797    
1798                                    QueryPos qPos = QueryPos.getInstance(q);
1799    
1800                                    if (uuid != null) {
1801                                            qPos.add(uuid);
1802                                    }
1803    
1804                                    qPos.add(groupId);
1805    
1806                                    count = (Long)q.uniqueResult();
1807                            }
1808                            catch (Exception e) {
1809                                    throw processException(e);
1810                            }
1811                            finally {
1812                                    if (count == null) {
1813                                            count = Long.valueOf(0);
1814                                    }
1815    
1816                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
1817                                            finderArgs, count);
1818    
1819                                    closeSession(session);
1820                            }
1821                    }
1822    
1823                    return count.intValue();
1824            }
1825    
1826            /**
1827             * Returns the number of m d r actions where ruleGroupInstanceId = &#63;.
1828             *
1829             * @param ruleGroupInstanceId the rule group instance ID
1830             * @return the number of matching m d r actions
1831             * @throws SystemException if a system exception occurred
1832             */
1833            public int countByRuleGroupInstanceId(long ruleGroupInstanceId)
1834                    throws SystemException {
1835                    Object[] finderArgs = new Object[] { ruleGroupInstanceId };
1836    
1837                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RULEGROUPINSTANCEID,
1838                                    finderArgs, this);
1839    
1840                    if (count == null) {
1841                            StringBundler query = new StringBundler(2);
1842    
1843                            query.append(_SQL_COUNT_MDRACTION_WHERE);
1844    
1845                            query.append(_FINDER_COLUMN_RULEGROUPINSTANCEID_RULEGROUPINSTANCEID_2);
1846    
1847                            String sql = query.toString();
1848    
1849                            Session session = null;
1850    
1851                            try {
1852                                    session = openSession();
1853    
1854                                    Query q = session.createQuery(sql);
1855    
1856                                    QueryPos qPos = QueryPos.getInstance(q);
1857    
1858                                    qPos.add(ruleGroupInstanceId);
1859    
1860                                    count = (Long)q.uniqueResult();
1861                            }
1862                            catch (Exception e) {
1863                                    throw processException(e);
1864                            }
1865                            finally {
1866                                    if (count == null) {
1867                                            count = Long.valueOf(0);
1868                                    }
1869    
1870                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RULEGROUPINSTANCEID,
1871                                            finderArgs, count);
1872    
1873                                    closeSession(session);
1874                            }
1875                    }
1876    
1877                    return count.intValue();
1878            }
1879    
1880            /**
1881             * Returns the number of m d r actions.
1882             *
1883             * @return the number of m d r actions
1884             * @throws SystemException if a system exception occurred
1885             */
1886            public int countAll() throws SystemException {
1887                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1888                                    FINDER_ARGS_EMPTY, this);
1889    
1890                    if (count == null) {
1891                            Session session = null;
1892    
1893                            try {
1894                                    session = openSession();
1895    
1896                                    Query q = session.createQuery(_SQL_COUNT_MDRACTION);
1897    
1898                                    count = (Long)q.uniqueResult();
1899                            }
1900                            catch (Exception e) {
1901                                    throw processException(e);
1902                            }
1903                            finally {
1904                                    if (count == null) {
1905                                            count = Long.valueOf(0);
1906                                    }
1907    
1908                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1909                                            FINDER_ARGS_EMPTY, count);
1910    
1911                                    closeSession(session);
1912                            }
1913                    }
1914    
1915                    return count.intValue();
1916            }
1917    
1918            /**
1919             * Initializes the m d r action persistence.
1920             */
1921            public void afterPropertiesSet() {
1922                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1923                                            com.liferay.portal.util.PropsUtil.get(
1924                                                    "value.object.listener.com.liferay.portlet.mobiledevicerules.model.MDRAction")));
1925    
1926                    if (listenerClassNames.length > 0) {
1927                            try {
1928                                    List<ModelListener<MDRAction>> listenersList = new ArrayList<ModelListener<MDRAction>>();
1929    
1930                                    for (String listenerClassName : listenerClassNames) {
1931                                            Class<?> clazz = getClass();
1932    
1933                                            listenersList.add((ModelListener<MDRAction>)InstanceFactory.newInstance(
1934                                                            clazz.getClassLoader(), listenerClassName));
1935                                    }
1936    
1937                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1938                            }
1939                            catch (Exception e) {
1940                                    _log.error(e);
1941                            }
1942                    }
1943            }
1944    
1945            public void destroy() {
1946                    EntityCacheUtil.removeCache(MDRActionImpl.class.getName());
1947                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1948                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1949            }
1950    
1951            @BeanReference(type = MDRActionPersistence.class)
1952            protected MDRActionPersistence mdrActionPersistence;
1953            @BeanReference(type = MDRRulePersistence.class)
1954            protected MDRRulePersistence mdrRulePersistence;
1955            @BeanReference(type = MDRRuleGroupPersistence.class)
1956            protected MDRRuleGroupPersistence mdrRuleGroupPersistence;
1957            @BeanReference(type = MDRRuleGroupInstancePersistence.class)
1958            protected MDRRuleGroupInstancePersistence mdrRuleGroupInstancePersistence;
1959            @BeanReference(type = ResourcePersistence.class)
1960            protected ResourcePersistence resourcePersistence;
1961            @BeanReference(type = UserPersistence.class)
1962            protected UserPersistence userPersistence;
1963            private static final String _SQL_SELECT_MDRACTION = "SELECT mdrAction FROM MDRAction mdrAction";
1964            private static final String _SQL_SELECT_MDRACTION_WHERE = "SELECT mdrAction FROM MDRAction mdrAction WHERE ";
1965            private static final String _SQL_COUNT_MDRACTION = "SELECT COUNT(mdrAction) FROM MDRAction mdrAction";
1966            private static final String _SQL_COUNT_MDRACTION_WHERE = "SELECT COUNT(mdrAction) FROM MDRAction mdrAction WHERE ";
1967            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mdrAction.uuid IS NULL";
1968            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrAction.uuid = ?";
1969            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrAction.uuid IS NULL OR mdrAction.uuid = ?)";
1970            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mdrAction.uuid IS NULL AND ";
1971            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrAction.uuid = ? AND ";
1972            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrAction.uuid IS NULL OR mdrAction.uuid = ?) AND ";
1973            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrAction.groupId = ?";
1974            private static final String _FINDER_COLUMN_RULEGROUPINSTANCEID_RULEGROUPINSTANCEID_2 =
1975                    "mdrAction.ruleGroupInstanceId = ?";
1976            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrAction.";
1977            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRAction exists with the primary key ";
1978            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRAction exists with the key {";
1979            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1980            private static Log _log = LogFactoryUtil.getLog(MDRActionPersistenceImpl.class);
1981            private static MDRAction _nullMDRAction = new MDRActionImpl() {
1982                            @Override
1983                            public Object clone() {
1984                                    return this;
1985                            }
1986    
1987                            @Override
1988                            public CacheModel<MDRAction> toCacheModel() {
1989                                    return _nullMDRActionCacheModel;
1990                            }
1991                    };
1992    
1993            private static CacheModel<MDRAction> _nullMDRActionCacheModel = new CacheModel<MDRAction>() {
1994                            public MDRAction toEntityModel() {
1995                                    return _nullMDRAction;
1996                            }
1997                    };
1998    }