001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.mobiledevicerules.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.GroupPersistence;
043    import com.liferay.portal.service.persistence.UserPersistence;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException;
047    import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup;
048    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupImpl;
049    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Collections;
055    import java.util.List;
056    
057    /**
058     * The persistence implementation for the m d r rule group service.
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Edward C. Han
065     * @see MDRRuleGroupPersistence
066     * @see MDRRuleGroupUtil
067     * @generated
068     */
069    public class MDRRuleGroupPersistenceImpl extends BasePersistenceImpl<MDRRuleGroup>
070            implements MDRRuleGroupPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * 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.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = MDRRuleGroupImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
082                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
084                            new String[] {
085                                    String.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
091                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
093                            new String[] { String.class.getName() },
094                            MDRRuleGroupModelImpl.UUID_COLUMN_BITMASK);
095            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
096                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
098                            new String[] { String.class.getName() });
099            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
100                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
101                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
102                            new String[] { String.class.getName(), Long.class.getName() },
103                            MDRRuleGroupModelImpl.UUID_COLUMN_BITMASK |
104                            MDRRuleGroupModelImpl.GROUPID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
106                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
108                            new String[] { String.class.getName(), Long.class.getName() });
109            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
110                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
111                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
112                            new String[] {
113                                    String.class.getName(), Long.class.getName(),
114                                    
115                            "java.lang.Integer", "java.lang.Integer",
116                                    "com.liferay.portal.kernel.util.OrderByComparator"
117                            });
118            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
119                    new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
120                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
122                            new String[] { String.class.getName(), Long.class.getName() },
123                            MDRRuleGroupModelImpl.UUID_COLUMN_BITMASK |
124                            MDRRuleGroupModelImpl.COMPANYID_COLUMN_BITMASK);
125            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
126                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
127                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
128                            new String[] { String.class.getName(), Long.class.getName() });
129            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
130                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
131                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
132                            new String[] {
133                                    Long.class.getName(),
134                                    
135                            "java.lang.Integer", "java.lang.Integer",
136                                    "com.liferay.portal.kernel.util.OrderByComparator"
137                            });
138            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
139                    new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
140                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
141                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
142                            new String[] { Long.class.getName() },
143                            MDRRuleGroupModelImpl.GROUPID_COLUMN_BITMASK);
144            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
145                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
146                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
147                            new String[] { Long.class.getName() });
148            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
149                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
150                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
151            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
152                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
153                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
154            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
155                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
156                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
157    
158            /**
159             * Caches the m d r rule group in the entity cache if it is enabled.
160             *
161             * @param mdrRuleGroup the m d r rule group
162             */
163            public void cacheResult(MDRRuleGroup mdrRuleGroup) {
164                    EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
165                            MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey(), mdrRuleGroup);
166    
167                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
168                            new Object[] {
169                                    mdrRuleGroup.getUuid(), Long.valueOf(mdrRuleGroup.getGroupId())
170                            }, mdrRuleGroup);
171    
172                    mdrRuleGroup.resetOriginalValues();
173            }
174    
175            /**
176             * Caches the m d r rule groups in the entity cache if it is enabled.
177             *
178             * @param mdrRuleGroups the m d r rule groups
179             */
180            public void cacheResult(List<MDRRuleGroup> mdrRuleGroups) {
181                    for (MDRRuleGroup mdrRuleGroup : mdrRuleGroups) {
182                            if (EntityCacheUtil.getResult(
183                                                    MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
184                                                    MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey()) == null) {
185                                    cacheResult(mdrRuleGroup);
186                            }
187                            else {
188                                    mdrRuleGroup.resetOriginalValues();
189                            }
190                    }
191            }
192    
193            /**
194             * Clears the cache for all m d r rule groups.
195             *
196             * <p>
197             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
198             * </p>
199             */
200            @Override
201            public void clearCache() {
202                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
203                            CacheRegistryUtil.clear(MDRRuleGroupImpl.class.getName());
204                    }
205    
206                    EntityCacheUtil.clearCache(MDRRuleGroupImpl.class.getName());
207    
208                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
209                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
210                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
211            }
212    
213            /**
214             * Clears the cache for the m d r rule group.
215             *
216             * <p>
217             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
218             * </p>
219             */
220            @Override
221            public void clearCache(MDRRuleGroup mdrRuleGroup) {
222                    EntityCacheUtil.removeResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
223                            MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey());
224    
225                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
226                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
227    
228                    clearUniqueFindersCache(mdrRuleGroup);
229            }
230    
231            @Override
232            public void clearCache(List<MDRRuleGroup> mdrRuleGroups) {
233                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
234                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
235    
236                    for (MDRRuleGroup mdrRuleGroup : mdrRuleGroups) {
237                            EntityCacheUtil.removeResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
238                                    MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey());
239    
240                            clearUniqueFindersCache(mdrRuleGroup);
241                    }
242            }
243    
244            protected void clearUniqueFindersCache(MDRRuleGroup mdrRuleGroup) {
245                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
246                            new Object[] {
247                                    mdrRuleGroup.getUuid(), Long.valueOf(mdrRuleGroup.getGroupId())
248                            });
249            }
250    
251            /**
252             * Creates a new m d r rule group with the primary key. Does not add the m d r rule group to the database.
253             *
254             * @param ruleGroupId the primary key for the new m d r rule group
255             * @return the new m d r rule group
256             */
257            public MDRRuleGroup create(long ruleGroupId) {
258                    MDRRuleGroup mdrRuleGroup = new MDRRuleGroupImpl();
259    
260                    mdrRuleGroup.setNew(true);
261                    mdrRuleGroup.setPrimaryKey(ruleGroupId);
262    
263                    String uuid = PortalUUIDUtil.generate();
264    
265                    mdrRuleGroup.setUuid(uuid);
266    
267                    return mdrRuleGroup;
268            }
269    
270            /**
271             * Removes the m d r rule group with the primary key from the database. Also notifies the appropriate model listeners.
272             *
273             * @param ruleGroupId the primary key of the m d r rule group
274             * @return the m d r rule group that was removed
275             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
276             * @throws SystemException if a system exception occurred
277             */
278            public MDRRuleGroup remove(long ruleGroupId)
279                    throws NoSuchRuleGroupException, SystemException {
280                    return remove(Long.valueOf(ruleGroupId));
281            }
282    
283            /**
284             * Removes the m d r rule group with the primary key from the database. Also notifies the appropriate model listeners.
285             *
286             * @param primaryKey the primary key of the m d r rule group
287             * @return the m d r rule group that was removed
288             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
289             * @throws SystemException if a system exception occurred
290             */
291            @Override
292            public MDRRuleGroup remove(Serializable primaryKey)
293                    throws NoSuchRuleGroupException, SystemException {
294                    Session session = null;
295    
296                    try {
297                            session = openSession();
298    
299                            MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)session.get(MDRRuleGroupImpl.class,
300                                            primaryKey);
301    
302                            if (mdrRuleGroup == null) {
303                                    if (_log.isWarnEnabled()) {
304                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
305                                    }
306    
307                                    throw new NoSuchRuleGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
308                                            primaryKey);
309                            }
310    
311                            return remove(mdrRuleGroup);
312                    }
313                    catch (NoSuchRuleGroupException nsee) {
314                            throw nsee;
315                    }
316                    catch (Exception e) {
317                            throw processException(e);
318                    }
319                    finally {
320                            closeSession(session);
321                    }
322            }
323    
324            @Override
325            protected MDRRuleGroup removeImpl(MDRRuleGroup mdrRuleGroup)
326                    throws SystemException {
327                    mdrRuleGroup = toUnwrappedModel(mdrRuleGroup);
328    
329                    Session session = null;
330    
331                    try {
332                            session = openSession();
333    
334                            if (mdrRuleGroup.isCachedModel()) {
335                                    mdrRuleGroup = (MDRRuleGroup)session.get(MDRRuleGroupImpl.class,
336                                                    mdrRuleGroup.getPrimaryKeyObj());
337                            }
338    
339                            session.delete(mdrRuleGroup);
340                    }
341                    catch (Exception e) {
342                            throw processException(e);
343                    }
344                    finally {
345                            closeSession(session);
346                    }
347    
348                    clearCache(mdrRuleGroup);
349    
350                    return mdrRuleGroup;
351            }
352    
353            @Override
354            public MDRRuleGroup updateImpl(
355                    com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup mdrRuleGroup)
356                    throws SystemException {
357                    mdrRuleGroup = toUnwrappedModel(mdrRuleGroup);
358    
359                    boolean isNew = mdrRuleGroup.isNew();
360    
361                    MDRRuleGroupModelImpl mdrRuleGroupModelImpl = (MDRRuleGroupModelImpl)mdrRuleGroup;
362    
363                    if (Validator.isNull(mdrRuleGroup.getUuid())) {
364                            String uuid = PortalUUIDUtil.generate();
365    
366                            mdrRuleGroup.setUuid(uuid);
367                    }
368    
369                    Session session = null;
370    
371                    try {
372                            session = openSession();
373    
374                            if (mdrRuleGroup.isNew()) {
375                                    session.save(mdrRuleGroup);
376    
377                                    mdrRuleGroup.setNew(false);
378                            }
379                            else {
380                                    session.merge(mdrRuleGroup);
381                            }
382                    }
383                    catch (Exception e) {
384                            throw processException(e);
385                    }
386                    finally {
387                            closeSession(session);
388                    }
389    
390                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
391    
392                    if (isNew || !MDRRuleGroupModelImpl.COLUMN_BITMASK_ENABLED) {
393                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
394                    }
395    
396                    else {
397                            if ((mdrRuleGroupModelImpl.getColumnBitmask() &
398                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
399                                    Object[] args = new Object[] {
400                                                    mdrRuleGroupModelImpl.getOriginalUuid()
401                                            };
402    
403                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
404                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
405                                            args);
406    
407                                    args = new Object[] { mdrRuleGroupModelImpl.getUuid() };
408    
409                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
410                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
411                                            args);
412                            }
413    
414                            if ((mdrRuleGroupModelImpl.getColumnBitmask() &
415                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
416                                    Object[] args = new Object[] {
417                                                    mdrRuleGroupModelImpl.getOriginalUuid(),
418                                                    Long.valueOf(mdrRuleGroupModelImpl.getOriginalCompanyId())
419                                            };
420    
421                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
422                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
423                                            args);
424    
425                                    args = new Object[] {
426                                                    mdrRuleGroupModelImpl.getUuid(),
427                                                    Long.valueOf(mdrRuleGroupModelImpl.getCompanyId())
428                                            };
429    
430                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
431                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
432                                            args);
433                            }
434    
435                            if ((mdrRuleGroupModelImpl.getColumnBitmask() &
436                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
437                                    Object[] args = new Object[] {
438                                                    Long.valueOf(mdrRuleGroupModelImpl.getOriginalGroupId())
439                                            };
440    
441                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
442                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
443                                            args);
444    
445                                    args = new Object[] {
446                                                    Long.valueOf(mdrRuleGroupModelImpl.getGroupId())
447                                            };
448    
449                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
450                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
451                                            args);
452                            }
453                    }
454    
455                    EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
456                            MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey(), mdrRuleGroup);
457    
458                    if (isNew) {
459                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
460                                    new Object[] {
461                                            mdrRuleGroup.getUuid(),
462                                            Long.valueOf(mdrRuleGroup.getGroupId())
463                                    }, mdrRuleGroup);
464                    }
465                    else {
466                            if ((mdrRuleGroupModelImpl.getColumnBitmask() &
467                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
468                                    Object[] args = new Object[] {
469                                                    mdrRuleGroupModelImpl.getOriginalUuid(),
470                                                    Long.valueOf(mdrRuleGroupModelImpl.getOriginalGroupId())
471                                            };
472    
473                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
474    
475                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
476    
477                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
478                                            new Object[] {
479                                                    mdrRuleGroup.getUuid(),
480                                                    Long.valueOf(mdrRuleGroup.getGroupId())
481                                            }, mdrRuleGroup);
482                            }
483                    }
484    
485                    return mdrRuleGroup;
486            }
487    
488            protected MDRRuleGroup toUnwrappedModel(MDRRuleGroup mdrRuleGroup) {
489                    if (mdrRuleGroup instanceof MDRRuleGroupImpl) {
490                            return mdrRuleGroup;
491                    }
492    
493                    MDRRuleGroupImpl mdrRuleGroupImpl = new MDRRuleGroupImpl();
494    
495                    mdrRuleGroupImpl.setNew(mdrRuleGroup.isNew());
496                    mdrRuleGroupImpl.setPrimaryKey(mdrRuleGroup.getPrimaryKey());
497    
498                    mdrRuleGroupImpl.setUuid(mdrRuleGroup.getUuid());
499                    mdrRuleGroupImpl.setRuleGroupId(mdrRuleGroup.getRuleGroupId());
500                    mdrRuleGroupImpl.setGroupId(mdrRuleGroup.getGroupId());
501                    mdrRuleGroupImpl.setCompanyId(mdrRuleGroup.getCompanyId());
502                    mdrRuleGroupImpl.setUserId(mdrRuleGroup.getUserId());
503                    mdrRuleGroupImpl.setUserName(mdrRuleGroup.getUserName());
504                    mdrRuleGroupImpl.setCreateDate(mdrRuleGroup.getCreateDate());
505                    mdrRuleGroupImpl.setModifiedDate(mdrRuleGroup.getModifiedDate());
506                    mdrRuleGroupImpl.setName(mdrRuleGroup.getName());
507                    mdrRuleGroupImpl.setDescription(mdrRuleGroup.getDescription());
508    
509                    return mdrRuleGroupImpl;
510            }
511    
512            /**
513             * 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.
514             *
515             * @param primaryKey the primary key of the m d r rule group
516             * @return the m d r rule group
517             * @throws com.liferay.portal.NoSuchModelException if a m d r rule group with the primary key could not be found
518             * @throws SystemException if a system exception occurred
519             */
520            @Override
521            public MDRRuleGroup findByPrimaryKey(Serializable primaryKey)
522                    throws NoSuchModelException, SystemException {
523                    return findByPrimaryKey(((Long)primaryKey).longValue());
524            }
525    
526            /**
527             * 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.
528             *
529             * @param ruleGroupId the primary key of the m d r rule group
530             * @return the m d r rule group
531             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
532             * @throws SystemException if a system exception occurred
533             */
534            public MDRRuleGroup findByPrimaryKey(long ruleGroupId)
535                    throws NoSuchRuleGroupException, SystemException {
536                    MDRRuleGroup mdrRuleGroup = fetchByPrimaryKey(ruleGroupId);
537    
538                    if (mdrRuleGroup == null) {
539                            if (_log.isWarnEnabled()) {
540                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + ruleGroupId);
541                            }
542    
543                            throw new NoSuchRuleGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
544                                    ruleGroupId);
545                    }
546    
547                    return mdrRuleGroup;
548            }
549    
550            /**
551             * Returns the m d r rule group with the primary key or returns <code>null</code> if it could not be found.
552             *
553             * @param primaryKey the primary key of the m d r rule group
554             * @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
555             * @throws SystemException if a system exception occurred
556             */
557            @Override
558            public MDRRuleGroup fetchByPrimaryKey(Serializable primaryKey)
559                    throws SystemException {
560                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
561            }
562    
563            /**
564             * Returns the m d r rule group with the primary key or returns <code>null</code> if it could not be found.
565             *
566             * @param ruleGroupId the primary key of the m d r rule group
567             * @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
568             * @throws SystemException if a system exception occurred
569             */
570            public MDRRuleGroup fetchByPrimaryKey(long ruleGroupId)
571                    throws SystemException {
572                    MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)EntityCacheUtil.getResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
573                                    MDRRuleGroupImpl.class, ruleGroupId);
574    
575                    if (mdrRuleGroup == _nullMDRRuleGroup) {
576                            return null;
577                    }
578    
579                    if (mdrRuleGroup == null) {
580                            Session session = null;
581    
582                            boolean hasException = false;
583    
584                            try {
585                                    session = openSession();
586    
587                                    mdrRuleGroup = (MDRRuleGroup)session.get(MDRRuleGroupImpl.class,
588                                                    Long.valueOf(ruleGroupId));
589                            }
590                            catch (Exception e) {
591                                    hasException = true;
592    
593                                    throw processException(e);
594                            }
595                            finally {
596                                    if (mdrRuleGroup != null) {
597                                            cacheResult(mdrRuleGroup);
598                                    }
599                                    else if (!hasException) {
600                                            EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
601                                                    MDRRuleGroupImpl.class, ruleGroupId, _nullMDRRuleGroup);
602                                    }
603    
604                                    closeSession(session);
605                            }
606                    }
607    
608                    return mdrRuleGroup;
609            }
610    
611            /**
612             * Returns all the m d r rule groups where uuid = &#63;.
613             *
614             * @param uuid the uuid
615             * @return the matching m d r rule groups
616             * @throws SystemException if a system exception occurred
617             */
618            public List<MDRRuleGroup> findByUuid(String uuid) throws SystemException {
619                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
620            }
621    
622            /**
623             * Returns a range of all the m d r rule groups where uuid = &#63;.
624             *
625             * <p>
626             * 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.
627             * </p>
628             *
629             * @param uuid the uuid
630             * @param start the lower bound of the range of m d r rule groups
631             * @param end the upper bound of the range of m d r rule groups (not inclusive)
632             * @return the range of matching m d r rule groups
633             * @throws SystemException if a system exception occurred
634             */
635            public List<MDRRuleGroup> findByUuid(String uuid, int start, int end)
636                    throws SystemException {
637                    return findByUuid(uuid, start, end, null);
638            }
639    
640            /**
641             * Returns an ordered range of all the m d r rule groups where uuid = &#63;.
642             *
643             * <p>
644             * 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.
645             * </p>
646             *
647             * @param uuid the uuid
648             * @param start the lower bound of the range of m d r rule groups
649             * @param end the upper bound of the range of m d r rule groups (not inclusive)
650             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
651             * @return the ordered range of matching m d r rule groups
652             * @throws SystemException if a system exception occurred
653             */
654            public List<MDRRuleGroup> findByUuid(String uuid, int start, int end,
655                    OrderByComparator orderByComparator) throws SystemException {
656                    FinderPath finderPath = null;
657                    Object[] finderArgs = null;
658    
659                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
660                                    (orderByComparator == null)) {
661                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
662                            finderArgs = new Object[] { uuid };
663                    }
664                    else {
665                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
666                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
667                    }
668    
669                    List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
670                                    finderArgs, this);
671    
672                    if ((list != null) && !list.isEmpty()) {
673                            for (MDRRuleGroup mdrRuleGroup : list) {
674                                    if (!Validator.equals(uuid, mdrRuleGroup.getUuid())) {
675                                            list = null;
676    
677                                            break;
678                                    }
679                            }
680                    }
681    
682                    if (list == null) {
683                            StringBundler query = null;
684    
685                            if (orderByComparator != null) {
686                                    query = new StringBundler(3 +
687                                                    (orderByComparator.getOrderByFields().length * 3));
688                            }
689                            else {
690                                    query = new StringBundler(2);
691                            }
692    
693                            query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
694    
695                            if (uuid == null) {
696                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
697                            }
698                            else {
699                                    if (uuid.equals(StringPool.BLANK)) {
700                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
701                                    }
702                                    else {
703                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
704                                    }
705                            }
706    
707                            if (orderByComparator != null) {
708                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
709                                            orderByComparator);
710                            }
711    
712                            String sql = query.toString();
713    
714                            Session session = null;
715    
716                            try {
717                                    session = openSession();
718    
719                                    Query q = session.createQuery(sql);
720    
721                                    QueryPos qPos = QueryPos.getInstance(q);
722    
723                                    if (uuid != null) {
724                                            qPos.add(uuid);
725                                    }
726    
727                                    list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
728                                                    start, end);
729                            }
730                            catch (Exception e) {
731                                    throw processException(e);
732                            }
733                            finally {
734                                    if (list == null) {
735                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
736                                    }
737                                    else {
738                                            cacheResult(list);
739    
740                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
741                                    }
742    
743                                    closeSession(session);
744                            }
745                    }
746    
747                    return list;
748            }
749    
750            /**
751             * Returns the first 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 first 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_First(String uuid,
760                    OrderByComparator orderByComparator)
761                    throws NoSuchRuleGroupException, SystemException {
762                    MDRRuleGroup mdrRuleGroup = fetchByUuid_First(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 first 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 first 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_First(String uuid,
789                    OrderByComparator orderByComparator) throws SystemException {
790                    List<MDRRuleGroup> list = findByUuid(uuid, 0, 1, orderByComparator);
791    
792                    if (!list.isEmpty()) {
793                            return list.get(0);
794                    }
795    
796                    return null;
797            }
798    
799            /**
800             * Returns the last m d r rule group in the ordered set where uuid = &#63;.
801             *
802             * @param uuid the uuid
803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
804             * @return the last matching m d r rule group
805             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
806             * @throws SystemException if a system exception occurred
807             */
808            public MDRRuleGroup findByUuid_Last(String uuid,
809                    OrderByComparator orderByComparator)
810                    throws NoSuchRuleGroupException, SystemException {
811                    MDRRuleGroup mdrRuleGroup = fetchByUuid_Last(uuid, orderByComparator);
812    
813                    if (mdrRuleGroup != null) {
814                            return mdrRuleGroup;
815                    }
816    
817                    StringBundler msg = new StringBundler(4);
818    
819                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
820    
821                    msg.append("uuid=");
822                    msg.append(uuid);
823    
824                    msg.append(StringPool.CLOSE_CURLY_BRACE);
825    
826                    throw new NoSuchRuleGroupException(msg.toString());
827            }
828    
829            /**
830             * Returns the last m d r rule group in the ordered set where uuid = &#63;.
831             *
832             * @param uuid the uuid
833             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
834             * @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
835             * @throws SystemException if a system exception occurred
836             */
837            public MDRRuleGroup fetchByUuid_Last(String uuid,
838                    OrderByComparator orderByComparator) throws SystemException {
839                    int count = countByUuid(uuid);
840    
841                    List<MDRRuleGroup> list = findByUuid(uuid, count - 1, count,
842                                    orderByComparator);
843    
844                    if (!list.isEmpty()) {
845                            return list.get(0);
846                    }
847    
848                    return null;
849            }
850    
851            /**
852             * Returns the m d r rule groups before and after the current m d r rule group in the ordered set where uuid = &#63;.
853             *
854             * @param ruleGroupId the primary key of the current m d r rule group
855             * @param uuid the uuid
856             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
857             * @return the previous, current, and next m d r rule group
858             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
859             * @throws SystemException if a system exception occurred
860             */
861            public MDRRuleGroup[] findByUuid_PrevAndNext(long ruleGroupId, String uuid,
862                    OrderByComparator orderByComparator)
863                    throws NoSuchRuleGroupException, SystemException {
864                    MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
865    
866                    Session session = null;
867    
868                    try {
869                            session = openSession();
870    
871                            MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
872    
873                            array[0] = getByUuid_PrevAndNext(session, mdrRuleGroup, uuid,
874                                            orderByComparator, true);
875    
876                            array[1] = mdrRuleGroup;
877    
878                            array[2] = getByUuid_PrevAndNext(session, mdrRuleGroup, uuid,
879                                            orderByComparator, false);
880    
881                            return array;
882                    }
883                    catch (Exception e) {
884                            throw processException(e);
885                    }
886                    finally {
887                            closeSession(session);
888                    }
889            }
890    
891            protected MDRRuleGroup getByUuid_PrevAndNext(Session session,
892                    MDRRuleGroup mdrRuleGroup, String uuid,
893                    OrderByComparator orderByComparator, boolean previous) {
894                    StringBundler query = null;
895    
896                    if (orderByComparator != null) {
897                            query = new StringBundler(6 +
898                                            (orderByComparator.getOrderByFields().length * 6));
899                    }
900                    else {
901                            query = new StringBundler(3);
902                    }
903    
904                    query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
905    
906                    if (uuid == null) {
907                            query.append(_FINDER_COLUMN_UUID_UUID_1);
908                    }
909                    else {
910                            if (uuid.equals(StringPool.BLANK)) {
911                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
912                            }
913                            else {
914                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
915                            }
916                    }
917    
918                    if (orderByComparator != null) {
919                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
920    
921                            if (orderByConditionFields.length > 0) {
922                                    query.append(WHERE_AND);
923                            }
924    
925                            for (int i = 0; i < orderByConditionFields.length; i++) {
926                                    query.append(_ORDER_BY_ENTITY_ALIAS);
927                                    query.append(orderByConditionFields[i]);
928    
929                                    if ((i + 1) < orderByConditionFields.length) {
930                                            if (orderByComparator.isAscending() ^ previous) {
931                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
932                                            }
933                                            else {
934                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
935                                            }
936                                    }
937                                    else {
938                                            if (orderByComparator.isAscending() ^ previous) {
939                                                    query.append(WHERE_GREATER_THAN);
940                                            }
941                                            else {
942                                                    query.append(WHERE_LESSER_THAN);
943                                            }
944                                    }
945                            }
946    
947                            query.append(ORDER_BY_CLAUSE);
948    
949                            String[] orderByFields = orderByComparator.getOrderByFields();
950    
951                            for (int i = 0; i < orderByFields.length; i++) {
952                                    query.append(_ORDER_BY_ENTITY_ALIAS);
953                                    query.append(orderByFields[i]);
954    
955                                    if ((i + 1) < orderByFields.length) {
956                                            if (orderByComparator.isAscending() ^ previous) {
957                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
958                                            }
959                                            else {
960                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
961                                            }
962                                    }
963                                    else {
964                                            if (orderByComparator.isAscending() ^ previous) {
965                                                    query.append(ORDER_BY_ASC);
966                                            }
967                                            else {
968                                                    query.append(ORDER_BY_DESC);
969                                            }
970                                    }
971                            }
972                    }
973    
974                    String sql = query.toString();
975    
976                    Query q = session.createQuery(sql);
977    
978                    q.setFirstResult(0);
979                    q.setMaxResults(2);
980    
981                    QueryPos qPos = QueryPos.getInstance(q);
982    
983                    if (uuid != null) {
984                            qPos.add(uuid);
985                    }
986    
987                    if (orderByComparator != null) {
988                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
989    
990                            for (Object value : values) {
991                                    qPos.add(value);
992                            }
993                    }
994    
995                    List<MDRRuleGroup> list = q.list();
996    
997                    if (list.size() == 2) {
998                            return list.get(1);
999                    }
1000                    else {
1001                            return null;
1002                    }
1003            }
1004    
1005            /**
1006             * 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.
1007             *
1008             * @param uuid the uuid
1009             * @param groupId the group ID
1010             * @return the matching m d r rule group
1011             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1012             * @throws SystemException if a system exception occurred
1013             */
1014            public MDRRuleGroup findByUUID_G(String uuid, long groupId)
1015                    throws NoSuchRuleGroupException, SystemException {
1016                    MDRRuleGroup mdrRuleGroup = fetchByUUID_G(uuid, groupId);
1017    
1018                    if (mdrRuleGroup == null) {
1019                            StringBundler msg = new StringBundler(6);
1020    
1021                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1022    
1023                            msg.append("uuid=");
1024                            msg.append(uuid);
1025    
1026                            msg.append(", groupId=");
1027                            msg.append(groupId);
1028    
1029                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1030    
1031                            if (_log.isWarnEnabled()) {
1032                                    _log.warn(msg.toString());
1033                            }
1034    
1035                            throw new NoSuchRuleGroupException(msg.toString());
1036                    }
1037    
1038                    return mdrRuleGroup;
1039            }
1040    
1041            /**
1042             * 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.
1043             *
1044             * @param uuid the uuid
1045             * @param groupId the group ID
1046             * @return the matching m d r rule group, or <code>null</code> if a matching m d r rule group could not be found
1047             * @throws SystemException if a system exception occurred
1048             */
1049            public MDRRuleGroup fetchByUUID_G(String uuid, long groupId)
1050                    throws SystemException {
1051                    return fetchByUUID_G(uuid, groupId, true);
1052            }
1053    
1054            /**
1055             * 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.
1056             *
1057             * @param uuid the uuid
1058             * @param groupId the group ID
1059             * @param retrieveFromCache whether to use the finder cache
1060             * @return the matching m d r rule group, or <code>null</code> if a matching m d r rule group could not be found
1061             * @throws SystemException if a system exception occurred
1062             */
1063            public MDRRuleGroup fetchByUUID_G(String uuid, long groupId,
1064                    boolean retrieveFromCache) throws SystemException {
1065                    Object[] finderArgs = new Object[] { uuid, groupId };
1066    
1067                    Object result = null;
1068    
1069                    if (retrieveFromCache) {
1070                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1071                                            finderArgs, this);
1072                    }
1073    
1074                    if (result instanceof MDRRuleGroup) {
1075                            MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)result;
1076    
1077                            if (!Validator.equals(uuid, mdrRuleGroup.getUuid()) ||
1078                                            (groupId != mdrRuleGroup.getGroupId())) {
1079                                    result = null;
1080                            }
1081                    }
1082    
1083                    if (result == null) {
1084                            StringBundler query = new StringBundler(3);
1085    
1086                            query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1087    
1088                            if (uuid == null) {
1089                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1090                            }
1091                            else {
1092                                    if (uuid.equals(StringPool.BLANK)) {
1093                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1094                                    }
1095                                    else {
1096                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1097                                    }
1098                            }
1099    
1100                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1101    
1102                            String sql = query.toString();
1103    
1104                            Session session = null;
1105    
1106                            try {
1107                                    session = openSession();
1108    
1109                                    Query q = session.createQuery(sql);
1110    
1111                                    QueryPos qPos = QueryPos.getInstance(q);
1112    
1113                                    if (uuid != null) {
1114                                            qPos.add(uuid);
1115                                    }
1116    
1117                                    qPos.add(groupId);
1118    
1119                                    List<MDRRuleGroup> list = q.list();
1120    
1121                                    result = list;
1122    
1123                                    MDRRuleGroup mdrRuleGroup = null;
1124    
1125                                    if (list.isEmpty()) {
1126                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1127                                                    finderArgs, list);
1128                                    }
1129                                    else {
1130                                            mdrRuleGroup = list.get(0);
1131    
1132                                            cacheResult(mdrRuleGroup);
1133    
1134                                            if ((mdrRuleGroup.getUuid() == null) ||
1135                                                            !mdrRuleGroup.getUuid().equals(uuid) ||
1136                                                            (mdrRuleGroup.getGroupId() != groupId)) {
1137                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1138                                                            finderArgs, mdrRuleGroup);
1139                                            }
1140                                    }
1141    
1142                                    return mdrRuleGroup;
1143                            }
1144                            catch (Exception e) {
1145                                    throw processException(e);
1146                            }
1147                            finally {
1148                                    if (result == null) {
1149                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1150                                                    finderArgs);
1151                                    }
1152    
1153                                    closeSession(session);
1154                            }
1155                    }
1156                    else {
1157                            if (result instanceof List<?>) {
1158                                    return null;
1159                            }
1160                            else {
1161                                    return (MDRRuleGroup)result;
1162                            }
1163                    }
1164            }
1165    
1166            /**
1167             * Returns all the m d r rule groups where uuid = &#63; and companyId = &#63;.
1168             *
1169             * @param uuid the uuid
1170             * @param companyId the company ID
1171             * @return the matching m d r rule groups
1172             * @throws SystemException if a system exception occurred
1173             */
1174            public List<MDRRuleGroup> findByUuid_C(String uuid, long companyId)
1175                    throws SystemException {
1176                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1177                            QueryUtil.ALL_POS, null);
1178            }
1179    
1180            /**
1181             * Returns a range of all the m d r rule groups where uuid = &#63; and companyId = &#63;.
1182             *
1183             * <p>
1184             * 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.
1185             * </p>
1186             *
1187             * @param uuid the uuid
1188             * @param companyId the company ID
1189             * @param start the lower bound of the range of m d r rule groups
1190             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1191             * @return the range of matching m d r rule groups
1192             * @throws SystemException if a system exception occurred
1193             */
1194            public List<MDRRuleGroup> findByUuid_C(String uuid, long companyId,
1195                    int start, int end) throws SystemException {
1196                    return findByUuid_C(uuid, companyId, start, end, null);
1197            }
1198    
1199            /**
1200             * Returns an ordered range of all the m d r rule groups where uuid = &#63; and companyId = &#63;.
1201             *
1202             * <p>
1203             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1204             * </p>
1205             *
1206             * @param uuid the uuid
1207             * @param companyId the company ID
1208             * @param start the lower bound of the range of m d r rule groups
1209             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1210             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1211             * @return the ordered range of matching m d r rule groups
1212             * @throws SystemException if a system exception occurred
1213             */
1214            public List<MDRRuleGroup> findByUuid_C(String uuid, long companyId,
1215                    int start, int end, OrderByComparator orderByComparator)
1216                    throws SystemException {
1217                    FinderPath finderPath = null;
1218                    Object[] finderArgs = null;
1219    
1220                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1221                                    (orderByComparator == null)) {
1222                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1223                            finderArgs = new Object[] { uuid, companyId };
1224                    }
1225                    else {
1226                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1227                            finderArgs = new Object[] {
1228                                            uuid, companyId,
1229                                            
1230                                            start, end, orderByComparator
1231                                    };
1232                    }
1233    
1234                    List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
1235                                    finderArgs, this);
1236    
1237                    if ((list != null) && !list.isEmpty()) {
1238                            for (MDRRuleGroup mdrRuleGroup : list) {
1239                                    if (!Validator.equals(uuid, mdrRuleGroup.getUuid()) ||
1240                                                    (companyId != mdrRuleGroup.getCompanyId())) {
1241                                            list = null;
1242    
1243                                            break;
1244                                    }
1245                            }
1246                    }
1247    
1248                    if (list == null) {
1249                            StringBundler query = null;
1250    
1251                            if (orderByComparator != null) {
1252                                    query = new StringBundler(4 +
1253                                                    (orderByComparator.getOrderByFields().length * 3));
1254                            }
1255                            else {
1256                                    query = new StringBundler(3);
1257                            }
1258    
1259                            query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1260    
1261                            if (uuid == null) {
1262                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1263                            }
1264                            else {
1265                                    if (uuid.equals(StringPool.BLANK)) {
1266                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1267                                    }
1268                                    else {
1269                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1270                                    }
1271                            }
1272    
1273                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1274    
1275                            if (orderByComparator != null) {
1276                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1277                                            orderByComparator);
1278                            }
1279    
1280                            String sql = query.toString();
1281    
1282                            Session session = null;
1283    
1284                            try {
1285                                    session = openSession();
1286    
1287                                    Query q = session.createQuery(sql);
1288    
1289                                    QueryPos qPos = QueryPos.getInstance(q);
1290    
1291                                    if (uuid != null) {
1292                                            qPos.add(uuid);
1293                                    }
1294    
1295                                    qPos.add(companyId);
1296    
1297                                    list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
1298                                                    start, end);
1299                            }
1300                            catch (Exception e) {
1301                                    throw processException(e);
1302                            }
1303                            finally {
1304                                    if (list == null) {
1305                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1306                                    }
1307                                    else {
1308                                            cacheResult(list);
1309    
1310                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1311                                    }
1312    
1313                                    closeSession(session);
1314                            }
1315                    }
1316    
1317                    return list;
1318            }
1319    
1320            /**
1321             * Returns the first m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1322             *
1323             * @param uuid the uuid
1324             * @param companyId the company ID
1325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1326             * @return the first matching m d r rule group
1327             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1328             * @throws SystemException if a system exception occurred
1329             */
1330            public MDRRuleGroup findByUuid_C_First(String uuid, long companyId,
1331                    OrderByComparator orderByComparator)
1332                    throws NoSuchRuleGroupException, SystemException {
1333                    MDRRuleGroup mdrRuleGroup = fetchByUuid_C_First(uuid, companyId,
1334                                    orderByComparator);
1335    
1336                    if (mdrRuleGroup != null) {
1337                            return mdrRuleGroup;
1338                    }
1339    
1340                    StringBundler msg = new StringBundler(6);
1341    
1342                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1343    
1344                    msg.append("uuid=");
1345                    msg.append(uuid);
1346    
1347                    msg.append(", companyId=");
1348                    msg.append(companyId);
1349    
1350                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1351    
1352                    throw new NoSuchRuleGroupException(msg.toString());
1353            }
1354    
1355            /**
1356             * Returns the first m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1357             *
1358             * @param uuid the uuid
1359             * @param companyId the company ID
1360             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1361             * @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
1362             * @throws SystemException if a system exception occurred
1363             */
1364            public MDRRuleGroup fetchByUuid_C_First(String uuid, long companyId,
1365                    OrderByComparator orderByComparator) throws SystemException {
1366                    List<MDRRuleGroup> list = findByUuid_C(uuid, companyId, 0, 1,
1367                                    orderByComparator);
1368    
1369                    if (!list.isEmpty()) {
1370                            return list.get(0);
1371                    }
1372    
1373                    return null;
1374            }
1375    
1376            /**
1377             * Returns the last m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1378             *
1379             * @param uuid the uuid
1380             * @param companyId the company ID
1381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1382             * @return the last matching m d r rule group
1383             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1384             * @throws SystemException if a system exception occurred
1385             */
1386            public MDRRuleGroup findByUuid_C_Last(String uuid, long companyId,
1387                    OrderByComparator orderByComparator)
1388                    throws NoSuchRuleGroupException, SystemException {
1389                    MDRRuleGroup mdrRuleGroup = fetchByUuid_C_Last(uuid, companyId,
1390                                    orderByComparator);
1391    
1392                    if (mdrRuleGroup != null) {
1393                            return mdrRuleGroup;
1394                    }
1395    
1396                    StringBundler msg = new StringBundler(6);
1397    
1398                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1399    
1400                    msg.append("uuid=");
1401                    msg.append(uuid);
1402    
1403                    msg.append(", companyId=");
1404                    msg.append(companyId);
1405    
1406                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1407    
1408                    throw new NoSuchRuleGroupException(msg.toString());
1409            }
1410    
1411            /**
1412             * Returns the last m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1413             *
1414             * @param uuid the uuid
1415             * @param companyId the company ID
1416             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1417             * @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
1418             * @throws SystemException if a system exception occurred
1419             */
1420            public MDRRuleGroup fetchByUuid_C_Last(String uuid, long companyId,
1421                    OrderByComparator orderByComparator) throws SystemException {
1422                    int count = countByUuid_C(uuid, companyId);
1423    
1424                    List<MDRRuleGroup> list = findByUuid_C(uuid, companyId, count - 1,
1425                                    count, orderByComparator);
1426    
1427                    if (!list.isEmpty()) {
1428                            return list.get(0);
1429                    }
1430    
1431                    return null;
1432            }
1433    
1434            /**
1435             * Returns the m d r rule groups before and after the current m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1436             *
1437             * @param ruleGroupId the primary key of the current m d r rule group
1438             * @param uuid the uuid
1439             * @param companyId the company ID
1440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1441             * @return the previous, current, and next m d r rule group
1442             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
1443             * @throws SystemException if a system exception occurred
1444             */
1445            public MDRRuleGroup[] findByUuid_C_PrevAndNext(long ruleGroupId,
1446                    String uuid, long companyId, OrderByComparator orderByComparator)
1447                    throws NoSuchRuleGroupException, SystemException {
1448                    MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
1449    
1450                    Session session = null;
1451    
1452                    try {
1453                            session = openSession();
1454    
1455                            MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
1456    
1457                            array[0] = getByUuid_C_PrevAndNext(session, mdrRuleGroup, uuid,
1458                                            companyId, orderByComparator, true);
1459    
1460                            array[1] = mdrRuleGroup;
1461    
1462                            array[2] = getByUuid_C_PrevAndNext(session, mdrRuleGroup, uuid,
1463                                            companyId, orderByComparator, false);
1464    
1465                            return array;
1466                    }
1467                    catch (Exception e) {
1468                            throw processException(e);
1469                    }
1470                    finally {
1471                            closeSession(session);
1472                    }
1473            }
1474    
1475            protected MDRRuleGroup getByUuid_C_PrevAndNext(Session session,
1476                    MDRRuleGroup mdrRuleGroup, String uuid, long companyId,
1477                    OrderByComparator orderByComparator, boolean previous) {
1478                    StringBundler query = null;
1479    
1480                    if (orderByComparator != null) {
1481                            query = new StringBundler(6 +
1482                                            (orderByComparator.getOrderByFields().length * 6));
1483                    }
1484                    else {
1485                            query = new StringBundler(3);
1486                    }
1487    
1488                    query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1489    
1490                    if (uuid == null) {
1491                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1492                    }
1493                    else {
1494                            if (uuid.equals(StringPool.BLANK)) {
1495                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1496                            }
1497                            else {
1498                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1499                            }
1500                    }
1501    
1502                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1503    
1504                    if (orderByComparator != null) {
1505                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1506    
1507                            if (orderByConditionFields.length > 0) {
1508                                    query.append(WHERE_AND);
1509                            }
1510    
1511                            for (int i = 0; i < orderByConditionFields.length; i++) {
1512                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1513                                    query.append(orderByConditionFields[i]);
1514    
1515                                    if ((i + 1) < orderByConditionFields.length) {
1516                                            if (orderByComparator.isAscending() ^ previous) {
1517                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1518                                            }
1519                                            else {
1520                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1521                                            }
1522                                    }
1523                                    else {
1524                                            if (orderByComparator.isAscending() ^ previous) {
1525                                                    query.append(WHERE_GREATER_THAN);
1526                                            }
1527                                            else {
1528                                                    query.append(WHERE_LESSER_THAN);
1529                                            }
1530                                    }
1531                            }
1532    
1533                            query.append(ORDER_BY_CLAUSE);
1534    
1535                            String[] orderByFields = orderByComparator.getOrderByFields();
1536    
1537                            for (int i = 0; i < orderByFields.length; i++) {
1538                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1539                                    query.append(orderByFields[i]);
1540    
1541                                    if ((i + 1) < orderByFields.length) {
1542                                            if (orderByComparator.isAscending() ^ previous) {
1543                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1544                                            }
1545                                            else {
1546                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1547                                            }
1548                                    }
1549                                    else {
1550                                            if (orderByComparator.isAscending() ^ previous) {
1551                                                    query.append(ORDER_BY_ASC);
1552                                            }
1553                                            else {
1554                                                    query.append(ORDER_BY_DESC);
1555                                            }
1556                                    }
1557                            }
1558                    }
1559    
1560                    String sql = query.toString();
1561    
1562                    Query q = session.createQuery(sql);
1563    
1564                    q.setFirstResult(0);
1565                    q.setMaxResults(2);
1566    
1567                    QueryPos qPos = QueryPos.getInstance(q);
1568    
1569                    if (uuid != null) {
1570                            qPos.add(uuid);
1571                    }
1572    
1573                    qPos.add(companyId);
1574    
1575                    if (orderByComparator != null) {
1576                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
1577    
1578                            for (Object value : values) {
1579                                    qPos.add(value);
1580                            }
1581                    }
1582    
1583                    List<MDRRuleGroup> list = q.list();
1584    
1585                    if (list.size() == 2) {
1586                            return list.get(1);
1587                    }
1588                    else {
1589                            return null;
1590                    }
1591            }
1592    
1593            /**
1594             * Returns all the m d r rule groups where groupId = &#63;.
1595             *
1596             * @param groupId the group ID
1597             * @return the matching m d r rule groups
1598             * @throws SystemException if a system exception occurred
1599             */
1600            public List<MDRRuleGroup> findByGroupId(long groupId)
1601                    throws SystemException {
1602                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1603            }
1604    
1605            /**
1606             * Returns a range of all the m d r rule groups where groupId = &#63;.
1607             *
1608             * <p>
1609             * 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.
1610             * </p>
1611             *
1612             * @param groupId the group ID
1613             * @param start the lower bound of the range of m d r rule groups
1614             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1615             * @return the range of matching m d r rule groups
1616             * @throws SystemException if a system exception occurred
1617             */
1618            public List<MDRRuleGroup> findByGroupId(long groupId, int start, int end)
1619                    throws SystemException {
1620                    return findByGroupId(groupId, start, end, null);
1621            }
1622    
1623            /**
1624             * Returns an ordered range of all the m d r rule groups where groupId = &#63;.
1625             *
1626             * <p>
1627             * 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.
1628             * </p>
1629             *
1630             * @param groupId the group ID
1631             * @param start the lower bound of the range of m d r rule groups
1632             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1633             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1634             * @return the ordered range of matching m d r rule groups
1635             * @throws SystemException if a system exception occurred
1636             */
1637            public List<MDRRuleGroup> findByGroupId(long groupId, int start, int end,
1638                    OrderByComparator orderByComparator) throws SystemException {
1639                    FinderPath finderPath = null;
1640                    Object[] finderArgs = null;
1641    
1642                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1643                                    (orderByComparator == null)) {
1644                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1645                            finderArgs = new Object[] { groupId };
1646                    }
1647                    else {
1648                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1649                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1650                    }
1651    
1652                    List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
1653                                    finderArgs, this);
1654    
1655                    if ((list != null) && !list.isEmpty()) {
1656                            for (MDRRuleGroup mdrRuleGroup : list) {
1657                                    if ((groupId != mdrRuleGroup.getGroupId())) {
1658                                            list = null;
1659    
1660                                            break;
1661                                    }
1662                            }
1663                    }
1664    
1665                    if (list == null) {
1666                            StringBundler query = null;
1667    
1668                            if (orderByComparator != null) {
1669                                    query = new StringBundler(3 +
1670                                                    (orderByComparator.getOrderByFields().length * 3));
1671                            }
1672                            else {
1673                                    query = new StringBundler(2);
1674                            }
1675    
1676                            query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1677    
1678                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1679    
1680                            if (orderByComparator != null) {
1681                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1682                                            orderByComparator);
1683                            }
1684    
1685                            String sql = query.toString();
1686    
1687                            Session session = null;
1688    
1689                            try {
1690                                    session = openSession();
1691    
1692                                    Query q = session.createQuery(sql);
1693    
1694                                    QueryPos qPos = QueryPos.getInstance(q);
1695    
1696                                    qPos.add(groupId);
1697    
1698                                    list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
1699                                                    start, end);
1700                            }
1701                            catch (Exception e) {
1702                                    throw processException(e);
1703                            }
1704                            finally {
1705                                    if (list == null) {
1706                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1707                                    }
1708                                    else {
1709                                            cacheResult(list);
1710    
1711                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1712                                    }
1713    
1714                                    closeSession(session);
1715                            }
1716                    }
1717    
1718                    return list;
1719            }
1720    
1721            /**
1722             * Returns the first m d r rule group in the ordered set where groupId = &#63;.
1723             *
1724             * @param groupId the group ID
1725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1726             * @return the first matching m d r rule group
1727             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1728             * @throws SystemException if a system exception occurred
1729             */
1730            public MDRRuleGroup findByGroupId_First(long groupId,
1731                    OrderByComparator orderByComparator)
1732                    throws NoSuchRuleGroupException, SystemException {
1733                    MDRRuleGroup mdrRuleGroup = fetchByGroupId_First(groupId,
1734                                    orderByComparator);
1735    
1736                    if (mdrRuleGroup != null) {
1737                            return mdrRuleGroup;
1738                    }
1739    
1740                    StringBundler msg = new StringBundler(4);
1741    
1742                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1743    
1744                    msg.append("groupId=");
1745                    msg.append(groupId);
1746    
1747                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1748    
1749                    throw new NoSuchRuleGroupException(msg.toString());
1750            }
1751    
1752            /**
1753             * Returns the first m d r rule group in the ordered set where groupId = &#63;.
1754             *
1755             * @param groupId the group ID
1756             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1757             * @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
1758             * @throws SystemException if a system exception occurred
1759             */
1760            public MDRRuleGroup fetchByGroupId_First(long groupId,
1761                    OrderByComparator orderByComparator) throws SystemException {
1762                    List<MDRRuleGroup> list = findByGroupId(groupId, 0, 1, orderByComparator);
1763    
1764                    if (!list.isEmpty()) {
1765                            return list.get(0);
1766                    }
1767    
1768                    return null;
1769            }
1770    
1771            /**
1772             * Returns the last m d r rule group in the ordered set where groupId = &#63;.
1773             *
1774             * @param groupId the group ID
1775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1776             * @return the last matching m d r rule group
1777             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1778             * @throws SystemException if a system exception occurred
1779             */
1780            public MDRRuleGroup findByGroupId_Last(long groupId,
1781                    OrderByComparator orderByComparator)
1782                    throws NoSuchRuleGroupException, SystemException {
1783                    MDRRuleGroup mdrRuleGroup = fetchByGroupId_Last(groupId,
1784                                    orderByComparator);
1785    
1786                    if (mdrRuleGroup != null) {
1787                            return mdrRuleGroup;
1788                    }
1789    
1790                    StringBundler msg = new StringBundler(4);
1791    
1792                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1793    
1794                    msg.append("groupId=");
1795                    msg.append(groupId);
1796    
1797                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1798    
1799                    throw new NoSuchRuleGroupException(msg.toString());
1800            }
1801    
1802            /**
1803             * Returns the last m d r rule group in the ordered set where groupId = &#63;.
1804             *
1805             * @param groupId the group ID
1806             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1807             * @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
1808             * @throws SystemException if a system exception occurred
1809             */
1810            public MDRRuleGroup fetchByGroupId_Last(long groupId,
1811                    OrderByComparator orderByComparator) throws SystemException {
1812                    int count = countByGroupId(groupId);
1813    
1814                    List<MDRRuleGroup> list = findByGroupId(groupId, count - 1, count,
1815                                    orderByComparator);
1816    
1817                    if (!list.isEmpty()) {
1818                            return list.get(0);
1819                    }
1820    
1821                    return null;
1822            }
1823    
1824            /**
1825             * Returns the m d r rule groups before and after the current m d r rule group in the ordered set where groupId = &#63;.
1826             *
1827             * @param ruleGroupId the primary key of the current m d r rule group
1828             * @param groupId the group ID
1829             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1830             * @return the previous, current, and next m d r rule group
1831             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
1832             * @throws SystemException if a system exception occurred
1833             */
1834            public MDRRuleGroup[] findByGroupId_PrevAndNext(long ruleGroupId,
1835                    long groupId, OrderByComparator orderByComparator)
1836                    throws NoSuchRuleGroupException, SystemException {
1837                    MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
1838    
1839                    Session session = null;
1840    
1841                    try {
1842                            session = openSession();
1843    
1844                            MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
1845    
1846                            array[0] = getByGroupId_PrevAndNext(session, mdrRuleGroup, groupId,
1847                                            orderByComparator, true);
1848    
1849                            array[1] = mdrRuleGroup;
1850    
1851                            array[2] = getByGroupId_PrevAndNext(session, mdrRuleGroup, groupId,
1852                                            orderByComparator, false);
1853    
1854                            return array;
1855                    }
1856                    catch (Exception e) {
1857                            throw processException(e);
1858                    }
1859                    finally {
1860                            closeSession(session);
1861                    }
1862            }
1863    
1864            protected MDRRuleGroup getByGroupId_PrevAndNext(Session session,
1865                    MDRRuleGroup mdrRuleGroup, long groupId,
1866                    OrderByComparator orderByComparator, boolean previous) {
1867                    StringBundler query = null;
1868    
1869                    if (orderByComparator != null) {
1870                            query = new StringBundler(6 +
1871                                            (orderByComparator.getOrderByFields().length * 6));
1872                    }
1873                    else {
1874                            query = new StringBundler(3);
1875                    }
1876    
1877                    query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1878    
1879                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1880    
1881                    if (orderByComparator != null) {
1882                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1883    
1884                            if (orderByConditionFields.length > 0) {
1885                                    query.append(WHERE_AND);
1886                            }
1887    
1888                            for (int i = 0; i < orderByConditionFields.length; i++) {
1889                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1890                                    query.append(orderByConditionFields[i]);
1891    
1892                                    if ((i + 1) < orderByConditionFields.length) {
1893                                            if (orderByComparator.isAscending() ^ previous) {
1894                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1895                                            }
1896                                            else {
1897                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1898                                            }
1899                                    }
1900                                    else {
1901                                            if (orderByComparator.isAscending() ^ previous) {
1902                                                    query.append(WHERE_GREATER_THAN);
1903                                            }
1904                                            else {
1905                                                    query.append(WHERE_LESSER_THAN);
1906                                            }
1907                                    }
1908                            }
1909    
1910                            query.append(ORDER_BY_CLAUSE);
1911    
1912                            String[] orderByFields = orderByComparator.getOrderByFields();
1913    
1914                            for (int i = 0; i < orderByFields.length; i++) {
1915                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1916                                    query.append(orderByFields[i]);
1917    
1918                                    if ((i + 1) < orderByFields.length) {
1919                                            if (orderByComparator.isAscending() ^ previous) {
1920                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1921                                            }
1922                                            else {
1923                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1924                                            }
1925                                    }
1926                                    else {
1927                                            if (orderByComparator.isAscending() ^ previous) {
1928                                                    query.append(ORDER_BY_ASC);
1929                                            }
1930                                            else {
1931                                                    query.append(ORDER_BY_DESC);
1932                                            }
1933                                    }
1934                            }
1935                    }
1936    
1937                    String sql = query.toString();
1938    
1939                    Query q = session.createQuery(sql);
1940    
1941                    q.setFirstResult(0);
1942                    q.setMaxResults(2);
1943    
1944                    QueryPos qPos = QueryPos.getInstance(q);
1945    
1946                    qPos.add(groupId);
1947    
1948                    if (orderByComparator != null) {
1949                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
1950    
1951                            for (Object value : values) {
1952                                    qPos.add(value);
1953                            }
1954                    }
1955    
1956                    List<MDRRuleGroup> list = q.list();
1957    
1958                    if (list.size() == 2) {
1959                            return list.get(1);
1960                    }
1961                    else {
1962                            return null;
1963                    }
1964            }
1965    
1966            /**
1967             * Returns all the m d r rule groups that the user has permission to view where groupId = &#63;.
1968             *
1969             * @param groupId the group ID
1970             * @return the matching m d r rule groups that the user has permission to view
1971             * @throws SystemException if a system exception occurred
1972             */
1973            public List<MDRRuleGroup> filterFindByGroupId(long groupId)
1974                    throws SystemException {
1975                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1976                            QueryUtil.ALL_POS, null);
1977            }
1978    
1979            /**
1980             * Returns a range of all the m d r rule groups that the user has permission to view where groupId = &#63;.
1981             *
1982             * <p>
1983             * 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.
1984             * </p>
1985             *
1986             * @param groupId the group ID
1987             * @param start the lower bound of the range of m d r rule groups
1988             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1989             * @return the range of matching m d r rule groups that the user has permission to view
1990             * @throws SystemException if a system exception occurred
1991             */
1992            public List<MDRRuleGroup> filterFindByGroupId(long groupId, int start,
1993                    int end) throws SystemException {
1994                    return filterFindByGroupId(groupId, start, end, null);
1995            }
1996    
1997            /**
1998             * Returns an ordered range of all the m d r rule groups that the user has permissions to view where groupId = &#63;.
1999             *
2000             * <p>
2001             * 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.
2002             * </p>
2003             *
2004             * @param groupId the group ID
2005             * @param start the lower bound of the range of m d r rule groups
2006             * @param end the upper bound of the range of m d r rule groups (not inclusive)
2007             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2008             * @return the ordered range of matching m d r rule groups that the user has permission to view
2009             * @throws SystemException if a system exception occurred
2010             */
2011            public List<MDRRuleGroup> filterFindByGroupId(long groupId, int start,
2012                    int end, OrderByComparator orderByComparator) throws SystemException {
2013                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2014                            return findByGroupId(groupId, start, end, orderByComparator);
2015                    }
2016    
2017                    StringBundler query = null;
2018    
2019                    if (orderByComparator != null) {
2020                            query = new StringBundler(3 +
2021                                            (orderByComparator.getOrderByFields().length * 3));
2022                    }
2023                    else {
2024                            query = new StringBundler(2);
2025                    }
2026    
2027                    if (getDB().isSupportsInlineDistinct()) {
2028                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_WHERE);
2029                    }
2030                    else {
2031                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1);
2032                    }
2033    
2034                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2035    
2036                    if (!getDB().isSupportsInlineDistinct()) {
2037                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2);
2038                    }
2039    
2040                    if (orderByComparator != null) {
2041                            if (getDB().isSupportsInlineDistinct()) {
2042                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2043                                            orderByComparator);
2044                            }
2045                            else {
2046                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2047                                            orderByComparator);
2048                            }
2049                    }
2050    
2051                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2052                                    MDRRuleGroup.class.getName(),
2053                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2054    
2055                    Session session = null;
2056    
2057                    try {
2058                            session = openSession();
2059    
2060                            SQLQuery q = session.createSQLQuery(sql);
2061    
2062                            if (getDB().isSupportsInlineDistinct()) {
2063                                    q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupImpl.class);
2064                            }
2065                            else {
2066                                    q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupImpl.class);
2067                            }
2068    
2069                            QueryPos qPos = QueryPos.getInstance(q);
2070    
2071                            qPos.add(groupId);
2072    
2073                            return (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(), start,
2074                                    end);
2075                    }
2076                    catch (Exception e) {
2077                            throw processException(e);
2078                    }
2079                    finally {
2080                            closeSession(session);
2081                    }
2082            }
2083    
2084            /**
2085             * 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;.
2086             *
2087             * @param ruleGroupId the primary key of the current m d r rule group
2088             * @param groupId the group ID
2089             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2090             * @return the previous, current, and next m d r rule group
2091             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
2092             * @throws SystemException if a system exception occurred
2093             */
2094            public MDRRuleGroup[] filterFindByGroupId_PrevAndNext(long ruleGroupId,
2095                    long groupId, OrderByComparator orderByComparator)
2096                    throws NoSuchRuleGroupException, SystemException {
2097                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2098                            return findByGroupId_PrevAndNext(ruleGroupId, groupId,
2099                                    orderByComparator);
2100                    }
2101    
2102                    MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
2103    
2104                    Session session = null;
2105    
2106                    try {
2107                            session = openSession();
2108    
2109                            MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
2110    
2111                            array[0] = filterGetByGroupId_PrevAndNext(session, mdrRuleGroup,
2112                                            groupId, orderByComparator, true);
2113    
2114                            array[1] = mdrRuleGroup;
2115    
2116                            array[2] = filterGetByGroupId_PrevAndNext(session, mdrRuleGroup,
2117                                            groupId, orderByComparator, false);
2118    
2119                            return array;
2120                    }
2121                    catch (Exception e) {
2122                            throw processException(e);
2123                    }
2124                    finally {
2125                            closeSession(session);
2126                    }
2127            }
2128    
2129            protected MDRRuleGroup filterGetByGroupId_PrevAndNext(Session session,
2130                    MDRRuleGroup mdrRuleGroup, long groupId,
2131                    OrderByComparator orderByComparator, boolean previous) {
2132                    StringBundler query = null;
2133    
2134                    if (orderByComparator != null) {
2135                            query = new StringBundler(6 +
2136                                            (orderByComparator.getOrderByFields().length * 6));
2137                    }
2138                    else {
2139                            query = new StringBundler(3);
2140                    }
2141    
2142                    if (getDB().isSupportsInlineDistinct()) {
2143                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_WHERE);
2144                    }
2145                    else {
2146                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1);
2147                    }
2148    
2149                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2150    
2151                    if (!getDB().isSupportsInlineDistinct()) {
2152                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2);
2153                    }
2154    
2155                    if (orderByComparator != null) {
2156                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2157    
2158                            if (orderByConditionFields.length > 0) {
2159                                    query.append(WHERE_AND);
2160                            }
2161    
2162                            for (int i = 0; i < orderByConditionFields.length; i++) {
2163                                    if (getDB().isSupportsInlineDistinct()) {
2164                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2165                                    }
2166                                    else {
2167                                            query.append(_ORDER_BY_ENTITY_TABLE);
2168                                    }
2169    
2170                                    query.append(orderByConditionFields[i]);
2171    
2172                                    if ((i + 1) < orderByConditionFields.length) {
2173                                            if (orderByComparator.isAscending() ^ previous) {
2174                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2175                                            }
2176                                            else {
2177                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2178                                            }
2179                                    }
2180                                    else {
2181                                            if (orderByComparator.isAscending() ^ previous) {
2182                                                    query.append(WHERE_GREATER_THAN);
2183                                            }
2184                                            else {
2185                                                    query.append(WHERE_LESSER_THAN);
2186                                            }
2187                                    }
2188                            }
2189    
2190                            query.append(ORDER_BY_CLAUSE);
2191    
2192                            String[] orderByFields = orderByComparator.getOrderByFields();
2193    
2194                            for (int i = 0; i < orderByFields.length; i++) {
2195                                    if (getDB().isSupportsInlineDistinct()) {
2196                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2197                                    }
2198                                    else {
2199                                            query.append(_ORDER_BY_ENTITY_TABLE);
2200                                    }
2201    
2202                                    query.append(orderByFields[i]);
2203    
2204                                    if ((i + 1) < orderByFields.length) {
2205                                            if (orderByComparator.isAscending() ^ previous) {
2206                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2207                                            }
2208                                            else {
2209                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2210                                            }
2211                                    }
2212                                    else {
2213                                            if (orderByComparator.isAscending() ^ previous) {
2214                                                    query.append(ORDER_BY_ASC);
2215                                            }
2216                                            else {
2217                                                    query.append(ORDER_BY_DESC);
2218                                            }
2219                                    }
2220                            }
2221                    }
2222    
2223                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2224                                    MDRRuleGroup.class.getName(),
2225                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2226    
2227                    SQLQuery q = session.createSQLQuery(sql);
2228    
2229                    q.setFirstResult(0);
2230                    q.setMaxResults(2);
2231    
2232                    if (getDB().isSupportsInlineDistinct()) {
2233                            q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupImpl.class);
2234                    }
2235                    else {
2236                            q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupImpl.class);
2237                    }
2238    
2239                    QueryPos qPos = QueryPos.getInstance(q);
2240    
2241                    qPos.add(groupId);
2242    
2243                    if (orderByComparator != null) {
2244                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
2245    
2246                            for (Object value : values) {
2247                                    qPos.add(value);
2248                            }
2249                    }
2250    
2251                    List<MDRRuleGroup> list = q.list();
2252    
2253                    if (list.size() == 2) {
2254                            return list.get(1);
2255                    }
2256                    else {
2257                            return null;
2258                    }
2259            }
2260    
2261            /**
2262             * Returns all the m d r rule groups.
2263             *
2264             * @return the m d r rule groups
2265             * @throws SystemException if a system exception occurred
2266             */
2267            public List<MDRRuleGroup> findAll() throws SystemException {
2268                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2269            }
2270    
2271            /**
2272             * Returns a range of all the m d r rule groups.
2273             *
2274             * <p>
2275             * 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.
2276             * </p>
2277             *
2278             * @param start the lower bound of the range of m d r rule groups
2279             * @param end the upper bound of the range of m d r rule groups (not inclusive)
2280             * @return the range of m d r rule groups
2281             * @throws SystemException if a system exception occurred
2282             */
2283            public List<MDRRuleGroup> findAll(int start, int end)
2284                    throws SystemException {
2285                    return findAll(start, end, null);
2286            }
2287    
2288            /**
2289             * Returns an ordered range of all the m d r rule groups.
2290             *
2291             * <p>
2292             * 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.
2293             * </p>
2294             *
2295             * @param start the lower bound of the range of m d r rule groups
2296             * @param end the upper bound of the range of m d r rule groups (not inclusive)
2297             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2298             * @return the ordered range of m d r rule groups
2299             * @throws SystemException if a system exception occurred
2300             */
2301            public List<MDRRuleGroup> findAll(int start, int end,
2302                    OrderByComparator orderByComparator) throws SystemException {
2303                    FinderPath finderPath = null;
2304                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2305    
2306                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2307                                    (orderByComparator == null)) {
2308                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2309                            finderArgs = FINDER_ARGS_EMPTY;
2310                    }
2311                    else {
2312                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2313                            finderArgs = new Object[] { start, end, orderByComparator };
2314                    }
2315    
2316                    List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
2317                                    finderArgs, this);
2318    
2319                    if (list == null) {
2320                            StringBundler query = null;
2321                            String sql = null;
2322    
2323                            if (orderByComparator != null) {
2324                                    query = new StringBundler(2 +
2325                                                    (orderByComparator.getOrderByFields().length * 3));
2326    
2327                                    query.append(_SQL_SELECT_MDRRULEGROUP);
2328    
2329                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2330                                            orderByComparator);
2331    
2332                                    sql = query.toString();
2333                            }
2334                            else {
2335                                    sql = _SQL_SELECT_MDRRULEGROUP;
2336                            }
2337    
2338                            Session session = null;
2339    
2340                            try {
2341                                    session = openSession();
2342    
2343                                    Query q = session.createQuery(sql);
2344    
2345                                    if (orderByComparator == null) {
2346                                            list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
2347                                                            start, end, false);
2348    
2349                                            Collections.sort(list);
2350                                    }
2351                                    else {
2352                                            list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
2353                                                            start, end);
2354                                    }
2355                            }
2356                            catch (Exception e) {
2357                                    throw processException(e);
2358                            }
2359                            finally {
2360                                    if (list == null) {
2361                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2362                                    }
2363                                    else {
2364                                            cacheResult(list);
2365    
2366                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2367                                    }
2368    
2369                                    closeSession(session);
2370                            }
2371                    }
2372    
2373                    return list;
2374            }
2375    
2376            /**
2377             * Removes all the m d r rule groups where uuid = &#63; from the database.
2378             *
2379             * @param uuid the uuid
2380             * @throws SystemException if a system exception occurred
2381             */
2382            public void removeByUuid(String uuid) throws SystemException {
2383                    for (MDRRuleGroup mdrRuleGroup : findByUuid(uuid)) {
2384                            remove(mdrRuleGroup);
2385                    }
2386            }
2387    
2388            /**
2389             * Removes the m d r rule group where uuid = &#63; and groupId = &#63; from the database.
2390             *
2391             * @param uuid the uuid
2392             * @param groupId the group ID
2393             * @return the m d r rule group that was removed
2394             * @throws SystemException if a system exception occurred
2395             */
2396            public MDRRuleGroup removeByUUID_G(String uuid, long groupId)
2397                    throws NoSuchRuleGroupException, SystemException {
2398                    MDRRuleGroup mdrRuleGroup = findByUUID_G(uuid, groupId);
2399    
2400                    return remove(mdrRuleGroup);
2401            }
2402    
2403            /**
2404             * Removes all the m d r rule groups where uuid = &#63; and companyId = &#63; from the database.
2405             *
2406             * @param uuid the uuid
2407             * @param companyId the company ID
2408             * @throws SystemException if a system exception occurred
2409             */
2410            public void removeByUuid_C(String uuid, long companyId)
2411                    throws SystemException {
2412                    for (MDRRuleGroup mdrRuleGroup : findByUuid_C(uuid, companyId)) {
2413                            remove(mdrRuleGroup);
2414                    }
2415            }
2416    
2417            /**
2418             * Removes all the m d r rule groups where groupId = &#63; from the database.
2419             *
2420             * @param groupId the group ID
2421             * @throws SystemException if a system exception occurred
2422             */
2423            public void removeByGroupId(long groupId) throws SystemException {
2424                    for (MDRRuleGroup mdrRuleGroup : findByGroupId(groupId)) {
2425                            remove(mdrRuleGroup);
2426                    }
2427            }
2428    
2429            /**
2430             * Removes all the m d r rule groups from the database.
2431             *
2432             * @throws SystemException if a system exception occurred
2433             */
2434            public void removeAll() throws SystemException {
2435                    for (MDRRuleGroup mdrRuleGroup : findAll()) {
2436                            remove(mdrRuleGroup);
2437                    }
2438            }
2439    
2440            /**
2441             * Returns the number of m d r rule groups where uuid = &#63;.
2442             *
2443             * @param uuid the uuid
2444             * @return the number of matching m d r rule groups
2445             * @throws SystemException if a system exception occurred
2446             */
2447            public int countByUuid(String uuid) throws SystemException {
2448                    Object[] finderArgs = new Object[] { uuid };
2449    
2450                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2451                                    finderArgs, this);
2452    
2453                    if (count == null) {
2454                            StringBundler query = new StringBundler(2);
2455    
2456                            query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
2457    
2458                            if (uuid == null) {
2459                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
2460                            }
2461                            else {
2462                                    if (uuid.equals(StringPool.BLANK)) {
2463                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
2464                                    }
2465                                    else {
2466                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
2467                                    }
2468                            }
2469    
2470                            String sql = query.toString();
2471    
2472                            Session session = null;
2473    
2474                            try {
2475                                    session = openSession();
2476    
2477                                    Query q = session.createQuery(sql);
2478    
2479                                    QueryPos qPos = QueryPos.getInstance(q);
2480    
2481                                    if (uuid != null) {
2482                                            qPos.add(uuid);
2483                                    }
2484    
2485                                    count = (Long)q.uniqueResult();
2486                            }
2487                            catch (Exception e) {
2488                                    throw processException(e);
2489                            }
2490                            finally {
2491                                    if (count == null) {
2492                                            count = Long.valueOf(0);
2493                                    }
2494    
2495                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2496                                            finderArgs, count);
2497    
2498                                    closeSession(session);
2499                            }
2500                    }
2501    
2502                    return count.intValue();
2503            }
2504    
2505            /**
2506             * Returns the number of m d r rule groups where uuid = &#63; and groupId = &#63;.
2507             *
2508             * @param uuid the uuid
2509             * @param groupId the group ID
2510             * @return the number of matching m d r rule groups
2511             * @throws SystemException if a system exception occurred
2512             */
2513            public int countByUUID_G(String uuid, long groupId)
2514                    throws SystemException {
2515                    Object[] finderArgs = new Object[] { uuid, groupId };
2516    
2517                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2518                                    finderArgs, this);
2519    
2520                    if (count == null) {
2521                            StringBundler query = new StringBundler(3);
2522    
2523                            query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
2524    
2525                            if (uuid == null) {
2526                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2527                            }
2528                            else {
2529                                    if (uuid.equals(StringPool.BLANK)) {
2530                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2531                                    }
2532                                    else {
2533                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2534                                    }
2535                            }
2536    
2537                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2538    
2539                            String sql = query.toString();
2540    
2541                            Session session = null;
2542    
2543                            try {
2544                                    session = openSession();
2545    
2546                                    Query q = session.createQuery(sql);
2547    
2548                                    QueryPos qPos = QueryPos.getInstance(q);
2549    
2550                                    if (uuid != null) {
2551                                            qPos.add(uuid);
2552                                    }
2553    
2554                                    qPos.add(groupId);
2555    
2556                                    count = (Long)q.uniqueResult();
2557                            }
2558                            catch (Exception e) {
2559                                    throw processException(e);
2560                            }
2561                            finally {
2562                                    if (count == null) {
2563                                            count = Long.valueOf(0);
2564                                    }
2565    
2566                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2567                                            finderArgs, count);
2568    
2569                                    closeSession(session);
2570                            }
2571                    }
2572    
2573                    return count.intValue();
2574            }
2575    
2576            /**
2577             * Returns the number of m d r rule groups where uuid = &#63; and companyId = &#63;.
2578             *
2579             * @param uuid the uuid
2580             * @param companyId the company ID
2581             * @return the number of matching m d r rule groups
2582             * @throws SystemException if a system exception occurred
2583             */
2584            public int countByUuid_C(String uuid, long companyId)
2585                    throws SystemException {
2586                    Object[] finderArgs = new Object[] { uuid, companyId };
2587    
2588                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
2589                                    finderArgs, this);
2590    
2591                    if (count == null) {
2592                            StringBundler query = new StringBundler(3);
2593    
2594                            query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
2595    
2596                            if (uuid == null) {
2597                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
2598                            }
2599                            else {
2600                                    if (uuid.equals(StringPool.BLANK)) {
2601                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
2602                                    }
2603                                    else {
2604                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
2605                                    }
2606                            }
2607    
2608                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
2609    
2610                            String sql = query.toString();
2611    
2612                            Session session = null;
2613    
2614                            try {
2615                                    session = openSession();
2616    
2617                                    Query q = session.createQuery(sql);
2618    
2619                                    QueryPos qPos = QueryPos.getInstance(q);
2620    
2621                                    if (uuid != null) {
2622                                            qPos.add(uuid);
2623                                    }
2624    
2625                                    qPos.add(companyId);
2626    
2627                                    count = (Long)q.uniqueResult();
2628                            }
2629                            catch (Exception e) {
2630                                    throw processException(e);
2631                            }
2632                            finally {
2633                                    if (count == null) {
2634                                            count = Long.valueOf(0);
2635                                    }
2636    
2637                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
2638                                            finderArgs, count);
2639    
2640                                    closeSession(session);
2641                            }
2642                    }
2643    
2644                    return count.intValue();
2645            }
2646    
2647            /**
2648             * Returns the number of m d r rule groups where groupId = &#63;.
2649             *
2650             * @param groupId the group ID
2651             * @return the number of matching m d r rule groups
2652             * @throws SystemException if a system exception occurred
2653             */
2654            public int countByGroupId(long groupId) throws SystemException {
2655                    Object[] finderArgs = new Object[] { groupId };
2656    
2657                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2658                                    finderArgs, this);
2659    
2660                    if (count == null) {
2661                            StringBundler query = new StringBundler(2);
2662    
2663                            query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
2664    
2665                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2666    
2667                            String sql = query.toString();
2668    
2669                            Session session = null;
2670    
2671                            try {
2672                                    session = openSession();
2673    
2674                                    Query q = session.createQuery(sql);
2675    
2676                                    QueryPos qPos = QueryPos.getInstance(q);
2677    
2678                                    qPos.add(groupId);
2679    
2680                                    count = (Long)q.uniqueResult();
2681                            }
2682                            catch (Exception e) {
2683                                    throw processException(e);
2684                            }
2685                            finally {
2686                                    if (count == null) {
2687                                            count = Long.valueOf(0);
2688                                    }
2689    
2690                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2691                                            finderArgs, count);
2692    
2693                                    closeSession(session);
2694                            }
2695                    }
2696    
2697                    return count.intValue();
2698            }
2699    
2700            /**
2701             * Returns the number of m d r rule groups that the user has permission to view where groupId = &#63;.
2702             *
2703             * @param groupId the group ID
2704             * @return the number of matching m d r rule groups that the user has permission to view
2705             * @throws SystemException if a system exception occurred
2706             */
2707            public int filterCountByGroupId(long groupId) throws SystemException {
2708                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2709                            return countByGroupId(groupId);
2710                    }
2711    
2712                    StringBundler query = new StringBundler(2);
2713    
2714                    query.append(_FILTER_SQL_COUNT_MDRRULEGROUP_WHERE);
2715    
2716                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2717    
2718                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2719                                    MDRRuleGroup.class.getName(),
2720                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2721    
2722                    Session session = null;
2723    
2724                    try {
2725                            session = openSession();
2726    
2727                            SQLQuery q = session.createSQLQuery(sql);
2728    
2729                            q.addScalar(COUNT_COLUMN_NAME,
2730                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2731    
2732                            QueryPos qPos = QueryPos.getInstance(q);
2733    
2734                            qPos.add(groupId);
2735    
2736                            Long count = (Long)q.uniqueResult();
2737    
2738                            return count.intValue();
2739                    }
2740                    catch (Exception e) {
2741                            throw processException(e);
2742                    }
2743                    finally {
2744                            closeSession(session);
2745                    }
2746            }
2747    
2748            /**
2749             * Returns the number of m d r rule groups.
2750             *
2751             * @return the number of m d r rule groups
2752             * @throws SystemException if a system exception occurred
2753             */
2754            public int countAll() throws SystemException {
2755                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2756                                    FINDER_ARGS_EMPTY, this);
2757    
2758                    if (count == null) {
2759                            Session session = null;
2760    
2761                            try {
2762                                    session = openSession();
2763    
2764                                    Query q = session.createQuery(_SQL_COUNT_MDRRULEGROUP);
2765    
2766                                    count = (Long)q.uniqueResult();
2767                            }
2768                            catch (Exception e) {
2769                                    throw processException(e);
2770                            }
2771                            finally {
2772                                    if (count == null) {
2773                                            count = Long.valueOf(0);
2774                                    }
2775    
2776                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2777                                            FINDER_ARGS_EMPTY, count);
2778    
2779                                    closeSession(session);
2780                            }
2781                    }
2782    
2783                    return count.intValue();
2784            }
2785    
2786            /**
2787             * Initializes the m d r rule group persistence.
2788             */
2789            public void afterPropertiesSet() {
2790                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2791                                            com.liferay.portal.util.PropsUtil.get(
2792                                                    "value.object.listener.com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup")));
2793    
2794                    if (listenerClassNames.length > 0) {
2795                            try {
2796                                    List<ModelListener<MDRRuleGroup>> listenersList = new ArrayList<ModelListener<MDRRuleGroup>>();
2797    
2798                                    for (String listenerClassName : listenerClassNames) {
2799                                            listenersList.add((ModelListener<MDRRuleGroup>)InstanceFactory.newInstance(
2800                                                            listenerClassName));
2801                                    }
2802    
2803                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2804                            }
2805                            catch (Exception e) {
2806                                    _log.error(e);
2807                            }
2808                    }
2809            }
2810    
2811            public void destroy() {
2812                    EntityCacheUtil.removeCache(MDRRuleGroupImpl.class.getName());
2813                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2814                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2815            }
2816    
2817            @BeanReference(type = MDRActionPersistence.class)
2818            protected MDRActionPersistence mdrActionPersistence;
2819            @BeanReference(type = MDRRulePersistence.class)
2820            protected MDRRulePersistence mdrRulePersistence;
2821            @BeanReference(type = MDRRuleGroupPersistence.class)
2822            protected MDRRuleGroupPersistence mdrRuleGroupPersistence;
2823            @BeanReference(type = MDRRuleGroupInstancePersistence.class)
2824            protected MDRRuleGroupInstancePersistence mdrRuleGroupInstancePersistence;
2825            @BeanReference(type = GroupPersistence.class)
2826            protected GroupPersistence groupPersistence;
2827            @BeanReference(type = UserPersistence.class)
2828            protected UserPersistence userPersistence;
2829            private static final String _SQL_SELECT_MDRRULEGROUP = "SELECT mdrRuleGroup FROM MDRRuleGroup mdrRuleGroup";
2830            private static final String _SQL_SELECT_MDRRULEGROUP_WHERE = "SELECT mdrRuleGroup FROM MDRRuleGroup mdrRuleGroup WHERE ";
2831            private static final String _SQL_COUNT_MDRRULEGROUP = "SELECT COUNT(mdrRuleGroup) FROM MDRRuleGroup mdrRuleGroup";
2832            private static final String _SQL_COUNT_MDRRULEGROUP_WHERE = "SELECT COUNT(mdrRuleGroup) FROM MDRRuleGroup mdrRuleGroup WHERE ";
2833            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mdrRuleGroup.uuid IS NULL";
2834            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrRuleGroup.uuid = ?";
2835            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrRuleGroup.uuid IS NULL OR mdrRuleGroup.uuid = ?)";
2836            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mdrRuleGroup.uuid IS NULL AND ";
2837            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrRuleGroup.uuid = ? AND ";
2838            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrRuleGroup.uuid IS NULL OR mdrRuleGroup.uuid = ?) AND ";
2839            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrRuleGroup.groupId = ?";
2840            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mdrRuleGroup.uuid IS NULL AND ";
2841            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mdrRuleGroup.uuid = ? AND ";
2842            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mdrRuleGroup.uuid IS NULL OR mdrRuleGroup.uuid = ?) AND ";
2843            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mdrRuleGroup.companyId = ?";
2844            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mdrRuleGroup.groupId = ?";
2845            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mdrRuleGroup.ruleGroupId";
2846            private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_WHERE = "SELECT DISTINCT {mdrRuleGroup.*} FROM MDRRuleGroup mdrRuleGroup WHERE ";
2847            private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1 =
2848                    "SELECT {MDRRuleGroup.*} FROM (SELECT DISTINCT mdrRuleGroup.ruleGroupId FROM MDRRuleGroup mdrRuleGroup WHERE ";
2849            private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2 =
2850                    ") TEMP_TABLE INNER JOIN MDRRuleGroup ON TEMP_TABLE.ruleGroupId = MDRRuleGroup.ruleGroupId";
2851            private static final String _FILTER_SQL_COUNT_MDRRULEGROUP_WHERE = "SELECT COUNT(DISTINCT mdrRuleGroup.ruleGroupId) AS COUNT_VALUE FROM MDRRuleGroup mdrRuleGroup WHERE ";
2852            private static final String _FILTER_ENTITY_ALIAS = "mdrRuleGroup";
2853            private static final String _FILTER_ENTITY_TABLE = "MDRRuleGroup";
2854            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRuleGroup.";
2855            private static final String _ORDER_BY_ENTITY_TABLE = "MDRRuleGroup.";
2856            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRuleGroup exists with the primary key ";
2857            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRuleGroup exists with the key {";
2858            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2859            private static Log _log = LogFactoryUtil.getLog(MDRRuleGroupPersistenceImpl.class);
2860            private static MDRRuleGroup _nullMDRRuleGroup = new MDRRuleGroupImpl() {
2861                            @Override
2862                            public Object clone() {
2863                                    return this;
2864                            }
2865    
2866                            @Override
2867                            public CacheModel<MDRRuleGroup> toCacheModel() {
2868                                    return _nullMDRRuleGroupCacheModel;
2869                            }
2870                    };
2871    
2872            private static CacheModel<MDRRuleGroup> _nullMDRRuleGroupCacheModel = new CacheModel<MDRRuleGroup>() {
2873                            public MDRRuleGroup toEntityModel() {
2874                                    return _nullMDRRuleGroup;
2875                            }
2876                    };
2877    }