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