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