001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.mobiledevicerules.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.SetUtil;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.UnmodifiableList;
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.impl.BasePersistenceImpl;
043    
044    import com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException;
045    import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance;
046    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceImpl;
047    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl;
048    
049    import java.io.Serializable;
050    
051    import java.util.ArrayList;
052    import java.util.Collections;
053    import java.util.List;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the m d r rule group instance service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Edward C. Han
064     * @see MDRRuleGroupInstancePersistence
065     * @see MDRRuleGroupInstanceUtil
066     * @generated
067     */
068    public class MDRRuleGroupInstancePersistenceImpl extends BasePersistenceImpl<MDRRuleGroupInstance>
069            implements MDRRuleGroupInstancePersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = MDRRuleGroupInstanceImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
081                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
082                            MDRRuleGroupInstanceImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
085                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
086                            MDRRuleGroupInstanceImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
089                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
092                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
093                            MDRRuleGroupInstanceImpl.class,
094                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
095                            new String[] {
096                                    String.class.getName(),
097                                    
098                            Integer.class.getName(), Integer.class.getName(),
099                                    OrderByComparator.class.getName()
100                            });
101            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
102                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
103                            MDRRuleGroupInstanceImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105                            new String[] { String.class.getName() },
106                            MDRRuleGroupInstanceModelImpl.UUID_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
108                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
110                            new String[] { String.class.getName() });
111    
112            /**
113             * Returns all the m d r rule group instances where uuid = &#63;.
114             *
115             * @param uuid the uuid
116             * @return the matching m d r rule group instances
117             * @throws SystemException if a system exception occurred
118             */
119            public List<MDRRuleGroupInstance> findByUuid(String uuid)
120                    throws SystemException {
121                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the m d r rule group instances where uuid = &#63;.
126             *
127             * <p>
128             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
129             * </p>
130             *
131             * @param uuid the uuid
132             * @param start the lower bound of the range of m d r rule group instances
133             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
134             * @return the range of matching m d r rule group instances
135             * @throws SystemException if a system exception occurred
136             */
137            public List<MDRRuleGroupInstance> findByUuid(String uuid, int start, int end)
138                    throws SystemException {
139                    return findByUuid(uuid, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the m d r rule group instances where uuid = &#63;.
144             *
145             * <p>
146             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
147             * </p>
148             *
149             * @param uuid the uuid
150             * @param start the lower bound of the range of m d r rule group instances
151             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching m d r rule group instances
154             * @throws SystemException if a system exception occurred
155             */
156            public List<MDRRuleGroupInstance> findByUuid(String uuid, int start,
157                    int end, OrderByComparator orderByComparator) throws SystemException {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
170                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
171                    }
172    
173                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
178                                    if (!Validator.equals(uuid, mdrRuleGroupInstance.getUuid())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
198    
199                            boolean bindUuid = false;
200    
201                            if (uuid == null) {
202                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
203                            }
204                            else if (uuid.equals(StringPool.BLANK)) {
205                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
206                            }
207                            else {
208                                    bindUuid = true;
209    
210                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
211                            }
212    
213                            if (orderByComparator != null) {
214                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
215                                            orderByComparator);
216                            }
217                            else
218                             if (pagination) {
219                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
220                            }
221    
222                            String sql = query.toString();
223    
224                            Session session = null;
225    
226                            try {
227                                    session = openSession();
228    
229                                    Query q = session.createQuery(sql);
230    
231                                    QueryPos qPos = QueryPos.getInstance(q);
232    
233                                    if (bindUuid) {
234                                            qPos.add(uuid);
235                                    }
236    
237                                    if (!pagination) {
238                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
239                                                            getDialect(), start, end, false);
240    
241                                            Collections.sort(list);
242    
243                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
244                                    }
245                                    else {
246                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
247                                                            getDialect(), start, end);
248                                    }
249    
250                                    cacheResult(list);
251    
252                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
253                            }
254                            catch (Exception e) {
255                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
256    
257                                    throw processException(e);
258                            }
259                            finally {
260                                    closeSession(session);
261                            }
262                    }
263    
264                    return list;
265            }
266    
267            /**
268             * Returns the first m d r rule group instance in the ordered set where uuid = &#63;.
269             *
270             * @param uuid the uuid
271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
272             * @return the first matching m d r rule group instance
273             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
274             * @throws SystemException if a system exception occurred
275             */
276            public MDRRuleGroupInstance findByUuid_First(String uuid,
277                    OrderByComparator orderByComparator)
278                    throws NoSuchRuleGroupInstanceException, SystemException {
279                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUuid_First(uuid,
280                                    orderByComparator);
281    
282                    if (mdrRuleGroupInstance != null) {
283                            return mdrRuleGroupInstance;
284                    }
285    
286                    StringBundler msg = new StringBundler(4);
287    
288                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
289    
290                    msg.append("uuid=");
291                    msg.append(uuid);
292    
293                    msg.append(StringPool.CLOSE_CURLY_BRACE);
294    
295                    throw new NoSuchRuleGroupInstanceException(msg.toString());
296            }
297    
298            /**
299             * Returns the first m d r rule group instance in the ordered set where uuid = &#63;.
300             *
301             * @param uuid the uuid
302             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
303             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
304             * @throws SystemException if a system exception occurred
305             */
306            public MDRRuleGroupInstance fetchByUuid_First(String uuid,
307                    OrderByComparator orderByComparator) throws SystemException {
308                    List<MDRRuleGroupInstance> list = findByUuid(uuid, 0, 1,
309                                    orderByComparator);
310    
311                    if (!list.isEmpty()) {
312                            return list.get(0);
313                    }
314    
315                    return null;
316            }
317    
318            /**
319             * Returns the last m d r rule group instance in the ordered set where uuid = &#63;.
320             *
321             * @param uuid the uuid
322             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
323             * @return the last matching m d r rule group instance
324             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
325             * @throws SystemException if a system exception occurred
326             */
327            public MDRRuleGroupInstance findByUuid_Last(String uuid,
328                    OrderByComparator orderByComparator)
329                    throws NoSuchRuleGroupInstanceException, SystemException {
330                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUuid_Last(uuid,
331                                    orderByComparator);
332    
333                    if (mdrRuleGroupInstance != null) {
334                            return mdrRuleGroupInstance;
335                    }
336    
337                    StringBundler msg = new StringBundler(4);
338    
339                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
340    
341                    msg.append("uuid=");
342                    msg.append(uuid);
343    
344                    msg.append(StringPool.CLOSE_CURLY_BRACE);
345    
346                    throw new NoSuchRuleGroupInstanceException(msg.toString());
347            }
348    
349            /**
350             * Returns the last m d r rule group instance in the ordered set where uuid = &#63;.
351             *
352             * @param uuid the uuid
353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
354             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
355             * @throws SystemException if a system exception occurred
356             */
357            public MDRRuleGroupInstance fetchByUuid_Last(String uuid,
358                    OrderByComparator orderByComparator) throws SystemException {
359                    int count = countByUuid(uuid);
360    
361                    List<MDRRuleGroupInstance> list = findByUuid(uuid, count - 1, count,
362                                    orderByComparator);
363    
364                    if (!list.isEmpty()) {
365                            return list.get(0);
366                    }
367    
368                    return null;
369            }
370    
371            /**
372             * 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;.
373             *
374             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
375             * @param uuid the uuid
376             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
377             * @return the previous, current, and next m d r rule group instance
378             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
379             * @throws SystemException if a system exception occurred
380             */
381            public MDRRuleGroupInstance[] findByUuid_PrevAndNext(
382                    long ruleGroupInstanceId, String uuid,
383                    OrderByComparator orderByComparator)
384                    throws NoSuchRuleGroupInstanceException, SystemException {
385                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
386    
387                    Session session = null;
388    
389                    try {
390                            session = openSession();
391    
392                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
393    
394                            array[0] = getByUuid_PrevAndNext(session, mdrRuleGroupInstance,
395                                            uuid, orderByComparator, true);
396    
397                            array[1] = mdrRuleGroupInstance;
398    
399                            array[2] = getByUuid_PrevAndNext(session, mdrRuleGroupInstance,
400                                            uuid, orderByComparator, false);
401    
402                            return array;
403                    }
404                    catch (Exception e) {
405                            throw processException(e);
406                    }
407                    finally {
408                            closeSession(session);
409                    }
410            }
411    
412            protected MDRRuleGroupInstance getByUuid_PrevAndNext(Session session,
413                    MDRRuleGroupInstance mdrRuleGroupInstance, String uuid,
414                    OrderByComparator orderByComparator, boolean previous) {
415                    StringBundler query = null;
416    
417                    if (orderByComparator != null) {
418                            query = new StringBundler(6 +
419                                            (orderByComparator.getOrderByFields().length * 6));
420                    }
421                    else {
422                            query = new StringBundler(3);
423                    }
424    
425                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
426    
427                    boolean bindUuid = false;
428    
429                    if (uuid == null) {
430                            query.append(_FINDER_COLUMN_UUID_UUID_1);
431                    }
432                    else if (uuid.equals(StringPool.BLANK)) {
433                            query.append(_FINDER_COLUMN_UUID_UUID_3);
434                    }
435                    else {
436                            bindUuid = true;
437    
438                            query.append(_FINDER_COLUMN_UUID_UUID_2);
439                    }
440    
441                    if (orderByComparator != null) {
442                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
443    
444                            if (orderByConditionFields.length > 0) {
445                                    query.append(WHERE_AND);
446                            }
447    
448                            for (int i = 0; i < orderByConditionFields.length; i++) {
449                                    query.append(_ORDER_BY_ENTITY_ALIAS);
450                                    query.append(orderByConditionFields[i]);
451    
452                                    if ((i + 1) < orderByConditionFields.length) {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
455                                            }
456                                            else {
457                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
458                                            }
459                                    }
460                                    else {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(WHERE_GREATER_THAN);
463                                            }
464                                            else {
465                                                    query.append(WHERE_LESSER_THAN);
466                                            }
467                                    }
468                            }
469    
470                            query.append(ORDER_BY_CLAUSE);
471    
472                            String[] orderByFields = orderByComparator.getOrderByFields();
473    
474                            for (int i = 0; i < orderByFields.length; i++) {
475                                    query.append(_ORDER_BY_ENTITY_ALIAS);
476                                    query.append(orderByFields[i]);
477    
478                                    if ((i + 1) < orderByFields.length) {
479                                            if (orderByComparator.isAscending() ^ previous) {
480                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
481                                            }
482                                            else {
483                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
484                                            }
485                                    }
486                                    else {
487                                            if (orderByComparator.isAscending() ^ previous) {
488                                                    query.append(ORDER_BY_ASC);
489                                            }
490                                            else {
491                                                    query.append(ORDER_BY_DESC);
492                                            }
493                                    }
494                            }
495                    }
496                    else {
497                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
498                    }
499    
500                    String sql = query.toString();
501    
502                    Query q = session.createQuery(sql);
503    
504                    q.setFirstResult(0);
505                    q.setMaxResults(2);
506    
507                    QueryPos qPos = QueryPos.getInstance(q);
508    
509                    if (bindUuid) {
510                            qPos.add(uuid);
511                    }
512    
513                    if (orderByComparator != null) {
514                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
515    
516                            for (Object value : values) {
517                                    qPos.add(value);
518                            }
519                    }
520    
521                    List<MDRRuleGroupInstance> list = q.list();
522    
523                    if (list.size() == 2) {
524                            return list.get(1);
525                    }
526                    else {
527                            return null;
528                    }
529            }
530    
531            /**
532             * Removes all the m d r rule group instances where uuid = &#63; from the database.
533             *
534             * @param uuid the uuid
535             * @throws SystemException if a system exception occurred
536             */
537            public void removeByUuid(String uuid) throws SystemException {
538                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByUuid(uuid,
539                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
540                            remove(mdrRuleGroupInstance);
541                    }
542            }
543    
544            /**
545             * Returns the number of m d r rule group instances where uuid = &#63;.
546             *
547             * @param uuid the uuid
548             * @return the number of matching m d r rule group instances
549             * @throws SystemException if a system exception occurred
550             */
551            public int countByUuid(String uuid) throws SystemException {
552                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
553    
554                    Object[] finderArgs = new Object[] { uuid };
555    
556                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
557                                    this);
558    
559                    if (count == null) {
560                            StringBundler query = new StringBundler(2);
561    
562                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
563    
564                            boolean bindUuid = false;
565    
566                            if (uuid == null) {
567                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
568                            }
569                            else if (uuid.equals(StringPool.BLANK)) {
570                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
571                            }
572                            else {
573                                    bindUuid = true;
574    
575                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
576                            }
577    
578                            String sql = query.toString();
579    
580                            Session session = null;
581    
582                            try {
583                                    session = openSession();
584    
585                                    Query q = session.createQuery(sql);
586    
587                                    QueryPos qPos = QueryPos.getInstance(q);
588    
589                                    if (bindUuid) {
590                                            qPos.add(uuid);
591                                    }
592    
593                                    count = (Long)q.uniqueResult();
594    
595                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
596                            }
597                            catch (Exception e) {
598                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
599    
600                                    throw processException(e);
601                            }
602                            finally {
603                                    closeSession(session);
604                            }
605                    }
606    
607                    return count.intValue();
608            }
609    
610            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mdrRuleGroupInstance.uuid IS NULL";
611            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrRuleGroupInstance.uuid = ?";
612            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrRuleGroupInstance.uuid IS NULL OR mdrRuleGroupInstance.uuid = '')";
613            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
614                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
615                            MDRRuleGroupInstanceImpl.class, FINDER_CLASS_NAME_ENTITY,
616                            "fetchByUUID_G",
617                            new String[] { String.class.getName(), Long.class.getName() },
618                            MDRRuleGroupInstanceModelImpl.UUID_COLUMN_BITMASK |
619                            MDRRuleGroupInstanceModelImpl.GROUPID_COLUMN_BITMASK);
620            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
621                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
622                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
623                            new String[] { String.class.getName(), Long.class.getName() });
624    
625            /**
626             * 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.
627             *
628             * @param uuid the uuid
629             * @param groupId the group ID
630             * @return the matching m d r rule group instance
631             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
632             * @throws SystemException if a system exception occurred
633             */
634            public MDRRuleGroupInstance findByUUID_G(String uuid, long groupId)
635                    throws NoSuchRuleGroupInstanceException, SystemException {
636                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUUID_G(uuid, groupId);
637    
638                    if (mdrRuleGroupInstance == null) {
639                            StringBundler msg = new StringBundler(6);
640    
641                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
642    
643                            msg.append("uuid=");
644                            msg.append(uuid);
645    
646                            msg.append(", groupId=");
647                            msg.append(groupId);
648    
649                            msg.append(StringPool.CLOSE_CURLY_BRACE);
650    
651                            if (_log.isWarnEnabled()) {
652                                    _log.warn(msg.toString());
653                            }
654    
655                            throw new NoSuchRuleGroupInstanceException(msg.toString());
656                    }
657    
658                    return mdrRuleGroupInstance;
659            }
660    
661            /**
662             * 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.
663             *
664             * @param uuid the uuid
665             * @param groupId the group ID
666             * @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
667             * @throws SystemException if a system exception occurred
668             */
669            public MDRRuleGroupInstance fetchByUUID_G(String uuid, long groupId)
670                    throws SystemException {
671                    return fetchByUUID_G(uuid, groupId, true);
672            }
673    
674            /**
675             * 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.
676             *
677             * @param uuid the uuid
678             * @param groupId the group ID
679             * @param retrieveFromCache whether to use the finder cache
680             * @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
681             * @throws SystemException if a system exception occurred
682             */
683            public MDRRuleGroupInstance fetchByUUID_G(String uuid, long groupId,
684                    boolean retrieveFromCache) throws SystemException {
685                    Object[] finderArgs = new Object[] { uuid, groupId };
686    
687                    Object result = null;
688    
689                    if (retrieveFromCache) {
690                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
691                                            finderArgs, this);
692                    }
693    
694                    if (result instanceof MDRRuleGroupInstance) {
695                            MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)result;
696    
697                            if (!Validator.equals(uuid, mdrRuleGroupInstance.getUuid()) ||
698                                            (groupId != mdrRuleGroupInstance.getGroupId())) {
699                                    result = null;
700                            }
701                    }
702    
703                    if (result == null) {
704                            StringBundler query = new StringBundler(4);
705    
706                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
707    
708                            boolean bindUuid = false;
709    
710                            if (uuid == null) {
711                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
712                            }
713                            else if (uuid.equals(StringPool.BLANK)) {
714                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
715                            }
716                            else {
717                                    bindUuid = true;
718    
719                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
720                            }
721    
722                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
723    
724                            String sql = query.toString();
725    
726                            Session session = null;
727    
728                            try {
729                                    session = openSession();
730    
731                                    Query q = session.createQuery(sql);
732    
733                                    QueryPos qPos = QueryPos.getInstance(q);
734    
735                                    if (bindUuid) {
736                                            qPos.add(uuid);
737                                    }
738    
739                                    qPos.add(groupId);
740    
741                                    List<MDRRuleGroupInstance> list = q.list();
742    
743                                    if (list.isEmpty()) {
744                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
745                                                    finderArgs, list);
746                                    }
747                                    else {
748                                            MDRRuleGroupInstance mdrRuleGroupInstance = list.get(0);
749    
750                                            result = mdrRuleGroupInstance;
751    
752                                            cacheResult(mdrRuleGroupInstance);
753    
754                                            if ((mdrRuleGroupInstance.getUuid() == null) ||
755                                                            !mdrRuleGroupInstance.getUuid().equals(uuid) ||
756                                                            (mdrRuleGroupInstance.getGroupId() != groupId)) {
757                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
758                                                            finderArgs, mdrRuleGroupInstance);
759                                            }
760                                    }
761                            }
762                            catch (Exception e) {
763                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
764                                            finderArgs);
765    
766                                    throw processException(e);
767                            }
768                            finally {
769                                    closeSession(session);
770                            }
771                    }
772    
773                    if (result instanceof List<?>) {
774                            return null;
775                    }
776                    else {
777                            return (MDRRuleGroupInstance)result;
778                    }
779            }
780    
781            /**
782             * Removes the m d r rule group instance where uuid = &#63; and groupId = &#63; from the database.
783             *
784             * @param uuid the uuid
785             * @param groupId the group ID
786             * @return the m d r rule group instance that was removed
787             * @throws SystemException if a system exception occurred
788             */
789            public MDRRuleGroupInstance removeByUUID_G(String uuid, long groupId)
790                    throws NoSuchRuleGroupInstanceException, SystemException {
791                    MDRRuleGroupInstance mdrRuleGroupInstance = findByUUID_G(uuid, groupId);
792    
793                    return remove(mdrRuleGroupInstance);
794            }
795    
796            /**
797             * Returns the number of m d r rule group instances where uuid = &#63; and groupId = &#63;.
798             *
799             * @param uuid the uuid
800             * @param groupId the group ID
801             * @return the number of matching m d r rule group instances
802             * @throws SystemException if a system exception occurred
803             */
804            public int countByUUID_G(String uuid, long groupId)
805                    throws SystemException {
806                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
807    
808                    Object[] finderArgs = new Object[] { uuid, groupId };
809    
810                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
811                                    this);
812    
813                    if (count == null) {
814                            StringBundler query = new StringBundler(3);
815    
816                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
817    
818                            boolean bindUuid = false;
819    
820                            if (uuid == null) {
821                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
822                            }
823                            else if (uuid.equals(StringPool.BLANK)) {
824                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
825                            }
826                            else {
827                                    bindUuid = true;
828    
829                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
830                            }
831    
832                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
833    
834                            String sql = query.toString();
835    
836                            Session session = null;
837    
838                            try {
839                                    session = openSession();
840    
841                                    Query q = session.createQuery(sql);
842    
843                                    QueryPos qPos = QueryPos.getInstance(q);
844    
845                                    if (bindUuid) {
846                                            qPos.add(uuid);
847                                    }
848    
849                                    qPos.add(groupId);
850    
851                                    count = (Long)q.uniqueResult();
852    
853                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
854                            }
855                            catch (Exception e) {
856                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
857    
858                                    throw processException(e);
859                            }
860                            finally {
861                                    closeSession(session);
862                            }
863                    }
864    
865                    return count.intValue();
866            }
867    
868            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mdrRuleGroupInstance.uuid IS NULL AND ";
869            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrRuleGroupInstance.uuid = ? AND ";
870            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrRuleGroupInstance.uuid IS NULL OR mdrRuleGroupInstance.uuid = '') AND ";
871            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrRuleGroupInstance.groupId = ?";
872            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
873                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
874                            MDRRuleGroupInstanceImpl.class,
875                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
876                            new String[] {
877                                    String.class.getName(), Long.class.getName(),
878                                    
879                            Integer.class.getName(), Integer.class.getName(),
880                                    OrderByComparator.class.getName()
881                            });
882            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
883                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
884                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
885                            MDRRuleGroupInstanceImpl.class,
886                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
887                            new String[] { String.class.getName(), Long.class.getName() },
888                            MDRRuleGroupInstanceModelImpl.UUID_COLUMN_BITMASK |
889                            MDRRuleGroupInstanceModelImpl.COMPANYID_COLUMN_BITMASK);
890            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
891                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
892                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
893                            new String[] { String.class.getName(), Long.class.getName() });
894    
895            /**
896             * Returns all the m d r rule group instances where uuid = &#63; and companyId = &#63;.
897             *
898             * @param uuid the uuid
899             * @param companyId the company ID
900             * @return the matching m d r rule group instances
901             * @throws SystemException if a system exception occurred
902             */
903            public List<MDRRuleGroupInstance> findByUuid_C(String uuid, long companyId)
904                    throws SystemException {
905                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
906                            QueryUtil.ALL_POS, null);
907            }
908    
909            /**
910             * Returns a range of all the m d r rule group instances where uuid = &#63; and companyId = &#63;.
911             *
912             * <p>
913             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
914             * </p>
915             *
916             * @param uuid the uuid
917             * @param companyId the company ID
918             * @param start the lower bound of the range of m d r rule group instances
919             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
920             * @return the range of matching m d r rule group instances
921             * @throws SystemException if a system exception occurred
922             */
923            public List<MDRRuleGroupInstance> findByUuid_C(String uuid, long companyId,
924                    int start, int end) throws SystemException {
925                    return findByUuid_C(uuid, companyId, start, end, null);
926            }
927    
928            /**
929             * Returns an ordered range of all the m d r rule group instances where uuid = &#63; and companyId = &#63;.
930             *
931             * <p>
932             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
933             * </p>
934             *
935             * @param uuid the uuid
936             * @param companyId the company ID
937             * @param start the lower bound of the range of m d r rule group instances
938             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
939             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
940             * @return the ordered range of matching m d r rule group instances
941             * @throws SystemException if a system exception occurred
942             */
943            public List<MDRRuleGroupInstance> findByUuid_C(String uuid, long companyId,
944                    int start, int end, OrderByComparator orderByComparator)
945                    throws SystemException {
946                    boolean pagination = true;
947                    FinderPath finderPath = null;
948                    Object[] finderArgs = null;
949    
950                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
951                                    (orderByComparator == null)) {
952                            pagination = false;
953                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
954                            finderArgs = new Object[] { uuid, companyId };
955                    }
956                    else {
957                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
958                            finderArgs = new Object[] {
959                                            uuid, companyId,
960                                            
961                                            start, end, orderByComparator
962                                    };
963                    }
964    
965                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
966                                    finderArgs, this);
967    
968                    if ((list != null) && !list.isEmpty()) {
969                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
970                                    if (!Validator.equals(uuid, mdrRuleGroupInstance.getUuid()) ||
971                                                    (companyId != mdrRuleGroupInstance.getCompanyId())) {
972                                            list = null;
973    
974                                            break;
975                                    }
976                            }
977                    }
978    
979                    if (list == null) {
980                            StringBundler query = null;
981    
982                            if (orderByComparator != null) {
983                                    query = new StringBundler(4 +
984                                                    (orderByComparator.getOrderByFields().length * 3));
985                            }
986                            else {
987                                    query = new StringBundler(4);
988                            }
989    
990                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
991    
992                            boolean bindUuid = false;
993    
994                            if (uuid == null) {
995                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
996                            }
997                            else if (uuid.equals(StringPool.BLANK)) {
998                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
999                            }
1000                            else {
1001                                    bindUuid = true;
1002    
1003                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1004                            }
1005    
1006                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1007    
1008                            if (orderByComparator != null) {
1009                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1010                                            orderByComparator);
1011                            }
1012                            else
1013                             if (pagination) {
1014                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1015                            }
1016    
1017                            String sql = query.toString();
1018    
1019                            Session session = null;
1020    
1021                            try {
1022                                    session = openSession();
1023    
1024                                    Query q = session.createQuery(sql);
1025    
1026                                    QueryPos qPos = QueryPos.getInstance(q);
1027    
1028                                    if (bindUuid) {
1029                                            qPos.add(uuid);
1030                                    }
1031    
1032                                    qPos.add(companyId);
1033    
1034                                    if (!pagination) {
1035                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1036                                                            getDialect(), start, end, false);
1037    
1038                                            Collections.sort(list);
1039    
1040                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
1041                                    }
1042                                    else {
1043                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1044                                                            getDialect(), start, end);
1045                                    }
1046    
1047                                    cacheResult(list);
1048    
1049                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1050                            }
1051                            catch (Exception e) {
1052                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1053    
1054                                    throw processException(e);
1055                            }
1056                            finally {
1057                                    closeSession(session);
1058                            }
1059                    }
1060    
1061                    return list;
1062            }
1063    
1064            /**
1065             * Returns the first m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1066             *
1067             * @param uuid the uuid
1068             * @param companyId the company ID
1069             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1070             * @return the first matching m d r rule group instance
1071             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1072             * @throws SystemException if a system exception occurred
1073             */
1074            public MDRRuleGroupInstance findByUuid_C_First(String uuid, long companyId,
1075                    OrderByComparator orderByComparator)
1076                    throws NoSuchRuleGroupInstanceException, SystemException {
1077                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUuid_C_First(uuid,
1078                                    companyId, orderByComparator);
1079    
1080                    if (mdrRuleGroupInstance != null) {
1081                            return mdrRuleGroupInstance;
1082                    }
1083    
1084                    StringBundler msg = new StringBundler(6);
1085    
1086                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1087    
1088                    msg.append("uuid=");
1089                    msg.append(uuid);
1090    
1091                    msg.append(", companyId=");
1092                    msg.append(companyId);
1093    
1094                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1095    
1096                    throw new NoSuchRuleGroupInstanceException(msg.toString());
1097            }
1098    
1099            /**
1100             * Returns the first m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1101             *
1102             * @param uuid the uuid
1103             * @param companyId the company ID
1104             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1105             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1106             * @throws SystemException if a system exception occurred
1107             */
1108            public MDRRuleGroupInstance fetchByUuid_C_First(String uuid,
1109                    long companyId, OrderByComparator orderByComparator)
1110                    throws SystemException {
1111                    List<MDRRuleGroupInstance> list = findByUuid_C(uuid, companyId, 0, 1,
1112                                    orderByComparator);
1113    
1114                    if (!list.isEmpty()) {
1115                            return list.get(0);
1116                    }
1117    
1118                    return null;
1119            }
1120    
1121            /**
1122             * Returns the last m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1123             *
1124             * @param uuid the uuid
1125             * @param companyId the company ID
1126             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1127             * @return the last matching m d r rule group instance
1128             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1129             * @throws SystemException if a system exception occurred
1130             */
1131            public MDRRuleGroupInstance findByUuid_C_Last(String uuid, long companyId,
1132                    OrderByComparator orderByComparator)
1133                    throws NoSuchRuleGroupInstanceException, SystemException {
1134                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUuid_C_Last(uuid,
1135                                    companyId, orderByComparator);
1136    
1137                    if (mdrRuleGroupInstance != null) {
1138                            return mdrRuleGroupInstance;
1139                    }
1140    
1141                    StringBundler msg = new StringBundler(6);
1142    
1143                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1144    
1145                    msg.append("uuid=");
1146                    msg.append(uuid);
1147    
1148                    msg.append(", companyId=");
1149                    msg.append(companyId);
1150    
1151                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1152    
1153                    throw new NoSuchRuleGroupInstanceException(msg.toString());
1154            }
1155    
1156            /**
1157             * Returns the last m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1158             *
1159             * @param uuid the uuid
1160             * @param companyId the company ID
1161             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1162             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1163             * @throws SystemException if a system exception occurred
1164             */
1165            public MDRRuleGroupInstance fetchByUuid_C_Last(String uuid, long companyId,
1166                    OrderByComparator orderByComparator) throws SystemException {
1167                    int count = countByUuid_C(uuid, companyId);
1168    
1169                    List<MDRRuleGroupInstance> list = findByUuid_C(uuid, companyId,
1170                                    count - 1, count, orderByComparator);
1171    
1172                    if (!list.isEmpty()) {
1173                            return list.get(0);
1174                    }
1175    
1176                    return null;
1177            }
1178    
1179            /**
1180             * 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; and companyId = &#63;.
1181             *
1182             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
1183             * @param uuid the uuid
1184             * @param companyId the company ID
1185             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1186             * @return the previous, current, and next m d r rule group instance
1187             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
1188             * @throws SystemException if a system exception occurred
1189             */
1190            public MDRRuleGroupInstance[] findByUuid_C_PrevAndNext(
1191                    long ruleGroupInstanceId, String uuid, long companyId,
1192                    OrderByComparator orderByComparator)
1193                    throws NoSuchRuleGroupInstanceException, SystemException {
1194                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
1195    
1196                    Session session = null;
1197    
1198                    try {
1199                            session = openSession();
1200    
1201                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
1202    
1203                            array[0] = getByUuid_C_PrevAndNext(session, mdrRuleGroupInstance,
1204                                            uuid, companyId, orderByComparator, true);
1205    
1206                            array[1] = mdrRuleGroupInstance;
1207    
1208                            array[2] = getByUuid_C_PrevAndNext(session, mdrRuleGroupInstance,
1209                                            uuid, companyId, orderByComparator, false);
1210    
1211                            return array;
1212                    }
1213                    catch (Exception e) {
1214                            throw processException(e);
1215                    }
1216                    finally {
1217                            closeSession(session);
1218                    }
1219            }
1220    
1221            protected MDRRuleGroupInstance getByUuid_C_PrevAndNext(Session session,
1222                    MDRRuleGroupInstance mdrRuleGroupInstance, String uuid, long companyId,
1223                    OrderByComparator orderByComparator, boolean previous) {
1224                    StringBundler query = null;
1225    
1226                    if (orderByComparator != null) {
1227                            query = new StringBundler(6 +
1228                                            (orderByComparator.getOrderByFields().length * 6));
1229                    }
1230                    else {
1231                            query = new StringBundler(3);
1232                    }
1233    
1234                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1235    
1236                    boolean bindUuid = false;
1237    
1238                    if (uuid == null) {
1239                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1240                    }
1241                    else if (uuid.equals(StringPool.BLANK)) {
1242                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1243                    }
1244                    else {
1245                            bindUuid = true;
1246    
1247                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1248                    }
1249    
1250                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1251    
1252                    if (orderByComparator != null) {
1253                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1254    
1255                            if (orderByConditionFields.length > 0) {
1256                                    query.append(WHERE_AND);
1257                            }
1258    
1259                            for (int i = 0; i < orderByConditionFields.length; i++) {
1260                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1261                                    query.append(orderByConditionFields[i]);
1262    
1263                                    if ((i + 1) < orderByConditionFields.length) {
1264                                            if (orderByComparator.isAscending() ^ previous) {
1265                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1266                                            }
1267                                            else {
1268                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1269                                            }
1270                                    }
1271                                    else {
1272                                            if (orderByComparator.isAscending() ^ previous) {
1273                                                    query.append(WHERE_GREATER_THAN);
1274                                            }
1275                                            else {
1276                                                    query.append(WHERE_LESSER_THAN);
1277                                            }
1278                                    }
1279                            }
1280    
1281                            query.append(ORDER_BY_CLAUSE);
1282    
1283                            String[] orderByFields = orderByComparator.getOrderByFields();
1284    
1285                            for (int i = 0; i < orderByFields.length; i++) {
1286                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1287                                    query.append(orderByFields[i]);
1288    
1289                                    if ((i + 1) < orderByFields.length) {
1290                                            if (orderByComparator.isAscending() ^ previous) {
1291                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1292                                            }
1293                                            else {
1294                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1295                                            }
1296                                    }
1297                                    else {
1298                                            if (orderByComparator.isAscending() ^ previous) {
1299                                                    query.append(ORDER_BY_ASC);
1300                                            }
1301                                            else {
1302                                                    query.append(ORDER_BY_DESC);
1303                                            }
1304                                    }
1305                            }
1306                    }
1307                    else {
1308                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1309                    }
1310    
1311                    String sql = query.toString();
1312    
1313                    Query q = session.createQuery(sql);
1314    
1315                    q.setFirstResult(0);
1316                    q.setMaxResults(2);
1317    
1318                    QueryPos qPos = QueryPos.getInstance(q);
1319    
1320                    if (bindUuid) {
1321                            qPos.add(uuid);
1322                    }
1323    
1324                    qPos.add(companyId);
1325    
1326                    if (orderByComparator != null) {
1327                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
1328    
1329                            for (Object value : values) {
1330                                    qPos.add(value);
1331                            }
1332                    }
1333    
1334                    List<MDRRuleGroupInstance> list = q.list();
1335    
1336                    if (list.size() == 2) {
1337                            return list.get(1);
1338                    }
1339                    else {
1340                            return null;
1341                    }
1342            }
1343    
1344            /**
1345             * Removes all the m d r rule group instances where uuid = &#63; and companyId = &#63; from the database.
1346             *
1347             * @param uuid the uuid
1348             * @param companyId the company ID
1349             * @throws SystemException if a system exception occurred
1350             */
1351            public void removeByUuid_C(String uuid, long companyId)
1352                    throws SystemException {
1353                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByUuid_C(uuid,
1354                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1355                            remove(mdrRuleGroupInstance);
1356                    }
1357            }
1358    
1359            /**
1360             * Returns the number of m d r rule group instances where uuid = &#63; and companyId = &#63;.
1361             *
1362             * @param uuid the uuid
1363             * @param companyId the company ID
1364             * @return the number of matching m d r rule group instances
1365             * @throws SystemException if a system exception occurred
1366             */
1367            public int countByUuid_C(String uuid, long companyId)
1368                    throws SystemException {
1369                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1370    
1371                    Object[] finderArgs = new Object[] { uuid, companyId };
1372    
1373                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1374                                    this);
1375    
1376                    if (count == null) {
1377                            StringBundler query = new StringBundler(3);
1378    
1379                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
1380    
1381                            boolean bindUuid = false;
1382    
1383                            if (uuid == null) {
1384                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1385                            }
1386                            else if (uuid.equals(StringPool.BLANK)) {
1387                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1388                            }
1389                            else {
1390                                    bindUuid = true;
1391    
1392                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1393                            }
1394    
1395                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1396    
1397                            String sql = query.toString();
1398    
1399                            Session session = null;
1400    
1401                            try {
1402                                    session = openSession();
1403    
1404                                    Query q = session.createQuery(sql);
1405    
1406                                    QueryPos qPos = QueryPos.getInstance(q);
1407    
1408                                    if (bindUuid) {
1409                                            qPos.add(uuid);
1410                                    }
1411    
1412                                    qPos.add(companyId);
1413    
1414                                    count = (Long)q.uniqueResult();
1415    
1416                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1417                            }
1418                            catch (Exception e) {
1419                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1420    
1421                                    throw processException(e);
1422                            }
1423                            finally {
1424                                    closeSession(session);
1425                            }
1426                    }
1427    
1428                    return count.intValue();
1429            }
1430    
1431            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mdrRuleGroupInstance.uuid IS NULL AND ";
1432            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mdrRuleGroupInstance.uuid = ? AND ";
1433            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mdrRuleGroupInstance.uuid IS NULL OR mdrRuleGroupInstance.uuid = '') AND ";
1434            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mdrRuleGroupInstance.companyId = ?";
1435            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
1436                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
1437                            MDRRuleGroupInstanceImpl.class,
1438                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1439                            new String[] {
1440                                    Long.class.getName(),
1441                                    
1442                            Integer.class.getName(), Integer.class.getName(),
1443                                    OrderByComparator.class.getName()
1444                            });
1445            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1446                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
1447                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
1448                            MDRRuleGroupInstanceImpl.class,
1449                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1450                            new String[] { Long.class.getName() },
1451                            MDRRuleGroupInstanceModelImpl.GROUPID_COLUMN_BITMASK);
1452            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
1453                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
1454                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1455                            new String[] { Long.class.getName() });
1456    
1457            /**
1458             * Returns all the m d r rule group instances where groupId = &#63;.
1459             *
1460             * @param groupId the group ID
1461             * @return the matching m d r rule group instances
1462             * @throws SystemException if a system exception occurred
1463             */
1464            public List<MDRRuleGroupInstance> findByGroupId(long groupId)
1465                    throws SystemException {
1466                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1467            }
1468    
1469            /**
1470             * Returns a range of all the m d r rule group instances where groupId = &#63;.
1471             *
1472             * <p>
1473             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1474             * </p>
1475             *
1476             * @param groupId the group ID
1477             * @param start the lower bound of the range of m d r rule group instances
1478             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1479             * @return the range of matching m d r rule group instances
1480             * @throws SystemException if a system exception occurred
1481             */
1482            public List<MDRRuleGroupInstance> findByGroupId(long groupId, int start,
1483                    int end) throws SystemException {
1484                    return findByGroupId(groupId, start, end, null);
1485            }
1486    
1487            /**
1488             * Returns an ordered range of all the m d r rule group instances where groupId = &#63;.
1489             *
1490             * <p>
1491             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1492             * </p>
1493             *
1494             * @param groupId the group ID
1495             * @param start the lower bound of the range of m d r rule group instances
1496             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1497             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1498             * @return the ordered range of matching m d r rule group instances
1499             * @throws SystemException if a system exception occurred
1500             */
1501            public List<MDRRuleGroupInstance> findByGroupId(long groupId, int start,
1502                    int end, OrderByComparator orderByComparator) throws SystemException {
1503                    boolean pagination = true;
1504                    FinderPath finderPath = null;
1505                    Object[] finderArgs = null;
1506    
1507                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1508                                    (orderByComparator == null)) {
1509                            pagination = false;
1510                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1511                            finderArgs = new Object[] { groupId };
1512                    }
1513                    else {
1514                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1515                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1516                    }
1517    
1518                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
1519                                    finderArgs, this);
1520    
1521                    if ((list != null) && !list.isEmpty()) {
1522                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
1523                                    if ((groupId != mdrRuleGroupInstance.getGroupId())) {
1524                                            list = null;
1525    
1526                                            break;
1527                                    }
1528                            }
1529                    }
1530    
1531                    if (list == null) {
1532                            StringBundler query = null;
1533    
1534                            if (orderByComparator != null) {
1535                                    query = new StringBundler(3 +
1536                                                    (orderByComparator.getOrderByFields().length * 3));
1537                            }
1538                            else {
1539                                    query = new StringBundler(3);
1540                            }
1541    
1542                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1543    
1544                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1545    
1546                            if (orderByComparator != null) {
1547                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1548                                            orderByComparator);
1549                            }
1550                            else
1551                             if (pagination) {
1552                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1553                            }
1554    
1555                            String sql = query.toString();
1556    
1557                            Session session = null;
1558    
1559                            try {
1560                                    session = openSession();
1561    
1562                                    Query q = session.createQuery(sql);
1563    
1564                                    QueryPos qPos = QueryPos.getInstance(q);
1565    
1566                                    qPos.add(groupId);
1567    
1568                                    if (!pagination) {
1569                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1570                                                            getDialect(), start, end, false);
1571    
1572                                            Collections.sort(list);
1573    
1574                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
1575                                    }
1576                                    else {
1577                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1578                                                            getDialect(), start, end);
1579                                    }
1580    
1581                                    cacheResult(list);
1582    
1583                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1584                            }
1585                            catch (Exception e) {
1586                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1587    
1588                                    throw processException(e);
1589                            }
1590                            finally {
1591                                    closeSession(session);
1592                            }
1593                    }
1594    
1595                    return list;
1596            }
1597    
1598            /**
1599             * Returns the first m d r rule group instance in the ordered set where groupId = &#63;.
1600             *
1601             * @param groupId the group ID
1602             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1603             * @return the first matching m d r rule group instance
1604             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1605             * @throws SystemException if a system exception occurred
1606             */
1607            public MDRRuleGroupInstance findByGroupId_First(long groupId,
1608                    OrderByComparator orderByComparator)
1609                    throws NoSuchRuleGroupInstanceException, SystemException {
1610                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByGroupId_First(groupId,
1611                                    orderByComparator);
1612    
1613                    if (mdrRuleGroupInstance != null) {
1614                            return mdrRuleGroupInstance;
1615                    }
1616    
1617                    StringBundler msg = new StringBundler(4);
1618    
1619                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1620    
1621                    msg.append("groupId=");
1622                    msg.append(groupId);
1623    
1624                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1625    
1626                    throw new NoSuchRuleGroupInstanceException(msg.toString());
1627            }
1628    
1629            /**
1630             * Returns the first m d r rule group instance in the ordered set where groupId = &#63;.
1631             *
1632             * @param groupId the group ID
1633             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1634             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1635             * @throws SystemException if a system exception occurred
1636             */
1637            public MDRRuleGroupInstance fetchByGroupId_First(long groupId,
1638                    OrderByComparator orderByComparator) throws SystemException {
1639                    List<MDRRuleGroupInstance> list = findByGroupId(groupId, 0, 1,
1640                                    orderByComparator);
1641    
1642                    if (!list.isEmpty()) {
1643                            return list.get(0);
1644                    }
1645    
1646                    return null;
1647            }
1648    
1649            /**
1650             * Returns the last m d r rule group instance in the ordered set where groupId = &#63;.
1651             *
1652             * @param groupId the group ID
1653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1654             * @return the last matching m d r rule group instance
1655             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1656             * @throws SystemException if a system exception occurred
1657             */
1658            public MDRRuleGroupInstance findByGroupId_Last(long groupId,
1659                    OrderByComparator orderByComparator)
1660                    throws NoSuchRuleGroupInstanceException, SystemException {
1661                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByGroupId_Last(groupId,
1662                                    orderByComparator);
1663    
1664                    if (mdrRuleGroupInstance != null) {
1665                            return mdrRuleGroupInstance;
1666                    }
1667    
1668                    StringBundler msg = new StringBundler(4);
1669    
1670                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1671    
1672                    msg.append("groupId=");
1673                    msg.append(groupId);
1674    
1675                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1676    
1677                    throw new NoSuchRuleGroupInstanceException(msg.toString());
1678            }
1679    
1680            /**
1681             * Returns the last m d r rule group instance in the ordered set where groupId = &#63;.
1682             *
1683             * @param groupId the group ID
1684             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1685             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1686             * @throws SystemException if a system exception occurred
1687             */
1688            public MDRRuleGroupInstance fetchByGroupId_Last(long groupId,
1689                    OrderByComparator orderByComparator) throws SystemException {
1690                    int count = countByGroupId(groupId);
1691    
1692                    List<MDRRuleGroupInstance> list = findByGroupId(groupId, count - 1,
1693                                    count, orderByComparator);
1694    
1695                    if (!list.isEmpty()) {
1696                            return list.get(0);
1697                    }
1698    
1699                    return null;
1700            }
1701    
1702            /**
1703             * 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;.
1704             *
1705             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
1706             * @param groupId the group ID
1707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1708             * @return the previous, current, and next m d r rule group instance
1709             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
1710             * @throws SystemException if a system exception occurred
1711             */
1712            public MDRRuleGroupInstance[] findByGroupId_PrevAndNext(
1713                    long ruleGroupInstanceId, long groupId,
1714                    OrderByComparator orderByComparator)
1715                    throws NoSuchRuleGroupInstanceException, SystemException {
1716                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
1717    
1718                    Session session = null;
1719    
1720                    try {
1721                            session = openSession();
1722    
1723                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
1724    
1725                            array[0] = getByGroupId_PrevAndNext(session, mdrRuleGroupInstance,
1726                                            groupId, orderByComparator, true);
1727    
1728                            array[1] = mdrRuleGroupInstance;
1729    
1730                            array[2] = getByGroupId_PrevAndNext(session, mdrRuleGroupInstance,
1731                                            groupId, orderByComparator, false);
1732    
1733                            return array;
1734                    }
1735                    catch (Exception e) {
1736                            throw processException(e);
1737                    }
1738                    finally {
1739                            closeSession(session);
1740                    }
1741            }
1742    
1743            protected MDRRuleGroupInstance getByGroupId_PrevAndNext(Session session,
1744                    MDRRuleGroupInstance mdrRuleGroupInstance, long groupId,
1745                    OrderByComparator orderByComparator, boolean previous) {
1746                    StringBundler query = null;
1747    
1748                    if (orderByComparator != null) {
1749                            query = new StringBundler(6 +
1750                                            (orderByComparator.getOrderByFields().length * 6));
1751                    }
1752                    else {
1753                            query = new StringBundler(3);
1754                    }
1755    
1756                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1757    
1758                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1759    
1760                    if (orderByComparator != null) {
1761                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1762    
1763                            if (orderByConditionFields.length > 0) {
1764                                    query.append(WHERE_AND);
1765                            }
1766    
1767                            for (int i = 0; i < orderByConditionFields.length; i++) {
1768                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1769                                    query.append(orderByConditionFields[i]);
1770    
1771                                    if ((i + 1) < orderByConditionFields.length) {
1772                                            if (orderByComparator.isAscending() ^ previous) {
1773                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1774                                            }
1775                                            else {
1776                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1777                                            }
1778                                    }
1779                                    else {
1780                                            if (orderByComparator.isAscending() ^ previous) {
1781                                                    query.append(WHERE_GREATER_THAN);
1782                                            }
1783                                            else {
1784                                                    query.append(WHERE_LESSER_THAN);
1785                                            }
1786                                    }
1787                            }
1788    
1789                            query.append(ORDER_BY_CLAUSE);
1790    
1791                            String[] orderByFields = orderByComparator.getOrderByFields();
1792    
1793                            for (int i = 0; i < orderByFields.length; i++) {
1794                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1795                                    query.append(orderByFields[i]);
1796    
1797                                    if ((i + 1) < orderByFields.length) {
1798                                            if (orderByComparator.isAscending() ^ previous) {
1799                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1800                                            }
1801                                            else {
1802                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1803                                            }
1804                                    }
1805                                    else {
1806                                            if (orderByComparator.isAscending() ^ previous) {
1807                                                    query.append(ORDER_BY_ASC);
1808                                            }
1809                                            else {
1810                                                    query.append(ORDER_BY_DESC);
1811                                            }
1812                                    }
1813                            }
1814                    }
1815                    else {
1816                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1817                    }
1818    
1819                    String sql = query.toString();
1820    
1821                    Query q = session.createQuery(sql);
1822    
1823                    q.setFirstResult(0);
1824                    q.setMaxResults(2);
1825    
1826                    QueryPos qPos = QueryPos.getInstance(q);
1827    
1828                    qPos.add(groupId);
1829    
1830                    if (orderByComparator != null) {
1831                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
1832    
1833                            for (Object value : values) {
1834                                    qPos.add(value);
1835                            }
1836                    }
1837    
1838                    List<MDRRuleGroupInstance> list = q.list();
1839    
1840                    if (list.size() == 2) {
1841                            return list.get(1);
1842                    }
1843                    else {
1844                            return null;
1845                    }
1846            }
1847    
1848            /**
1849             * Returns all the m d r rule group instances that the user has permission to view where groupId = &#63;.
1850             *
1851             * @param groupId the group ID
1852             * @return the matching m d r rule group instances that the user has permission to view
1853             * @throws SystemException if a system exception occurred
1854             */
1855            public List<MDRRuleGroupInstance> filterFindByGroupId(long groupId)
1856                    throws SystemException {
1857                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1858                            QueryUtil.ALL_POS, null);
1859            }
1860    
1861            /**
1862             * Returns a range of all the m d r rule group instances that the user has permission to view where groupId = &#63;.
1863             *
1864             * <p>
1865             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1866             * </p>
1867             *
1868             * @param groupId the group ID
1869             * @param start the lower bound of the range of m d r rule group instances
1870             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1871             * @return the range of matching m d r rule group instances that the user has permission to view
1872             * @throws SystemException if a system exception occurred
1873             */
1874            public List<MDRRuleGroupInstance> filterFindByGroupId(long groupId,
1875                    int start, int end) throws SystemException {
1876                    return filterFindByGroupId(groupId, start, end, null);
1877            }
1878    
1879            /**
1880             * Returns an ordered range of all the m d r rule group instances that the user has permissions to view where groupId = &#63;.
1881             *
1882             * <p>
1883             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1884             * </p>
1885             *
1886             * @param groupId the group ID
1887             * @param start the lower bound of the range of m d r rule group instances
1888             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1889             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1890             * @return the ordered range of matching m d r rule group instances that the user has permission to view
1891             * @throws SystemException if a system exception occurred
1892             */
1893            public List<MDRRuleGroupInstance> filterFindByGroupId(long groupId,
1894                    int start, int end, OrderByComparator orderByComparator)
1895                    throws SystemException {
1896                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1897                            return findByGroupId(groupId, start, end, orderByComparator);
1898                    }
1899    
1900                    StringBundler query = null;
1901    
1902                    if (orderByComparator != null) {
1903                            query = new StringBundler(3 +
1904                                            (orderByComparator.getOrderByFields().length * 3));
1905                    }
1906                    else {
1907                            query = new StringBundler(3);
1908                    }
1909    
1910                    if (getDB().isSupportsInlineDistinct()) {
1911                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1912                    }
1913                    else {
1914                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
1915                    }
1916    
1917                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1918    
1919                    if (!getDB().isSupportsInlineDistinct()) {
1920                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
1921                    }
1922    
1923                    if (orderByComparator != null) {
1924                            if (getDB().isSupportsInlineDistinct()) {
1925                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1926                                            orderByComparator, true);
1927                            }
1928                            else {
1929                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1930                                            orderByComparator, true);
1931                            }
1932                    }
1933                    else {
1934                            if (getDB().isSupportsInlineDistinct()) {
1935                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1936                            }
1937                            else {
1938                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_SQL);
1939                            }
1940                    }
1941    
1942                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1943                                    MDRRuleGroupInstance.class.getName(),
1944                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1945    
1946                    Session session = null;
1947    
1948                    try {
1949                            session = openSession();
1950    
1951                            SQLQuery q = session.createSQLQuery(sql);
1952    
1953                            if (getDB().isSupportsInlineDistinct()) {
1954                                    q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
1955                            }
1956                            else {
1957                                    q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
1958                            }
1959    
1960                            QueryPos qPos = QueryPos.getInstance(q);
1961    
1962                            qPos.add(groupId);
1963    
1964                            return (List<MDRRuleGroupInstance>)QueryUtil.list(q, getDialect(),
1965                                    start, end);
1966                    }
1967                    catch (Exception e) {
1968                            throw processException(e);
1969                    }
1970                    finally {
1971                            closeSession(session);
1972                    }
1973            }
1974    
1975            /**
1976             * 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;.
1977             *
1978             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
1979             * @param groupId the group ID
1980             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1981             * @return the previous, current, and next m d r rule group instance
1982             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
1983             * @throws SystemException if a system exception occurred
1984             */
1985            public MDRRuleGroupInstance[] filterFindByGroupId_PrevAndNext(
1986                    long ruleGroupInstanceId, long groupId,
1987                    OrderByComparator orderByComparator)
1988                    throws NoSuchRuleGroupInstanceException, SystemException {
1989                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1990                            return findByGroupId_PrevAndNext(ruleGroupInstanceId, groupId,
1991                                    orderByComparator);
1992                    }
1993    
1994                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
1995    
1996                    Session session = null;
1997    
1998                    try {
1999                            session = openSession();
2000    
2001                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
2002    
2003                            array[0] = filterGetByGroupId_PrevAndNext(session,
2004                                            mdrRuleGroupInstance, groupId, orderByComparator, true);
2005    
2006                            array[1] = mdrRuleGroupInstance;
2007    
2008                            array[2] = filterGetByGroupId_PrevAndNext(session,
2009                                            mdrRuleGroupInstance, groupId, orderByComparator, false);
2010    
2011                            return array;
2012                    }
2013                    catch (Exception e) {
2014                            throw processException(e);
2015                    }
2016                    finally {
2017                            closeSession(session);
2018                    }
2019            }
2020    
2021            protected MDRRuleGroupInstance filterGetByGroupId_PrevAndNext(
2022                    Session session, MDRRuleGroupInstance mdrRuleGroupInstance,
2023                    long groupId, OrderByComparator orderByComparator, boolean previous) {
2024                    StringBundler query = null;
2025    
2026                    if (orderByComparator != null) {
2027                            query = new StringBundler(6 +
2028                                            (orderByComparator.getOrderByFields().length * 6));
2029                    }
2030                    else {
2031                            query = new StringBundler(3);
2032                    }
2033    
2034                    if (getDB().isSupportsInlineDistinct()) {
2035                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2036                    }
2037                    else {
2038                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
2039                    }
2040    
2041                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2042    
2043                    if (!getDB().isSupportsInlineDistinct()) {
2044                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
2045                    }
2046    
2047                    if (orderByComparator != null) {
2048                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2049    
2050                            if (orderByConditionFields.length > 0) {
2051                                    query.append(WHERE_AND);
2052                            }
2053    
2054                            for (int i = 0; i < orderByConditionFields.length; i++) {
2055                                    if (getDB().isSupportsInlineDistinct()) {
2056                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2057                                    }
2058                                    else {
2059                                            query.append(_ORDER_BY_ENTITY_TABLE);
2060                                    }
2061    
2062                                    query.append(orderByConditionFields[i]);
2063    
2064                                    if ((i + 1) < orderByConditionFields.length) {
2065                                            if (orderByComparator.isAscending() ^ previous) {
2066                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2067                                            }
2068                                            else {
2069                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2070                                            }
2071                                    }
2072                                    else {
2073                                            if (orderByComparator.isAscending() ^ previous) {
2074                                                    query.append(WHERE_GREATER_THAN);
2075                                            }
2076                                            else {
2077                                                    query.append(WHERE_LESSER_THAN);
2078                                            }
2079                                    }
2080                            }
2081    
2082                            query.append(ORDER_BY_CLAUSE);
2083    
2084                            String[] orderByFields = orderByComparator.getOrderByFields();
2085    
2086                            for (int i = 0; i < orderByFields.length; i++) {
2087                                    if (getDB().isSupportsInlineDistinct()) {
2088                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2089                                    }
2090                                    else {
2091                                            query.append(_ORDER_BY_ENTITY_TABLE);
2092                                    }
2093    
2094                                    query.append(orderByFields[i]);
2095    
2096                                    if ((i + 1) < orderByFields.length) {
2097                                            if (orderByComparator.isAscending() ^ previous) {
2098                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2099                                            }
2100                                            else {
2101                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2102                                            }
2103                                    }
2104                                    else {
2105                                            if (orderByComparator.isAscending() ^ previous) {
2106                                                    query.append(ORDER_BY_ASC);
2107                                            }
2108                                            else {
2109                                                    query.append(ORDER_BY_DESC);
2110                                            }
2111                                    }
2112                            }
2113                    }
2114                    else {
2115                            if (getDB().isSupportsInlineDistinct()) {
2116                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
2117                            }
2118                            else {
2119                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_SQL);
2120                            }
2121                    }
2122    
2123                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2124                                    MDRRuleGroupInstance.class.getName(),
2125                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2126    
2127                    SQLQuery q = session.createSQLQuery(sql);
2128    
2129                    q.setFirstResult(0);
2130                    q.setMaxResults(2);
2131    
2132                    if (getDB().isSupportsInlineDistinct()) {
2133                            q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
2134                    }
2135                    else {
2136                            q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
2137                    }
2138    
2139                    QueryPos qPos = QueryPos.getInstance(q);
2140    
2141                    qPos.add(groupId);
2142    
2143                    if (orderByComparator != null) {
2144                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
2145    
2146                            for (Object value : values) {
2147                                    qPos.add(value);
2148                            }
2149                    }
2150    
2151                    List<MDRRuleGroupInstance> list = q.list();
2152    
2153                    if (list.size() == 2) {
2154                            return list.get(1);
2155                    }
2156                    else {
2157                            return null;
2158                    }
2159            }
2160    
2161            /**
2162             * Removes all the m d r rule group instances where groupId = &#63; from the database.
2163             *
2164             * @param groupId the group ID
2165             * @throws SystemException if a system exception occurred
2166             */
2167            public void removeByGroupId(long groupId) throws SystemException {
2168                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByGroupId(
2169                                    groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2170                            remove(mdrRuleGroupInstance);
2171                    }
2172            }
2173    
2174            /**
2175             * Returns the number of m d r rule group instances where groupId = &#63;.
2176             *
2177             * @param groupId the group ID
2178             * @return the number of matching m d r rule group instances
2179             * @throws SystemException if a system exception occurred
2180             */
2181            public int countByGroupId(long groupId) throws SystemException {
2182                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2183    
2184                    Object[] finderArgs = new Object[] { groupId };
2185    
2186                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2187                                    this);
2188    
2189                    if (count == null) {
2190                            StringBundler query = new StringBundler(2);
2191    
2192                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
2193    
2194                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2195    
2196                            String sql = query.toString();
2197    
2198                            Session session = null;
2199    
2200                            try {
2201                                    session = openSession();
2202    
2203                                    Query q = session.createQuery(sql);
2204    
2205                                    QueryPos qPos = QueryPos.getInstance(q);
2206    
2207                                    qPos.add(groupId);
2208    
2209                                    count = (Long)q.uniqueResult();
2210    
2211                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2212                            }
2213                            catch (Exception e) {
2214                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2215    
2216                                    throw processException(e);
2217                            }
2218                            finally {
2219                                    closeSession(session);
2220                            }
2221                    }
2222    
2223                    return count.intValue();
2224            }
2225    
2226            /**
2227             * Returns the number of m d r rule group instances that the user has permission to view where groupId = &#63;.
2228             *
2229             * @param groupId the group ID
2230             * @return the number of matching m d r rule group instances that the user has permission to view
2231             * @throws SystemException if a system exception occurred
2232             */
2233            public int filterCountByGroupId(long groupId) throws SystemException {
2234                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2235                            return countByGroupId(groupId);
2236                    }
2237    
2238                    StringBundler query = new StringBundler(2);
2239    
2240                    query.append(_FILTER_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
2241    
2242                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2243    
2244                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2245                                    MDRRuleGroupInstance.class.getName(),
2246                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2247    
2248                    Session session = null;
2249    
2250                    try {
2251                            session = openSession();
2252    
2253                            SQLQuery q = session.createSQLQuery(sql);
2254    
2255                            q.addScalar(COUNT_COLUMN_NAME,
2256                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2257    
2258                            QueryPos qPos = QueryPos.getInstance(q);
2259    
2260                            qPos.add(groupId);
2261    
2262                            Long count = (Long)q.uniqueResult();
2263    
2264                            return count.intValue();
2265                    }
2266                    catch (Exception e) {
2267                            throw processException(e);
2268                    }
2269                    finally {
2270                            closeSession(session);
2271                    }
2272            }
2273    
2274            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mdrRuleGroupInstance.groupId = ?";
2275            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID =
2276                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2277                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
2278                            MDRRuleGroupInstanceImpl.class,
2279                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRuleGroupId",
2280                            new String[] {
2281                                    Long.class.getName(),
2282                                    
2283                            Integer.class.getName(), Integer.class.getName(),
2284                                    OrderByComparator.class.getName()
2285                            });
2286            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID =
2287                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2288                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
2289                            MDRRuleGroupInstanceImpl.class,
2290                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRuleGroupId",
2291                            new String[] { Long.class.getName() },
2292                            MDRRuleGroupInstanceModelImpl.RULEGROUPID_COLUMN_BITMASK);
2293            public static final FinderPath FINDER_PATH_COUNT_BY_RULEGROUPID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2294                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
2295                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRuleGroupId",
2296                            new String[] { Long.class.getName() });
2297    
2298            /**
2299             * Returns all the m d r rule group instances where ruleGroupId = &#63;.
2300             *
2301             * @param ruleGroupId the rule group ID
2302             * @return the matching m d r rule group instances
2303             * @throws SystemException if a system exception occurred
2304             */
2305            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId)
2306                    throws SystemException {
2307                    return findByRuleGroupId(ruleGroupId, QueryUtil.ALL_POS,
2308                            QueryUtil.ALL_POS, null);
2309            }
2310    
2311            /**
2312             * Returns a range of all the m d r rule group instances where ruleGroupId = &#63;.
2313             *
2314             * <p>
2315             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2316             * </p>
2317             *
2318             * @param ruleGroupId the rule group ID
2319             * @param start the lower bound of the range of m d r rule group instances
2320             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2321             * @return the range of matching m d r rule group instances
2322             * @throws SystemException if a system exception occurred
2323             */
2324            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId,
2325                    int start, int end) throws SystemException {
2326                    return findByRuleGroupId(ruleGroupId, start, end, null);
2327            }
2328    
2329            /**
2330             * Returns an ordered range of all the m d r rule group instances where ruleGroupId = &#63;.
2331             *
2332             * <p>
2333             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2334             * </p>
2335             *
2336             * @param ruleGroupId the rule group ID
2337             * @param start the lower bound of the range of m d r rule group instances
2338             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2339             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2340             * @return the ordered range of matching m d r rule group instances
2341             * @throws SystemException if a system exception occurred
2342             */
2343            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId,
2344                    int start, int end, OrderByComparator orderByComparator)
2345                    throws SystemException {
2346                    boolean pagination = true;
2347                    FinderPath finderPath = null;
2348                    Object[] finderArgs = null;
2349    
2350                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2351                                    (orderByComparator == null)) {
2352                            pagination = false;
2353                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID;
2354                            finderArgs = new Object[] { ruleGroupId };
2355                    }
2356                    else {
2357                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID;
2358                            finderArgs = new Object[] { ruleGroupId, start, end, orderByComparator };
2359                    }
2360    
2361                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
2362                                    finderArgs, this);
2363    
2364                    if ((list != null) && !list.isEmpty()) {
2365                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
2366                                    if ((ruleGroupId != mdrRuleGroupInstance.getRuleGroupId())) {
2367                                            list = null;
2368    
2369                                            break;
2370                                    }
2371                            }
2372                    }
2373    
2374                    if (list == null) {
2375                            StringBundler query = null;
2376    
2377                            if (orderByComparator != null) {
2378                                    query = new StringBundler(3 +
2379                                                    (orderByComparator.getOrderByFields().length * 3));
2380                            }
2381                            else {
2382                                    query = new StringBundler(3);
2383                            }
2384    
2385                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2386    
2387                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
2388    
2389                            if (orderByComparator != null) {
2390                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2391                                            orderByComparator);
2392                            }
2393                            else
2394                             if (pagination) {
2395                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
2396                            }
2397    
2398                            String sql = query.toString();
2399    
2400                            Session session = null;
2401    
2402                            try {
2403                                    session = openSession();
2404    
2405                                    Query q = session.createQuery(sql);
2406    
2407                                    QueryPos qPos = QueryPos.getInstance(q);
2408    
2409                                    qPos.add(ruleGroupId);
2410    
2411                                    if (!pagination) {
2412                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2413                                                            getDialect(), start, end, false);
2414    
2415                                            Collections.sort(list);
2416    
2417                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
2418                                    }
2419                                    else {
2420                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2421                                                            getDialect(), start, end);
2422                                    }
2423    
2424                                    cacheResult(list);
2425    
2426                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2427                            }
2428                            catch (Exception e) {
2429                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2430    
2431                                    throw processException(e);
2432                            }
2433                            finally {
2434                                    closeSession(session);
2435                            }
2436                    }
2437    
2438                    return list;
2439            }
2440    
2441            /**
2442             * Returns the first m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2443             *
2444             * @param ruleGroupId the rule group ID
2445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2446             * @return the first matching m d r rule group instance
2447             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2448             * @throws SystemException if a system exception occurred
2449             */
2450            public MDRRuleGroupInstance findByRuleGroupId_First(long ruleGroupId,
2451                    OrderByComparator orderByComparator)
2452                    throws NoSuchRuleGroupInstanceException, SystemException {
2453                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByRuleGroupId_First(ruleGroupId,
2454                                    orderByComparator);
2455    
2456                    if (mdrRuleGroupInstance != null) {
2457                            return mdrRuleGroupInstance;
2458                    }
2459    
2460                    StringBundler msg = new StringBundler(4);
2461    
2462                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2463    
2464                    msg.append("ruleGroupId=");
2465                    msg.append(ruleGroupId);
2466    
2467                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2468    
2469                    throw new NoSuchRuleGroupInstanceException(msg.toString());
2470            }
2471    
2472            /**
2473             * Returns the first m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2474             *
2475             * @param ruleGroupId the rule group ID
2476             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2477             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
2478             * @throws SystemException if a system exception occurred
2479             */
2480            public MDRRuleGroupInstance fetchByRuleGroupId_First(long ruleGroupId,
2481                    OrderByComparator orderByComparator) throws SystemException {
2482                    List<MDRRuleGroupInstance> list = findByRuleGroupId(ruleGroupId, 0, 1,
2483                                    orderByComparator);
2484    
2485                    if (!list.isEmpty()) {
2486                            return list.get(0);
2487                    }
2488    
2489                    return null;
2490            }
2491    
2492            /**
2493             * Returns the last m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2494             *
2495             * @param ruleGroupId the rule group ID
2496             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2497             * @return the last matching m d r rule group instance
2498             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2499             * @throws SystemException if a system exception occurred
2500             */
2501            public MDRRuleGroupInstance findByRuleGroupId_Last(long ruleGroupId,
2502                    OrderByComparator orderByComparator)
2503                    throws NoSuchRuleGroupInstanceException, SystemException {
2504                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByRuleGroupId_Last(ruleGroupId,
2505                                    orderByComparator);
2506    
2507                    if (mdrRuleGroupInstance != null) {
2508                            return mdrRuleGroupInstance;
2509                    }
2510    
2511                    StringBundler msg = new StringBundler(4);
2512    
2513                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2514    
2515                    msg.append("ruleGroupId=");
2516                    msg.append(ruleGroupId);
2517    
2518                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2519    
2520                    throw new NoSuchRuleGroupInstanceException(msg.toString());
2521            }
2522    
2523            /**
2524             * Returns the last m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2525             *
2526             * @param ruleGroupId the rule group ID
2527             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2528             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
2529             * @throws SystemException if a system exception occurred
2530             */
2531            public MDRRuleGroupInstance fetchByRuleGroupId_Last(long ruleGroupId,
2532                    OrderByComparator orderByComparator) throws SystemException {
2533                    int count = countByRuleGroupId(ruleGroupId);
2534    
2535                    List<MDRRuleGroupInstance> list = findByRuleGroupId(ruleGroupId,
2536                                    count - 1, count, orderByComparator);
2537    
2538                    if (!list.isEmpty()) {
2539                            return list.get(0);
2540                    }
2541    
2542                    return null;
2543            }
2544    
2545            /**
2546             * 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;.
2547             *
2548             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
2549             * @param ruleGroupId the rule group ID
2550             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2551             * @return the previous, current, and next m d r rule group instance
2552             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
2553             * @throws SystemException if a system exception occurred
2554             */
2555            public MDRRuleGroupInstance[] findByRuleGroupId_PrevAndNext(
2556                    long ruleGroupInstanceId, long ruleGroupId,
2557                    OrderByComparator orderByComparator)
2558                    throws NoSuchRuleGroupInstanceException, SystemException {
2559                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
2560    
2561                    Session session = null;
2562    
2563                    try {
2564                            session = openSession();
2565    
2566                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
2567    
2568                            array[0] = getByRuleGroupId_PrevAndNext(session,
2569                                            mdrRuleGroupInstance, ruleGroupId, orderByComparator, true);
2570    
2571                            array[1] = mdrRuleGroupInstance;
2572    
2573                            array[2] = getByRuleGroupId_PrevAndNext(session,
2574                                            mdrRuleGroupInstance, ruleGroupId, orderByComparator, false);
2575    
2576                            return array;
2577                    }
2578                    catch (Exception e) {
2579                            throw processException(e);
2580                    }
2581                    finally {
2582                            closeSession(session);
2583                    }
2584            }
2585    
2586            protected MDRRuleGroupInstance getByRuleGroupId_PrevAndNext(
2587                    Session session, MDRRuleGroupInstance mdrRuleGroupInstance,
2588                    long ruleGroupId, OrderByComparator orderByComparator, boolean previous) {
2589                    StringBundler query = null;
2590    
2591                    if (orderByComparator != null) {
2592                            query = new StringBundler(6 +
2593                                            (orderByComparator.getOrderByFields().length * 6));
2594                    }
2595                    else {
2596                            query = new StringBundler(3);
2597                    }
2598    
2599                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2600    
2601                    query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
2602    
2603                    if (orderByComparator != null) {
2604                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2605    
2606                            if (orderByConditionFields.length > 0) {
2607                                    query.append(WHERE_AND);
2608                            }
2609    
2610                            for (int i = 0; i < orderByConditionFields.length; i++) {
2611                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2612                                    query.append(orderByConditionFields[i]);
2613    
2614                                    if ((i + 1) < orderByConditionFields.length) {
2615                                            if (orderByComparator.isAscending() ^ previous) {
2616                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2617                                            }
2618                                            else {
2619                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2620                                            }
2621                                    }
2622                                    else {
2623                                            if (orderByComparator.isAscending() ^ previous) {
2624                                                    query.append(WHERE_GREATER_THAN);
2625                                            }
2626                                            else {
2627                                                    query.append(WHERE_LESSER_THAN);
2628                                            }
2629                                    }
2630                            }
2631    
2632                            query.append(ORDER_BY_CLAUSE);
2633    
2634                            String[] orderByFields = orderByComparator.getOrderByFields();
2635    
2636                            for (int i = 0; i < orderByFields.length; i++) {
2637                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2638                                    query.append(orderByFields[i]);
2639    
2640                                    if ((i + 1) < orderByFields.length) {
2641                                            if (orderByComparator.isAscending() ^ previous) {
2642                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2643                                            }
2644                                            else {
2645                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2646                                            }
2647                                    }
2648                                    else {
2649                                            if (orderByComparator.isAscending() ^ previous) {
2650                                                    query.append(ORDER_BY_ASC);
2651                                            }
2652                                            else {
2653                                                    query.append(ORDER_BY_DESC);
2654                                            }
2655                                    }
2656                            }
2657                    }
2658                    else {
2659                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
2660                    }
2661    
2662                    String sql = query.toString();
2663    
2664                    Query q = session.createQuery(sql);
2665    
2666                    q.setFirstResult(0);
2667                    q.setMaxResults(2);
2668    
2669                    QueryPos qPos = QueryPos.getInstance(q);
2670    
2671                    qPos.add(ruleGroupId);
2672    
2673                    if (orderByComparator != null) {
2674                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
2675    
2676                            for (Object value : values) {
2677                                    qPos.add(value);
2678                            }
2679                    }
2680    
2681                    List<MDRRuleGroupInstance> list = q.list();
2682    
2683                    if (list.size() == 2) {
2684                            return list.get(1);
2685                    }
2686                    else {
2687                            return null;
2688                    }
2689            }
2690    
2691            /**
2692             * Removes all the m d r rule group instances where ruleGroupId = &#63; from the database.
2693             *
2694             * @param ruleGroupId the rule group ID
2695             * @throws SystemException if a system exception occurred
2696             */
2697            public void removeByRuleGroupId(long ruleGroupId) throws SystemException {
2698                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByRuleGroupId(
2699                                    ruleGroupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2700                            remove(mdrRuleGroupInstance);
2701                    }
2702            }
2703    
2704            /**
2705             * Returns the number of m d r rule group instances where ruleGroupId = &#63;.
2706             *
2707             * @param ruleGroupId the rule group ID
2708             * @return the number of matching m d r rule group instances
2709             * @throws SystemException if a system exception occurred
2710             */
2711            public int countByRuleGroupId(long ruleGroupId) throws SystemException {
2712                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RULEGROUPID;
2713    
2714                    Object[] finderArgs = new Object[] { ruleGroupId };
2715    
2716                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2717                                    this);
2718    
2719                    if (count == null) {
2720                            StringBundler query = new StringBundler(2);
2721    
2722                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
2723    
2724                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
2725    
2726                            String sql = query.toString();
2727    
2728                            Session session = null;
2729    
2730                            try {
2731                                    session = openSession();
2732    
2733                                    Query q = session.createQuery(sql);
2734    
2735                                    QueryPos qPos = QueryPos.getInstance(q);
2736    
2737                                    qPos.add(ruleGroupId);
2738    
2739                                    count = (Long)q.uniqueResult();
2740    
2741                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2742                            }
2743                            catch (Exception e) {
2744                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2745    
2746                                    throw processException(e);
2747                            }
2748                            finally {
2749                                    closeSession(session);
2750                            }
2751                    }
2752    
2753                    return count.intValue();
2754            }
2755    
2756            private static final String _FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2 = "mdrRuleGroupInstance.ruleGroupId = ?";
2757            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2758                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
2759                            MDRRuleGroupInstanceImpl.class,
2760                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
2761                            new String[] {
2762                                    Long.class.getName(), Long.class.getName(),
2763                                    
2764                            Integer.class.getName(), Integer.class.getName(),
2765                                    OrderByComparator.class.getName()
2766                            });
2767            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2768                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
2769                            MDRRuleGroupInstanceImpl.class,
2770                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
2771                            new String[] { Long.class.getName(), Long.class.getName() },
2772                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2773                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK);
2774            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2775                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
2776                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2777                            new String[] { Long.class.getName(), Long.class.getName() });
2778    
2779            /**
2780             * Returns all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
2781             *
2782             * @param classNameId the class name ID
2783             * @param classPK the class p k
2784             * @return the matching m d r rule group instances
2785             * @throws SystemException if a system exception occurred
2786             */
2787            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK)
2788                    throws SystemException {
2789                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
2790                            QueryUtil.ALL_POS, null);
2791            }
2792    
2793            /**
2794             * Returns a range of all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
2795             *
2796             * <p>
2797             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2798             * </p>
2799             *
2800             * @param classNameId the class name ID
2801             * @param classPK the class p k
2802             * @param start the lower bound of the range of m d r rule group instances
2803             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2804             * @return the range of matching m d r rule group instances
2805             * @throws SystemException if a system exception occurred
2806             */
2807            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK,
2808                    int start, int end) throws SystemException {
2809                    return findByC_C(classNameId, classPK, start, end, null);
2810            }
2811    
2812            /**
2813             * Returns an ordered range of all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
2814             *
2815             * <p>
2816             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2817             * </p>
2818             *
2819             * @param classNameId the class name ID
2820             * @param classPK the class p k
2821             * @param start the lower bound of the range of m d r rule group instances
2822             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2823             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2824             * @return the ordered range of matching m d r rule group instances
2825             * @throws SystemException if a system exception occurred
2826             */
2827            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK,
2828                    int start, int end, OrderByComparator orderByComparator)
2829                    throws SystemException {
2830                    boolean pagination = true;
2831                    FinderPath finderPath = null;
2832                    Object[] finderArgs = null;
2833    
2834                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2835                                    (orderByComparator == null)) {
2836                            pagination = false;
2837                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2838                            finderArgs = new Object[] { classNameId, classPK };
2839                    }
2840                    else {
2841                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2842                            finderArgs = new Object[] {
2843                                            classNameId, classPK,
2844                                            
2845                                            start, end, orderByComparator
2846                                    };
2847                    }
2848    
2849                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
2850                                    finderArgs, this);
2851    
2852                    if ((list != null) && !list.isEmpty()) {
2853                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
2854                                    if ((classNameId != mdrRuleGroupInstance.getClassNameId()) ||
2855                                                    (classPK != mdrRuleGroupInstance.getClassPK())) {
2856                                            list = null;
2857    
2858                                            break;
2859                                    }
2860                            }
2861                    }
2862    
2863                    if (list == null) {
2864                            StringBundler query = null;
2865    
2866                            if (orderByComparator != null) {
2867                                    query = new StringBundler(4 +
2868                                                    (orderByComparator.getOrderByFields().length * 3));
2869                            }
2870                            else {
2871                                    query = new StringBundler(4);
2872                            }
2873    
2874                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2875    
2876                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2877    
2878                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2879    
2880                            if (orderByComparator != null) {
2881                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2882                                            orderByComparator);
2883                            }
2884                            else
2885                             if (pagination) {
2886                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
2887                            }
2888    
2889                            String sql = query.toString();
2890    
2891                            Session session = null;
2892    
2893                            try {
2894                                    session = openSession();
2895    
2896                                    Query q = session.createQuery(sql);
2897    
2898                                    QueryPos qPos = QueryPos.getInstance(q);
2899    
2900                                    qPos.add(classNameId);
2901    
2902                                    qPos.add(classPK);
2903    
2904                                    if (!pagination) {
2905                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2906                                                            getDialect(), start, end, false);
2907    
2908                                            Collections.sort(list);
2909    
2910                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
2911                                    }
2912                                    else {
2913                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2914                                                            getDialect(), start, end);
2915                                    }
2916    
2917                                    cacheResult(list);
2918    
2919                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2920                            }
2921                            catch (Exception e) {
2922                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2923    
2924                                    throw processException(e);
2925                            }
2926                            finally {
2927                                    closeSession(session);
2928                            }
2929                    }
2930    
2931                    return list;
2932            }
2933    
2934            /**
2935             * Returns the first m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
2936             *
2937             * @param classNameId the class name ID
2938             * @param classPK the class p k
2939             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2940             * @return the first matching m d r rule group instance
2941             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2942             * @throws SystemException if a system exception occurred
2943             */
2944            public MDRRuleGroupInstance findByC_C_First(long classNameId, long classPK,
2945                    OrderByComparator orderByComparator)
2946                    throws NoSuchRuleGroupInstanceException, SystemException {
2947                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByC_C_First(classNameId,
2948                                    classPK, orderByComparator);
2949    
2950                    if (mdrRuleGroupInstance != null) {
2951                            return mdrRuleGroupInstance;
2952                    }
2953    
2954                    StringBundler msg = new StringBundler(6);
2955    
2956                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2957    
2958                    msg.append("classNameId=");
2959                    msg.append(classNameId);
2960    
2961                    msg.append(", classPK=");
2962                    msg.append(classPK);
2963    
2964                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2965    
2966                    throw new NoSuchRuleGroupInstanceException(msg.toString());
2967            }
2968    
2969            /**
2970             * Returns the first m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
2971             *
2972             * @param classNameId the class name ID
2973             * @param classPK the class p k
2974             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2975             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
2976             * @throws SystemException if a system exception occurred
2977             */
2978            public MDRRuleGroupInstance fetchByC_C_First(long classNameId,
2979                    long classPK, OrderByComparator orderByComparator)
2980                    throws SystemException {
2981                    List<MDRRuleGroupInstance> list = findByC_C(classNameId, classPK, 0, 1,
2982                                    orderByComparator);
2983    
2984                    if (!list.isEmpty()) {
2985                            return list.get(0);
2986                    }
2987    
2988                    return null;
2989            }
2990    
2991            /**
2992             * Returns the last m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
2993             *
2994             * @param classNameId the class name ID
2995             * @param classPK the class p k
2996             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2997             * @return the last matching m d r rule group instance
2998             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2999             * @throws SystemException if a system exception occurred
3000             */
3001            public MDRRuleGroupInstance findByC_C_Last(long classNameId, long classPK,
3002                    OrderByComparator orderByComparator)
3003                    throws NoSuchRuleGroupInstanceException, SystemException {
3004                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByC_C_Last(classNameId,
3005                                    classPK, orderByComparator);
3006    
3007                    if (mdrRuleGroupInstance != null) {
3008                            return mdrRuleGroupInstance;
3009                    }
3010    
3011                    StringBundler msg = new StringBundler(6);
3012    
3013                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3014    
3015                    msg.append("classNameId=");
3016                    msg.append(classNameId);
3017    
3018                    msg.append(", classPK=");
3019                    msg.append(classPK);
3020    
3021                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3022    
3023                    throw new NoSuchRuleGroupInstanceException(msg.toString());
3024            }
3025    
3026            /**
3027             * Returns the last m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
3028             *
3029             * @param classNameId the class name ID
3030             * @param classPK the class p k
3031             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3032             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
3033             * @throws SystemException if a system exception occurred
3034             */
3035            public MDRRuleGroupInstance fetchByC_C_Last(long classNameId, long classPK,
3036                    OrderByComparator orderByComparator) throws SystemException {
3037                    int count = countByC_C(classNameId, classPK);
3038    
3039                    List<MDRRuleGroupInstance> list = findByC_C(classNameId, classPK,
3040                                    count - 1, count, orderByComparator);
3041    
3042                    if (!list.isEmpty()) {
3043                            return list.get(0);
3044                    }
3045    
3046                    return null;
3047            }
3048    
3049            /**
3050             * 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;.
3051             *
3052             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
3053             * @param classNameId the class name ID
3054             * @param classPK the class p k
3055             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3056             * @return the previous, current, and next m d r rule group instance
3057             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
3058             * @throws SystemException if a system exception occurred
3059             */
3060            public MDRRuleGroupInstance[] findByC_C_PrevAndNext(
3061                    long ruleGroupInstanceId, long classNameId, long classPK,
3062                    OrderByComparator orderByComparator)
3063                    throws NoSuchRuleGroupInstanceException, SystemException {
3064                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
3065    
3066                    Session session = null;
3067    
3068                    try {
3069                            session = openSession();
3070    
3071                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
3072    
3073                            array[0] = getByC_C_PrevAndNext(session, mdrRuleGroupInstance,
3074                                            classNameId, classPK, orderByComparator, true);
3075    
3076                            array[1] = mdrRuleGroupInstance;
3077    
3078                            array[2] = getByC_C_PrevAndNext(session, mdrRuleGroupInstance,
3079                                            classNameId, classPK, orderByComparator, false);
3080    
3081                            return array;
3082                    }
3083                    catch (Exception e) {
3084                            throw processException(e);
3085                    }
3086                    finally {
3087                            closeSession(session);
3088                    }
3089            }
3090    
3091            protected MDRRuleGroupInstance getByC_C_PrevAndNext(Session session,
3092                    MDRRuleGroupInstance mdrRuleGroupInstance, long classNameId,
3093                    long classPK, OrderByComparator orderByComparator, boolean previous) {
3094                    StringBundler query = null;
3095    
3096                    if (orderByComparator != null) {
3097                            query = new StringBundler(6 +
3098                                            (orderByComparator.getOrderByFields().length * 6));
3099                    }
3100                    else {
3101                            query = new StringBundler(3);
3102                    }
3103    
3104                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3105    
3106                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3107    
3108                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3109    
3110                    if (orderByComparator != null) {
3111                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3112    
3113                            if (orderByConditionFields.length > 0) {
3114                                    query.append(WHERE_AND);
3115                            }
3116    
3117                            for (int i = 0; i < orderByConditionFields.length; i++) {
3118                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3119                                    query.append(orderByConditionFields[i]);
3120    
3121                                    if ((i + 1) < orderByConditionFields.length) {
3122                                            if (orderByComparator.isAscending() ^ previous) {
3123                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3124                                            }
3125                                            else {
3126                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3127                                            }
3128                                    }
3129                                    else {
3130                                            if (orderByComparator.isAscending() ^ previous) {
3131                                                    query.append(WHERE_GREATER_THAN);
3132                                            }
3133                                            else {
3134                                                    query.append(WHERE_LESSER_THAN);
3135                                            }
3136                                    }
3137                            }
3138    
3139                            query.append(ORDER_BY_CLAUSE);
3140    
3141                            String[] orderByFields = orderByComparator.getOrderByFields();
3142    
3143                            for (int i = 0; i < orderByFields.length; i++) {
3144                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3145                                    query.append(orderByFields[i]);
3146    
3147                                    if ((i + 1) < orderByFields.length) {
3148                                            if (orderByComparator.isAscending() ^ previous) {
3149                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3150                                            }
3151                                            else {
3152                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3153                                            }
3154                                    }
3155                                    else {
3156                                            if (orderByComparator.isAscending() ^ previous) {
3157                                                    query.append(ORDER_BY_ASC);
3158                                            }
3159                                            else {
3160                                                    query.append(ORDER_BY_DESC);
3161                                            }
3162                                    }
3163                            }
3164                    }
3165                    else {
3166                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
3167                    }
3168    
3169                    String sql = query.toString();
3170    
3171                    Query q = session.createQuery(sql);
3172    
3173                    q.setFirstResult(0);
3174                    q.setMaxResults(2);
3175    
3176                    QueryPos qPos = QueryPos.getInstance(q);
3177    
3178                    qPos.add(classNameId);
3179    
3180                    qPos.add(classPK);
3181    
3182                    if (orderByComparator != null) {
3183                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
3184    
3185                            for (Object value : values) {
3186                                    qPos.add(value);
3187                            }
3188                    }
3189    
3190                    List<MDRRuleGroupInstance> list = q.list();
3191    
3192                    if (list.size() == 2) {
3193                            return list.get(1);
3194                    }
3195                    else {
3196                            return null;
3197                    }
3198            }
3199    
3200            /**
3201             * Removes all the m d r rule group instances where classNameId = &#63; and classPK = &#63; from the database.
3202             *
3203             * @param classNameId the class name ID
3204             * @param classPK the class p k
3205             * @throws SystemException if a system exception occurred
3206             */
3207            public void removeByC_C(long classNameId, long classPK)
3208                    throws SystemException {
3209                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByC_C(
3210                                    classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3211                            remove(mdrRuleGroupInstance);
3212                    }
3213            }
3214    
3215            /**
3216             * Returns the number of m d r rule group instances where classNameId = &#63; and classPK = &#63;.
3217             *
3218             * @param classNameId the class name ID
3219             * @param classPK the class p k
3220             * @return the number of matching m d r rule group instances
3221             * @throws SystemException if a system exception occurred
3222             */
3223            public int countByC_C(long classNameId, long classPK)
3224                    throws SystemException {
3225                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
3226    
3227                    Object[] finderArgs = new Object[] { classNameId, classPK };
3228    
3229                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3230                                    this);
3231    
3232                    if (count == null) {
3233                            StringBundler query = new StringBundler(3);
3234    
3235                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3236    
3237                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3238    
3239                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3240    
3241                            String sql = query.toString();
3242    
3243                            Session session = null;
3244    
3245                            try {
3246                                    session = openSession();
3247    
3248                                    Query q = session.createQuery(sql);
3249    
3250                                    QueryPos qPos = QueryPos.getInstance(q);
3251    
3252                                    qPos.add(classNameId);
3253    
3254                                    qPos.add(classPK);
3255    
3256                                    count = (Long)q.uniqueResult();
3257    
3258                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3259                            }
3260                            catch (Exception e) {
3261                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3262    
3263                                    throw processException(e);
3264                            }
3265                            finally {
3266                                    closeSession(session);
3267                            }
3268                    }
3269    
3270                    return count.intValue();
3271            }
3272    
3273            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
3274            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ?";
3275            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
3276                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
3277                            MDRRuleGroupInstanceImpl.class,
3278                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C",
3279                            new String[] {
3280                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3281                                    
3282                            Integer.class.getName(), Integer.class.getName(),
3283                                    OrderByComparator.class.getName()
3284                            });
3285            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
3286                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
3287                            MDRRuleGroupInstanceImpl.class,
3288                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C",
3289                            new String[] {
3290                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
3291                            },
3292                            MDRRuleGroupInstanceModelImpl.GROUPID_COLUMN_BITMASK |
3293                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3294                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK);
3295            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
3296                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
3297                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C",
3298                            new String[] {
3299                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
3300                            });
3301    
3302            /**
3303             * Returns all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3304             *
3305             * @param groupId the group ID
3306             * @param classNameId the class name ID
3307             * @param classPK the class p k
3308             * @return the matching m d r rule group instances
3309             * @throws SystemException if a system exception occurred
3310             */
3311            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
3312                    long classNameId, long classPK) throws SystemException {
3313                    return findByG_C_C(groupId, classNameId, classPK, QueryUtil.ALL_POS,
3314                            QueryUtil.ALL_POS, null);
3315            }
3316    
3317            /**
3318             * Returns a range of all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3319             *
3320             * <p>
3321             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3322             * </p>
3323             *
3324             * @param groupId the group ID
3325             * @param classNameId the class name ID
3326             * @param classPK the class p k
3327             * @param start the lower bound of the range of m d r rule group instances
3328             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
3329             * @return the range of matching m d r rule group instances
3330             * @throws SystemException if a system exception occurred
3331             */
3332            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
3333                    long classNameId, long classPK, int start, int end)
3334                    throws SystemException {
3335                    return findByG_C_C(groupId, classNameId, classPK, start, end, null);
3336            }
3337    
3338            /**
3339             * Returns an ordered range of all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3340             *
3341             * <p>
3342             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3343             * </p>
3344             *
3345             * @param groupId the group ID
3346             * @param classNameId the class name ID
3347             * @param classPK the class p k
3348             * @param start the lower bound of the range of m d r rule group instances
3349             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
3350             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3351             * @return the ordered range of matching m d r rule group instances
3352             * @throws SystemException if a system exception occurred
3353             */
3354            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
3355                    long classNameId, long classPK, int start, int end,
3356                    OrderByComparator orderByComparator) throws SystemException {
3357                    boolean pagination = true;
3358                    FinderPath finderPath = null;
3359                    Object[] finderArgs = null;
3360    
3361                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3362                                    (orderByComparator == null)) {
3363                            pagination = false;
3364                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C;
3365                            finderArgs = new Object[] { groupId, classNameId, classPK };
3366                    }
3367                    else {
3368                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C;
3369                            finderArgs = new Object[] {
3370                                            groupId, classNameId, classPK,
3371                                            
3372                                            start, end, orderByComparator
3373                                    };
3374                    }
3375    
3376                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
3377                                    finderArgs, this);
3378    
3379                    if ((list != null) && !list.isEmpty()) {
3380                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
3381                                    if ((groupId != mdrRuleGroupInstance.getGroupId()) ||
3382                                                    (classNameId != mdrRuleGroupInstance.getClassNameId()) ||
3383                                                    (classPK != mdrRuleGroupInstance.getClassPK())) {
3384                                            list = null;
3385    
3386                                            break;
3387                                    }
3388                            }
3389                    }
3390    
3391                    if (list == null) {
3392                            StringBundler query = null;
3393    
3394                            if (orderByComparator != null) {
3395                                    query = new StringBundler(5 +
3396                                                    (orderByComparator.getOrderByFields().length * 3));
3397                            }
3398                            else {
3399                                    query = new StringBundler(5);
3400                            }
3401    
3402                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3403    
3404                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3405    
3406                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3407    
3408                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3409    
3410                            if (orderByComparator != null) {
3411                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3412                                            orderByComparator);
3413                            }
3414                            else
3415                             if (pagination) {
3416                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
3417                            }
3418    
3419                            String sql = query.toString();
3420    
3421                            Session session = null;
3422    
3423                            try {
3424                                    session = openSession();
3425    
3426                                    Query q = session.createQuery(sql);
3427    
3428                                    QueryPos qPos = QueryPos.getInstance(q);
3429    
3430                                    qPos.add(groupId);
3431    
3432                                    qPos.add(classNameId);
3433    
3434                                    qPos.add(classPK);
3435    
3436                                    if (!pagination) {
3437                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
3438                                                            getDialect(), start, end, false);
3439    
3440                                            Collections.sort(list);
3441    
3442                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
3443                                    }
3444                                    else {
3445                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
3446                                                            getDialect(), start, end);
3447                                    }
3448    
3449                                    cacheResult(list);
3450    
3451                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3452                            }
3453                            catch (Exception e) {
3454                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3455    
3456                                    throw processException(e);
3457                            }
3458                            finally {
3459                                    closeSession(session);
3460                            }
3461                    }
3462    
3463                    return list;
3464            }
3465    
3466            /**
3467             * Returns the first m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3468             *
3469             * @param groupId the group ID
3470             * @param classNameId the class name ID
3471             * @param classPK the class p k
3472             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3473             * @return the first matching m d r rule group instance
3474             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
3475             * @throws SystemException if a system exception occurred
3476             */
3477            public MDRRuleGroupInstance findByG_C_C_First(long groupId,
3478                    long classNameId, long classPK, OrderByComparator orderByComparator)
3479                    throws NoSuchRuleGroupInstanceException, SystemException {
3480                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByG_C_C_First(groupId,
3481                                    classNameId, classPK, orderByComparator);
3482    
3483                    if (mdrRuleGroupInstance != null) {
3484                            return mdrRuleGroupInstance;
3485                    }
3486    
3487                    StringBundler msg = new StringBundler(8);
3488    
3489                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3490    
3491                    msg.append("groupId=");
3492                    msg.append(groupId);
3493    
3494                    msg.append(", classNameId=");
3495                    msg.append(classNameId);
3496    
3497                    msg.append(", classPK=");
3498                    msg.append(classPK);
3499    
3500                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3501    
3502                    throw new NoSuchRuleGroupInstanceException(msg.toString());
3503            }
3504    
3505            /**
3506             * Returns the first m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3507             *
3508             * @param groupId the group ID
3509             * @param classNameId the class name ID
3510             * @param classPK the class p k
3511             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3512             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
3513             * @throws SystemException if a system exception occurred
3514             */
3515            public MDRRuleGroupInstance fetchByG_C_C_First(long groupId,
3516                    long classNameId, long classPK, OrderByComparator orderByComparator)
3517                    throws SystemException {
3518                    List<MDRRuleGroupInstance> list = findByG_C_C(groupId, classNameId,
3519                                    classPK, 0, 1, orderByComparator);
3520    
3521                    if (!list.isEmpty()) {
3522                            return list.get(0);
3523                    }
3524    
3525                    return null;
3526            }
3527    
3528            /**
3529             * Returns the last m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3530             *
3531             * @param groupId the group ID
3532             * @param classNameId the class name ID
3533             * @param classPK the class p k
3534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3535             * @return the last matching m d r rule group instance
3536             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
3537             * @throws SystemException if a system exception occurred
3538             */
3539            public MDRRuleGroupInstance findByG_C_C_Last(long groupId,
3540                    long classNameId, long classPK, OrderByComparator orderByComparator)
3541                    throws NoSuchRuleGroupInstanceException, SystemException {
3542                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByG_C_C_Last(groupId,
3543                                    classNameId, classPK, orderByComparator);
3544    
3545                    if (mdrRuleGroupInstance != null) {
3546                            return mdrRuleGroupInstance;
3547                    }
3548    
3549                    StringBundler msg = new StringBundler(8);
3550    
3551                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3552    
3553                    msg.append("groupId=");
3554                    msg.append(groupId);
3555    
3556                    msg.append(", classNameId=");
3557                    msg.append(classNameId);
3558    
3559                    msg.append(", classPK=");
3560                    msg.append(classPK);
3561    
3562                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3563    
3564                    throw new NoSuchRuleGroupInstanceException(msg.toString());
3565            }
3566    
3567            /**
3568             * Returns the last m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3569             *
3570             * @param groupId the group ID
3571             * @param classNameId the class name ID
3572             * @param classPK the class p k
3573             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3574             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
3575             * @throws SystemException if a system exception occurred
3576             */
3577            public MDRRuleGroupInstance fetchByG_C_C_Last(long groupId,
3578                    long classNameId, long classPK, OrderByComparator orderByComparator)
3579                    throws SystemException {
3580                    int count = countByG_C_C(groupId, classNameId, classPK);
3581    
3582                    List<MDRRuleGroupInstance> list = findByG_C_C(groupId, classNameId,
3583                                    classPK, count - 1, count, orderByComparator);
3584    
3585                    if (!list.isEmpty()) {
3586                            return list.get(0);
3587                    }
3588    
3589                    return null;
3590            }
3591    
3592            /**
3593             * 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;.
3594             *
3595             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
3596             * @param groupId the group ID
3597             * @param classNameId the class name ID
3598             * @param classPK the class p k
3599             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3600             * @return the previous, current, and next m d r rule group instance
3601             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
3602             * @throws SystemException if a system exception occurred
3603             */
3604            public MDRRuleGroupInstance[] findByG_C_C_PrevAndNext(
3605                    long ruleGroupInstanceId, long groupId, long classNameId, long classPK,
3606                    OrderByComparator orderByComparator)
3607                    throws NoSuchRuleGroupInstanceException, SystemException {
3608                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
3609    
3610                    Session session = null;
3611    
3612                    try {
3613                            session = openSession();
3614    
3615                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
3616    
3617                            array[0] = getByG_C_C_PrevAndNext(session, mdrRuleGroupInstance,
3618                                            groupId, classNameId, classPK, orderByComparator, true);
3619    
3620                            array[1] = mdrRuleGroupInstance;
3621    
3622                            array[2] = getByG_C_C_PrevAndNext(session, mdrRuleGroupInstance,
3623                                            groupId, classNameId, classPK, orderByComparator, false);
3624    
3625                            return array;
3626                    }
3627                    catch (Exception e) {
3628                            throw processException(e);
3629                    }
3630                    finally {
3631                            closeSession(session);
3632                    }
3633            }
3634    
3635            protected MDRRuleGroupInstance getByG_C_C_PrevAndNext(Session session,
3636                    MDRRuleGroupInstance mdrRuleGroupInstance, long groupId,
3637                    long classNameId, long classPK, OrderByComparator orderByComparator,
3638                    boolean previous) {
3639                    StringBundler query = null;
3640    
3641                    if (orderByComparator != null) {
3642                            query = new StringBundler(6 +
3643                                            (orderByComparator.getOrderByFields().length * 6));
3644                    }
3645                    else {
3646                            query = new StringBundler(3);
3647                    }
3648    
3649                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3650    
3651                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3652    
3653                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3654    
3655                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3656    
3657                    if (orderByComparator != null) {
3658                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3659    
3660                            if (orderByConditionFields.length > 0) {
3661                                    query.append(WHERE_AND);
3662                            }
3663    
3664                            for (int i = 0; i < orderByConditionFields.length; i++) {
3665                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3666                                    query.append(orderByConditionFields[i]);
3667    
3668                                    if ((i + 1) < orderByConditionFields.length) {
3669                                            if (orderByComparator.isAscending() ^ previous) {
3670                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3671                                            }
3672                                            else {
3673                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3674                                            }
3675                                    }
3676                                    else {
3677                                            if (orderByComparator.isAscending() ^ previous) {
3678                                                    query.append(WHERE_GREATER_THAN);
3679                                            }
3680                                            else {
3681                                                    query.append(WHERE_LESSER_THAN);
3682                                            }
3683                                    }
3684                            }
3685    
3686                            query.append(ORDER_BY_CLAUSE);
3687    
3688                            String[] orderByFields = orderByComparator.getOrderByFields();
3689    
3690                            for (int i = 0; i < orderByFields.length; i++) {
3691                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3692                                    query.append(orderByFields[i]);
3693    
3694                                    if ((i + 1) < orderByFields.length) {
3695                                            if (orderByComparator.isAscending() ^ previous) {
3696                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3697                                            }
3698                                            else {
3699                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3700                                            }
3701                                    }
3702                                    else {
3703                                            if (orderByComparator.isAscending() ^ previous) {
3704                                                    query.append(ORDER_BY_ASC);
3705                                            }
3706                                            else {
3707                                                    query.append(ORDER_BY_DESC);
3708                                            }
3709                                    }
3710                            }
3711                    }
3712                    else {
3713                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
3714                    }
3715    
3716                    String sql = query.toString();
3717    
3718                    Query q = session.createQuery(sql);
3719    
3720                    q.setFirstResult(0);
3721                    q.setMaxResults(2);
3722    
3723                    QueryPos qPos = QueryPos.getInstance(q);
3724    
3725                    qPos.add(groupId);
3726    
3727                    qPos.add(classNameId);
3728    
3729                    qPos.add(classPK);
3730    
3731                    if (orderByComparator != null) {
3732                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
3733    
3734                            for (Object value : values) {
3735                                    qPos.add(value);
3736                            }
3737                    }
3738    
3739                    List<MDRRuleGroupInstance> list = q.list();
3740    
3741                    if (list.size() == 2) {
3742                            return list.get(1);
3743                    }
3744                    else {
3745                            return null;
3746                    }
3747            }
3748    
3749            /**
3750             * 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;.
3751             *
3752             * @param groupId the group ID
3753             * @param classNameId the class name ID
3754             * @param classPK the class p k
3755             * @return the matching m d r rule group instances that the user has permission to view
3756             * @throws SystemException if a system exception occurred
3757             */
3758            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
3759                    long classNameId, long classPK) throws SystemException {
3760                    return filterFindByG_C_C(groupId, classNameId, classPK,
3761                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3762            }
3763    
3764            /**
3765             * 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;.
3766             *
3767             * <p>
3768             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3769             * </p>
3770             *
3771             * @param groupId the group ID
3772             * @param classNameId the class name ID
3773             * @param classPK the class p k
3774             * @param start the lower bound of the range of m d r rule group instances
3775             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
3776             * @return the range of matching m d r rule group instances that the user has permission to view
3777             * @throws SystemException if a system exception occurred
3778             */
3779            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
3780                    long classNameId, long classPK, int start, int end)
3781                    throws SystemException {
3782                    return filterFindByG_C_C(groupId, classNameId, classPK, start, end, null);
3783            }
3784    
3785            /**
3786             * 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;.
3787             *
3788             * <p>
3789             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3790             * </p>
3791             *
3792             * @param groupId the group ID
3793             * @param classNameId the class name ID
3794             * @param classPK the class p k
3795             * @param start the lower bound of the range of m d r rule group instances
3796             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
3797             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3798             * @return the ordered range of matching m d r rule group instances that the user has permission to view
3799             * @throws SystemException if a system exception occurred
3800             */
3801            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
3802                    long classNameId, long classPK, int start, int end,
3803                    OrderByComparator orderByComparator) throws SystemException {
3804                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3805                            return findByG_C_C(groupId, classNameId, classPK, start, end,
3806                                    orderByComparator);
3807                    }
3808    
3809                    StringBundler query = null;
3810    
3811                    if (orderByComparator != null) {
3812                            query = new StringBundler(5 +
3813                                            (orderByComparator.getOrderByFields().length * 3));
3814                    }
3815                    else {
3816                            query = new StringBundler(5);
3817                    }
3818    
3819                    if (getDB().isSupportsInlineDistinct()) {
3820                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3821                    }
3822                    else {
3823                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
3824                    }
3825    
3826                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3827    
3828                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3829    
3830                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3831    
3832                    if (!getDB().isSupportsInlineDistinct()) {
3833                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
3834                    }
3835    
3836                    if (orderByComparator != null) {
3837                            if (getDB().isSupportsInlineDistinct()) {
3838                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3839                                            orderByComparator, true);
3840                            }
3841                            else {
3842                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3843                                            orderByComparator, true);
3844                            }
3845                    }
3846                    else {
3847                            if (getDB().isSupportsInlineDistinct()) {
3848                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
3849                            }
3850                            else {
3851                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_SQL);
3852                            }
3853                    }
3854    
3855                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3856                                    MDRRuleGroupInstance.class.getName(),
3857                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3858    
3859                    Session session = null;
3860    
3861                    try {
3862                            session = openSession();
3863    
3864                            SQLQuery q = session.createSQLQuery(sql);
3865    
3866                            if (getDB().isSupportsInlineDistinct()) {
3867                                    q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
3868                            }
3869                            else {
3870                                    q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
3871                            }
3872    
3873                            QueryPos qPos = QueryPos.getInstance(q);
3874    
3875                            qPos.add(groupId);
3876    
3877                            qPos.add(classNameId);
3878    
3879                            qPos.add(classPK);
3880    
3881                            return (List<MDRRuleGroupInstance>)QueryUtil.list(q, getDialect(),
3882                                    start, end);
3883                    }
3884                    catch (Exception e) {
3885                            throw processException(e);
3886                    }
3887                    finally {
3888                            closeSession(session);
3889                    }
3890            }
3891    
3892            /**
3893             * 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;.
3894             *
3895             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
3896             * @param groupId the group ID
3897             * @param classNameId the class name ID
3898             * @param classPK the class p k
3899             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3900             * @return the previous, current, and next m d r rule group instance
3901             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
3902             * @throws SystemException if a system exception occurred
3903             */
3904            public MDRRuleGroupInstance[] filterFindByG_C_C_PrevAndNext(
3905                    long ruleGroupInstanceId, long groupId, long classNameId, long classPK,
3906                    OrderByComparator orderByComparator)
3907                    throws NoSuchRuleGroupInstanceException, SystemException {
3908                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3909                            return findByG_C_C_PrevAndNext(ruleGroupInstanceId, groupId,
3910                                    classNameId, classPK, orderByComparator);
3911                    }
3912    
3913                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
3914    
3915                    Session session = null;
3916    
3917                    try {
3918                            session = openSession();
3919    
3920                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
3921    
3922                            array[0] = filterGetByG_C_C_PrevAndNext(session,
3923                                            mdrRuleGroupInstance, groupId, classNameId, classPK,
3924                                            orderByComparator, true);
3925    
3926                            array[1] = mdrRuleGroupInstance;
3927    
3928                            array[2] = filterGetByG_C_C_PrevAndNext(session,
3929                                            mdrRuleGroupInstance, groupId, classNameId, classPK,
3930                                            orderByComparator, false);
3931    
3932                            return array;
3933                    }
3934                    catch (Exception e) {
3935                            throw processException(e);
3936                    }
3937                    finally {
3938                            closeSession(session);
3939                    }
3940            }
3941    
3942            protected MDRRuleGroupInstance filterGetByG_C_C_PrevAndNext(
3943                    Session session, MDRRuleGroupInstance mdrRuleGroupInstance,
3944                    long groupId, long classNameId, long classPK,
3945                    OrderByComparator orderByComparator, boolean previous) {
3946                    StringBundler query = null;
3947    
3948                    if (orderByComparator != null) {
3949                            query = new StringBundler(6 +
3950                                            (orderByComparator.getOrderByFields().length * 6));
3951                    }
3952                    else {
3953                            query = new StringBundler(3);
3954                    }
3955    
3956                    if (getDB().isSupportsInlineDistinct()) {
3957                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3958                    }
3959                    else {
3960                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
3961                    }
3962    
3963                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3964    
3965                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3966    
3967                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3968    
3969                    if (!getDB().isSupportsInlineDistinct()) {
3970                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
3971                    }
3972    
3973                    if (orderByComparator != null) {
3974                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3975    
3976                            if (orderByConditionFields.length > 0) {
3977                                    query.append(WHERE_AND);
3978                            }
3979    
3980                            for (int i = 0; i < orderByConditionFields.length; i++) {
3981                                    if (getDB().isSupportsInlineDistinct()) {
3982                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3983                                    }
3984                                    else {
3985                                            query.append(_ORDER_BY_ENTITY_TABLE);
3986                                    }
3987    
3988                                    query.append(orderByConditionFields[i]);
3989    
3990                                    if ((i + 1) < orderByConditionFields.length) {
3991                                            if (orderByComparator.isAscending() ^ previous) {
3992                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3993                                            }
3994                                            else {
3995                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3996                                            }
3997                                    }
3998                                    else {
3999                                            if (orderByComparator.isAscending() ^ previous) {
4000                                                    query.append(WHERE_GREATER_THAN);
4001                                            }
4002                                            else {
4003                                                    query.append(WHERE_LESSER_THAN);
4004                                            }
4005                                    }
4006                            }
4007    
4008                            query.append(ORDER_BY_CLAUSE);
4009    
4010                            String[] orderByFields = orderByComparator.getOrderByFields();
4011    
4012                            for (int i = 0; i < orderByFields.length; i++) {
4013                                    if (getDB().isSupportsInlineDistinct()) {
4014                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4015                                    }
4016                                    else {
4017                                            query.append(_ORDER_BY_ENTITY_TABLE);
4018                                    }
4019    
4020                                    query.append(orderByFields[i]);
4021    
4022                                    if ((i + 1) < orderByFields.length) {
4023                                            if (orderByComparator.isAscending() ^ previous) {
4024                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4025                                            }
4026                                            else {
4027                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4028                                            }
4029                                    }
4030                                    else {
4031                                            if (orderByComparator.isAscending() ^ previous) {
4032                                                    query.append(ORDER_BY_ASC);
4033                                            }
4034                                            else {
4035                                                    query.append(ORDER_BY_DESC);
4036                                            }
4037                                    }
4038                            }
4039                    }
4040                    else {
4041                            if (getDB().isSupportsInlineDistinct()) {
4042                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
4043                            }
4044                            else {
4045                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_SQL);
4046                            }
4047                    }
4048    
4049                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4050                                    MDRRuleGroupInstance.class.getName(),
4051                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4052    
4053                    SQLQuery q = session.createSQLQuery(sql);
4054    
4055                    q.setFirstResult(0);
4056                    q.setMaxResults(2);
4057    
4058                    if (getDB().isSupportsInlineDistinct()) {
4059                            q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
4060                    }
4061                    else {
4062                            q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
4063                    }
4064    
4065                    QueryPos qPos = QueryPos.getInstance(q);
4066    
4067                    qPos.add(groupId);
4068    
4069                    qPos.add(classNameId);
4070    
4071                    qPos.add(classPK);
4072    
4073                    if (orderByComparator != null) {
4074                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
4075    
4076                            for (Object value : values) {
4077                                    qPos.add(value);
4078                            }
4079                    }
4080    
4081                    List<MDRRuleGroupInstance> list = q.list();
4082    
4083                    if (list.size() == 2) {
4084                            return list.get(1);
4085                    }
4086                    else {
4087                            return null;
4088                    }
4089            }
4090    
4091            /**
4092             * Removes all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
4093             *
4094             * @param groupId the group ID
4095             * @param classNameId the class name ID
4096             * @param classPK the class p k
4097             * @throws SystemException if a system exception occurred
4098             */
4099            public void removeByG_C_C(long groupId, long classNameId, long classPK)
4100                    throws SystemException {
4101                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByG_C_C(groupId,
4102                                    classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4103                            remove(mdrRuleGroupInstance);
4104                    }
4105            }
4106    
4107            /**
4108             * Returns the number of m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4109             *
4110             * @param groupId the group ID
4111             * @param classNameId the class name ID
4112             * @param classPK the class p k
4113             * @return the number of matching m d r rule group instances
4114             * @throws SystemException if a system exception occurred
4115             */
4116            public int countByG_C_C(long groupId, long classNameId, long classPK)
4117                    throws SystemException {
4118                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C;
4119    
4120                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK };
4121    
4122                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4123                                    this);
4124    
4125                    if (count == null) {
4126                            StringBundler query = new StringBundler(4);
4127    
4128                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
4129    
4130                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
4131    
4132                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
4133    
4134                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
4135    
4136                            String sql = query.toString();
4137    
4138                            Session session = null;
4139    
4140                            try {
4141                                    session = openSession();
4142    
4143                                    Query q = session.createQuery(sql);
4144    
4145                                    QueryPos qPos = QueryPos.getInstance(q);
4146    
4147                                    qPos.add(groupId);
4148    
4149                                    qPos.add(classNameId);
4150    
4151                                    qPos.add(classPK);
4152    
4153                                    count = (Long)q.uniqueResult();
4154    
4155                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4156                            }
4157                            catch (Exception e) {
4158                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4159    
4160                                    throw processException(e);
4161                            }
4162                            finally {
4163                                    closeSession(session);
4164                            }
4165                    }
4166    
4167                    return count.intValue();
4168            }
4169    
4170            /**
4171             * 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;.
4172             *
4173             * @param groupId the group ID
4174             * @param classNameId the class name ID
4175             * @param classPK the class p k
4176             * @return the number of matching m d r rule group instances that the user has permission to view
4177             * @throws SystemException if a system exception occurred
4178             */
4179            public int filterCountByG_C_C(long groupId, long classNameId, long classPK)
4180                    throws SystemException {
4181                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4182                            return countByG_C_C(groupId, classNameId, classPK);
4183                    }
4184    
4185                    StringBundler query = new StringBundler(4);
4186    
4187                    query.append(_FILTER_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
4188    
4189                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
4190    
4191                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
4192    
4193                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
4194    
4195                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4196                                    MDRRuleGroupInstance.class.getName(),
4197                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4198    
4199                    Session session = null;
4200    
4201                    try {
4202                            session = openSession();
4203    
4204                            SQLQuery q = session.createSQLQuery(sql);
4205    
4206                            q.addScalar(COUNT_COLUMN_NAME,
4207                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4208    
4209                            QueryPos qPos = QueryPos.getInstance(q);
4210    
4211                            qPos.add(groupId);
4212    
4213                            qPos.add(classNameId);
4214    
4215                            qPos.add(classPK);
4216    
4217                            Long count = (Long)q.uniqueResult();
4218    
4219                            return count.intValue();
4220                    }
4221                    catch (Exception e) {
4222                            throw processException(e);
4223                    }
4224                    finally {
4225                            closeSession(session);
4226                    }
4227            }
4228    
4229            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "mdrRuleGroupInstance.groupId = ? AND ";
4230            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
4231            private static final String _FINDER_COLUMN_G_C_C_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ?";
4232            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_R = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4233                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
4234                            MDRRuleGroupInstanceImpl.class, FINDER_CLASS_NAME_ENTITY,
4235                            "fetchByC_C_R",
4236                            new String[] {
4237                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
4238                            },
4239                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4240                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK |
4241                            MDRRuleGroupInstanceModelImpl.RULEGROUPID_COLUMN_BITMASK);
4242            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_R = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4243                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
4244                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_R",
4245                            new String[] {
4246                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
4247                            });
4248    
4249            /**
4250             * 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.
4251             *
4252             * @param classNameId the class name ID
4253             * @param classPK the class p k
4254             * @param ruleGroupId the rule group ID
4255             * @return the matching m d r rule group instance
4256             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
4257             * @throws SystemException if a system exception occurred
4258             */
4259            public MDRRuleGroupInstance findByC_C_R(long classNameId, long classPK,
4260                    long ruleGroupId)
4261                    throws NoSuchRuleGroupInstanceException, SystemException {
4262                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByC_C_R(classNameId,
4263                                    classPK, ruleGroupId);
4264    
4265                    if (mdrRuleGroupInstance == null) {
4266                            StringBundler msg = new StringBundler(8);
4267    
4268                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4269    
4270                            msg.append("classNameId=");
4271                            msg.append(classNameId);
4272    
4273                            msg.append(", classPK=");
4274                            msg.append(classPK);
4275    
4276                            msg.append(", ruleGroupId=");
4277                            msg.append(ruleGroupId);
4278    
4279                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4280    
4281                            if (_log.isWarnEnabled()) {
4282                                    _log.warn(msg.toString());
4283                            }
4284    
4285                            throw new NoSuchRuleGroupInstanceException(msg.toString());
4286                    }
4287    
4288                    return mdrRuleGroupInstance;
4289            }
4290    
4291            /**
4292             * 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.
4293             *
4294             * @param classNameId the class name ID
4295             * @param classPK the class p k
4296             * @param ruleGroupId the rule group ID
4297             * @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
4298             * @throws SystemException if a system exception occurred
4299             */
4300            public MDRRuleGroupInstance fetchByC_C_R(long classNameId, long classPK,
4301                    long ruleGroupId) throws SystemException {
4302                    return fetchByC_C_R(classNameId, classPK, ruleGroupId, true);
4303            }
4304    
4305            /**
4306             * 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.
4307             *
4308             * @param classNameId the class name ID
4309             * @param classPK the class p k
4310             * @param ruleGroupId the rule group ID
4311             * @param retrieveFromCache whether to use the finder cache
4312             * @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
4313             * @throws SystemException if a system exception occurred
4314             */
4315            public MDRRuleGroupInstance fetchByC_C_R(long classNameId, long classPK,
4316                    long ruleGroupId, boolean retrieveFromCache) throws SystemException {
4317                    Object[] finderArgs = new Object[] { classNameId, classPK, ruleGroupId };
4318    
4319                    Object result = null;
4320    
4321                    if (retrieveFromCache) {
4322                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_R,
4323                                            finderArgs, this);
4324                    }
4325    
4326                    if (result instanceof MDRRuleGroupInstance) {
4327                            MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)result;
4328    
4329                            if ((classNameId != mdrRuleGroupInstance.getClassNameId()) ||
4330                                            (classPK != mdrRuleGroupInstance.getClassPK()) ||
4331                                            (ruleGroupId != mdrRuleGroupInstance.getRuleGroupId())) {
4332                                    result = null;
4333                            }
4334                    }
4335    
4336                    if (result == null) {
4337                            StringBundler query = new StringBundler(5);
4338    
4339                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
4340    
4341                            query.append(_FINDER_COLUMN_C_C_R_CLASSNAMEID_2);
4342    
4343                            query.append(_FINDER_COLUMN_C_C_R_CLASSPK_2);
4344    
4345                            query.append(_FINDER_COLUMN_C_C_R_RULEGROUPID_2);
4346    
4347                            String sql = query.toString();
4348    
4349                            Session session = null;
4350    
4351                            try {
4352                                    session = openSession();
4353    
4354                                    Query q = session.createQuery(sql);
4355    
4356                                    QueryPos qPos = QueryPos.getInstance(q);
4357    
4358                                    qPos.add(classNameId);
4359    
4360                                    qPos.add(classPK);
4361    
4362                                    qPos.add(ruleGroupId);
4363    
4364                                    List<MDRRuleGroupInstance> list = q.list();
4365    
4366                                    if (list.isEmpty()) {
4367                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
4368                                                    finderArgs, list);
4369                                    }
4370                                    else {
4371                                            MDRRuleGroupInstance mdrRuleGroupInstance = list.get(0);
4372    
4373                                            result = mdrRuleGroupInstance;
4374    
4375                                            cacheResult(mdrRuleGroupInstance);
4376    
4377                                            if ((mdrRuleGroupInstance.getClassNameId() != classNameId) ||
4378                                                            (mdrRuleGroupInstance.getClassPK() != classPK) ||
4379                                                            (mdrRuleGroupInstance.getRuleGroupId() != ruleGroupId)) {
4380                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
4381                                                            finderArgs, mdrRuleGroupInstance);
4382                                            }
4383                                    }
4384                            }
4385                            catch (Exception e) {
4386                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R,
4387                                            finderArgs);
4388    
4389                                    throw processException(e);
4390                            }
4391                            finally {
4392                                    closeSession(session);
4393                            }
4394                    }
4395    
4396                    if (result instanceof List<?>) {
4397                            return null;
4398                    }
4399                    else {
4400                            return (MDRRuleGroupInstance)result;
4401                    }
4402            }
4403    
4404            /**
4405             * Removes the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; from the database.
4406             *
4407             * @param classNameId the class name ID
4408             * @param classPK the class p k
4409             * @param ruleGroupId the rule group ID
4410             * @return the m d r rule group instance that was removed
4411             * @throws SystemException if a system exception occurred
4412             */
4413            public MDRRuleGroupInstance removeByC_C_R(long classNameId, long classPK,
4414                    long ruleGroupId)
4415                    throws NoSuchRuleGroupInstanceException, SystemException {
4416                    MDRRuleGroupInstance mdrRuleGroupInstance = findByC_C_R(classNameId,
4417                                    classPK, ruleGroupId);
4418    
4419                    return remove(mdrRuleGroupInstance);
4420            }
4421    
4422            /**
4423             * Returns the number of m d r rule group instances where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63;.
4424             *
4425             * @param classNameId the class name ID
4426             * @param classPK the class p k
4427             * @param ruleGroupId the rule group ID
4428             * @return the number of matching m d r rule group instances
4429             * @throws SystemException if a system exception occurred
4430             */
4431            public int countByC_C_R(long classNameId, long classPK, long ruleGroupId)
4432                    throws SystemException {
4433                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_R;
4434    
4435                    Object[] finderArgs = new Object[] { classNameId, classPK, ruleGroupId };
4436    
4437                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4438                                    this);
4439    
4440                    if (count == null) {
4441                            StringBundler query = new StringBundler(4);
4442    
4443                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
4444    
4445                            query.append(_FINDER_COLUMN_C_C_R_CLASSNAMEID_2);
4446    
4447                            query.append(_FINDER_COLUMN_C_C_R_CLASSPK_2);
4448    
4449                            query.append(_FINDER_COLUMN_C_C_R_RULEGROUPID_2);
4450    
4451                            String sql = query.toString();
4452    
4453                            Session session = null;
4454    
4455                            try {
4456                                    session = openSession();
4457    
4458                                    Query q = session.createQuery(sql);
4459    
4460                                    QueryPos qPos = QueryPos.getInstance(q);
4461    
4462                                    qPos.add(classNameId);
4463    
4464                                    qPos.add(classPK);
4465    
4466                                    qPos.add(ruleGroupId);
4467    
4468                                    count = (Long)q.uniqueResult();
4469    
4470                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4471                            }
4472                            catch (Exception e) {
4473                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4474    
4475                                    throw processException(e);
4476                            }
4477                            finally {
4478                                    closeSession(session);
4479                            }
4480                    }
4481    
4482                    return count.intValue();
4483            }
4484    
4485            private static final String _FINDER_COLUMN_C_C_R_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
4486            private static final String _FINDER_COLUMN_C_C_R_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ? AND ";
4487            private static final String _FINDER_COLUMN_C_C_R_RULEGROUPID_2 = "mdrRuleGroupInstance.ruleGroupId = ?";
4488    
4489            /**
4490             * Caches the m d r rule group instance in the entity cache if it is enabled.
4491             *
4492             * @param mdrRuleGroupInstance the m d r rule group instance
4493             */
4494            public void cacheResult(MDRRuleGroupInstance mdrRuleGroupInstance) {
4495                    EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4496                            MDRRuleGroupInstanceImpl.class,
4497                            mdrRuleGroupInstance.getPrimaryKey(), mdrRuleGroupInstance);
4498    
4499                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4500                            new Object[] {
4501                                    mdrRuleGroupInstance.getUuid(),
4502                                    mdrRuleGroupInstance.getGroupId()
4503                            }, mdrRuleGroupInstance);
4504    
4505                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
4506                            new Object[] {
4507                                    mdrRuleGroupInstance.getClassNameId(),
4508                                    mdrRuleGroupInstance.getClassPK(),
4509                                    mdrRuleGroupInstance.getRuleGroupId()
4510                            }, mdrRuleGroupInstance);
4511    
4512                    mdrRuleGroupInstance.resetOriginalValues();
4513            }
4514    
4515            /**
4516             * Caches the m d r rule group instances in the entity cache if it is enabled.
4517             *
4518             * @param mdrRuleGroupInstances the m d r rule group instances
4519             */
4520            public void cacheResult(List<MDRRuleGroupInstance> mdrRuleGroupInstances) {
4521                    for (MDRRuleGroupInstance mdrRuleGroupInstance : mdrRuleGroupInstances) {
4522                            if (EntityCacheUtil.getResult(
4523                                                    MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4524                                                    MDRRuleGroupInstanceImpl.class,
4525                                                    mdrRuleGroupInstance.getPrimaryKey()) == null) {
4526                                    cacheResult(mdrRuleGroupInstance);
4527                            }
4528                            else {
4529                                    mdrRuleGroupInstance.resetOriginalValues();
4530                            }
4531                    }
4532            }
4533    
4534            /**
4535             * Clears the cache for all m d r rule group instances.
4536             *
4537             * <p>
4538             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4539             * </p>
4540             */
4541            @Override
4542            public void clearCache() {
4543                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4544                            CacheRegistryUtil.clear(MDRRuleGroupInstanceImpl.class.getName());
4545                    }
4546    
4547                    EntityCacheUtil.clearCache(MDRRuleGroupInstanceImpl.class.getName());
4548    
4549                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4550                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4551                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4552            }
4553    
4554            /**
4555             * Clears the cache for the m d r rule group instance.
4556             *
4557             * <p>
4558             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4559             * </p>
4560             */
4561            @Override
4562            public void clearCache(MDRRuleGroupInstance mdrRuleGroupInstance) {
4563                    EntityCacheUtil.removeResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4564                            MDRRuleGroupInstanceImpl.class, mdrRuleGroupInstance.getPrimaryKey());
4565    
4566                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4567                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4568    
4569                    clearUniqueFindersCache(mdrRuleGroupInstance);
4570            }
4571    
4572            @Override
4573            public void clearCache(List<MDRRuleGroupInstance> mdrRuleGroupInstances) {
4574                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4575                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4576    
4577                    for (MDRRuleGroupInstance mdrRuleGroupInstance : mdrRuleGroupInstances) {
4578                            EntityCacheUtil.removeResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4579                                    MDRRuleGroupInstanceImpl.class,
4580                                    mdrRuleGroupInstance.getPrimaryKey());
4581    
4582                            clearUniqueFindersCache(mdrRuleGroupInstance);
4583                    }
4584            }
4585    
4586            protected void cacheUniqueFindersCache(
4587                    MDRRuleGroupInstance mdrRuleGroupInstance) {
4588                    if (mdrRuleGroupInstance.isNew()) {
4589                            Object[] args = new Object[] {
4590                                            mdrRuleGroupInstance.getUuid(),
4591                                            mdrRuleGroupInstance.getGroupId()
4592                                    };
4593    
4594                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4595                                    Long.valueOf(1));
4596                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4597                                    mdrRuleGroupInstance);
4598    
4599                            args = new Object[] {
4600                                            mdrRuleGroupInstance.getClassNameId(),
4601                                            mdrRuleGroupInstance.getClassPK(),
4602                                            mdrRuleGroupInstance.getRuleGroupId()
4603                                    };
4604    
4605                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_R, args,
4606                                    Long.valueOf(1));
4607                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R, args,
4608                                    mdrRuleGroupInstance);
4609                    }
4610                    else {
4611                            MDRRuleGroupInstanceModelImpl mdrRuleGroupInstanceModelImpl = (MDRRuleGroupInstanceModelImpl)mdrRuleGroupInstance;
4612    
4613                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4614                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4615                                    Object[] args = new Object[] {
4616                                                    mdrRuleGroupInstance.getUuid(),
4617                                                    mdrRuleGroupInstance.getGroupId()
4618                                            };
4619    
4620                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4621                                            Long.valueOf(1));
4622                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4623                                            mdrRuleGroupInstance);
4624                            }
4625    
4626                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4627                                            FINDER_PATH_FETCH_BY_C_C_R.getColumnBitmask()) != 0) {
4628                                    Object[] args = new Object[] {
4629                                                    mdrRuleGroupInstance.getClassNameId(),
4630                                                    mdrRuleGroupInstance.getClassPK(),
4631                                                    mdrRuleGroupInstance.getRuleGroupId()
4632                                            };
4633    
4634                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_R, args,
4635                                            Long.valueOf(1));
4636                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R, args,
4637                                            mdrRuleGroupInstance);
4638                            }
4639                    }
4640            }
4641    
4642            protected void clearUniqueFindersCache(
4643                    MDRRuleGroupInstance mdrRuleGroupInstance) {
4644                    MDRRuleGroupInstanceModelImpl mdrRuleGroupInstanceModelImpl = (MDRRuleGroupInstanceModelImpl)mdrRuleGroupInstance;
4645    
4646                    Object[] args = new Object[] {
4647                                    mdrRuleGroupInstance.getUuid(),
4648                                    mdrRuleGroupInstance.getGroupId()
4649                            };
4650    
4651                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4652                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4653    
4654                    if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4655                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4656                            args = new Object[] {
4657                                            mdrRuleGroupInstanceModelImpl.getOriginalUuid(),
4658                                            mdrRuleGroupInstanceModelImpl.getOriginalGroupId()
4659                                    };
4660    
4661                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4662                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4663                    }
4664    
4665                    args = new Object[] {
4666                                    mdrRuleGroupInstance.getClassNameId(),
4667                                    mdrRuleGroupInstance.getClassPK(),
4668                                    mdrRuleGroupInstance.getRuleGroupId()
4669                            };
4670    
4671                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_R, args);
4672                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R, args);
4673    
4674                    if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4675                                    FINDER_PATH_FETCH_BY_C_C_R.getColumnBitmask()) != 0) {
4676                            args = new Object[] {
4677                                            mdrRuleGroupInstanceModelImpl.getOriginalClassNameId(),
4678                                            mdrRuleGroupInstanceModelImpl.getOriginalClassPK(),
4679                                            mdrRuleGroupInstanceModelImpl.getOriginalRuleGroupId()
4680                                    };
4681    
4682                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_R, args);
4683                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R, args);
4684                    }
4685            }
4686    
4687            /**
4688             * 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.
4689             *
4690             * @param ruleGroupInstanceId the primary key for the new m d r rule group instance
4691             * @return the new m d r rule group instance
4692             */
4693            public MDRRuleGroupInstance create(long ruleGroupInstanceId) {
4694                    MDRRuleGroupInstance mdrRuleGroupInstance = new MDRRuleGroupInstanceImpl();
4695    
4696                    mdrRuleGroupInstance.setNew(true);
4697                    mdrRuleGroupInstance.setPrimaryKey(ruleGroupInstanceId);
4698    
4699                    String uuid = PortalUUIDUtil.generate();
4700    
4701                    mdrRuleGroupInstance.setUuid(uuid);
4702    
4703                    return mdrRuleGroupInstance;
4704            }
4705    
4706            /**
4707             * Removes the m d r rule group instance with the primary key from the database. Also notifies the appropriate model listeners.
4708             *
4709             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
4710             * @return the m d r rule group instance that was removed
4711             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
4712             * @throws SystemException if a system exception occurred
4713             */
4714            public MDRRuleGroupInstance remove(long ruleGroupInstanceId)
4715                    throws NoSuchRuleGroupInstanceException, SystemException {
4716                    return remove((Serializable)ruleGroupInstanceId);
4717            }
4718    
4719            /**
4720             * Removes the m d r rule group instance with the primary key from the database. Also notifies the appropriate model listeners.
4721             *
4722             * @param primaryKey the primary key of the m d r rule group instance
4723             * @return the m d r rule group instance that was removed
4724             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
4725             * @throws SystemException if a system exception occurred
4726             */
4727            @Override
4728            public MDRRuleGroupInstance remove(Serializable primaryKey)
4729                    throws NoSuchRuleGroupInstanceException, SystemException {
4730                    Session session = null;
4731    
4732                    try {
4733                            session = openSession();
4734    
4735                            MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)session.get(MDRRuleGroupInstanceImpl.class,
4736                                            primaryKey);
4737    
4738                            if (mdrRuleGroupInstance == null) {
4739                                    if (_log.isWarnEnabled()) {
4740                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4741                                    }
4742    
4743                                    throw new NoSuchRuleGroupInstanceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4744                                            primaryKey);
4745                            }
4746    
4747                            return remove(mdrRuleGroupInstance);
4748                    }
4749                    catch (NoSuchRuleGroupInstanceException nsee) {
4750                            throw nsee;
4751                    }
4752                    catch (Exception e) {
4753                            throw processException(e);
4754                    }
4755                    finally {
4756                            closeSession(session);
4757                    }
4758            }
4759    
4760            @Override
4761            protected MDRRuleGroupInstance removeImpl(
4762                    MDRRuleGroupInstance mdrRuleGroupInstance) throws SystemException {
4763                    mdrRuleGroupInstance = toUnwrappedModel(mdrRuleGroupInstance);
4764    
4765                    Session session = null;
4766    
4767                    try {
4768                            session = openSession();
4769    
4770                            if (!session.contains(mdrRuleGroupInstance)) {
4771                                    mdrRuleGroupInstance = (MDRRuleGroupInstance)session.get(MDRRuleGroupInstanceImpl.class,
4772                                                    mdrRuleGroupInstance.getPrimaryKeyObj());
4773                            }
4774    
4775                            if (mdrRuleGroupInstance != null) {
4776                                    session.delete(mdrRuleGroupInstance);
4777                            }
4778                    }
4779                    catch (Exception e) {
4780                            throw processException(e);
4781                    }
4782                    finally {
4783                            closeSession(session);
4784                    }
4785    
4786                    if (mdrRuleGroupInstance != null) {
4787                            clearCache(mdrRuleGroupInstance);
4788                    }
4789    
4790                    return mdrRuleGroupInstance;
4791            }
4792    
4793            @Override
4794            public MDRRuleGroupInstance updateImpl(
4795                    com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance mdrRuleGroupInstance)
4796                    throws SystemException {
4797                    mdrRuleGroupInstance = toUnwrappedModel(mdrRuleGroupInstance);
4798    
4799                    boolean isNew = mdrRuleGroupInstance.isNew();
4800    
4801                    MDRRuleGroupInstanceModelImpl mdrRuleGroupInstanceModelImpl = (MDRRuleGroupInstanceModelImpl)mdrRuleGroupInstance;
4802    
4803                    if (Validator.isNull(mdrRuleGroupInstance.getUuid())) {
4804                            String uuid = PortalUUIDUtil.generate();
4805    
4806                            mdrRuleGroupInstance.setUuid(uuid);
4807                    }
4808    
4809                    Session session = null;
4810    
4811                    try {
4812                            session = openSession();
4813    
4814                            if (mdrRuleGroupInstance.isNew()) {
4815                                    session.save(mdrRuleGroupInstance);
4816    
4817                                    mdrRuleGroupInstance.setNew(false);
4818                            }
4819                            else {
4820                                    session.merge(mdrRuleGroupInstance);
4821                            }
4822                    }
4823                    catch (Exception e) {
4824                            throw processException(e);
4825                    }
4826                    finally {
4827                            closeSession(session);
4828                    }
4829    
4830                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4831    
4832                    if (isNew || !MDRRuleGroupInstanceModelImpl.COLUMN_BITMASK_ENABLED) {
4833                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4834                    }
4835    
4836                    else {
4837                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4838                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4839                                    Object[] args = new Object[] {
4840                                                    mdrRuleGroupInstanceModelImpl.getOriginalUuid()
4841                                            };
4842    
4843                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4844                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4845                                            args);
4846    
4847                                    args = new Object[] { mdrRuleGroupInstanceModelImpl.getUuid() };
4848    
4849                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4850                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4851                                            args);
4852                            }
4853    
4854                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4855                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4856                                    Object[] args = new Object[] {
4857                                                    mdrRuleGroupInstanceModelImpl.getOriginalUuid(),
4858                                                    mdrRuleGroupInstanceModelImpl.getOriginalCompanyId()
4859                                            };
4860    
4861                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4862                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4863                                            args);
4864    
4865                                    args = new Object[] {
4866                                                    mdrRuleGroupInstanceModelImpl.getUuid(),
4867                                                    mdrRuleGroupInstanceModelImpl.getCompanyId()
4868                                            };
4869    
4870                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4871                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4872                                            args);
4873                            }
4874    
4875                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4876                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
4877                                    Object[] args = new Object[] {
4878                                                    mdrRuleGroupInstanceModelImpl.getOriginalGroupId()
4879                                            };
4880    
4881                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4882                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4883                                            args);
4884    
4885                                    args = new Object[] { mdrRuleGroupInstanceModelImpl.getGroupId() };
4886    
4887                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4888                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4889                                            args);
4890                            }
4891    
4892                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4893                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID.getColumnBitmask()) != 0) {
4894                                    Object[] args = new Object[] {
4895                                                    mdrRuleGroupInstanceModelImpl.getOriginalRuleGroupId()
4896                                            };
4897    
4898                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
4899                                            args);
4900                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
4901                                            args);
4902    
4903                                    args = new Object[] {
4904                                                    mdrRuleGroupInstanceModelImpl.getRuleGroupId()
4905                                            };
4906    
4907                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
4908                                            args);
4909                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
4910                                            args);
4911                            }
4912    
4913                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4914                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
4915                                    Object[] args = new Object[] {
4916                                                    mdrRuleGroupInstanceModelImpl.getOriginalClassNameId(),
4917                                                    mdrRuleGroupInstanceModelImpl.getOriginalClassPK()
4918                                            };
4919    
4920                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4921                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4922                                            args);
4923    
4924                                    args = new Object[] {
4925                                                    mdrRuleGroupInstanceModelImpl.getClassNameId(),
4926                                                    mdrRuleGroupInstanceModelImpl.getClassPK()
4927                                            };
4928    
4929                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4930                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4931                                            args);
4932                            }
4933    
4934                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4935                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C.getColumnBitmask()) != 0) {
4936                                    Object[] args = new Object[] {
4937                                                    mdrRuleGroupInstanceModelImpl.getOriginalGroupId(),
4938                                                    mdrRuleGroupInstanceModelImpl.getOriginalClassNameId(),
4939                                                    mdrRuleGroupInstanceModelImpl.getOriginalClassPK()
4940                                            };
4941    
4942                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
4943                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
4944                                            args);
4945    
4946                                    args = new Object[] {
4947                                                    mdrRuleGroupInstanceModelImpl.getGroupId(),
4948                                                    mdrRuleGroupInstanceModelImpl.getClassNameId(),
4949                                                    mdrRuleGroupInstanceModelImpl.getClassPK()
4950                                            };
4951    
4952                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
4953                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
4954                                            args);
4955                            }
4956                    }
4957    
4958                    EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4959                            MDRRuleGroupInstanceImpl.class,
4960                            mdrRuleGroupInstance.getPrimaryKey(), mdrRuleGroupInstance);
4961    
4962                    clearUniqueFindersCache(mdrRuleGroupInstance);
4963                    cacheUniqueFindersCache(mdrRuleGroupInstance);
4964    
4965                    return mdrRuleGroupInstance;
4966            }
4967    
4968            protected MDRRuleGroupInstance toUnwrappedModel(
4969                    MDRRuleGroupInstance mdrRuleGroupInstance) {
4970                    if (mdrRuleGroupInstance instanceof MDRRuleGroupInstanceImpl) {
4971                            return mdrRuleGroupInstance;
4972                    }
4973    
4974                    MDRRuleGroupInstanceImpl mdrRuleGroupInstanceImpl = new MDRRuleGroupInstanceImpl();
4975    
4976                    mdrRuleGroupInstanceImpl.setNew(mdrRuleGroupInstance.isNew());
4977                    mdrRuleGroupInstanceImpl.setPrimaryKey(mdrRuleGroupInstance.getPrimaryKey());
4978    
4979                    mdrRuleGroupInstanceImpl.setUuid(mdrRuleGroupInstance.getUuid());
4980                    mdrRuleGroupInstanceImpl.setRuleGroupInstanceId(mdrRuleGroupInstance.getRuleGroupInstanceId());
4981                    mdrRuleGroupInstanceImpl.setGroupId(mdrRuleGroupInstance.getGroupId());
4982                    mdrRuleGroupInstanceImpl.setCompanyId(mdrRuleGroupInstance.getCompanyId());
4983                    mdrRuleGroupInstanceImpl.setUserId(mdrRuleGroupInstance.getUserId());
4984                    mdrRuleGroupInstanceImpl.setUserName(mdrRuleGroupInstance.getUserName());
4985                    mdrRuleGroupInstanceImpl.setCreateDate(mdrRuleGroupInstance.getCreateDate());
4986                    mdrRuleGroupInstanceImpl.setModifiedDate(mdrRuleGroupInstance.getModifiedDate());
4987                    mdrRuleGroupInstanceImpl.setClassNameId(mdrRuleGroupInstance.getClassNameId());
4988                    mdrRuleGroupInstanceImpl.setClassPK(mdrRuleGroupInstance.getClassPK());
4989                    mdrRuleGroupInstanceImpl.setRuleGroupId(mdrRuleGroupInstance.getRuleGroupId());
4990                    mdrRuleGroupInstanceImpl.setPriority(mdrRuleGroupInstance.getPriority());
4991    
4992                    return mdrRuleGroupInstanceImpl;
4993            }
4994    
4995            /**
4996             * 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.
4997             *
4998             * @param primaryKey the primary key of the m d r rule group instance
4999             * @return the m d r rule group instance
5000             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
5001             * @throws SystemException if a system exception occurred
5002             */
5003            @Override
5004            public MDRRuleGroupInstance findByPrimaryKey(Serializable primaryKey)
5005                    throws NoSuchRuleGroupInstanceException, SystemException {
5006                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByPrimaryKey(primaryKey);
5007    
5008                    if (mdrRuleGroupInstance == null) {
5009                            if (_log.isWarnEnabled()) {
5010                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5011                            }
5012    
5013                            throw new NoSuchRuleGroupInstanceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5014                                    primaryKey);
5015                    }
5016    
5017                    return mdrRuleGroupInstance;
5018            }
5019    
5020            /**
5021             * 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.
5022             *
5023             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
5024             * @return the m d r rule group instance
5025             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
5026             * @throws SystemException if a system exception occurred
5027             */
5028            public MDRRuleGroupInstance findByPrimaryKey(long ruleGroupInstanceId)
5029                    throws NoSuchRuleGroupInstanceException, SystemException {
5030                    return findByPrimaryKey((Serializable)ruleGroupInstanceId);
5031            }
5032    
5033            /**
5034             * Returns the m d r rule group instance with the primary key or returns <code>null</code> if it could not be found.
5035             *
5036             * @param primaryKey the primary key of the m d r rule group instance
5037             * @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
5038             * @throws SystemException if a system exception occurred
5039             */
5040            @Override
5041            public MDRRuleGroupInstance fetchByPrimaryKey(Serializable primaryKey)
5042                    throws SystemException {
5043                    MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)EntityCacheUtil.getResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
5044                                    MDRRuleGroupInstanceImpl.class, primaryKey);
5045    
5046                    if (mdrRuleGroupInstance == _nullMDRRuleGroupInstance) {
5047                            return null;
5048                    }
5049    
5050                    if (mdrRuleGroupInstance == null) {
5051                            Session session = null;
5052    
5053                            try {
5054                                    session = openSession();
5055    
5056                                    mdrRuleGroupInstance = (MDRRuleGroupInstance)session.get(MDRRuleGroupInstanceImpl.class,
5057                                                    primaryKey);
5058    
5059                                    if (mdrRuleGroupInstance != null) {
5060                                            cacheResult(mdrRuleGroupInstance);
5061                                    }
5062                                    else {
5063                                            EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
5064                                                    MDRRuleGroupInstanceImpl.class, primaryKey,
5065                                                    _nullMDRRuleGroupInstance);
5066                                    }
5067                            }
5068                            catch (Exception e) {
5069                                    EntityCacheUtil.removeResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
5070                                            MDRRuleGroupInstanceImpl.class, primaryKey);
5071    
5072                                    throw processException(e);
5073                            }
5074                            finally {
5075                                    closeSession(session);
5076                            }
5077                    }
5078    
5079                    return mdrRuleGroupInstance;
5080            }
5081    
5082            /**
5083             * Returns the m d r rule group instance with the primary key or returns <code>null</code> if it could not be found.
5084             *
5085             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
5086             * @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
5087             * @throws SystemException if a system exception occurred
5088             */
5089            public MDRRuleGroupInstance fetchByPrimaryKey(long ruleGroupInstanceId)
5090                    throws SystemException {
5091                    return fetchByPrimaryKey((Serializable)ruleGroupInstanceId);
5092            }
5093    
5094            /**
5095             * Returns all the m d r rule group instances.
5096             *
5097             * @return the m d r rule group instances
5098             * @throws SystemException if a system exception occurred
5099             */
5100            public List<MDRRuleGroupInstance> findAll() throws SystemException {
5101                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5102            }
5103    
5104            /**
5105             * Returns a range of all the m d r rule group instances.
5106             *
5107             * <p>
5108             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5109             * </p>
5110             *
5111             * @param start the lower bound of the range of m d r rule group instances
5112             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
5113             * @return the range of m d r rule group instances
5114             * @throws SystemException if a system exception occurred
5115             */
5116            public List<MDRRuleGroupInstance> findAll(int start, int end)
5117                    throws SystemException {
5118                    return findAll(start, end, null);
5119            }
5120    
5121            /**
5122             * Returns an ordered range of all the m d r rule group instances.
5123             *
5124             * <p>
5125             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5126             * </p>
5127             *
5128             * @param start the lower bound of the range of m d r rule group instances
5129             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
5130             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5131             * @return the ordered range of m d r rule group instances
5132             * @throws SystemException if a system exception occurred
5133             */
5134            public List<MDRRuleGroupInstance> findAll(int start, int end,
5135                    OrderByComparator orderByComparator) throws SystemException {
5136                    boolean pagination = true;
5137                    FinderPath finderPath = null;
5138                    Object[] finderArgs = null;
5139    
5140                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5141                                    (orderByComparator == null)) {
5142                            pagination = false;
5143                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5144                            finderArgs = FINDER_ARGS_EMPTY;
5145                    }
5146                    else {
5147                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5148                            finderArgs = new Object[] { start, end, orderByComparator };
5149                    }
5150    
5151                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
5152                                    finderArgs, this);
5153    
5154                    if (list == null) {
5155                            StringBundler query = null;
5156                            String sql = null;
5157    
5158                            if (orderByComparator != null) {
5159                                    query = new StringBundler(2 +
5160                                                    (orderByComparator.getOrderByFields().length * 3));
5161    
5162                                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE);
5163    
5164                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5165                                            orderByComparator);
5166    
5167                                    sql = query.toString();
5168                            }
5169                            else {
5170                                    sql = _SQL_SELECT_MDRRULEGROUPINSTANCE;
5171    
5172                                    if (pagination) {
5173                                            sql = sql.concat(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
5174                                    }
5175                            }
5176    
5177                            Session session = null;
5178    
5179                            try {
5180                                    session = openSession();
5181    
5182                                    Query q = session.createQuery(sql);
5183    
5184                                    if (!pagination) {
5185                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
5186                                                            getDialect(), start, end, false);
5187    
5188                                            Collections.sort(list);
5189    
5190                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
5191                                    }
5192                                    else {
5193                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
5194                                                            getDialect(), start, end);
5195                                    }
5196    
5197                                    cacheResult(list);
5198    
5199                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5200                            }
5201                            catch (Exception e) {
5202                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5203    
5204                                    throw processException(e);
5205                            }
5206                            finally {
5207                                    closeSession(session);
5208                            }
5209                    }
5210    
5211                    return list;
5212            }
5213    
5214            /**
5215             * Removes all the m d r rule group instances from the database.
5216             *
5217             * @throws SystemException if a system exception occurred
5218             */
5219            public void removeAll() throws SystemException {
5220                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findAll()) {
5221                            remove(mdrRuleGroupInstance);
5222                    }
5223            }
5224    
5225            /**
5226             * Returns the number of m d r rule group instances.
5227             *
5228             * @return the number of m d r rule group instances
5229             * @throws SystemException if a system exception occurred
5230             */
5231            public int countAll() throws SystemException {
5232                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5233                                    FINDER_ARGS_EMPTY, this);
5234    
5235                    if (count == null) {
5236                            Session session = null;
5237    
5238                            try {
5239                                    session = openSession();
5240    
5241                                    Query q = session.createQuery(_SQL_COUNT_MDRRULEGROUPINSTANCE);
5242    
5243                                    count = (Long)q.uniqueResult();
5244    
5245                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5246                                            FINDER_ARGS_EMPTY, count);
5247                            }
5248                            catch (Exception e) {
5249                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5250                                            FINDER_ARGS_EMPTY);
5251    
5252                                    throw processException(e);
5253                            }
5254                            finally {
5255                                    closeSession(session);
5256                            }
5257                    }
5258    
5259                    return count.intValue();
5260            }
5261    
5262            @Override
5263            protected Set<String> getBadColumnNames() {
5264                    return _badColumnNames;
5265            }
5266    
5267            /**
5268             * Initializes the m d r rule group instance persistence.
5269             */
5270            public void afterPropertiesSet() {
5271                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5272                                            com.liferay.portal.util.PropsUtil.get(
5273                                                    "value.object.listener.com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance")));
5274    
5275                    if (listenerClassNames.length > 0) {
5276                            try {
5277                                    List<ModelListener<MDRRuleGroupInstance>> listenersList = new ArrayList<ModelListener<MDRRuleGroupInstance>>();
5278    
5279                                    for (String listenerClassName : listenerClassNames) {
5280                                            listenersList.add((ModelListener<MDRRuleGroupInstance>)InstanceFactory.newInstance(
5281                                                            getClassLoader(), listenerClassName));
5282                                    }
5283    
5284                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5285                            }
5286                            catch (Exception e) {
5287                                    _log.error(e);
5288                            }
5289                    }
5290            }
5291    
5292            public void destroy() {
5293                    EntityCacheUtil.removeCache(MDRRuleGroupInstanceImpl.class.getName());
5294                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5295                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5296                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5297            }
5298    
5299            private static final String _SQL_SELECT_MDRRULEGROUPINSTANCE = "SELECT mdrRuleGroupInstance FROM MDRRuleGroupInstance mdrRuleGroupInstance";
5300            private static final String _SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE = "SELECT mdrRuleGroupInstance FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5301            private static final String _SQL_COUNT_MDRRULEGROUPINSTANCE = "SELECT COUNT(mdrRuleGroupInstance) FROM MDRRuleGroupInstance mdrRuleGroupInstance";
5302            private static final String _SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE = "SELECT COUNT(mdrRuleGroupInstance) FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5303            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mdrRuleGroupInstance.ruleGroupInstanceId";
5304            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE = "SELECT DISTINCT {mdrRuleGroupInstance.*} FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5305            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1 =
5306                    "SELECT {MDRRuleGroupInstance.*} FROM (SELECT DISTINCT mdrRuleGroupInstance.ruleGroupInstanceId FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5307            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2 =
5308                    ") TEMP_TABLE INNER JOIN MDRRuleGroupInstance ON TEMP_TABLE.ruleGroupInstanceId = MDRRuleGroupInstance.ruleGroupInstanceId";
5309            private static final String _FILTER_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE = "SELECT COUNT(DISTINCT mdrRuleGroupInstance.ruleGroupInstanceId) AS COUNT_VALUE FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5310            private static final String _FILTER_ENTITY_ALIAS = "mdrRuleGroupInstance";
5311            private static final String _FILTER_ENTITY_TABLE = "MDRRuleGroupInstance";
5312            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRuleGroupInstance.";
5313            private static final String _ORDER_BY_ENTITY_TABLE = "MDRRuleGroupInstance.";
5314            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRuleGroupInstance exists with the primary key ";
5315            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRuleGroupInstance exists with the key {";
5316            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5317            private static Log _log = LogFactoryUtil.getLog(MDRRuleGroupInstancePersistenceImpl.class);
5318            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
5319                                    "uuid"
5320                            });
5321            private static MDRRuleGroupInstance _nullMDRRuleGroupInstance = new MDRRuleGroupInstanceImpl() {
5322                            @Override
5323                            public Object clone() {
5324                                    return this;
5325                            }
5326    
5327                            @Override
5328                            public CacheModel<MDRRuleGroupInstance> toCacheModel() {
5329                                    return _nullMDRRuleGroupInstanceCacheModel;
5330                            }
5331                    };
5332    
5333            private static CacheModel<MDRRuleGroupInstance> _nullMDRRuleGroupInstanceCacheModel =
5334                    new CacheModel<MDRRuleGroupInstance>() {
5335                            public MDRRuleGroupInstance toEntityModel() {
5336                                    return _nullMDRRuleGroupInstance;
5337                            }
5338                    };
5339    }