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