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