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