001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.mobiledevicerules.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
042    import com.liferay.portal.service.persistence.BatchSessionUtil;
043    import com.liferay.portal.service.persistence.LayoutPersistence;
044    import com.liferay.portal.service.persistence.LayoutSetPersistence;
045    import com.liferay.portal.service.persistence.ResourcePersistence;
046    import com.liferay.portal.service.persistence.UserPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException;
050    import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance;
051    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceImpl;
052    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    
060    /**
061     * The persistence implementation for the m d r rule group instance service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Edward C. Han
068     * @see MDRRuleGroupInstancePersistence
069     * @see MDRRuleGroupInstanceUtil
070     * @generated
071     */
072    public class MDRRuleGroupInstancePersistenceImpl extends BasePersistenceImpl<MDRRuleGroupInstance>
073            implements MDRRuleGroupInstancePersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * Never modify or reference this class directly. Always use {@link MDRRuleGroupInstanceUtil} to access the m d r rule group instance persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = MDRRuleGroupInstanceImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
085                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
086                            MDRRuleGroupInstanceImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
088                            new String[] {
089                                    String.class.getName(),
090                                    
091                            "java.lang.Integer", "java.lang.Integer",
092                                    "com.liferay.portal.kernel.util.OrderByComparator"
093                            });
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
095                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
096                            MDRRuleGroupInstanceImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
098                            new String[] { String.class.getName() },
099                            MDRRuleGroupInstanceModelImpl.UUID_COLUMN_BITMASK);
100            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
101                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
103                            new String[] { String.class.getName() });
104            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
105                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
106                            MDRRuleGroupInstanceImpl.class, FINDER_CLASS_NAME_ENTITY,
107                            "fetchByUUID_G",
108                            new String[] { String.class.getName(), Long.class.getName() },
109                            MDRRuleGroupInstanceModelImpl.UUID_COLUMN_BITMASK |
110                            MDRRuleGroupInstanceModelImpl.GROUPID_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
112                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
114                            new String[] { String.class.getName(), Long.class.getName() });
115            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID =
116                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
117                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
118                            MDRRuleGroupInstanceImpl.class,
119                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRuleGroupId",
120                            new String[] {
121                                    Long.class.getName(),
122                                    
123                            "java.lang.Integer", "java.lang.Integer",
124                                    "com.liferay.portal.kernel.util.OrderByComparator"
125                            });
126            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID =
127                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
128                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
129                            MDRRuleGroupInstanceImpl.class,
130                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRuleGroupId",
131                            new String[] { Long.class.getName() },
132                            MDRRuleGroupInstanceModelImpl.RULEGROUPID_COLUMN_BITMASK);
133            public static final FinderPath FINDER_PATH_COUNT_BY_RULEGROUPID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
134                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
135                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRuleGroupId",
136                            new String[] { Long.class.getName() });
137            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
138                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
139                            MDRRuleGroupInstanceImpl.class,
140                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
141                            new String[] {
142                                    Long.class.getName(), Long.class.getName(),
143                                    
144                            "java.lang.Integer", "java.lang.Integer",
145                                    "com.liferay.portal.kernel.util.OrderByComparator"
146                            });
147            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
148                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
149                            MDRRuleGroupInstanceImpl.class,
150                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
151                            new String[] { Long.class.getName(), Long.class.getName() },
152                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
153                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK);
154            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
155                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
156                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
157                            new String[] { Long.class.getName(), Long.class.getName() });
158            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
159                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
160                            MDRRuleGroupInstanceImpl.class,
161                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C",
162                            new String[] {
163                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
164                                    
165                            "java.lang.Integer", "java.lang.Integer",
166                                    "com.liferay.portal.kernel.util.OrderByComparator"
167                            });
168            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
169                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
170                            MDRRuleGroupInstanceImpl.class,
171                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C",
172                            new String[] {
173                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
174                            },
175                            MDRRuleGroupInstanceModelImpl.GROUPID_COLUMN_BITMASK |
176                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
177                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK);
178            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
179                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
180                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C",
181                            new String[] {
182                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
183                            });
184            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_R = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
185                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
186                            MDRRuleGroupInstanceImpl.class, FINDER_CLASS_NAME_ENTITY,
187                            "fetchByC_C_R",
188                            new String[] {
189                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
190                            },
191                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
192                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK |
193                            MDRRuleGroupInstanceModelImpl.RULEGROUPID_COLUMN_BITMASK);
194            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_R = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
195                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
196                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_R",
197                            new String[] {
198                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
199                            });
200            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
201                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
202                            MDRRuleGroupInstanceImpl.class,
203                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
204            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
205                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
206                            MDRRuleGroupInstanceImpl.class,
207                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
208            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
209                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
210                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
211    
212            /**
213             * Caches the m d r rule group instance in the entity cache if it is enabled.
214             *
215             * @param mdrRuleGroupInstance the m d r rule group instance
216             */
217            public void cacheResult(MDRRuleGroupInstance mdrRuleGroupInstance) {
218                    EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
219                            MDRRuleGroupInstanceImpl.class,
220                            mdrRuleGroupInstance.getPrimaryKey(), mdrRuleGroupInstance);
221    
222                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
223                            new Object[] {
224                                    mdrRuleGroupInstance.getUuid(),
225                                    Long.valueOf(mdrRuleGroupInstance.getGroupId())
226                            }, mdrRuleGroupInstance);
227    
228                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
229                            new Object[] {
230                                    Long.valueOf(mdrRuleGroupInstance.getClassNameId()),
231                                    Long.valueOf(mdrRuleGroupInstance.getClassPK()),
232                                    Long.valueOf(mdrRuleGroupInstance.getRuleGroupId())
233                            }, mdrRuleGroupInstance);
234    
235                    mdrRuleGroupInstance.resetOriginalValues();
236            }
237    
238            /**
239             * Caches the m d r rule group instances in the entity cache if it is enabled.
240             *
241             * @param mdrRuleGroupInstances the m d r rule group instances
242             */
243            public void cacheResult(List<MDRRuleGroupInstance> mdrRuleGroupInstances) {
244                    for (MDRRuleGroupInstance mdrRuleGroupInstance : mdrRuleGroupInstances) {
245                            if (EntityCacheUtil.getResult(
246                                                    MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
247                                                    MDRRuleGroupInstanceImpl.class,
248                                                    mdrRuleGroupInstance.getPrimaryKey()) == null) {
249                                    cacheResult(mdrRuleGroupInstance);
250                            }
251                            else {
252                                    mdrRuleGroupInstance.resetOriginalValues();
253                            }
254                    }
255            }
256    
257            /**
258             * Clears the cache for all m d r rule group instances.
259             *
260             * <p>
261             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
262             * </p>
263             */
264            @Override
265            public void clearCache() {
266                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
267                            CacheRegistryUtil.clear(MDRRuleGroupInstanceImpl.class.getName());
268                    }
269    
270                    EntityCacheUtil.clearCache(MDRRuleGroupInstanceImpl.class.getName());
271    
272                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
273                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
274                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
275            }
276    
277            /**
278             * Clears the cache for the m d r rule group instance.
279             *
280             * <p>
281             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
282             * </p>
283             */
284            @Override
285            public void clearCache(MDRRuleGroupInstance mdrRuleGroupInstance) {
286                    EntityCacheUtil.removeResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
287                            MDRRuleGroupInstanceImpl.class, mdrRuleGroupInstance.getPrimaryKey());
288    
289                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
290                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
291    
292                    clearUniqueFindersCache(mdrRuleGroupInstance);
293            }
294    
295            @Override
296            public void clearCache(List<MDRRuleGroupInstance> mdrRuleGroupInstances) {
297                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
298                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
299    
300                    for (MDRRuleGroupInstance mdrRuleGroupInstance : mdrRuleGroupInstances) {
301                            EntityCacheUtil.removeResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
302                                    MDRRuleGroupInstanceImpl.class,
303                                    mdrRuleGroupInstance.getPrimaryKey());
304    
305                            clearUniqueFindersCache(mdrRuleGroupInstance);
306                    }
307            }
308    
309            protected void clearUniqueFindersCache(
310                    MDRRuleGroupInstance mdrRuleGroupInstance) {
311                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
312                            new Object[] {
313                                    mdrRuleGroupInstance.getUuid(),
314                                    Long.valueOf(mdrRuleGroupInstance.getGroupId())
315                            });
316    
317                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R,
318                            new Object[] {
319                                    Long.valueOf(mdrRuleGroupInstance.getClassNameId()),
320                                    Long.valueOf(mdrRuleGroupInstance.getClassPK()),
321                                    Long.valueOf(mdrRuleGroupInstance.getRuleGroupId())
322                            });
323            }
324    
325            /**
326             * Creates a new m d r rule group instance with the primary key. Does not add the m d r rule group instance to the database.
327             *
328             * @param ruleGroupInstanceId the primary key for the new m d r rule group instance
329             * @return the new m d r rule group instance
330             */
331            public MDRRuleGroupInstance create(long ruleGroupInstanceId) {
332                    MDRRuleGroupInstance mdrRuleGroupInstance = new MDRRuleGroupInstanceImpl();
333    
334                    mdrRuleGroupInstance.setNew(true);
335                    mdrRuleGroupInstance.setPrimaryKey(ruleGroupInstanceId);
336    
337                    String uuid = PortalUUIDUtil.generate();
338    
339                    mdrRuleGroupInstance.setUuid(uuid);
340    
341                    return mdrRuleGroupInstance;
342            }
343    
344            /**
345             * Removes the m d r rule group instance with the primary key from the database. Also notifies the appropriate model listeners.
346             *
347             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
348             * @return the m d r rule group instance that was removed
349             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
350             * @throws SystemException if a system exception occurred
351             */
352            public MDRRuleGroupInstance remove(long ruleGroupInstanceId)
353                    throws NoSuchRuleGroupInstanceException, SystemException {
354                    return remove(Long.valueOf(ruleGroupInstanceId));
355            }
356    
357            /**
358             * Removes the m d r rule group instance with the primary key from the database. Also notifies the appropriate model listeners.
359             *
360             * @param primaryKey the primary key of the m d r rule group instance
361             * @return the m d r rule group instance that was removed
362             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
363             * @throws SystemException if a system exception occurred
364             */
365            @Override
366            public MDRRuleGroupInstance remove(Serializable primaryKey)
367                    throws NoSuchRuleGroupInstanceException, SystemException {
368                    Session session = null;
369    
370                    try {
371                            session = openSession();
372    
373                            MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)session.get(MDRRuleGroupInstanceImpl.class,
374                                            primaryKey);
375    
376                            if (mdrRuleGroupInstance == null) {
377                                    if (_log.isWarnEnabled()) {
378                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
379                                    }
380    
381                                    throw new NoSuchRuleGroupInstanceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
382                                            primaryKey);
383                            }
384    
385                            return remove(mdrRuleGroupInstance);
386                    }
387                    catch (NoSuchRuleGroupInstanceException nsee) {
388                            throw nsee;
389                    }
390                    catch (Exception e) {
391                            throw processException(e);
392                    }
393                    finally {
394                            closeSession(session);
395                    }
396            }
397    
398            @Override
399            protected MDRRuleGroupInstance removeImpl(
400                    MDRRuleGroupInstance mdrRuleGroupInstance) throws SystemException {
401                    mdrRuleGroupInstance = toUnwrappedModel(mdrRuleGroupInstance);
402    
403                    Session session = null;
404    
405                    try {
406                            session = openSession();
407    
408                            BatchSessionUtil.delete(session, mdrRuleGroupInstance);
409                    }
410                    catch (Exception e) {
411                            throw processException(e);
412                    }
413                    finally {
414                            closeSession(session);
415                    }
416    
417                    clearCache(mdrRuleGroupInstance);
418    
419                    return mdrRuleGroupInstance;
420            }
421    
422            @Override
423            public MDRRuleGroupInstance updateImpl(
424                    com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance mdrRuleGroupInstance,
425                    boolean merge) throws SystemException {
426                    mdrRuleGroupInstance = toUnwrappedModel(mdrRuleGroupInstance);
427    
428                    boolean isNew = mdrRuleGroupInstance.isNew();
429    
430                    MDRRuleGroupInstanceModelImpl mdrRuleGroupInstanceModelImpl = (MDRRuleGroupInstanceModelImpl)mdrRuleGroupInstance;
431    
432                    if (Validator.isNull(mdrRuleGroupInstance.getUuid())) {
433                            String uuid = PortalUUIDUtil.generate();
434    
435                            mdrRuleGroupInstance.setUuid(uuid);
436                    }
437    
438                    Session session = null;
439    
440                    try {
441                            session = openSession();
442    
443                            BatchSessionUtil.update(session, mdrRuleGroupInstance, merge);
444    
445                            mdrRuleGroupInstance.setNew(false);
446                    }
447                    catch (Exception e) {
448                            throw processException(e);
449                    }
450                    finally {
451                            closeSession(session);
452                    }
453    
454                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
455    
456                    if (isNew || !MDRRuleGroupInstanceModelImpl.COLUMN_BITMASK_ENABLED) {
457                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
458                    }
459    
460                    else {
461                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
462                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
463                                    Object[] args = new Object[] {
464                                                    mdrRuleGroupInstanceModelImpl.getOriginalUuid()
465                                            };
466    
467                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
468                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
469                                            args);
470    
471                                    args = new Object[] { mdrRuleGroupInstanceModelImpl.getUuid() };
472    
473                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
474                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
475                                            args);
476                            }
477    
478                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
479                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID.getColumnBitmask()) != 0) {
480                                    Object[] args = new Object[] {
481                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalRuleGroupId())
482                                            };
483    
484                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
485                                            args);
486                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
487                                            args);
488    
489                                    args = new Object[] {
490                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getRuleGroupId())
491                                            };
492    
493                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
494                                            args);
495                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
496                                            args);
497                            }
498    
499                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
500                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
501                                    Object[] args = new Object[] {
502                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalClassNameId()),
503                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalClassPK())
504                                            };
505    
506                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
507                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
508                                            args);
509    
510                                    args = new Object[] {
511                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getClassNameId()),
512                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getClassPK())
513                                            };
514    
515                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
516                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
517                                            args);
518                            }
519    
520                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
521                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C.getColumnBitmask()) != 0) {
522                                    Object[] args = new Object[] {
523                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalGroupId()),
524                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalClassNameId()),
525                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalClassPK())
526                                            };
527    
528                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
529                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
530                                            args);
531    
532                                    args = new Object[] {
533                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getGroupId()),
534                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getClassNameId()),
535                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getClassPK())
536                                            };
537    
538                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
539                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
540                                            args);
541                            }
542                    }
543    
544                    EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
545                            MDRRuleGroupInstanceImpl.class,
546                            mdrRuleGroupInstance.getPrimaryKey(), mdrRuleGroupInstance);
547    
548                    if (isNew) {
549                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
550                                    new Object[] {
551                                            mdrRuleGroupInstance.getUuid(),
552                                            Long.valueOf(mdrRuleGroupInstance.getGroupId())
553                                    }, mdrRuleGroupInstance);
554    
555                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
556                                    new Object[] {
557                                            Long.valueOf(mdrRuleGroupInstance.getClassNameId()),
558                                            Long.valueOf(mdrRuleGroupInstance.getClassPK()),
559                                            Long.valueOf(mdrRuleGroupInstance.getRuleGroupId())
560                                    }, mdrRuleGroupInstance);
561                    }
562                    else {
563                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
564                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
565                                    Object[] args = new Object[] {
566                                                    mdrRuleGroupInstanceModelImpl.getOriginalUuid(),
567                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalGroupId())
568                                            };
569    
570                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
571                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
572    
573                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
574                                            new Object[] {
575                                                    mdrRuleGroupInstance.getUuid(),
576                                                    Long.valueOf(mdrRuleGroupInstance.getGroupId())
577                                            }, mdrRuleGroupInstance);
578                            }
579    
580                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
581                                            FINDER_PATH_FETCH_BY_C_C_R.getColumnBitmask()) != 0) {
582                                    Object[] args = new Object[] {
583                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalClassNameId()),
584                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalClassPK()),
585                                                    Long.valueOf(mdrRuleGroupInstanceModelImpl.getOriginalRuleGroupId())
586                                            };
587    
588                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_R, args);
589                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R, args);
590    
591                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
592                                            new Object[] {
593                                                    Long.valueOf(mdrRuleGroupInstance.getClassNameId()),
594                                                    Long.valueOf(mdrRuleGroupInstance.getClassPK()),
595                                                    Long.valueOf(mdrRuleGroupInstance.getRuleGroupId())
596                                            }, mdrRuleGroupInstance);
597                            }
598                    }
599    
600                    return mdrRuleGroupInstance;
601            }
602    
603            protected MDRRuleGroupInstance toUnwrappedModel(
604                    MDRRuleGroupInstance mdrRuleGroupInstance) {
605                    if (mdrRuleGroupInstance instanceof MDRRuleGroupInstanceImpl) {
606                            return mdrRuleGroupInstance;
607                    }
608    
609                    MDRRuleGroupInstanceImpl mdrRuleGroupInstanceImpl = new MDRRuleGroupInstanceImpl();
610    
611                    mdrRuleGroupInstanceImpl.setNew(mdrRuleGroupInstance.isNew());
612                    mdrRuleGroupInstanceImpl.setPrimaryKey(mdrRuleGroupInstance.getPrimaryKey());
613    
614                    mdrRuleGroupInstanceImpl.setUuid(mdrRuleGroupInstance.getUuid());
615                    mdrRuleGroupInstanceImpl.setRuleGroupInstanceId(mdrRuleGroupInstance.getRuleGroupInstanceId());
616                    mdrRuleGroupInstanceImpl.setGroupId(mdrRuleGroupInstance.getGroupId());
617                    mdrRuleGroupInstanceImpl.setCompanyId(mdrRuleGroupInstance.getCompanyId());
618                    mdrRuleGroupInstanceImpl.setUserId(mdrRuleGroupInstance.getUserId());
619                    mdrRuleGroupInstanceImpl.setUserName(mdrRuleGroupInstance.getUserName());
620                    mdrRuleGroupInstanceImpl.setCreateDate(mdrRuleGroupInstance.getCreateDate());
621                    mdrRuleGroupInstanceImpl.setModifiedDate(mdrRuleGroupInstance.getModifiedDate());
622                    mdrRuleGroupInstanceImpl.setClassNameId(mdrRuleGroupInstance.getClassNameId());
623                    mdrRuleGroupInstanceImpl.setClassPK(mdrRuleGroupInstance.getClassPK());
624                    mdrRuleGroupInstanceImpl.setRuleGroupId(mdrRuleGroupInstance.getRuleGroupId());
625                    mdrRuleGroupInstanceImpl.setPriority(mdrRuleGroupInstance.getPriority());
626    
627                    return mdrRuleGroupInstanceImpl;
628            }
629    
630            /**
631             * Returns the m d r rule group instance with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
632             *
633             * @param primaryKey the primary key of the m d r rule group instance
634             * @return the m d r rule group instance
635             * @throws com.liferay.portal.NoSuchModelException if a m d r rule group instance with the primary key could not be found
636             * @throws SystemException if a system exception occurred
637             */
638            @Override
639            public MDRRuleGroupInstance findByPrimaryKey(Serializable primaryKey)
640                    throws NoSuchModelException, SystemException {
641                    return findByPrimaryKey(((Long)primaryKey).longValue());
642            }
643    
644            /**
645             * Returns the m d r rule group instance with the primary key or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException} if it could not be found.
646             *
647             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
648             * @return the m d r rule group instance
649             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
650             * @throws SystemException if a system exception occurred
651             */
652            public MDRRuleGroupInstance findByPrimaryKey(long ruleGroupInstanceId)
653                    throws NoSuchRuleGroupInstanceException, SystemException {
654                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByPrimaryKey(ruleGroupInstanceId);
655    
656                    if (mdrRuleGroupInstance == null) {
657                            if (_log.isWarnEnabled()) {
658                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
659                                            ruleGroupInstanceId);
660                            }
661    
662                            throw new NoSuchRuleGroupInstanceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
663                                    ruleGroupInstanceId);
664                    }
665    
666                    return mdrRuleGroupInstance;
667            }
668    
669            /**
670             * Returns the m d r rule group instance with the primary key or returns <code>null</code> if it could not be found.
671             *
672             * @param primaryKey the primary key of the m d r rule group instance
673             * @return the m d r rule group instance, or <code>null</code> if a m d r rule group instance with the primary key could not be found
674             * @throws SystemException if a system exception occurred
675             */
676            @Override
677            public MDRRuleGroupInstance fetchByPrimaryKey(Serializable primaryKey)
678                    throws SystemException {
679                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
680            }
681    
682            /**
683             * Returns the m d r rule group instance with the primary key or returns <code>null</code> if it could not be found.
684             *
685             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
686             * @return the m d r rule group instance, or <code>null</code> if a m d r rule group instance with the primary key could not be found
687             * @throws SystemException if a system exception occurred
688             */
689            public MDRRuleGroupInstance fetchByPrimaryKey(long ruleGroupInstanceId)
690                    throws SystemException {
691                    MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)EntityCacheUtil.getResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
692                                    MDRRuleGroupInstanceImpl.class, ruleGroupInstanceId);
693    
694                    if (mdrRuleGroupInstance == _nullMDRRuleGroupInstance) {
695                            return null;
696                    }
697    
698                    if (mdrRuleGroupInstance == null) {
699                            Session session = null;
700    
701                            boolean hasException = false;
702    
703                            try {
704                                    session = openSession();
705    
706                                    mdrRuleGroupInstance = (MDRRuleGroupInstance)session.get(MDRRuleGroupInstanceImpl.class,
707                                                    Long.valueOf(ruleGroupInstanceId));
708                            }
709                            catch (Exception e) {
710                                    hasException = true;
711    
712                                    throw processException(e);
713                            }
714                            finally {
715                                    if (mdrRuleGroupInstance != null) {
716                                            cacheResult(mdrRuleGroupInstance);
717                                    }
718                                    else if (!hasException) {
719                                            EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
720                                                    MDRRuleGroupInstanceImpl.class, ruleGroupInstanceId,
721                                                    _nullMDRRuleGroupInstance);
722                                    }
723    
724                                    closeSession(session);
725                            }
726                    }
727    
728                    return mdrRuleGroupInstance;
729            }
730    
731            /**
732             * Returns all the m d r rule group instances where uuid = &#63;.
733             *
734             * @param uuid the uuid
735             * @return the matching m d r rule group instances
736             * @throws SystemException if a system exception occurred
737             */
738            public List<MDRRuleGroupInstance> findByUuid(String uuid)
739                    throws SystemException {
740                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
741            }
742    
743            /**
744             * Returns a range of all the m d r rule group instances where uuid = &#63;.
745             *
746             * <p>
747             * 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.
748             * </p>
749             *
750             * @param uuid the uuid
751             * @param start the lower bound of the range of m d r rule group instances
752             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
753             * @return the range of matching m d r rule group instances
754             * @throws SystemException if a system exception occurred
755             */
756            public List<MDRRuleGroupInstance> findByUuid(String uuid, int start, int end)
757                    throws SystemException {
758                    return findByUuid(uuid, start, end, null);
759            }
760    
761            /**
762             * Returns an ordered range of all the m d r rule group instances where uuid = &#63;.
763             *
764             * <p>
765             * 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.
766             * </p>
767             *
768             * @param uuid the uuid
769             * @param start the lower bound of the range of m d r rule group instances
770             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
771             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
772             * @return the ordered range of matching m d r rule group instances
773             * @throws SystemException if a system exception occurred
774             */
775            public List<MDRRuleGroupInstance> findByUuid(String uuid, int start,
776                    int end, OrderByComparator orderByComparator) throws SystemException {
777                    FinderPath finderPath = null;
778                    Object[] finderArgs = null;
779    
780                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
781                                    (orderByComparator == null)) {
782                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
783                            finderArgs = new Object[] { uuid };
784                    }
785                    else {
786                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
787                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
788                    }
789    
790                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
791                                    finderArgs, this);
792    
793                    if (list == null) {
794                            StringBundler query = null;
795    
796                            if (orderByComparator != null) {
797                                    query = new StringBundler(3 +
798                                                    (orderByComparator.getOrderByFields().length * 3));
799                            }
800                            else {
801                                    query = new StringBundler(2);
802                            }
803    
804                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
805    
806                            if (uuid == null) {
807                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
808                            }
809                            else {
810                                    if (uuid.equals(StringPool.BLANK)) {
811                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
812                                    }
813                                    else {
814                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
815                                    }
816                            }
817    
818                            if (orderByComparator != null) {
819                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
820                                            orderByComparator);
821                            }
822    
823                            String sql = query.toString();
824    
825                            Session session = null;
826    
827                            try {
828                                    session = openSession();
829    
830                                    Query q = session.createQuery(sql);
831    
832                                    QueryPos qPos = QueryPos.getInstance(q);
833    
834                                    if (uuid != null) {
835                                            qPos.add(uuid);
836                                    }
837    
838                                    list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
839                                                    getDialect(), start, end);
840                            }
841                            catch (Exception e) {
842                                    throw processException(e);
843                            }
844                            finally {
845                                    if (list == null) {
846                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
847                                    }
848                                    else {
849                                            cacheResult(list);
850    
851                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
852                                    }
853    
854                                    closeSession(session);
855                            }
856                    }
857    
858                    return list;
859            }
860    
861            /**
862             * Returns the first m d r rule group instance in the ordered set where uuid = &#63;.
863             *
864             * <p>
865             * 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.
866             * </p>
867             *
868             * @param uuid the uuid
869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
870             * @return the first matching m d r rule group instance
871             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
872             * @throws SystemException if a system exception occurred
873             */
874            public MDRRuleGroupInstance findByUuid_First(String uuid,
875                    OrderByComparator orderByComparator)
876                    throws NoSuchRuleGroupInstanceException, SystemException {
877                    List<MDRRuleGroupInstance> list = findByUuid(uuid, 0, 1,
878                                    orderByComparator);
879    
880                    if (list.isEmpty()) {
881                            StringBundler msg = new StringBundler(4);
882    
883                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
884    
885                            msg.append("uuid=");
886                            msg.append(uuid);
887    
888                            msg.append(StringPool.CLOSE_CURLY_BRACE);
889    
890                            throw new NoSuchRuleGroupInstanceException(msg.toString());
891                    }
892                    else {
893                            return list.get(0);
894                    }
895            }
896    
897            /**
898             * Returns the last m d r rule group instance in the ordered set where uuid = &#63;.
899             *
900             * <p>
901             * 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.
902             * </p>
903             *
904             * @param uuid the uuid
905             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
906             * @return the last matching m d r rule group instance
907             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
908             * @throws SystemException if a system exception occurred
909             */
910            public MDRRuleGroupInstance findByUuid_Last(String uuid,
911                    OrderByComparator orderByComparator)
912                    throws NoSuchRuleGroupInstanceException, SystemException {
913                    int count = countByUuid(uuid);
914    
915                    List<MDRRuleGroupInstance> list = findByUuid(uuid, count - 1, count,
916                                    orderByComparator);
917    
918                    if (list.isEmpty()) {
919                            StringBundler msg = new StringBundler(4);
920    
921                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
922    
923                            msg.append("uuid=");
924                            msg.append(uuid);
925    
926                            msg.append(StringPool.CLOSE_CURLY_BRACE);
927    
928                            throw new NoSuchRuleGroupInstanceException(msg.toString());
929                    }
930                    else {
931                            return list.get(0);
932                    }
933            }
934    
935            /**
936             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where uuid = &#63;.
937             *
938             * <p>
939             * 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.
940             * </p>
941             *
942             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
943             * @param uuid the uuid
944             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
945             * @return the previous, current, and next m d r rule group instance
946             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
947             * @throws SystemException if a system exception occurred
948             */
949            public MDRRuleGroupInstance[] findByUuid_PrevAndNext(
950                    long ruleGroupInstanceId, String uuid,
951                    OrderByComparator orderByComparator)
952                    throws NoSuchRuleGroupInstanceException, SystemException {
953                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
954    
955                    Session session = null;
956    
957                    try {
958                            session = openSession();
959    
960                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
961    
962                            array[0] = getByUuid_PrevAndNext(session, mdrRuleGroupInstance,
963                                            uuid, orderByComparator, true);
964    
965                            array[1] = mdrRuleGroupInstance;
966    
967                            array[2] = getByUuid_PrevAndNext(session, mdrRuleGroupInstance,
968                                            uuid, orderByComparator, false);
969    
970                            return array;
971                    }
972                    catch (Exception e) {
973                            throw processException(e);
974                    }
975                    finally {
976                            closeSession(session);
977                    }
978            }
979    
980            protected MDRRuleGroupInstance getByUuid_PrevAndNext(Session session,
981                    MDRRuleGroupInstance mdrRuleGroupInstance, String uuid,
982                    OrderByComparator orderByComparator, boolean previous) {
983                    StringBundler query = null;
984    
985                    if (orderByComparator != null) {
986                            query = new StringBundler(6 +
987                                            (orderByComparator.getOrderByFields().length * 6));
988                    }
989                    else {
990                            query = new StringBundler(3);
991                    }
992    
993                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
994    
995                    if (uuid == null) {
996                            query.append(_FINDER_COLUMN_UUID_UUID_1);
997                    }
998                    else {
999                            if (uuid.equals(StringPool.BLANK)) {
1000                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1001                            }
1002                            else {
1003                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1004                            }
1005                    }
1006    
1007                    if (orderByComparator != null) {
1008                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1009    
1010                            if (orderByConditionFields.length > 0) {
1011                                    query.append(WHERE_AND);
1012                            }
1013    
1014                            for (int i = 0; i < orderByConditionFields.length; i++) {
1015                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1016                                    query.append(orderByConditionFields[i]);
1017    
1018                                    if ((i + 1) < orderByConditionFields.length) {
1019                                            if (orderByComparator.isAscending() ^ previous) {
1020                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1021                                            }
1022                                            else {
1023                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1024                                            }
1025                                    }
1026                                    else {
1027                                            if (orderByComparator.isAscending() ^ previous) {
1028                                                    query.append(WHERE_GREATER_THAN);
1029                                            }
1030                                            else {
1031                                                    query.append(WHERE_LESSER_THAN);
1032                                            }
1033                                    }
1034                            }
1035    
1036                            query.append(ORDER_BY_CLAUSE);
1037    
1038                            String[] orderByFields = orderByComparator.getOrderByFields();
1039    
1040                            for (int i = 0; i < orderByFields.length; i++) {
1041                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1042                                    query.append(orderByFields[i]);
1043    
1044                                    if ((i + 1) < orderByFields.length) {
1045                                            if (orderByComparator.isAscending() ^ previous) {
1046                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1047                                            }
1048                                            else {
1049                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1050                                            }
1051                                    }
1052                                    else {
1053                                            if (orderByComparator.isAscending() ^ previous) {
1054                                                    query.append(ORDER_BY_ASC);
1055                                            }
1056                                            else {
1057                                                    query.append(ORDER_BY_DESC);
1058                                            }
1059                                    }
1060                            }
1061                    }
1062    
1063                    String sql = query.toString();
1064    
1065                    Query q = session.createQuery(sql);
1066    
1067                    q.setFirstResult(0);
1068                    q.setMaxResults(2);
1069    
1070                    QueryPos qPos = QueryPos.getInstance(q);
1071    
1072                    if (uuid != null) {
1073                            qPos.add(uuid);
1074                    }
1075    
1076                    if (orderByComparator != null) {
1077                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
1078    
1079                            for (Object value : values) {
1080                                    qPos.add(value);
1081                            }
1082                    }
1083    
1084                    List<MDRRuleGroupInstance> list = q.list();
1085    
1086                    if (list.size() == 2) {
1087                            return list.get(1);
1088                    }
1089                    else {
1090                            return null;
1091                    }
1092            }
1093    
1094            /**
1095             * Returns the m d r rule group instance where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException} if it could not be found.
1096             *
1097             * @param uuid the uuid
1098             * @param groupId the group ID
1099             * @return the matching m d r rule group instance
1100             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1101             * @throws SystemException if a system exception occurred
1102             */
1103            public MDRRuleGroupInstance findByUUID_G(String uuid, long groupId)
1104                    throws NoSuchRuleGroupInstanceException, SystemException {
1105                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUUID_G(uuid, groupId);
1106    
1107                    if (mdrRuleGroupInstance == null) {
1108                            StringBundler msg = new StringBundler(6);
1109    
1110                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1111    
1112                            msg.append("uuid=");
1113                            msg.append(uuid);
1114    
1115                            msg.append(", groupId=");
1116                            msg.append(groupId);
1117    
1118                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1119    
1120                            if (_log.isWarnEnabled()) {
1121                                    _log.warn(msg.toString());
1122                            }
1123    
1124                            throw new NoSuchRuleGroupInstanceException(msg.toString());
1125                    }
1126    
1127                    return mdrRuleGroupInstance;
1128            }
1129    
1130            /**
1131             * Returns the m d r rule group instance where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1132             *
1133             * @param uuid the uuid
1134             * @param groupId the group ID
1135             * @return the matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1136             * @throws SystemException if a system exception occurred
1137             */
1138            public MDRRuleGroupInstance fetchByUUID_G(String uuid, long groupId)
1139                    throws SystemException {
1140                    return fetchByUUID_G(uuid, groupId, true);
1141            }
1142    
1143            /**
1144             * Returns the m d r rule group instance where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1145             *
1146             * @param uuid the uuid
1147             * @param groupId the group ID
1148             * @param retrieveFromCache whether to use the finder cache
1149             * @return the matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1150             * @throws SystemException if a system exception occurred
1151             */
1152            public MDRRuleGroupInstance fetchByUUID_G(String uuid, long groupId,
1153                    boolean retrieveFromCache) throws SystemException {
1154                    Object[] finderArgs = new Object[] { uuid, groupId };
1155    
1156                    Object result = null;
1157    
1158                    if (retrieveFromCache) {
1159                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1160                                            finderArgs, this);
1161                    }
1162    
1163                    if (result == null) {
1164                            StringBundler query = new StringBundler(3);
1165    
1166                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1167    
1168                            if (uuid == null) {
1169                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1170                            }
1171                            else {
1172                                    if (uuid.equals(StringPool.BLANK)) {
1173                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1174                                    }
1175                                    else {
1176                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1177                                    }
1178                            }
1179    
1180                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1181    
1182                            String sql = query.toString();
1183    
1184                            Session session = null;
1185    
1186                            try {
1187                                    session = openSession();
1188    
1189                                    Query q = session.createQuery(sql);
1190    
1191                                    QueryPos qPos = QueryPos.getInstance(q);
1192    
1193                                    if (uuid != null) {
1194                                            qPos.add(uuid);
1195                                    }
1196    
1197                                    qPos.add(groupId);
1198    
1199                                    List<MDRRuleGroupInstance> list = q.list();
1200    
1201                                    result = list;
1202    
1203                                    MDRRuleGroupInstance mdrRuleGroupInstance = null;
1204    
1205                                    if (list.isEmpty()) {
1206                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1207                                                    finderArgs, list);
1208                                    }
1209                                    else {
1210                                            mdrRuleGroupInstance = list.get(0);
1211    
1212                                            cacheResult(mdrRuleGroupInstance);
1213    
1214                                            if ((mdrRuleGroupInstance.getUuid() == null) ||
1215                                                            !mdrRuleGroupInstance.getUuid().equals(uuid) ||
1216                                                            (mdrRuleGroupInstance.getGroupId() != groupId)) {
1217                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1218                                                            finderArgs, mdrRuleGroupInstance);
1219                                            }
1220                                    }
1221    
1222                                    return mdrRuleGroupInstance;
1223                            }
1224                            catch (Exception e) {
1225                                    throw processException(e);
1226                            }
1227                            finally {
1228                                    if (result == null) {
1229                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1230                                                    finderArgs);
1231                                    }
1232    
1233                                    closeSession(session);
1234                            }
1235                    }
1236                    else {
1237                            if (result instanceof List<?>) {
1238                                    return null;
1239                            }
1240                            else {
1241                                    return (MDRRuleGroupInstance)result;
1242                            }
1243                    }
1244            }
1245    
1246            /**
1247             * Returns all the m d r rule group instances where ruleGroupId = &#63;.
1248             *
1249             * @param ruleGroupId the rule group ID
1250             * @return the matching m d r rule group instances
1251             * @throws SystemException if a system exception occurred
1252             */
1253            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId)
1254                    throws SystemException {
1255                    return findByRuleGroupId(ruleGroupId, QueryUtil.ALL_POS,
1256                            QueryUtil.ALL_POS, null);
1257            }
1258    
1259            /**
1260             * Returns a range of all the m d r rule group instances where ruleGroupId = &#63;.
1261             *
1262             * <p>
1263             * 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.
1264             * </p>
1265             *
1266             * @param ruleGroupId the rule group ID
1267             * @param start the lower bound of the range of m d r rule group instances
1268             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1269             * @return the range of matching m d r rule group instances
1270             * @throws SystemException if a system exception occurred
1271             */
1272            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId,
1273                    int start, int end) throws SystemException {
1274                    return findByRuleGroupId(ruleGroupId, start, end, null);
1275            }
1276    
1277            /**
1278             * Returns an ordered range of all the m d r rule group instances where ruleGroupId = &#63;.
1279             *
1280             * <p>
1281             * 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.
1282             * </p>
1283             *
1284             * @param ruleGroupId the rule group ID
1285             * @param start the lower bound of the range of m d r rule group instances
1286             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1287             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1288             * @return the ordered range of matching m d r rule group instances
1289             * @throws SystemException if a system exception occurred
1290             */
1291            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId,
1292                    int start, int end, OrderByComparator orderByComparator)
1293                    throws SystemException {
1294                    FinderPath finderPath = null;
1295                    Object[] finderArgs = null;
1296    
1297                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1298                                    (orderByComparator == null)) {
1299                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID;
1300                            finderArgs = new Object[] { ruleGroupId };
1301                    }
1302                    else {
1303                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID;
1304                            finderArgs = new Object[] { ruleGroupId, start, end, orderByComparator };
1305                    }
1306    
1307                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
1308                                    finderArgs, this);
1309    
1310                    if (list == null) {
1311                            StringBundler query = null;
1312    
1313                            if (orderByComparator != null) {
1314                                    query = new StringBundler(3 +
1315                                                    (orderByComparator.getOrderByFields().length * 3));
1316                            }
1317                            else {
1318                                    query = new StringBundler(2);
1319                            }
1320    
1321                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1322    
1323                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
1324    
1325                            if (orderByComparator != null) {
1326                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1327                                            orderByComparator);
1328                            }
1329    
1330                            String sql = query.toString();
1331    
1332                            Session session = null;
1333    
1334                            try {
1335                                    session = openSession();
1336    
1337                                    Query q = session.createQuery(sql);
1338    
1339                                    QueryPos qPos = QueryPos.getInstance(q);
1340    
1341                                    qPos.add(ruleGroupId);
1342    
1343                                    list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1344                                                    getDialect(), start, end);
1345                            }
1346                            catch (Exception e) {
1347                                    throw processException(e);
1348                            }
1349                            finally {
1350                                    if (list == null) {
1351                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1352                                    }
1353                                    else {
1354                                            cacheResult(list);
1355    
1356                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1357                                    }
1358    
1359                                    closeSession(session);
1360                            }
1361                    }
1362    
1363                    return list;
1364            }
1365    
1366            /**
1367             * Returns the first m d r rule group instance in the ordered set where ruleGroupId = &#63;.
1368             *
1369             * <p>
1370             * 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.
1371             * </p>
1372             *
1373             * @param ruleGroupId the rule group ID
1374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1375             * @return the first matching m d r rule group instance
1376             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1377             * @throws SystemException if a system exception occurred
1378             */
1379            public MDRRuleGroupInstance findByRuleGroupId_First(long ruleGroupId,
1380                    OrderByComparator orderByComparator)
1381                    throws NoSuchRuleGroupInstanceException, SystemException {
1382                    List<MDRRuleGroupInstance> list = findByRuleGroupId(ruleGroupId, 0, 1,
1383                                    orderByComparator);
1384    
1385                    if (list.isEmpty()) {
1386                            StringBundler msg = new StringBundler(4);
1387    
1388                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1389    
1390                            msg.append("ruleGroupId=");
1391                            msg.append(ruleGroupId);
1392    
1393                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1394    
1395                            throw new NoSuchRuleGroupInstanceException(msg.toString());
1396                    }
1397                    else {
1398                            return list.get(0);
1399                    }
1400            }
1401    
1402            /**
1403             * Returns the last m d r rule group instance in the ordered set where ruleGroupId = &#63;.
1404             *
1405             * <p>
1406             * 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.
1407             * </p>
1408             *
1409             * @param ruleGroupId the rule group ID
1410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1411             * @return the last matching m d r rule group instance
1412             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1413             * @throws SystemException if a system exception occurred
1414             */
1415            public MDRRuleGroupInstance findByRuleGroupId_Last(long ruleGroupId,
1416                    OrderByComparator orderByComparator)
1417                    throws NoSuchRuleGroupInstanceException, SystemException {
1418                    int count = countByRuleGroupId(ruleGroupId);
1419    
1420                    List<MDRRuleGroupInstance> list = findByRuleGroupId(ruleGroupId,
1421                                    count - 1, count, orderByComparator);
1422    
1423                    if (list.isEmpty()) {
1424                            StringBundler msg = new StringBundler(4);
1425    
1426                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1427    
1428                            msg.append("ruleGroupId=");
1429                            msg.append(ruleGroupId);
1430    
1431                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1432    
1433                            throw new NoSuchRuleGroupInstanceException(msg.toString());
1434                    }
1435                    else {
1436                            return list.get(0);
1437                    }
1438            }
1439    
1440            /**
1441             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where ruleGroupId = &#63;.
1442             *
1443             * <p>
1444             * 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.
1445             * </p>
1446             *
1447             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
1448             * @param ruleGroupId the rule group ID
1449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1450             * @return the previous, current, and next m d r rule group instance
1451             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
1452             * @throws SystemException if a system exception occurred
1453             */
1454            public MDRRuleGroupInstance[] findByRuleGroupId_PrevAndNext(
1455                    long ruleGroupInstanceId, long ruleGroupId,
1456                    OrderByComparator orderByComparator)
1457                    throws NoSuchRuleGroupInstanceException, SystemException {
1458                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
1459    
1460                    Session session = null;
1461    
1462                    try {
1463                            session = openSession();
1464    
1465                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
1466    
1467                            array[0] = getByRuleGroupId_PrevAndNext(session,
1468                                            mdrRuleGroupInstance, ruleGroupId, orderByComparator, true);
1469    
1470                            array[1] = mdrRuleGroupInstance;
1471    
1472                            array[2] = getByRuleGroupId_PrevAndNext(session,
1473                                            mdrRuleGroupInstance, ruleGroupId, orderByComparator, false);
1474    
1475                            return array;
1476                    }
1477                    catch (Exception e) {
1478                            throw processException(e);
1479                    }
1480                    finally {
1481                            closeSession(session);
1482                    }
1483            }
1484    
1485            protected MDRRuleGroupInstance getByRuleGroupId_PrevAndNext(
1486                    Session session, MDRRuleGroupInstance mdrRuleGroupInstance,
1487                    long ruleGroupId, OrderByComparator orderByComparator, boolean previous) {
1488                    StringBundler query = null;
1489    
1490                    if (orderByComparator != null) {
1491                            query = new StringBundler(6 +
1492                                            (orderByComparator.getOrderByFields().length * 6));
1493                    }
1494                    else {
1495                            query = new StringBundler(3);
1496                    }
1497    
1498                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1499    
1500                    query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
1501    
1502                    if (orderByComparator != null) {
1503                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1504    
1505                            if (orderByConditionFields.length > 0) {
1506                                    query.append(WHERE_AND);
1507                            }
1508    
1509                            for (int i = 0; i < orderByConditionFields.length; i++) {
1510                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1511                                    query.append(orderByConditionFields[i]);
1512    
1513                                    if ((i + 1) < orderByConditionFields.length) {
1514                                            if (orderByComparator.isAscending() ^ previous) {
1515                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1516                                            }
1517                                            else {
1518                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1519                                            }
1520                                    }
1521                                    else {
1522                                            if (orderByComparator.isAscending() ^ previous) {
1523                                                    query.append(WHERE_GREATER_THAN);
1524                                            }
1525                                            else {
1526                                                    query.append(WHERE_LESSER_THAN);
1527                                            }
1528                                    }
1529                            }
1530    
1531                            query.append(ORDER_BY_CLAUSE);
1532    
1533                            String[] orderByFields = orderByComparator.getOrderByFields();
1534    
1535                            for (int i = 0; i < orderByFields.length; i++) {
1536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1537                                    query.append(orderByFields[i]);
1538    
1539                                    if ((i + 1) < orderByFields.length) {
1540                                            if (orderByComparator.isAscending() ^ previous) {
1541                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1542                                            }
1543                                            else {
1544                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1545                                            }
1546                                    }
1547                                    else {
1548                                            if (orderByComparator.isAscending() ^ previous) {
1549                                                    query.append(ORDER_BY_ASC);
1550                                            }
1551                                            else {
1552                                                    query.append(ORDER_BY_DESC);
1553                                            }
1554                                    }
1555                            }
1556                    }
1557    
1558                    String sql = query.toString();
1559    
1560                    Query q = session.createQuery(sql);
1561    
1562                    q.setFirstResult(0);
1563                    q.setMaxResults(2);
1564    
1565                    QueryPos qPos = QueryPos.getInstance(q);
1566    
1567                    qPos.add(ruleGroupId);
1568    
1569                    if (orderByComparator != null) {
1570                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
1571    
1572                            for (Object value : values) {
1573                                    qPos.add(value);
1574                            }
1575                    }
1576    
1577                    List<MDRRuleGroupInstance> list = q.list();
1578    
1579                    if (list.size() == 2) {
1580                            return list.get(1);
1581                    }
1582                    else {
1583                            return null;
1584                    }
1585            }
1586    
1587            /**
1588             * Returns all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
1589             *
1590             * @param classNameId the class name ID
1591             * @param classPK the class p k
1592             * @return the matching m d r rule group instances
1593             * @throws SystemException if a system exception occurred
1594             */
1595            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK)
1596                    throws SystemException {
1597                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
1598                            QueryUtil.ALL_POS, null);
1599            }
1600    
1601            /**
1602             * Returns a range of all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
1603             *
1604             * <p>
1605             * 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.
1606             * </p>
1607             *
1608             * @param classNameId the class name ID
1609             * @param classPK the class p k
1610             * @param start the lower bound of the range of m d r rule group instances
1611             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1612             * @return the range of matching m d r rule group instances
1613             * @throws SystemException if a system exception occurred
1614             */
1615            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK,
1616                    int start, int end) throws SystemException {
1617                    return findByC_C(classNameId, classPK, start, end, null);
1618            }
1619    
1620            /**
1621             * Returns an ordered range of all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
1622             *
1623             * <p>
1624             * 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.
1625             * </p>
1626             *
1627             * @param classNameId the class name ID
1628             * @param classPK the class p k
1629             * @param start the lower bound of the range of m d r rule group instances
1630             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1631             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1632             * @return the ordered range of matching m d r rule group instances
1633             * @throws SystemException if a system exception occurred
1634             */
1635            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK,
1636                    int start, int end, OrderByComparator orderByComparator)
1637                    throws SystemException {
1638                    FinderPath finderPath = null;
1639                    Object[] finderArgs = null;
1640    
1641                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1642                                    (orderByComparator == null)) {
1643                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
1644                            finderArgs = new Object[] { classNameId, classPK };
1645                    }
1646                    else {
1647                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
1648                            finderArgs = new Object[] {
1649                                            classNameId, classPK,
1650                                            
1651                                            start, end, orderByComparator
1652                                    };
1653                    }
1654    
1655                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
1656                                    finderArgs, this);
1657    
1658                    if (list == null) {
1659                            StringBundler query = null;
1660    
1661                            if (orderByComparator != null) {
1662                                    query = new StringBundler(4 +
1663                                                    (orderByComparator.getOrderByFields().length * 3));
1664                            }
1665                            else {
1666                                    query = new StringBundler(3);
1667                            }
1668    
1669                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1670    
1671                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1672    
1673                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1674    
1675                            if (orderByComparator != null) {
1676                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1677                                            orderByComparator);
1678                            }
1679    
1680                            String sql = query.toString();
1681    
1682                            Session session = null;
1683    
1684                            try {
1685                                    session = openSession();
1686    
1687                                    Query q = session.createQuery(sql);
1688    
1689                                    QueryPos qPos = QueryPos.getInstance(q);
1690    
1691                                    qPos.add(classNameId);
1692    
1693                                    qPos.add(classPK);
1694    
1695                                    list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1696                                                    getDialect(), start, end);
1697                            }
1698                            catch (Exception e) {
1699                                    throw processException(e);
1700                            }
1701                            finally {
1702                                    if (list == null) {
1703                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1704                                    }
1705                                    else {
1706                                            cacheResult(list);
1707    
1708                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1709                                    }
1710    
1711                                    closeSession(session);
1712                            }
1713                    }
1714    
1715                    return list;
1716            }
1717    
1718            /**
1719             * Returns the first m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
1720             *
1721             * <p>
1722             * 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.
1723             * </p>
1724             *
1725             * @param classNameId the class name ID
1726             * @param classPK the class p k
1727             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1728             * @return the first matching m d r rule group instance
1729             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1730             * @throws SystemException if a system exception occurred
1731             */
1732            public MDRRuleGroupInstance findByC_C_First(long classNameId, long classPK,
1733                    OrderByComparator orderByComparator)
1734                    throws NoSuchRuleGroupInstanceException, SystemException {
1735                    List<MDRRuleGroupInstance> list = findByC_C(classNameId, classPK, 0, 1,
1736                                    orderByComparator);
1737    
1738                    if (list.isEmpty()) {
1739                            StringBundler msg = new StringBundler(6);
1740    
1741                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1742    
1743                            msg.append("classNameId=");
1744                            msg.append(classNameId);
1745    
1746                            msg.append(", classPK=");
1747                            msg.append(classPK);
1748    
1749                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1750    
1751                            throw new NoSuchRuleGroupInstanceException(msg.toString());
1752                    }
1753                    else {
1754                            return list.get(0);
1755                    }
1756            }
1757    
1758            /**
1759             * Returns the last m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
1760             *
1761             * <p>
1762             * 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.
1763             * </p>
1764             *
1765             * @param classNameId the class name ID
1766             * @param classPK the class p k
1767             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1768             * @return the last matching m d r rule group instance
1769             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1770             * @throws SystemException if a system exception occurred
1771             */
1772            public MDRRuleGroupInstance findByC_C_Last(long classNameId, long classPK,
1773                    OrderByComparator orderByComparator)
1774                    throws NoSuchRuleGroupInstanceException, SystemException {
1775                    int count = countByC_C(classNameId, classPK);
1776    
1777                    List<MDRRuleGroupInstance> list = findByC_C(classNameId, classPK,
1778                                    count - 1, count, orderByComparator);
1779    
1780                    if (list.isEmpty()) {
1781                            StringBundler msg = new StringBundler(6);
1782    
1783                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1784    
1785                            msg.append("classNameId=");
1786                            msg.append(classNameId);
1787    
1788                            msg.append(", classPK=");
1789                            msg.append(classPK);
1790    
1791                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1792    
1793                            throw new NoSuchRuleGroupInstanceException(msg.toString());
1794                    }
1795                    else {
1796                            return list.get(0);
1797                    }
1798            }
1799    
1800            /**
1801             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
1802             *
1803             * <p>
1804             * 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.
1805             * </p>
1806             *
1807             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
1808             * @param classNameId the class name ID
1809             * @param classPK the class p k
1810             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1811             * @return the previous, current, and next m d r rule group instance
1812             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
1813             * @throws SystemException if a system exception occurred
1814             */
1815            public MDRRuleGroupInstance[] findByC_C_PrevAndNext(
1816                    long ruleGroupInstanceId, long classNameId, long classPK,
1817                    OrderByComparator orderByComparator)
1818                    throws NoSuchRuleGroupInstanceException, SystemException {
1819                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
1820    
1821                    Session session = null;
1822    
1823                    try {
1824                            session = openSession();
1825    
1826                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
1827    
1828                            array[0] = getByC_C_PrevAndNext(session, mdrRuleGroupInstance,
1829                                            classNameId, classPK, orderByComparator, true);
1830    
1831                            array[1] = mdrRuleGroupInstance;
1832    
1833                            array[2] = getByC_C_PrevAndNext(session, mdrRuleGroupInstance,
1834                                            classNameId, classPK, orderByComparator, false);
1835    
1836                            return array;
1837                    }
1838                    catch (Exception e) {
1839                            throw processException(e);
1840                    }
1841                    finally {
1842                            closeSession(session);
1843                    }
1844            }
1845    
1846            protected MDRRuleGroupInstance getByC_C_PrevAndNext(Session session,
1847                    MDRRuleGroupInstance mdrRuleGroupInstance, long classNameId,
1848                    long classPK, OrderByComparator orderByComparator, boolean previous) {
1849                    StringBundler query = null;
1850    
1851                    if (orderByComparator != null) {
1852                            query = new StringBundler(6 +
1853                                            (orderByComparator.getOrderByFields().length * 6));
1854                    }
1855                    else {
1856                            query = new StringBundler(3);
1857                    }
1858    
1859                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1860    
1861                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1862    
1863                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1864    
1865                    if (orderByComparator != null) {
1866                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1867    
1868                            if (orderByConditionFields.length > 0) {
1869                                    query.append(WHERE_AND);
1870                            }
1871    
1872                            for (int i = 0; i < orderByConditionFields.length; i++) {
1873                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1874                                    query.append(orderByConditionFields[i]);
1875    
1876                                    if ((i + 1) < orderByConditionFields.length) {
1877                                            if (orderByComparator.isAscending() ^ previous) {
1878                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1879                                            }
1880                                            else {
1881                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1882                                            }
1883                                    }
1884                                    else {
1885                                            if (orderByComparator.isAscending() ^ previous) {
1886                                                    query.append(WHERE_GREATER_THAN);
1887                                            }
1888                                            else {
1889                                                    query.append(WHERE_LESSER_THAN);
1890                                            }
1891                                    }
1892                            }
1893    
1894                            query.append(ORDER_BY_CLAUSE);
1895    
1896                            String[] orderByFields = orderByComparator.getOrderByFields();
1897    
1898                            for (int i = 0; i < orderByFields.length; i++) {
1899                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1900                                    query.append(orderByFields[i]);
1901    
1902                                    if ((i + 1) < orderByFields.length) {
1903                                            if (orderByComparator.isAscending() ^ previous) {
1904                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1905                                            }
1906                                            else {
1907                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1908                                            }
1909                                    }
1910                                    else {
1911                                            if (orderByComparator.isAscending() ^ previous) {
1912                                                    query.append(ORDER_BY_ASC);
1913                                            }
1914                                            else {
1915                                                    query.append(ORDER_BY_DESC);
1916                                            }
1917                                    }
1918                            }
1919                    }
1920    
1921                    String sql = query.toString();
1922    
1923                    Query q = session.createQuery(sql);
1924    
1925                    q.setFirstResult(0);
1926                    q.setMaxResults(2);
1927    
1928                    QueryPos qPos = QueryPos.getInstance(q);
1929    
1930                    qPos.add(classNameId);
1931    
1932                    qPos.add(classPK);
1933    
1934                    if (orderByComparator != null) {
1935                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
1936    
1937                            for (Object value : values) {
1938                                    qPos.add(value);
1939                            }
1940                    }
1941    
1942                    List<MDRRuleGroupInstance> list = q.list();
1943    
1944                    if (list.size() == 2) {
1945                            return list.get(1);
1946                    }
1947                    else {
1948                            return null;
1949                    }
1950            }
1951    
1952            /**
1953             * Returns all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1954             *
1955             * @param groupId the group ID
1956             * @param classNameId the class name ID
1957             * @param classPK the class p k
1958             * @return the matching m d r rule group instances
1959             * @throws SystemException if a system exception occurred
1960             */
1961            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
1962                    long classNameId, long classPK) throws SystemException {
1963                    return findByG_C_C(groupId, classNameId, classPK, QueryUtil.ALL_POS,
1964                            QueryUtil.ALL_POS, null);
1965            }
1966    
1967            /**
1968             * Returns a range of all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1969             *
1970             * <p>
1971             * 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.
1972             * </p>
1973             *
1974             * @param groupId the group ID
1975             * @param classNameId the class name ID
1976             * @param classPK the class p k
1977             * @param start the lower bound of the range of m d r rule group instances
1978             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1979             * @return the range of matching m d r rule group instances
1980             * @throws SystemException if a system exception occurred
1981             */
1982            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
1983                    long classNameId, long classPK, int start, int end)
1984                    throws SystemException {
1985                    return findByG_C_C(groupId, classNameId, classPK, start, end, null);
1986            }
1987    
1988            /**
1989             * Returns an ordered range of all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
1990             *
1991             * <p>
1992             * 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.
1993             * </p>
1994             *
1995             * @param groupId the group ID
1996             * @param classNameId the class name ID
1997             * @param classPK the class p k
1998             * @param start the lower bound of the range of m d r rule group instances
1999             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2000             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2001             * @return the ordered range of matching m d r rule group instances
2002             * @throws SystemException if a system exception occurred
2003             */
2004            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
2005                    long classNameId, long classPK, int start, int end,
2006                    OrderByComparator orderByComparator) throws SystemException {
2007                    FinderPath finderPath = null;
2008                    Object[] finderArgs = null;
2009    
2010                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2011                                    (orderByComparator == null)) {
2012                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C;
2013                            finderArgs = new Object[] { groupId, classNameId, classPK };
2014                    }
2015                    else {
2016                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C;
2017                            finderArgs = new Object[] {
2018                                            groupId, classNameId, classPK,
2019                                            
2020                                            start, end, orderByComparator
2021                                    };
2022                    }
2023    
2024                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
2025                                    finderArgs, this);
2026    
2027                    if (list == null) {
2028                            StringBundler query = null;
2029    
2030                            if (orderByComparator != null) {
2031                                    query = new StringBundler(5 +
2032                                                    (orderByComparator.getOrderByFields().length * 3));
2033                            }
2034                            else {
2035                                    query = new StringBundler(4);
2036                            }
2037    
2038                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2039    
2040                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
2041    
2042                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
2043    
2044                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
2045    
2046                            if (orderByComparator != null) {
2047                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2048                                            orderByComparator);
2049                            }
2050    
2051                            String sql = query.toString();
2052    
2053                            Session session = null;
2054    
2055                            try {
2056                                    session = openSession();
2057    
2058                                    Query q = session.createQuery(sql);
2059    
2060                                    QueryPos qPos = QueryPos.getInstance(q);
2061    
2062                                    qPos.add(groupId);
2063    
2064                                    qPos.add(classNameId);
2065    
2066                                    qPos.add(classPK);
2067    
2068                                    list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2069                                                    getDialect(), start, end);
2070                            }
2071                            catch (Exception e) {
2072                                    throw processException(e);
2073                            }
2074                            finally {
2075                                    if (list == null) {
2076                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2077                                    }
2078                                    else {
2079                                            cacheResult(list);
2080    
2081                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2082                                    }
2083    
2084                                    closeSession(session);
2085                            }
2086                    }
2087    
2088                    return list;
2089            }
2090    
2091            /**
2092             * Returns the first m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
2093             *
2094             * <p>
2095             * 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.
2096             * </p>
2097             *
2098             * @param groupId the group ID
2099             * @param classNameId the class name ID
2100             * @param classPK the class p k
2101             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2102             * @return the first matching m d r rule group instance
2103             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2104             * @throws SystemException if a system exception occurred
2105             */
2106            public MDRRuleGroupInstance findByG_C_C_First(long groupId,
2107                    long classNameId, long classPK, OrderByComparator orderByComparator)
2108                    throws NoSuchRuleGroupInstanceException, SystemException {
2109                    List<MDRRuleGroupInstance> list = findByG_C_C(groupId, classNameId,
2110                                    classPK, 0, 1, orderByComparator);
2111    
2112                    if (list.isEmpty()) {
2113                            StringBundler msg = new StringBundler(8);
2114    
2115                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2116    
2117                            msg.append("groupId=");
2118                            msg.append(groupId);
2119    
2120                            msg.append(", classNameId=");
2121                            msg.append(classNameId);
2122    
2123                            msg.append(", classPK=");
2124                            msg.append(classPK);
2125    
2126                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2127    
2128                            throw new NoSuchRuleGroupInstanceException(msg.toString());
2129                    }
2130                    else {
2131                            return list.get(0);
2132                    }
2133            }
2134    
2135            /**
2136             * Returns the last m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
2137             *
2138             * <p>
2139             * 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.
2140             * </p>
2141             *
2142             * @param groupId the group ID
2143             * @param classNameId the class name ID
2144             * @param classPK the class p k
2145             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2146             * @return the last matching m d r rule group instance
2147             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2148             * @throws SystemException if a system exception occurred
2149             */
2150            public MDRRuleGroupInstance findByG_C_C_Last(long groupId,
2151                    long classNameId, long classPK, OrderByComparator orderByComparator)
2152                    throws NoSuchRuleGroupInstanceException, SystemException {
2153                    int count = countByG_C_C(groupId, classNameId, classPK);
2154    
2155                    List<MDRRuleGroupInstance> list = findByG_C_C(groupId, classNameId,
2156                                    classPK, count - 1, count, orderByComparator);
2157    
2158                    if (list.isEmpty()) {
2159                            StringBundler msg = new StringBundler(8);
2160    
2161                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2162    
2163                            msg.append("groupId=");
2164                            msg.append(groupId);
2165    
2166                            msg.append(", classNameId=");
2167                            msg.append(classNameId);
2168    
2169                            msg.append(", classPK=");
2170                            msg.append(classPK);
2171    
2172                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2173    
2174                            throw new NoSuchRuleGroupInstanceException(msg.toString());
2175                    }
2176                    else {
2177                            return list.get(0);
2178                    }
2179            }
2180    
2181            /**
2182             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
2183             *
2184             * <p>
2185             * 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.
2186             * </p>
2187             *
2188             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
2189             * @param groupId the group ID
2190             * @param classNameId the class name ID
2191             * @param classPK the class p k
2192             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2193             * @return the previous, current, and next m d r rule group instance
2194             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
2195             * @throws SystemException if a system exception occurred
2196             */
2197            public MDRRuleGroupInstance[] findByG_C_C_PrevAndNext(
2198                    long ruleGroupInstanceId, long groupId, long classNameId, long classPK,
2199                    OrderByComparator orderByComparator)
2200                    throws NoSuchRuleGroupInstanceException, SystemException {
2201                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
2202    
2203                    Session session = null;
2204    
2205                    try {
2206                            session = openSession();
2207    
2208                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
2209    
2210                            array[0] = getByG_C_C_PrevAndNext(session, mdrRuleGroupInstance,
2211                                            groupId, classNameId, classPK, orderByComparator, true);
2212    
2213                            array[1] = mdrRuleGroupInstance;
2214    
2215                            array[2] = getByG_C_C_PrevAndNext(session, mdrRuleGroupInstance,
2216                                            groupId, classNameId, classPK, orderByComparator, false);
2217    
2218                            return array;
2219                    }
2220                    catch (Exception e) {
2221                            throw processException(e);
2222                    }
2223                    finally {
2224                            closeSession(session);
2225                    }
2226            }
2227    
2228            protected MDRRuleGroupInstance getByG_C_C_PrevAndNext(Session session,
2229                    MDRRuleGroupInstance mdrRuleGroupInstance, long groupId,
2230                    long classNameId, long classPK, OrderByComparator orderByComparator,
2231                    boolean previous) {
2232                    StringBundler query = null;
2233    
2234                    if (orderByComparator != null) {
2235                            query = new StringBundler(6 +
2236                                            (orderByComparator.getOrderByFields().length * 6));
2237                    }
2238                    else {
2239                            query = new StringBundler(3);
2240                    }
2241    
2242                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2243    
2244                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
2245    
2246                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
2247    
2248                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
2249    
2250                    if (orderByComparator != null) {
2251                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2252    
2253                            if (orderByConditionFields.length > 0) {
2254                                    query.append(WHERE_AND);
2255                            }
2256    
2257                            for (int i = 0; i < orderByConditionFields.length; i++) {
2258                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2259                                    query.append(orderByConditionFields[i]);
2260    
2261                                    if ((i + 1) < orderByConditionFields.length) {
2262                                            if (orderByComparator.isAscending() ^ previous) {
2263                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2264                                            }
2265                                            else {
2266                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2267                                            }
2268                                    }
2269                                    else {
2270                                            if (orderByComparator.isAscending() ^ previous) {
2271                                                    query.append(WHERE_GREATER_THAN);
2272                                            }
2273                                            else {
2274                                                    query.append(WHERE_LESSER_THAN);
2275                                            }
2276                                    }
2277                            }
2278    
2279                            query.append(ORDER_BY_CLAUSE);
2280    
2281                            String[] orderByFields = orderByComparator.getOrderByFields();
2282    
2283                            for (int i = 0; i < orderByFields.length; i++) {
2284                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2285                                    query.append(orderByFields[i]);
2286    
2287                                    if ((i + 1) < orderByFields.length) {
2288                                            if (orderByComparator.isAscending() ^ previous) {
2289                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2290                                            }
2291                                            else {
2292                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2293                                            }
2294                                    }
2295                                    else {
2296                                            if (orderByComparator.isAscending() ^ previous) {
2297                                                    query.append(ORDER_BY_ASC);
2298                                            }
2299                                            else {
2300                                                    query.append(ORDER_BY_DESC);
2301                                            }
2302                                    }
2303                            }
2304                    }
2305    
2306                    String sql = query.toString();
2307    
2308                    Query q = session.createQuery(sql);
2309    
2310                    q.setFirstResult(0);
2311                    q.setMaxResults(2);
2312    
2313                    QueryPos qPos = QueryPos.getInstance(q);
2314    
2315                    qPos.add(groupId);
2316    
2317                    qPos.add(classNameId);
2318    
2319                    qPos.add(classPK);
2320    
2321                    if (orderByComparator != null) {
2322                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
2323    
2324                            for (Object value : values) {
2325                                    qPos.add(value);
2326                            }
2327                    }
2328    
2329                    List<MDRRuleGroupInstance> list = q.list();
2330    
2331                    if (list.size() == 2) {
2332                            return list.get(1);
2333                    }
2334                    else {
2335                            return null;
2336                    }
2337            }
2338    
2339            /**
2340             * Returns all the m d r rule group instances that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
2341             *
2342             * @param groupId the group ID
2343             * @param classNameId the class name ID
2344             * @param classPK the class p k
2345             * @return the matching m d r rule group instances that the user has permission to view
2346             * @throws SystemException if a system exception occurred
2347             */
2348            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
2349                    long classNameId, long classPK) throws SystemException {
2350                    return filterFindByG_C_C(groupId, classNameId, classPK,
2351                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2352            }
2353    
2354            /**
2355             * Returns a range of all the m d r rule group instances that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
2356             *
2357             * <p>
2358             * 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.
2359             * </p>
2360             *
2361             * @param groupId the group ID
2362             * @param classNameId the class name ID
2363             * @param classPK the class p k
2364             * @param start the lower bound of the range of m d r rule group instances
2365             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2366             * @return the range of matching m d r rule group instances that the user has permission to view
2367             * @throws SystemException if a system exception occurred
2368             */
2369            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
2370                    long classNameId, long classPK, int start, int end)
2371                    throws SystemException {
2372                    return filterFindByG_C_C(groupId, classNameId, classPK, start, end, null);
2373            }
2374    
2375            /**
2376             * Returns an ordered range of all the m d r rule group instances that the user has permissions to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
2377             *
2378             * <p>
2379             * 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.
2380             * </p>
2381             *
2382             * @param groupId the group ID
2383             * @param classNameId the class name ID
2384             * @param classPK the class p k
2385             * @param start the lower bound of the range of m d r rule group instances
2386             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2387             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2388             * @return the ordered range of matching m d r rule group instances that the user has permission to view
2389             * @throws SystemException if a system exception occurred
2390             */
2391            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
2392                    long classNameId, long classPK, int start, int end,
2393                    OrderByComparator orderByComparator) throws SystemException {
2394                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2395                            return findByG_C_C(groupId, classNameId, classPK, start, end,
2396                                    orderByComparator);
2397                    }
2398    
2399                    StringBundler query = null;
2400    
2401                    if (orderByComparator != null) {
2402                            query = new StringBundler(5 +
2403                                            (orderByComparator.getOrderByFields().length * 3));
2404                    }
2405                    else {
2406                            query = new StringBundler(4);
2407                    }
2408    
2409                    if (getDB().isSupportsInlineDistinct()) {
2410                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2411                    }
2412                    else {
2413                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
2414                    }
2415    
2416                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
2417    
2418                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
2419    
2420                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
2421    
2422                    if (!getDB().isSupportsInlineDistinct()) {
2423                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
2424                    }
2425    
2426                    if (orderByComparator != null) {
2427                            if (getDB().isSupportsInlineDistinct()) {
2428                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2429                                            orderByComparator);
2430                            }
2431                            else {
2432                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2433                                            orderByComparator);
2434                            }
2435                    }
2436    
2437                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2438                                    MDRRuleGroupInstance.class.getName(),
2439                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2440    
2441                    Session session = null;
2442    
2443                    try {
2444                            session = openSession();
2445    
2446                            SQLQuery q = session.createSQLQuery(sql);
2447    
2448                            if (getDB().isSupportsInlineDistinct()) {
2449                                    q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
2450                            }
2451                            else {
2452                                    q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
2453                            }
2454    
2455                            QueryPos qPos = QueryPos.getInstance(q);
2456    
2457                            qPos.add(groupId);
2458    
2459                            qPos.add(classNameId);
2460    
2461                            qPos.add(classPK);
2462    
2463                            return (List<MDRRuleGroupInstance>)QueryUtil.list(q, getDialect(),
2464                                    start, end);
2465                    }
2466                    catch (Exception e) {
2467                            throw processException(e);
2468                    }
2469                    finally {
2470                            closeSession(session);
2471                    }
2472            }
2473    
2474            /**
2475             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set of m d r rule group instances that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
2476             *
2477             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
2478             * @param groupId the group ID
2479             * @param classNameId the class name ID
2480             * @param classPK the class p k
2481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2482             * @return the previous, current, and next m d r rule group instance
2483             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
2484             * @throws SystemException if a system exception occurred
2485             */
2486            public MDRRuleGroupInstance[] filterFindByG_C_C_PrevAndNext(
2487                    long ruleGroupInstanceId, long groupId, long classNameId, long classPK,
2488                    OrderByComparator orderByComparator)
2489                    throws NoSuchRuleGroupInstanceException, SystemException {
2490                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2491                            return findByG_C_C_PrevAndNext(ruleGroupInstanceId, groupId,
2492                                    classNameId, classPK, orderByComparator);
2493                    }
2494    
2495                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
2496    
2497                    Session session = null;
2498    
2499                    try {
2500                            session = openSession();
2501    
2502                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
2503    
2504                            array[0] = filterGetByG_C_C_PrevAndNext(session,
2505                                            mdrRuleGroupInstance, groupId, classNameId, classPK,
2506                                            orderByComparator, true);
2507    
2508                            array[1] = mdrRuleGroupInstance;
2509    
2510                            array[2] = filterGetByG_C_C_PrevAndNext(session,
2511                                            mdrRuleGroupInstance, groupId, classNameId, classPK,
2512                                            orderByComparator, false);
2513    
2514                            return array;
2515                    }
2516                    catch (Exception e) {
2517                            throw processException(e);
2518                    }
2519                    finally {
2520                            closeSession(session);
2521                    }
2522            }
2523    
2524            protected MDRRuleGroupInstance filterGetByG_C_C_PrevAndNext(
2525                    Session session, MDRRuleGroupInstance mdrRuleGroupInstance,
2526                    long groupId, long classNameId, long classPK,
2527                    OrderByComparator orderByComparator, boolean previous) {
2528                    StringBundler query = null;
2529    
2530                    if (orderByComparator != null) {
2531                            query = new StringBundler(6 +
2532                                            (orderByComparator.getOrderByFields().length * 6));
2533                    }
2534                    else {
2535                            query = new StringBundler(3);
2536                    }
2537    
2538                    if (getDB().isSupportsInlineDistinct()) {
2539                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2540                    }
2541                    else {
2542                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
2543                    }
2544    
2545                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
2546    
2547                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
2548    
2549                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
2550    
2551                    if (!getDB().isSupportsInlineDistinct()) {
2552                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
2553                    }
2554    
2555                    if (orderByComparator != null) {
2556                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2557    
2558                            if (orderByConditionFields.length > 0) {
2559                                    query.append(WHERE_AND);
2560                            }
2561    
2562                            for (int i = 0; i < orderByConditionFields.length; i++) {
2563                                    if (getDB().isSupportsInlineDistinct()) {
2564                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2565                                    }
2566                                    else {
2567                                            query.append(_ORDER_BY_ENTITY_TABLE);
2568                                    }
2569    
2570                                    query.append(orderByConditionFields[i]);
2571    
2572                                    if ((i + 1) < orderByConditionFields.length) {
2573                                            if (orderByComparator.isAscending() ^ previous) {
2574                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2575                                            }
2576                                            else {
2577                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2578                                            }
2579                                    }
2580                                    else {
2581                                            if (orderByComparator.isAscending() ^ previous) {
2582                                                    query.append(WHERE_GREATER_THAN);
2583                                            }
2584                                            else {
2585                                                    query.append(WHERE_LESSER_THAN);
2586                                            }
2587                                    }
2588                            }
2589    
2590                            query.append(ORDER_BY_CLAUSE);
2591    
2592                            String[] orderByFields = orderByComparator.getOrderByFields();
2593    
2594                            for (int i = 0; i < orderByFields.length; i++) {
2595                                    if (getDB().isSupportsInlineDistinct()) {
2596                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2597                                    }
2598                                    else {
2599                                            query.append(_ORDER_BY_ENTITY_TABLE);
2600                                    }
2601    
2602                                    query.append(orderByFields[i]);
2603    
2604                                    if ((i + 1) < orderByFields.length) {
2605                                            if (orderByComparator.isAscending() ^ previous) {
2606                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2607                                            }
2608                                            else {
2609                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2610                                            }
2611                                    }
2612                                    else {
2613                                            if (orderByComparator.isAscending() ^ previous) {
2614                                                    query.append(ORDER_BY_ASC);
2615                                            }
2616                                            else {
2617                                                    query.append(ORDER_BY_DESC);
2618                                            }
2619                                    }
2620                            }
2621                    }
2622    
2623                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2624                                    MDRRuleGroupInstance.class.getName(),
2625                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2626    
2627                    SQLQuery q = session.createSQLQuery(sql);
2628    
2629                    q.setFirstResult(0);
2630                    q.setMaxResults(2);
2631    
2632                    if (getDB().isSupportsInlineDistinct()) {
2633                            q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
2634                    }
2635                    else {
2636                            q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
2637                    }
2638    
2639                    QueryPos qPos = QueryPos.getInstance(q);
2640    
2641                    qPos.add(groupId);
2642    
2643                    qPos.add(classNameId);
2644    
2645                    qPos.add(classPK);
2646    
2647                    if (orderByComparator != null) {
2648                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
2649    
2650                            for (Object value : values) {
2651                                    qPos.add(value);
2652                            }
2653                    }
2654    
2655                    List<MDRRuleGroupInstance> list = q.list();
2656    
2657                    if (list.size() == 2) {
2658                            return list.get(1);
2659                    }
2660                    else {
2661                            return null;
2662                    }
2663            }
2664    
2665            /**
2666             * Returns the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException} if it could not be found.
2667             *
2668             * @param classNameId the class name ID
2669             * @param classPK the class p k
2670             * @param ruleGroupId the rule group ID
2671             * @return the matching m d r rule group instance
2672             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2673             * @throws SystemException if a system exception occurred
2674             */
2675            public MDRRuleGroupInstance findByC_C_R(long classNameId, long classPK,
2676                    long ruleGroupId)
2677                    throws NoSuchRuleGroupInstanceException, SystemException {
2678                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByC_C_R(classNameId,
2679                                    classPK, ruleGroupId);
2680    
2681                    if (mdrRuleGroupInstance == null) {
2682                            StringBundler msg = new StringBundler(8);
2683    
2684                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2685    
2686                            msg.append("classNameId=");
2687                            msg.append(classNameId);
2688    
2689                            msg.append(", classPK=");
2690                            msg.append(classPK);
2691    
2692                            msg.append(", ruleGroupId=");
2693                            msg.append(ruleGroupId);
2694    
2695                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2696    
2697                            if (_log.isWarnEnabled()) {
2698                                    _log.warn(msg.toString());
2699                            }
2700    
2701                            throw new NoSuchRuleGroupInstanceException(msg.toString());
2702                    }
2703    
2704                    return mdrRuleGroupInstance;
2705            }
2706    
2707            /**
2708             * Returns the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2709             *
2710             * @param classNameId the class name ID
2711             * @param classPK the class p k
2712             * @param ruleGroupId the rule group ID
2713             * @return the matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
2714             * @throws SystemException if a system exception occurred
2715             */
2716            public MDRRuleGroupInstance fetchByC_C_R(long classNameId, long classPK,
2717                    long ruleGroupId) throws SystemException {
2718                    return fetchByC_C_R(classNameId, classPK, ruleGroupId, true);
2719            }
2720    
2721            /**
2722             * Returns the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2723             *
2724             * @param classNameId the class name ID
2725             * @param classPK the class p k
2726             * @param ruleGroupId the rule group ID
2727             * @param retrieveFromCache whether to use the finder cache
2728             * @return the matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
2729             * @throws SystemException if a system exception occurred
2730             */
2731            public MDRRuleGroupInstance fetchByC_C_R(long classNameId, long classPK,
2732                    long ruleGroupId, boolean retrieveFromCache) throws SystemException {
2733                    Object[] finderArgs = new Object[] { classNameId, classPK, ruleGroupId };
2734    
2735                    Object result = null;
2736    
2737                    if (retrieveFromCache) {
2738                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_R,
2739                                            finderArgs, this);
2740                    }
2741    
2742                    if (result == null) {
2743                            StringBundler query = new StringBundler(4);
2744    
2745                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2746    
2747                            query.append(_FINDER_COLUMN_C_C_R_CLASSNAMEID_2);
2748    
2749                            query.append(_FINDER_COLUMN_C_C_R_CLASSPK_2);
2750    
2751                            query.append(_FINDER_COLUMN_C_C_R_RULEGROUPID_2);
2752    
2753                            String sql = query.toString();
2754    
2755                            Session session = null;
2756    
2757                            try {
2758                                    session = openSession();
2759    
2760                                    Query q = session.createQuery(sql);
2761    
2762                                    QueryPos qPos = QueryPos.getInstance(q);
2763    
2764                                    qPos.add(classNameId);
2765    
2766                                    qPos.add(classPK);
2767    
2768                                    qPos.add(ruleGroupId);
2769    
2770                                    List<MDRRuleGroupInstance> list = q.list();
2771    
2772                                    result = list;
2773    
2774                                    MDRRuleGroupInstance mdrRuleGroupInstance = null;
2775    
2776                                    if (list.isEmpty()) {
2777                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
2778                                                    finderArgs, list);
2779                                    }
2780                                    else {
2781                                            mdrRuleGroupInstance = list.get(0);
2782    
2783                                            cacheResult(mdrRuleGroupInstance);
2784    
2785                                            if ((mdrRuleGroupInstance.getClassNameId() != classNameId) ||
2786                                                            (mdrRuleGroupInstance.getClassPK() != classPK) ||
2787                                                            (mdrRuleGroupInstance.getRuleGroupId() != ruleGroupId)) {
2788                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
2789                                                            finderArgs, mdrRuleGroupInstance);
2790                                            }
2791                                    }
2792    
2793                                    return mdrRuleGroupInstance;
2794                            }
2795                            catch (Exception e) {
2796                                    throw processException(e);
2797                            }
2798                            finally {
2799                                    if (result == null) {
2800                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R,
2801                                                    finderArgs);
2802                                    }
2803    
2804                                    closeSession(session);
2805                            }
2806                    }
2807                    else {
2808                            if (result instanceof List<?>) {
2809                                    return null;
2810                            }
2811                            else {
2812                                    return (MDRRuleGroupInstance)result;
2813                            }
2814                    }
2815            }
2816    
2817            /**
2818             * Returns all the m d r rule group instances.
2819             *
2820             * @return the m d r rule group instances
2821             * @throws SystemException if a system exception occurred
2822             */
2823            public List<MDRRuleGroupInstance> findAll() throws SystemException {
2824                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2825            }
2826    
2827            /**
2828             * Returns a range of all the m d r rule group instances.
2829             *
2830             * <p>
2831             * 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.
2832             * </p>
2833             *
2834             * @param start the lower bound of the range of m d r rule group instances
2835             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2836             * @return the range of m d r rule group instances
2837             * @throws SystemException if a system exception occurred
2838             */
2839            public List<MDRRuleGroupInstance> findAll(int start, int end)
2840                    throws SystemException {
2841                    return findAll(start, end, null);
2842            }
2843    
2844            /**
2845             * Returns an ordered range of all the m d r rule group instances.
2846             *
2847             * <p>
2848             * 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.
2849             * </p>
2850             *
2851             * @param start the lower bound of the range of m d r rule group instances
2852             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2853             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2854             * @return the ordered range of m d r rule group instances
2855             * @throws SystemException if a system exception occurred
2856             */
2857            public List<MDRRuleGroupInstance> findAll(int start, int end,
2858                    OrderByComparator orderByComparator) throws SystemException {
2859                    FinderPath finderPath = null;
2860                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2861    
2862                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2863                                    (orderByComparator == null)) {
2864                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2865                            finderArgs = FINDER_ARGS_EMPTY;
2866                    }
2867                    else {
2868                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2869                            finderArgs = new Object[] { start, end, orderByComparator };
2870                    }
2871    
2872                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
2873                                    finderArgs, this);
2874    
2875                    if (list == null) {
2876                            StringBundler query = null;
2877                            String sql = null;
2878    
2879                            if (orderByComparator != null) {
2880                                    query = new StringBundler(2 +
2881                                                    (orderByComparator.getOrderByFields().length * 3));
2882    
2883                                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE);
2884    
2885                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2886                                            orderByComparator);
2887    
2888                                    sql = query.toString();
2889                            }
2890                            else {
2891                                    sql = _SQL_SELECT_MDRRULEGROUPINSTANCE;
2892                            }
2893    
2894                            Session session = null;
2895    
2896                            try {
2897                                    session = openSession();
2898    
2899                                    Query q = session.createQuery(sql);
2900    
2901                                    if (orderByComparator == null) {
2902                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2903                                                            getDialect(), start, end, false);
2904    
2905                                            Collections.sort(list);
2906                                    }
2907                                    else {
2908                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2909                                                            getDialect(), start, end);
2910                                    }
2911                            }
2912                            catch (Exception e) {
2913                                    throw processException(e);
2914                            }
2915                            finally {
2916                                    if (list == null) {
2917                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2918                                    }
2919                                    else {
2920                                            cacheResult(list);
2921    
2922                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2923                                    }
2924    
2925                                    closeSession(session);
2926                            }
2927                    }
2928    
2929                    return list;
2930            }
2931    
2932            /**
2933             * Removes all the m d r rule group instances where uuid = &#63; from the database.
2934             *
2935             * @param uuid the uuid
2936             * @throws SystemException if a system exception occurred
2937             */
2938            public void removeByUuid(String uuid) throws SystemException {
2939                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByUuid(uuid)) {
2940                            remove(mdrRuleGroupInstance);
2941                    }
2942            }
2943    
2944            /**
2945             * Removes the m d r rule group instance where uuid = &#63; and groupId = &#63; from the database.
2946             *
2947             * @param uuid the uuid
2948             * @param groupId the group ID
2949             * @throws SystemException if a system exception occurred
2950             */
2951            public void removeByUUID_G(String uuid, long groupId)
2952                    throws NoSuchRuleGroupInstanceException, SystemException {
2953                    MDRRuleGroupInstance mdrRuleGroupInstance = findByUUID_G(uuid, groupId);
2954    
2955                    remove(mdrRuleGroupInstance);
2956            }
2957    
2958            /**
2959             * Removes all the m d r rule group instances where ruleGroupId = &#63; from the database.
2960             *
2961             * @param ruleGroupId the rule group ID
2962             * @throws SystemException if a system exception occurred
2963             */
2964            public void removeByRuleGroupId(long ruleGroupId) throws SystemException {
2965                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByRuleGroupId(
2966                                    ruleGroupId)) {
2967                            remove(mdrRuleGroupInstance);
2968                    }
2969            }
2970    
2971            /**
2972             * Removes all the m d r rule group instances where classNameId = &#63; and classPK = &#63; from the database.
2973             *
2974             * @param classNameId the class name ID
2975             * @param classPK the class p k
2976             * @throws SystemException if a system exception occurred
2977             */
2978            public void removeByC_C(long classNameId, long classPK)
2979                    throws SystemException {
2980                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByC_C(
2981                                    classNameId, classPK)) {
2982                            remove(mdrRuleGroupInstance);
2983                    }
2984            }
2985    
2986            /**
2987             * Removes all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2988             *
2989             * @param groupId the group ID
2990             * @param classNameId the class name ID
2991             * @param classPK the class p k
2992             * @throws SystemException if a system exception occurred
2993             */
2994            public void removeByG_C_C(long groupId, long classNameId, long classPK)
2995                    throws SystemException {
2996                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByG_C_C(groupId,
2997                                    classNameId, classPK)) {
2998                            remove(mdrRuleGroupInstance);
2999                    }
3000            }
3001    
3002            /**
3003             * Removes the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; from the database.
3004             *
3005             * @param classNameId the class name ID
3006             * @param classPK the class p k
3007             * @param ruleGroupId the rule group ID
3008             * @throws SystemException if a system exception occurred
3009             */
3010            public void removeByC_C_R(long classNameId, long classPK, long ruleGroupId)
3011                    throws NoSuchRuleGroupInstanceException, SystemException {
3012                    MDRRuleGroupInstance mdrRuleGroupInstance = findByC_C_R(classNameId,
3013                                    classPK, ruleGroupId);
3014    
3015                    remove(mdrRuleGroupInstance);
3016            }
3017    
3018            /**
3019             * Removes all the m d r rule group instances from the database.
3020             *
3021             * @throws SystemException if a system exception occurred
3022             */
3023            public void removeAll() throws SystemException {
3024                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findAll()) {
3025                            remove(mdrRuleGroupInstance);
3026                    }
3027            }
3028    
3029            /**
3030             * Returns the number of m d r rule group instances where uuid = &#63;.
3031             *
3032             * @param uuid the uuid
3033             * @return the number of matching m d r rule group instances
3034             * @throws SystemException if a system exception occurred
3035             */
3036            public int countByUuid(String uuid) throws SystemException {
3037                    Object[] finderArgs = new Object[] { uuid };
3038    
3039                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3040                                    finderArgs, this);
3041    
3042                    if (count == null) {
3043                            StringBundler query = new StringBundler(2);
3044    
3045                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3046    
3047                            if (uuid == null) {
3048                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
3049                            }
3050                            else {
3051                                    if (uuid.equals(StringPool.BLANK)) {
3052                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
3053                                    }
3054                                    else {
3055                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
3056                                    }
3057                            }
3058    
3059                            String sql = query.toString();
3060    
3061                            Session session = null;
3062    
3063                            try {
3064                                    session = openSession();
3065    
3066                                    Query q = session.createQuery(sql);
3067    
3068                                    QueryPos qPos = QueryPos.getInstance(q);
3069    
3070                                    if (uuid != null) {
3071                                            qPos.add(uuid);
3072                                    }
3073    
3074                                    count = (Long)q.uniqueResult();
3075                            }
3076                            catch (Exception e) {
3077                                    throw processException(e);
3078                            }
3079                            finally {
3080                                    if (count == null) {
3081                                            count = Long.valueOf(0);
3082                                    }
3083    
3084                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3085                                            finderArgs, count);
3086    
3087                                    closeSession(session);
3088                            }
3089                    }
3090    
3091                    return count.intValue();
3092            }
3093    
3094            /**
3095             * Returns the number of m d r rule group instances where uuid = &#63; and groupId = &#63;.
3096             *
3097             * @param uuid the uuid
3098             * @param groupId the group ID
3099             * @return the number of matching m d r rule group instances
3100             * @throws SystemException if a system exception occurred
3101             */
3102            public int countByUUID_G(String uuid, long groupId)
3103                    throws SystemException {
3104                    Object[] finderArgs = new Object[] { uuid, groupId };
3105    
3106                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3107                                    finderArgs, this);
3108    
3109                    if (count == null) {
3110                            StringBundler query = new StringBundler(3);
3111    
3112                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3113    
3114                            if (uuid == null) {
3115                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3116                            }
3117                            else {
3118                                    if (uuid.equals(StringPool.BLANK)) {
3119                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3120                                    }
3121                                    else {
3122                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3123                                    }
3124                            }
3125    
3126                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3127    
3128                            String sql = query.toString();
3129    
3130                            Session session = null;
3131    
3132                            try {
3133                                    session = openSession();
3134    
3135                                    Query q = session.createQuery(sql);
3136    
3137                                    QueryPos qPos = QueryPos.getInstance(q);
3138    
3139                                    if (uuid != null) {
3140                                            qPos.add(uuid);
3141                                    }
3142    
3143                                    qPos.add(groupId);
3144    
3145                                    count = (Long)q.uniqueResult();
3146                            }
3147                            catch (Exception e) {
3148                                    throw processException(e);
3149                            }
3150                            finally {
3151                                    if (count == null) {
3152                                            count = Long.valueOf(0);
3153                                    }
3154    
3155                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3156                                            finderArgs, count);
3157    
3158                                    closeSession(session);
3159                            }
3160                    }
3161    
3162                    return count.intValue();
3163            }
3164    
3165            /**
3166             * Returns the number of m d r rule group instances where ruleGroupId = &#63;.
3167             *
3168             * @param ruleGroupId the rule group ID
3169             * @return the number of matching m d r rule group instances
3170             * @throws SystemException if a system exception occurred
3171             */
3172            public int countByRuleGroupId(long ruleGroupId) throws SystemException {
3173                    Object[] finderArgs = new Object[] { ruleGroupId };
3174    
3175                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
3176                                    finderArgs, this);
3177    
3178                    if (count == null) {
3179                            StringBundler query = new StringBundler(2);
3180    
3181                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3182    
3183                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
3184    
3185                            String sql = query.toString();
3186    
3187                            Session session = null;
3188    
3189                            try {
3190                                    session = openSession();
3191    
3192                                    Query q = session.createQuery(sql);
3193    
3194                                    QueryPos qPos = QueryPos.getInstance(q);
3195    
3196                                    qPos.add(ruleGroupId);
3197    
3198                                    count = (Long)q.uniqueResult();
3199                            }
3200                            catch (Exception e) {
3201                                    throw processException(e);
3202                            }
3203                            finally {
3204                                    if (count == null) {
3205                                            count = Long.valueOf(0);
3206                                    }
3207    
3208                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
3209                                            finderArgs, count);
3210    
3211                                    closeSession(session);
3212                            }
3213                    }
3214    
3215                    return count.intValue();
3216            }
3217    
3218            /**
3219             * Returns the number of m d r rule group instances where classNameId = &#63; and classPK = &#63;.
3220             *
3221             * @param classNameId the class name ID
3222             * @param classPK the class p k
3223             * @return the number of matching m d r rule group instances
3224             * @throws SystemException if a system exception occurred
3225             */
3226            public int countByC_C(long classNameId, long classPK)
3227                    throws SystemException {
3228                    Object[] finderArgs = new Object[] { classNameId, classPK };
3229    
3230                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
3231                                    finderArgs, this);
3232    
3233                    if (count == null) {
3234                            StringBundler query = new StringBundler(3);
3235    
3236                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3237    
3238                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3239    
3240                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3241    
3242                            String sql = query.toString();
3243    
3244                            Session session = null;
3245    
3246                            try {
3247                                    session = openSession();
3248    
3249                                    Query q = session.createQuery(sql);
3250    
3251                                    QueryPos qPos = QueryPos.getInstance(q);
3252    
3253                                    qPos.add(classNameId);
3254    
3255                                    qPos.add(classPK);
3256    
3257                                    count = (Long)q.uniqueResult();
3258                            }
3259                            catch (Exception e) {
3260                                    throw processException(e);
3261                            }
3262                            finally {
3263                                    if (count == null) {
3264                                            count = Long.valueOf(0);
3265                                    }
3266    
3267                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
3268                                            count);
3269    
3270                                    closeSession(session);
3271                            }
3272                    }
3273    
3274                    return count.intValue();
3275            }
3276    
3277            /**
3278             * Returns the number of m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3279             *
3280             * @param groupId the group ID
3281             * @param classNameId the class name ID
3282             * @param classPK the class p k
3283             * @return the number of matching m d r rule group instances
3284             * @throws SystemException if a system exception occurred
3285             */
3286            public int countByG_C_C(long groupId, long classNameId, long classPK)
3287                    throws SystemException {
3288                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK };
3289    
3290                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_C,
3291                                    finderArgs, this);
3292    
3293                    if (count == null) {
3294                            StringBundler query = new StringBundler(4);
3295    
3296                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3297    
3298                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3299    
3300                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3301    
3302                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3303    
3304                            String sql = query.toString();
3305    
3306                            Session session = null;
3307    
3308                            try {
3309                                    session = openSession();
3310    
3311                                    Query q = session.createQuery(sql);
3312    
3313                                    QueryPos qPos = QueryPos.getInstance(q);
3314    
3315                                    qPos.add(groupId);
3316    
3317                                    qPos.add(classNameId);
3318    
3319                                    qPos.add(classPK);
3320    
3321                                    count = (Long)q.uniqueResult();
3322                            }
3323                            catch (Exception e) {
3324                                    throw processException(e);
3325                            }
3326                            finally {
3327                                    if (count == null) {
3328                                            count = Long.valueOf(0);
3329                                    }
3330    
3331                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_C,
3332                                            finderArgs, count);
3333    
3334                                    closeSession(session);
3335                            }
3336                    }
3337    
3338                    return count.intValue();
3339            }
3340    
3341            /**
3342             * Returns the number of m d r rule group instances that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3343             *
3344             * @param groupId the group ID
3345             * @param classNameId the class name ID
3346             * @param classPK the class p k
3347             * @return the number of matching m d r rule group instances that the user has permission to view
3348             * @throws SystemException if a system exception occurred
3349             */
3350            public int filterCountByG_C_C(long groupId, long classNameId, long classPK)
3351                    throws SystemException {
3352                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3353                            return countByG_C_C(groupId, classNameId, classPK);
3354                    }
3355    
3356                    StringBundler query = new StringBundler(4);
3357    
3358                    query.append(_FILTER_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3359    
3360                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3361    
3362                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3363    
3364                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3365    
3366                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3367                                    MDRRuleGroupInstance.class.getName(),
3368                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3369    
3370                    Session session = null;
3371    
3372                    try {
3373                            session = openSession();
3374    
3375                            SQLQuery q = session.createSQLQuery(sql);
3376    
3377                            q.addScalar(COUNT_COLUMN_NAME,
3378                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3379    
3380                            QueryPos qPos = QueryPos.getInstance(q);
3381    
3382                            qPos.add(groupId);
3383    
3384                            qPos.add(classNameId);
3385    
3386                            qPos.add(classPK);
3387    
3388                            Long count = (Long)q.uniqueResult();
3389    
3390                            return count.intValue();
3391                    }
3392                    catch (Exception e) {
3393                            throw processException(e);
3394                    }
3395                    finally {
3396                            closeSession(session);
3397                    }
3398            }
3399    
3400            /**
3401             * Returns the number of m d r rule group instances where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63;.
3402             *
3403             * @param classNameId the class name ID
3404             * @param classPK the class p k
3405             * @param ruleGroupId the rule group ID
3406             * @return the number of matching m d r rule group instances
3407             * @throws SystemException if a system exception occurred
3408             */
3409            public int countByC_C_R(long classNameId, long classPK, long ruleGroupId)
3410                    throws SystemException {
3411                    Object[] finderArgs = new Object[] { classNameId, classPK, ruleGroupId };
3412    
3413                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_R,
3414                                    finderArgs, this);
3415    
3416                    if (count == null) {
3417                            StringBundler query = new StringBundler(4);
3418    
3419                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3420    
3421                            query.append(_FINDER_COLUMN_C_C_R_CLASSNAMEID_2);
3422    
3423                            query.append(_FINDER_COLUMN_C_C_R_CLASSPK_2);
3424    
3425                            query.append(_FINDER_COLUMN_C_C_R_RULEGROUPID_2);
3426    
3427                            String sql = query.toString();
3428    
3429                            Session session = null;
3430    
3431                            try {
3432                                    session = openSession();
3433    
3434                                    Query q = session.createQuery(sql);
3435    
3436                                    QueryPos qPos = QueryPos.getInstance(q);
3437    
3438                                    qPos.add(classNameId);
3439    
3440                                    qPos.add(classPK);
3441    
3442                                    qPos.add(ruleGroupId);
3443    
3444                                    count = (Long)q.uniqueResult();
3445                            }
3446                            catch (Exception e) {
3447                                    throw processException(e);
3448                            }
3449                            finally {
3450                                    if (count == null) {
3451                                            count = Long.valueOf(0);
3452                                    }
3453    
3454                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_R,
3455                                            finderArgs, count);
3456    
3457                                    closeSession(session);
3458                            }
3459                    }
3460    
3461                    return count.intValue();
3462            }
3463    
3464            /**
3465             * Returns the number of m d r rule group instances.
3466             *
3467             * @return the number of m d r rule group instances
3468             * @throws SystemException if a system exception occurred
3469             */
3470            public int countAll() throws SystemException {
3471                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3472                                    FINDER_ARGS_EMPTY, this);
3473    
3474                    if (count == null) {
3475                            Session session = null;
3476    
3477                            try {
3478                                    session = openSession();
3479    
3480                                    Query q = session.createQuery(_SQL_COUNT_MDRRULEGROUPINSTANCE);
3481    
3482                                    count = (Long)q.uniqueResult();
3483                            }
3484                            catch (Exception e) {
3485                                    throw processException(e);
3486                            }
3487                            finally {
3488                                    if (count == null) {
3489                                            count = Long.valueOf(0);
3490                                    }
3491    
3492                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3493                                            FINDER_ARGS_EMPTY, count);
3494    
3495                                    closeSession(session);
3496                            }
3497                    }
3498    
3499                    return count.intValue();
3500            }
3501    
3502            /**
3503             * Initializes the m d r rule group instance persistence.
3504             */
3505            public void afterPropertiesSet() {
3506                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3507                                            com.liferay.portal.util.PropsUtil.get(
3508                                                    "value.object.listener.com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance")));
3509    
3510                    if (listenerClassNames.length > 0) {
3511                            try {
3512                                    List<ModelListener<MDRRuleGroupInstance>> listenersList = new ArrayList<ModelListener<MDRRuleGroupInstance>>();
3513    
3514                                    for (String listenerClassName : listenerClassNames) {
3515                                            listenersList.add((ModelListener<MDRRuleGroupInstance>)InstanceFactory.newInstance(
3516                                                            listenerClassName));
3517                                    }
3518    
3519                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3520                            }
3521                            catch (Exception e) {
3522                                    _log.error(e);
3523                            }
3524                    }
3525            }
3526    
3527            public void destroy() {
3528                    EntityCacheUtil.removeCache(MDRRuleGroupInstanceImpl.class.getName());
3529                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3530                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3531            }
3532    
3533            @BeanReference(type = MDRActionPersistence.class)
3534            protected MDRActionPersistence mdrActionPersistence;
3535            @BeanReference(type = MDRRulePersistence.class)
3536            protected MDRRulePersistence mdrRulePersistence;
3537            @BeanReference(type = MDRRuleGroupPersistence.class)
3538            protected MDRRuleGroupPersistence mdrRuleGroupPersistence;
3539            @BeanReference(type = MDRRuleGroupInstancePersistence.class)
3540            protected MDRRuleGroupInstancePersistence mdrRuleGroupInstancePersistence;
3541            @BeanReference(type = LayoutPersistence.class)
3542            protected LayoutPersistence layoutPersistence;
3543            @BeanReference(type = LayoutSetPersistence.class)
3544            protected LayoutSetPersistence layoutSetPersistence;
3545            @BeanReference(type = ResourcePersistence.class)
3546            protected ResourcePersistence resourcePersistence;
3547            @BeanReference(type = UserPersistence.class)
3548            protected UserPersistence userPersistence;
3549            private static final String _SQL_SELECT_MDRRULEGROUPINSTANCE = "SELECT mdrRuleGroupInstance FROM MDRRuleGroupInstance mdrRuleGroupInstance";
3550            private static final String _SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE = "SELECT mdrRuleGroupInstance FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
3551            private static final String _SQL_COUNT_MDRRULEGROUPINSTANCE = "SELECT COUNT(mdrRuleGroupInstance) FROM MDRRuleGroupInstance mdrRuleGroupInstance";
3552            private static final String _SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE = "SELECT COUNT(mdrRuleGroupInstance) FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
3553            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mdrRuleGroupInstance.uuid IS NULL";
3554            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrRuleGroupInstance.uuid = ?";
3555            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrRuleGroupInstance.uuid IS NULL OR mdrRuleGroupInstance.uuid = ?)";
3556            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mdrRuleGroupInstance.uuid IS NULL AND ";
3557            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrRuleGroupInstance.uuid = ? AND ";
3558            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrRuleGroupInstance.uuid IS NULL OR mdrRuleGroupInstance.uuid = ?) AND ";
3559            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrRuleGroupInstance.groupId = ?";
3560            private static final String _FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2 = "mdrRuleGroupInstance.ruleGroupId = ?";
3561            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
3562            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ?";
3563            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "mdrRuleGroupInstance.groupId = ? AND ";
3564            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
3565            private static final String _FINDER_COLUMN_G_C_C_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ?";
3566            private static final String _FINDER_COLUMN_C_C_R_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
3567            private static final String _FINDER_COLUMN_C_C_R_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ? AND ";
3568            private static final String _FINDER_COLUMN_C_C_R_RULEGROUPID_2 = "mdrRuleGroupInstance.ruleGroupId = ?";
3569            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mdrRuleGroupInstance.ruleGroupInstanceId";
3570            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE = "SELECT DISTINCT {mdrRuleGroupInstance.*} FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
3571            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1 =
3572                    "SELECT {MDRRuleGroupInstance.*} FROM (SELECT DISTINCT mdrRuleGroupInstance.ruleGroupInstanceId FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
3573            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2 =
3574                    ") TEMP_TABLE INNER JOIN MDRRuleGroupInstance ON TEMP_TABLE.ruleGroupInstanceId = MDRRuleGroupInstance.ruleGroupInstanceId";
3575            private static final String _FILTER_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE = "SELECT COUNT(DISTINCT mdrRuleGroupInstance.ruleGroupInstanceId) AS COUNT_VALUE FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
3576            private static final String _FILTER_ENTITY_ALIAS = "mdrRuleGroupInstance";
3577            private static final String _FILTER_ENTITY_TABLE = "MDRRuleGroupInstance";
3578            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRuleGroupInstance.";
3579            private static final String _ORDER_BY_ENTITY_TABLE = "MDRRuleGroupInstance.";
3580            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRuleGroupInstance exists with the primary key ";
3581            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRuleGroupInstance exists with the key {";
3582            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3583            private static Log _log = LogFactoryUtil.getLog(MDRRuleGroupInstancePersistenceImpl.class);
3584            private static MDRRuleGroupInstance _nullMDRRuleGroupInstance = new MDRRuleGroupInstanceImpl() {
3585                            @Override
3586                            public Object clone() {
3587                                    return this;
3588                            }
3589    
3590                            @Override
3591                            public CacheModel<MDRRuleGroupInstance> toCacheModel() {
3592                                    return _nullMDRRuleGroupInstanceCacheModel;
3593                            }
3594                    };
3595    
3596            private static CacheModel<MDRRuleGroupInstance> _nullMDRRuleGroupInstanceCacheModel =
3597                    new CacheModel<MDRRuleGroupInstance>() {
3598                            public MDRRuleGroupInstance toEntityModel() {
3599                                    return _nullMDRRuleGroupInstance;
3600                            }
3601                    };
3602    }