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