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