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