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