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