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