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