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.Session;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.OrderByComparator;
029    import com.liferay.portal.kernel.util.SetUtil;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringPool;
032    import com.liferay.portal.kernel.util.Validator;
033    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.service.ServiceContext;
036    import com.liferay.portal.service.ServiceContextThreadLocal;
037    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038    
039    import com.liferay.portlet.mobiledevicerules.NoSuchRuleException;
040    import com.liferay.portlet.mobiledevicerules.model.MDRRule;
041    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleImpl;
042    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleModelImpl;
043    import com.liferay.portlet.mobiledevicerules.service.persistence.MDRRulePersistence;
044    
045    import java.io.Serializable;
046    
047    import java.util.Collections;
048    import java.util.Date;
049    import java.util.HashMap;
050    import java.util.HashSet;
051    import java.util.Iterator;
052    import java.util.List;
053    import java.util.Map;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the m d r rule service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Edward C. Han
064     * @see MDRRulePersistence
065     * @see com.liferay.portlet.mobiledevicerules.service.persistence.MDRRuleUtil
066     * @generated
067     */
068    @ProviderType
069    public class MDRRulePersistenceImpl extends BasePersistenceImpl<MDRRule>
070            implements MDRRulePersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link MDRRuleUtil} to access the m d r rule persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = MDRRuleImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
082                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
085                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
088                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
091                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
093                            new String[] {
094                                    String.class.getName(),
095                                    
096                            Integer.class.getName(), Integer.class.getName(),
097                                    OrderByComparator.class.getName()
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
100                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102                            new String[] { String.class.getName() },
103                            MDRRuleModelImpl.UUID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
105                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107                            new String[] { String.class.getName() });
108    
109            /**
110             * Returns all the m d r rules where uuid = &#63;.
111             *
112             * @param uuid the uuid
113             * @return the matching m d r rules
114             */
115            @Override
116            public List<MDRRule> findByUuid(String uuid) {
117                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118            }
119    
120            /**
121             * Returns a range of all the m d r rules where uuid = &#63;.
122             *
123             * <p>
124             * 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 MDRRuleModelImpl}. 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.
125             * </p>
126             *
127             * @param uuid the uuid
128             * @param start the lower bound of the range of m d r rules
129             * @param end the upper bound of the range of m d r rules (not inclusive)
130             * @return the range of matching m d r rules
131             */
132            @Override
133            public List<MDRRule> findByUuid(String uuid, int start, int end) {
134                    return findByUuid(uuid, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the m d r rules where uuid = &#63;.
139             *
140             * <p>
141             * 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 MDRRuleModelImpl}. 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.
142             * </p>
143             *
144             * @param uuid the uuid
145             * @param start the lower bound of the range of m d r rules
146             * @param end the upper bound of the range of m d r rules (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching m d r rules
149             */
150            @Override
151            public List<MDRRule> findByUuid(String uuid, int start, int end,
152                    OrderByComparator<MDRRule> orderByComparator) {
153                    boolean pagination = true;
154                    FinderPath finderPath = null;
155                    Object[] finderArgs = null;
156    
157                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158                                    (orderByComparator == null)) {
159                            pagination = false;
160                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
161                            finderArgs = new Object[] { uuid };
162                    }
163                    else {
164                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
165                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
166                    }
167    
168                    List<MDRRule> list = (List<MDRRule>)FinderCacheUtil.getResult(finderPath,
169                                    finderArgs, this);
170    
171                    if ((list != null) && !list.isEmpty()) {
172                            for (MDRRule mdrRule : list) {
173                                    if (!Validator.equals(uuid, mdrRule.getUuid())) {
174                                            list = null;
175    
176                                            break;
177                                    }
178                            }
179                    }
180    
181                    if (list == null) {
182                            StringBundler query = null;
183    
184                            if (orderByComparator != null) {
185                                    query = new StringBundler(3 +
186                                                    (orderByComparator.getOrderByFields().length * 3));
187                            }
188                            else {
189                                    query = new StringBundler(3);
190                            }
191    
192                            query.append(_SQL_SELECT_MDRRULE_WHERE);
193    
194                            boolean bindUuid = false;
195    
196                            if (uuid == null) {
197                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
198                            }
199                            else if (uuid.equals(StringPool.BLANK)) {
200                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
201                            }
202                            else {
203                                    bindUuid = true;
204    
205                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
206                            }
207    
208                            if (orderByComparator != null) {
209                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210                                            orderByComparator);
211                            }
212                            else
213                             if (pagination) {
214                                    query.append(MDRRuleModelImpl.ORDER_BY_JPQL);
215                            }
216    
217                            String sql = query.toString();
218    
219                            Session session = null;
220    
221                            try {
222                                    session = openSession();
223    
224                                    Query q = session.createQuery(sql);
225    
226                                    QueryPos qPos = QueryPos.getInstance(q);
227    
228                                    if (bindUuid) {
229                                            qPos.add(uuid);
230                                    }
231    
232                                    if (!pagination) {
233                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
234                                                            start, end, false);
235    
236                                            Collections.sort(list);
237    
238                                            list = Collections.unmodifiableList(list);
239                                    }
240                                    else {
241                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
242                                                            start, end);
243                                    }
244    
245                                    cacheResult(list);
246    
247                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
248                            }
249                            catch (Exception e) {
250                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
251    
252                                    throw processException(e);
253                            }
254                            finally {
255                                    closeSession(session);
256                            }
257                    }
258    
259                    return list;
260            }
261    
262            /**
263             * Returns the first m d r rule in the ordered set where uuid = &#63;.
264             *
265             * @param uuid the uuid
266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
267             * @return the first matching m d r rule
268             * @throws NoSuchRuleException if a matching m d r rule could not be found
269             */
270            @Override
271            public MDRRule findByUuid_First(String uuid,
272                    OrderByComparator<MDRRule> orderByComparator)
273                    throws NoSuchRuleException {
274                    MDRRule mdrRule = fetchByUuid_First(uuid, orderByComparator);
275    
276                    if (mdrRule != null) {
277                            return mdrRule;
278                    }
279    
280                    StringBundler msg = new StringBundler(4);
281    
282                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283    
284                    msg.append("uuid=");
285                    msg.append(uuid);
286    
287                    msg.append(StringPool.CLOSE_CURLY_BRACE);
288    
289                    throw new NoSuchRuleException(msg.toString());
290            }
291    
292            /**
293             * Returns the first m d r rule in the ordered set where uuid = &#63;.
294             *
295             * @param uuid the uuid
296             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
297             * @return the first matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
298             */
299            @Override
300            public MDRRule fetchByUuid_First(String uuid,
301                    OrderByComparator<MDRRule> orderByComparator) {
302                    List<MDRRule> list = findByUuid(uuid, 0, 1, orderByComparator);
303    
304                    if (!list.isEmpty()) {
305                            return list.get(0);
306                    }
307    
308                    return null;
309            }
310    
311            /**
312             * Returns the last m d r rule in the ordered set where uuid = &#63;.
313             *
314             * @param uuid the uuid
315             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
316             * @return the last matching m d r rule
317             * @throws NoSuchRuleException if a matching m d r rule could not be found
318             */
319            @Override
320            public MDRRule findByUuid_Last(String uuid,
321                    OrderByComparator<MDRRule> orderByComparator)
322                    throws NoSuchRuleException {
323                    MDRRule mdrRule = fetchByUuid_Last(uuid, orderByComparator);
324    
325                    if (mdrRule != null) {
326                            return mdrRule;
327                    }
328    
329                    StringBundler msg = new StringBundler(4);
330    
331                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
332    
333                    msg.append("uuid=");
334                    msg.append(uuid);
335    
336                    msg.append(StringPool.CLOSE_CURLY_BRACE);
337    
338                    throw new NoSuchRuleException(msg.toString());
339            }
340    
341            /**
342             * Returns the last m d r rule in the ordered set where uuid = &#63;.
343             *
344             * @param uuid the uuid
345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
346             * @return the last matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
347             */
348            @Override
349            public MDRRule fetchByUuid_Last(String uuid,
350                    OrderByComparator<MDRRule> orderByComparator) {
351                    int count = countByUuid(uuid);
352    
353                    if (count == 0) {
354                            return null;
355                    }
356    
357                    List<MDRRule> list = findByUuid(uuid, count - 1, count,
358                                    orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the m d r rules before and after the current m d r rule in the ordered set where uuid = &#63;.
369             *
370             * @param ruleId the primary key of the current m d r rule
371             * @param uuid the uuid
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next m d r rule
374             * @throws NoSuchRuleException if a m d r rule with the primary key could not be found
375             */
376            @Override
377            public MDRRule[] findByUuid_PrevAndNext(long ruleId, String uuid,
378                    OrderByComparator<MDRRule> orderByComparator)
379                    throws NoSuchRuleException {
380                    MDRRule mdrRule = findByPrimaryKey(ruleId);
381    
382                    Session session = null;
383    
384                    try {
385                            session = openSession();
386    
387                            MDRRule[] array = new MDRRuleImpl[3];
388    
389                            array[0] = getByUuid_PrevAndNext(session, mdrRule, uuid,
390                                            orderByComparator, true);
391    
392                            array[1] = mdrRule;
393    
394                            array[2] = getByUuid_PrevAndNext(session, mdrRule, uuid,
395                                            orderByComparator, false);
396    
397                            return array;
398                    }
399                    catch (Exception e) {
400                            throw processException(e);
401                    }
402                    finally {
403                            closeSession(session);
404                    }
405            }
406    
407            protected MDRRule getByUuid_PrevAndNext(Session session, MDRRule mdrRule,
408                    String uuid, OrderByComparator<MDRRule> orderByComparator,
409                    boolean previous) {
410                    StringBundler query = null;
411    
412                    if (orderByComparator != null) {
413                            query = new StringBundler(6 +
414                                            (orderByComparator.getOrderByFields().length * 6));
415                    }
416                    else {
417                            query = new StringBundler(3);
418                    }
419    
420                    query.append(_SQL_SELECT_MDRRULE_WHERE);
421    
422                    boolean bindUuid = false;
423    
424                    if (uuid == null) {
425                            query.append(_FINDER_COLUMN_UUID_UUID_1);
426                    }
427                    else if (uuid.equals(StringPool.BLANK)) {
428                            query.append(_FINDER_COLUMN_UUID_UUID_3);
429                    }
430                    else {
431                            bindUuid = true;
432    
433                            query.append(_FINDER_COLUMN_UUID_UUID_2);
434                    }
435    
436                    if (orderByComparator != null) {
437                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438    
439                            if (orderByConditionFields.length > 0) {
440                                    query.append(WHERE_AND);
441                            }
442    
443                            for (int i = 0; i < orderByConditionFields.length; i++) {
444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
445                                    query.append(orderByConditionFields[i]);
446    
447                                    if ((i + 1) < orderByConditionFields.length) {
448                                            if (orderByComparator.isAscending() ^ previous) {
449                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
450                                            }
451                                            else {
452                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
453                                            }
454                                    }
455                                    else {
456                                            if (orderByComparator.isAscending() ^ previous) {
457                                                    query.append(WHERE_GREATER_THAN);
458                                            }
459                                            else {
460                                                    query.append(WHERE_LESSER_THAN);
461                                            }
462                                    }
463                            }
464    
465                            query.append(ORDER_BY_CLAUSE);
466    
467                            String[] orderByFields = orderByComparator.getOrderByFields();
468    
469                            for (int i = 0; i < orderByFields.length; i++) {
470                                    query.append(_ORDER_BY_ENTITY_ALIAS);
471                                    query.append(orderByFields[i]);
472    
473                                    if ((i + 1) < orderByFields.length) {
474                                            if (orderByComparator.isAscending() ^ previous) {
475                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
476                                            }
477                                            else {
478                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
479                                            }
480                                    }
481                                    else {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(ORDER_BY_ASC);
484                                            }
485                                            else {
486                                                    query.append(ORDER_BY_DESC);
487                                            }
488                                    }
489                            }
490                    }
491                    else {
492                            query.append(MDRRuleModelImpl.ORDER_BY_JPQL);
493                    }
494    
495                    String sql = query.toString();
496    
497                    Query q = session.createQuery(sql);
498    
499                    q.setFirstResult(0);
500                    q.setMaxResults(2);
501    
502                    QueryPos qPos = QueryPos.getInstance(q);
503    
504                    if (bindUuid) {
505                            qPos.add(uuid);
506                    }
507    
508                    if (orderByComparator != null) {
509                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRule);
510    
511                            for (Object value : values) {
512                                    qPos.add(value);
513                            }
514                    }
515    
516                    List<MDRRule> list = q.list();
517    
518                    if (list.size() == 2) {
519                            return list.get(1);
520                    }
521                    else {
522                            return null;
523                    }
524            }
525    
526            /**
527             * Removes all the m d r rules where uuid = &#63; from the database.
528             *
529             * @param uuid the uuid
530             */
531            @Override
532            public void removeByUuid(String uuid) {
533                    for (MDRRule mdrRule : findByUuid(uuid, QueryUtil.ALL_POS,
534                                    QueryUtil.ALL_POS, null)) {
535                            remove(mdrRule);
536                    }
537            }
538    
539            /**
540             * Returns the number of m d r rules where uuid = &#63;.
541             *
542             * @param uuid the uuid
543             * @return the number of matching m d r rules
544             */
545            @Override
546            public int countByUuid(String uuid) {
547                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
548    
549                    Object[] finderArgs = new Object[] { uuid };
550    
551                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
552                                    this);
553    
554                    if (count == null) {
555                            StringBundler query = new StringBundler(2);
556    
557                            query.append(_SQL_COUNT_MDRRULE_WHERE);
558    
559                            boolean bindUuid = false;
560    
561                            if (uuid == null) {
562                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
563                            }
564                            else if (uuid.equals(StringPool.BLANK)) {
565                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
566                            }
567                            else {
568                                    bindUuid = true;
569    
570                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
571                            }
572    
573                            String sql = query.toString();
574    
575                            Session session = null;
576    
577                            try {
578                                    session = openSession();
579    
580                                    Query q = session.createQuery(sql);
581    
582                                    QueryPos qPos = QueryPos.getInstance(q);
583    
584                                    if (bindUuid) {
585                                            qPos.add(uuid);
586                                    }
587    
588                                    count = (Long)q.uniqueResult();
589    
590                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
591                            }
592                            catch (Exception e) {
593                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
594    
595                                    throw processException(e);
596                            }
597                            finally {
598                                    closeSession(session);
599                            }
600                    }
601    
602                    return count.intValue();
603            }
604    
605            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mdrRule.uuid IS NULL";
606            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrRule.uuid = ?";
607            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrRule.uuid IS NULL OR mdrRule.uuid = '')";
608            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
609                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
610                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
611                            new String[] { String.class.getName(), Long.class.getName() },
612                            MDRRuleModelImpl.UUID_COLUMN_BITMASK |
613                            MDRRuleModelImpl.GROUPID_COLUMN_BITMASK);
614            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
615                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
616                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
617                            new String[] { String.class.getName(), Long.class.getName() });
618    
619            /**
620             * Returns the m d r rule where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchRuleException} if it could not be found.
621             *
622             * @param uuid the uuid
623             * @param groupId the group ID
624             * @return the matching m d r rule
625             * @throws NoSuchRuleException if a matching m d r rule could not be found
626             */
627            @Override
628            public MDRRule findByUUID_G(String uuid, long groupId)
629                    throws NoSuchRuleException {
630                    MDRRule mdrRule = fetchByUUID_G(uuid, groupId);
631    
632                    if (mdrRule == null) {
633                            StringBundler msg = new StringBundler(6);
634    
635                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
636    
637                            msg.append("uuid=");
638                            msg.append(uuid);
639    
640                            msg.append(", groupId=");
641                            msg.append(groupId);
642    
643                            msg.append(StringPool.CLOSE_CURLY_BRACE);
644    
645                            if (_log.isWarnEnabled()) {
646                                    _log.warn(msg.toString());
647                            }
648    
649                            throw new NoSuchRuleException(msg.toString());
650                    }
651    
652                    return mdrRule;
653            }
654    
655            /**
656             * Returns the m d r rule where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
657             *
658             * @param uuid the uuid
659             * @param groupId the group ID
660             * @return the matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
661             */
662            @Override
663            public MDRRule fetchByUUID_G(String uuid, long groupId) {
664                    return fetchByUUID_G(uuid, groupId, true);
665            }
666    
667            /**
668             * Returns the m d r rule where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
669             *
670             * @param uuid the uuid
671             * @param groupId the group ID
672             * @param retrieveFromCache whether to use the finder cache
673             * @return the matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
674             */
675            @Override
676            public MDRRule fetchByUUID_G(String uuid, long groupId,
677                    boolean retrieveFromCache) {
678                    Object[] finderArgs = new Object[] { uuid, groupId };
679    
680                    Object result = null;
681    
682                    if (retrieveFromCache) {
683                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
684                                            finderArgs, this);
685                    }
686    
687                    if (result instanceof MDRRule) {
688                            MDRRule mdrRule = (MDRRule)result;
689    
690                            if (!Validator.equals(uuid, mdrRule.getUuid()) ||
691                                            (groupId != mdrRule.getGroupId())) {
692                                    result = null;
693                            }
694                    }
695    
696                    if (result == null) {
697                            StringBundler query = new StringBundler(4);
698    
699                            query.append(_SQL_SELECT_MDRRULE_WHERE);
700    
701                            boolean bindUuid = false;
702    
703                            if (uuid == null) {
704                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
705                            }
706                            else if (uuid.equals(StringPool.BLANK)) {
707                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
708                            }
709                            else {
710                                    bindUuid = true;
711    
712                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
713                            }
714    
715                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
716    
717                            String sql = query.toString();
718    
719                            Session session = null;
720    
721                            try {
722                                    session = openSession();
723    
724                                    Query q = session.createQuery(sql);
725    
726                                    QueryPos qPos = QueryPos.getInstance(q);
727    
728                                    if (bindUuid) {
729                                            qPos.add(uuid);
730                                    }
731    
732                                    qPos.add(groupId);
733    
734                                    List<MDRRule> list = q.list();
735    
736                                    if (list.isEmpty()) {
737                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
738                                                    finderArgs, list);
739                                    }
740                                    else {
741                                            MDRRule mdrRule = list.get(0);
742    
743                                            result = mdrRule;
744    
745                                            cacheResult(mdrRule);
746    
747                                            if ((mdrRule.getUuid() == null) ||
748                                                            !mdrRule.getUuid().equals(uuid) ||
749                                                            (mdrRule.getGroupId() != groupId)) {
750                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
751                                                            finderArgs, mdrRule);
752                                            }
753                                    }
754                            }
755                            catch (Exception e) {
756                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
757                                            finderArgs);
758    
759                                    throw processException(e);
760                            }
761                            finally {
762                                    closeSession(session);
763                            }
764                    }
765    
766                    if (result instanceof List<?>) {
767                            return null;
768                    }
769                    else {
770                            return (MDRRule)result;
771                    }
772            }
773    
774            /**
775             * Removes the m d r rule where uuid = &#63; and groupId = &#63; from the database.
776             *
777             * @param uuid the uuid
778             * @param groupId the group ID
779             * @return the m d r rule that was removed
780             */
781            @Override
782            public MDRRule removeByUUID_G(String uuid, long groupId)
783                    throws NoSuchRuleException {
784                    MDRRule mdrRule = findByUUID_G(uuid, groupId);
785    
786                    return remove(mdrRule);
787            }
788    
789            /**
790             * Returns the number of m d r rules where uuid = &#63; and groupId = &#63;.
791             *
792             * @param uuid the uuid
793             * @param groupId the group ID
794             * @return the number of matching m d r rules
795             */
796            @Override
797            public int countByUUID_G(String uuid, long groupId) {
798                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
799    
800                    Object[] finderArgs = new Object[] { uuid, groupId };
801    
802                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
803                                    this);
804    
805                    if (count == null) {
806                            StringBundler query = new StringBundler(3);
807    
808                            query.append(_SQL_COUNT_MDRRULE_WHERE);
809    
810                            boolean bindUuid = false;
811    
812                            if (uuid == null) {
813                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
814                            }
815                            else if (uuid.equals(StringPool.BLANK)) {
816                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
817                            }
818                            else {
819                                    bindUuid = true;
820    
821                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
822                            }
823    
824                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
825    
826                            String sql = query.toString();
827    
828                            Session session = null;
829    
830                            try {
831                                    session = openSession();
832    
833                                    Query q = session.createQuery(sql);
834    
835                                    QueryPos qPos = QueryPos.getInstance(q);
836    
837                                    if (bindUuid) {
838                                            qPos.add(uuid);
839                                    }
840    
841                                    qPos.add(groupId);
842    
843                                    count = (Long)q.uniqueResult();
844    
845                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
846                            }
847                            catch (Exception e) {
848                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
849    
850                                    throw processException(e);
851                            }
852                            finally {
853                                    closeSession(session);
854                            }
855                    }
856    
857                    return count.intValue();
858            }
859    
860            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mdrRule.uuid IS NULL AND ";
861            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrRule.uuid = ? AND ";
862            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrRule.uuid IS NULL OR mdrRule.uuid = '') AND ";
863            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrRule.groupId = ?";
864            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
865                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
866                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
867                            new String[] {
868                                    String.class.getName(), Long.class.getName(),
869                                    
870                            Integer.class.getName(), Integer.class.getName(),
871                                    OrderByComparator.class.getName()
872                            });
873            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
874                    new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
875                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
876                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
877                            new String[] { String.class.getName(), Long.class.getName() },
878                            MDRRuleModelImpl.UUID_COLUMN_BITMASK |
879                            MDRRuleModelImpl.COMPANYID_COLUMN_BITMASK);
880            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
881                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
882                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
883                            new String[] { String.class.getName(), Long.class.getName() });
884    
885            /**
886             * Returns all the m d r rules where uuid = &#63; and companyId = &#63;.
887             *
888             * @param uuid the uuid
889             * @param companyId the company ID
890             * @return the matching m d r rules
891             */
892            @Override
893            public List<MDRRule> findByUuid_C(String uuid, long companyId) {
894                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
895                            QueryUtil.ALL_POS, null);
896            }
897    
898            /**
899             * Returns a range of all the m d r rules where uuid = &#63; and companyId = &#63;.
900             *
901             * <p>
902             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 MDRRuleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
903             * </p>
904             *
905             * @param uuid the uuid
906             * @param companyId the company ID
907             * @param start the lower bound of the range of m d r rules
908             * @param end the upper bound of the range of m d r rules (not inclusive)
909             * @return the range of matching m d r rules
910             */
911            @Override
912            public List<MDRRule> findByUuid_C(String uuid, long companyId, int start,
913                    int end) {
914                    return findByUuid_C(uuid, companyId, start, end, null);
915            }
916    
917            /**
918             * Returns an ordered range of all the m d r rules where uuid = &#63; and companyId = &#63;.
919             *
920             * <p>
921             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 MDRRuleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
922             * </p>
923             *
924             * @param uuid the uuid
925             * @param companyId the company ID
926             * @param start the lower bound of the range of m d r rules
927             * @param end the upper bound of the range of m d r rules (not inclusive)
928             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
929             * @return the ordered range of matching m d r rules
930             */
931            @Override
932            public List<MDRRule> findByUuid_C(String uuid, long companyId, int start,
933                    int end, OrderByComparator<MDRRule> orderByComparator) {
934                    boolean pagination = true;
935                    FinderPath finderPath = null;
936                    Object[] finderArgs = null;
937    
938                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
939                                    (orderByComparator == null)) {
940                            pagination = false;
941                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
942                            finderArgs = new Object[] { uuid, companyId };
943                    }
944                    else {
945                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
946                            finderArgs = new Object[] {
947                                            uuid, companyId,
948                                            
949                                            start, end, orderByComparator
950                                    };
951                    }
952    
953                    List<MDRRule> list = (List<MDRRule>)FinderCacheUtil.getResult(finderPath,
954                                    finderArgs, this);
955    
956                    if ((list != null) && !list.isEmpty()) {
957                            for (MDRRule mdrRule : list) {
958                                    if (!Validator.equals(uuid, mdrRule.getUuid()) ||
959                                                    (companyId != mdrRule.getCompanyId())) {
960                                            list = null;
961    
962                                            break;
963                                    }
964                            }
965                    }
966    
967                    if (list == null) {
968                            StringBundler query = null;
969    
970                            if (orderByComparator != null) {
971                                    query = new StringBundler(4 +
972                                                    (orderByComparator.getOrderByFields().length * 3));
973                            }
974                            else {
975                                    query = new StringBundler(4);
976                            }
977    
978                            query.append(_SQL_SELECT_MDRRULE_WHERE);
979    
980                            boolean bindUuid = false;
981    
982                            if (uuid == null) {
983                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
984                            }
985                            else if (uuid.equals(StringPool.BLANK)) {
986                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
987                            }
988                            else {
989                                    bindUuid = true;
990    
991                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
992                            }
993    
994                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
995    
996                            if (orderByComparator != null) {
997                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
998                                            orderByComparator);
999                            }
1000                            else
1001                             if (pagination) {
1002                                    query.append(MDRRuleModelImpl.ORDER_BY_JPQL);
1003                            }
1004    
1005                            String sql = query.toString();
1006    
1007                            Session session = null;
1008    
1009                            try {
1010                                    session = openSession();
1011    
1012                                    Query q = session.createQuery(sql);
1013    
1014                                    QueryPos qPos = QueryPos.getInstance(q);
1015    
1016                                    if (bindUuid) {
1017                                            qPos.add(uuid);
1018                                    }
1019    
1020                                    qPos.add(companyId);
1021    
1022                                    if (!pagination) {
1023                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
1024                                                            start, end, false);
1025    
1026                                            Collections.sort(list);
1027    
1028                                            list = Collections.unmodifiableList(list);
1029                                    }
1030                                    else {
1031                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
1032                                                            start, end);
1033                                    }
1034    
1035                                    cacheResult(list);
1036    
1037                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1038                            }
1039                            catch (Exception e) {
1040                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1041    
1042                                    throw processException(e);
1043                            }
1044                            finally {
1045                                    closeSession(session);
1046                            }
1047                    }
1048    
1049                    return list;
1050            }
1051    
1052            /**
1053             * Returns the first m d r rule in the ordered set where uuid = &#63; and companyId = &#63;.
1054             *
1055             * @param uuid the uuid
1056             * @param companyId the company ID
1057             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1058             * @return the first matching m d r rule
1059             * @throws NoSuchRuleException if a matching m d r rule could not be found
1060             */
1061            @Override
1062            public MDRRule findByUuid_C_First(String uuid, long companyId,
1063                    OrderByComparator<MDRRule> orderByComparator)
1064                    throws NoSuchRuleException {
1065                    MDRRule mdrRule = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1066    
1067                    if (mdrRule != null) {
1068                            return mdrRule;
1069                    }
1070    
1071                    StringBundler msg = new StringBundler(6);
1072    
1073                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1074    
1075                    msg.append("uuid=");
1076                    msg.append(uuid);
1077    
1078                    msg.append(", companyId=");
1079                    msg.append(companyId);
1080    
1081                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1082    
1083                    throw new NoSuchRuleException(msg.toString());
1084            }
1085    
1086            /**
1087             * Returns the first m d r rule in the ordered set where uuid = &#63; and companyId = &#63;.
1088             *
1089             * @param uuid the uuid
1090             * @param companyId the company ID
1091             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1092             * @return the first matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
1093             */
1094            @Override
1095            public MDRRule fetchByUuid_C_First(String uuid, long companyId,
1096                    OrderByComparator<MDRRule> orderByComparator) {
1097                    List<MDRRule> list = findByUuid_C(uuid, companyId, 0, 1,
1098                                    orderByComparator);
1099    
1100                    if (!list.isEmpty()) {
1101                            return list.get(0);
1102                    }
1103    
1104                    return null;
1105            }
1106    
1107            /**
1108             * Returns the last m d r rule in the ordered set where uuid = &#63; and companyId = &#63;.
1109             *
1110             * @param uuid the uuid
1111             * @param companyId the company ID
1112             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1113             * @return the last matching m d r rule
1114             * @throws NoSuchRuleException if a matching m d r rule could not be found
1115             */
1116            @Override
1117            public MDRRule findByUuid_C_Last(String uuid, long companyId,
1118                    OrderByComparator<MDRRule> orderByComparator)
1119                    throws NoSuchRuleException {
1120                    MDRRule mdrRule = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1121    
1122                    if (mdrRule != null) {
1123                            return mdrRule;
1124                    }
1125    
1126                    StringBundler msg = new StringBundler(6);
1127    
1128                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1129    
1130                    msg.append("uuid=");
1131                    msg.append(uuid);
1132    
1133                    msg.append(", companyId=");
1134                    msg.append(companyId);
1135    
1136                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1137    
1138                    throw new NoSuchRuleException(msg.toString());
1139            }
1140    
1141            /**
1142             * Returns the last m d r rule in the ordered set where uuid = &#63; and companyId = &#63;.
1143             *
1144             * @param uuid the uuid
1145             * @param companyId the company ID
1146             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1147             * @return the last matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
1148             */
1149            @Override
1150            public MDRRule fetchByUuid_C_Last(String uuid, long companyId,
1151                    OrderByComparator<MDRRule> orderByComparator) {
1152                    int count = countByUuid_C(uuid, companyId);
1153    
1154                    if (count == 0) {
1155                            return null;
1156                    }
1157    
1158                    List<MDRRule> list = findByUuid_C(uuid, companyId, count - 1, count,
1159                                    orderByComparator);
1160    
1161                    if (!list.isEmpty()) {
1162                            return list.get(0);
1163                    }
1164    
1165                    return null;
1166            }
1167    
1168            /**
1169             * Returns the m d r rules before and after the current m d r rule in the ordered set where uuid = &#63; and companyId = &#63;.
1170             *
1171             * @param ruleId the primary key of the current m d r rule
1172             * @param uuid the uuid
1173             * @param companyId the company ID
1174             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1175             * @return the previous, current, and next m d r rule
1176             * @throws NoSuchRuleException if a m d r rule with the primary key could not be found
1177             */
1178            @Override
1179            public MDRRule[] findByUuid_C_PrevAndNext(long ruleId, String uuid,
1180                    long companyId, OrderByComparator<MDRRule> orderByComparator)
1181                    throws NoSuchRuleException {
1182                    MDRRule mdrRule = findByPrimaryKey(ruleId);
1183    
1184                    Session session = null;
1185    
1186                    try {
1187                            session = openSession();
1188    
1189                            MDRRule[] array = new MDRRuleImpl[3];
1190    
1191                            array[0] = getByUuid_C_PrevAndNext(session, mdrRule, uuid,
1192                                            companyId, orderByComparator, true);
1193    
1194                            array[1] = mdrRule;
1195    
1196                            array[2] = getByUuid_C_PrevAndNext(session, mdrRule, uuid,
1197                                            companyId, orderByComparator, false);
1198    
1199                            return array;
1200                    }
1201                    catch (Exception e) {
1202                            throw processException(e);
1203                    }
1204                    finally {
1205                            closeSession(session);
1206                    }
1207            }
1208    
1209            protected MDRRule getByUuid_C_PrevAndNext(Session session, MDRRule mdrRule,
1210                    String uuid, long companyId,
1211                    OrderByComparator<MDRRule> orderByComparator, boolean previous) {
1212                    StringBundler query = null;
1213    
1214                    if (orderByComparator != null) {
1215                            query = new StringBundler(6 +
1216                                            (orderByComparator.getOrderByFields().length * 6));
1217                    }
1218                    else {
1219                            query = new StringBundler(3);
1220                    }
1221    
1222                    query.append(_SQL_SELECT_MDRRULE_WHERE);
1223    
1224                    boolean bindUuid = false;
1225    
1226                    if (uuid == null) {
1227                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1228                    }
1229                    else if (uuid.equals(StringPool.BLANK)) {
1230                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1231                    }
1232                    else {
1233                            bindUuid = true;
1234    
1235                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1236                    }
1237    
1238                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1239    
1240                    if (orderByComparator != null) {
1241                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1242    
1243                            if (orderByConditionFields.length > 0) {
1244                                    query.append(WHERE_AND);
1245                            }
1246    
1247                            for (int i = 0; i < orderByConditionFields.length; i++) {
1248                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1249                                    query.append(orderByConditionFields[i]);
1250    
1251                                    if ((i + 1) < orderByConditionFields.length) {
1252                                            if (orderByComparator.isAscending() ^ previous) {
1253                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1254                                            }
1255                                            else {
1256                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1257                                            }
1258                                    }
1259                                    else {
1260                                            if (orderByComparator.isAscending() ^ previous) {
1261                                                    query.append(WHERE_GREATER_THAN);
1262                                            }
1263                                            else {
1264                                                    query.append(WHERE_LESSER_THAN);
1265                                            }
1266                                    }
1267                            }
1268    
1269                            query.append(ORDER_BY_CLAUSE);
1270    
1271                            String[] orderByFields = orderByComparator.getOrderByFields();
1272    
1273                            for (int i = 0; i < orderByFields.length; i++) {
1274                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1275                                    query.append(orderByFields[i]);
1276    
1277                                    if ((i + 1) < orderByFields.length) {
1278                                            if (orderByComparator.isAscending() ^ previous) {
1279                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1280                                            }
1281                                            else {
1282                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1283                                            }
1284                                    }
1285                                    else {
1286                                            if (orderByComparator.isAscending() ^ previous) {
1287                                                    query.append(ORDER_BY_ASC);
1288                                            }
1289                                            else {
1290                                                    query.append(ORDER_BY_DESC);
1291                                            }
1292                                    }
1293                            }
1294                    }
1295                    else {
1296                            query.append(MDRRuleModelImpl.ORDER_BY_JPQL);
1297                    }
1298    
1299                    String sql = query.toString();
1300    
1301                    Query q = session.createQuery(sql);
1302    
1303                    q.setFirstResult(0);
1304                    q.setMaxResults(2);
1305    
1306                    QueryPos qPos = QueryPos.getInstance(q);
1307    
1308                    if (bindUuid) {
1309                            qPos.add(uuid);
1310                    }
1311    
1312                    qPos.add(companyId);
1313    
1314                    if (orderByComparator != null) {
1315                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRule);
1316    
1317                            for (Object value : values) {
1318                                    qPos.add(value);
1319                            }
1320                    }
1321    
1322                    List<MDRRule> list = q.list();
1323    
1324                    if (list.size() == 2) {
1325                            return list.get(1);
1326                    }
1327                    else {
1328                            return null;
1329                    }
1330            }
1331    
1332            /**
1333             * Removes all the m d r rules where uuid = &#63; and companyId = &#63; from the database.
1334             *
1335             * @param uuid the uuid
1336             * @param companyId the company ID
1337             */
1338            @Override
1339            public void removeByUuid_C(String uuid, long companyId) {
1340                    for (MDRRule mdrRule : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1341                                    QueryUtil.ALL_POS, null)) {
1342                            remove(mdrRule);
1343                    }
1344            }
1345    
1346            /**
1347             * Returns the number of m d r rules where uuid = &#63; and companyId = &#63;.
1348             *
1349             * @param uuid the uuid
1350             * @param companyId the company ID
1351             * @return the number of matching m d r rules
1352             */
1353            @Override
1354            public int countByUuid_C(String uuid, long companyId) {
1355                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1356    
1357                    Object[] finderArgs = new Object[] { uuid, companyId };
1358    
1359                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1360                                    this);
1361    
1362                    if (count == null) {
1363                            StringBundler query = new StringBundler(3);
1364    
1365                            query.append(_SQL_COUNT_MDRRULE_WHERE);
1366    
1367                            boolean bindUuid = false;
1368    
1369                            if (uuid == null) {
1370                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1371                            }
1372                            else if (uuid.equals(StringPool.BLANK)) {
1373                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1374                            }
1375                            else {
1376                                    bindUuid = true;
1377    
1378                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1379                            }
1380    
1381                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1382    
1383                            String sql = query.toString();
1384    
1385                            Session session = null;
1386    
1387                            try {
1388                                    session = openSession();
1389    
1390                                    Query q = session.createQuery(sql);
1391    
1392                                    QueryPos qPos = QueryPos.getInstance(q);
1393    
1394                                    if (bindUuid) {
1395                                            qPos.add(uuid);
1396                                    }
1397    
1398                                    qPos.add(companyId);
1399    
1400                                    count = (Long)q.uniqueResult();
1401    
1402                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1403                            }
1404                            catch (Exception e) {
1405                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1406    
1407                                    throw processException(e);
1408                            }
1409                            finally {
1410                                    closeSession(session);
1411                            }
1412                    }
1413    
1414                    return count.intValue();
1415            }
1416    
1417            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mdrRule.uuid IS NULL AND ";
1418            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mdrRule.uuid = ? AND ";
1419            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mdrRule.uuid IS NULL OR mdrRule.uuid = '') AND ";
1420            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mdrRule.companyId = ?";
1421            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID =
1422                    new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1423                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
1424                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRuleGroupId",
1425                            new String[] {
1426                                    Long.class.getName(),
1427                                    
1428                            Integer.class.getName(), Integer.class.getName(),
1429                                    OrderByComparator.class.getName()
1430                            });
1431            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID =
1432                    new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1433                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, MDRRuleImpl.class,
1434                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRuleGroupId",
1435                            new String[] { Long.class.getName() },
1436                            MDRRuleModelImpl.RULEGROUPID_COLUMN_BITMASK);
1437            public static final FinderPath FINDER_PATH_COUNT_BY_RULEGROUPID = new FinderPath(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1438                            MDRRuleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1439                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRuleGroupId",
1440                            new String[] { Long.class.getName() });
1441    
1442            /**
1443             * Returns all the m d r rules where ruleGroupId = &#63;.
1444             *
1445             * @param ruleGroupId the rule group ID
1446             * @return the matching m d r rules
1447             */
1448            @Override
1449            public List<MDRRule> findByRuleGroupId(long ruleGroupId) {
1450                    return findByRuleGroupId(ruleGroupId, QueryUtil.ALL_POS,
1451                            QueryUtil.ALL_POS, null);
1452            }
1453    
1454            /**
1455             * Returns a range of all the m d r rules where ruleGroupId = &#63;.
1456             *
1457             * <p>
1458             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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 MDRRuleModelImpl}. 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.
1459             * </p>
1460             *
1461             * @param ruleGroupId the rule group ID
1462             * @param start the lower bound of the range of m d r rules
1463             * @param end the upper bound of the range of m d r rules (not inclusive)
1464             * @return the range of matching m d r rules
1465             */
1466            @Override
1467            public List<MDRRule> findByRuleGroupId(long ruleGroupId, int start, int end) {
1468                    return findByRuleGroupId(ruleGroupId, start, end, null);
1469            }
1470    
1471            /**
1472             * Returns an ordered range of all the m d r rules where ruleGroupId = &#63;.
1473             *
1474             * <p>
1475             * 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 MDRRuleModelImpl}. 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.
1476             * </p>
1477             *
1478             * @param ruleGroupId the rule group ID
1479             * @param start the lower bound of the range of m d r rules
1480             * @param end the upper bound of the range of m d r rules (not inclusive)
1481             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1482             * @return the ordered range of matching m d r rules
1483             */
1484            @Override
1485            public List<MDRRule> findByRuleGroupId(long ruleGroupId, int start,
1486                    int end, OrderByComparator<MDRRule> orderByComparator) {
1487                    boolean pagination = true;
1488                    FinderPath finderPath = null;
1489                    Object[] finderArgs = null;
1490    
1491                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1492                                    (orderByComparator == null)) {
1493                            pagination = false;
1494                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID;
1495                            finderArgs = new Object[] { ruleGroupId };
1496                    }
1497                    else {
1498                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID;
1499                            finderArgs = new Object[] { ruleGroupId, start, end, orderByComparator };
1500                    }
1501    
1502                    List<MDRRule> list = (List<MDRRule>)FinderCacheUtil.getResult(finderPath,
1503                                    finderArgs, this);
1504    
1505                    if ((list != null) && !list.isEmpty()) {
1506                            for (MDRRule mdrRule : list) {
1507                                    if ((ruleGroupId != mdrRule.getRuleGroupId())) {
1508                                            list = null;
1509    
1510                                            break;
1511                                    }
1512                            }
1513                    }
1514    
1515                    if (list == null) {
1516                            StringBundler query = null;
1517    
1518                            if (orderByComparator != null) {
1519                                    query = new StringBundler(3 +
1520                                                    (orderByComparator.getOrderByFields().length * 3));
1521                            }
1522                            else {
1523                                    query = new StringBundler(3);
1524                            }
1525    
1526                            query.append(_SQL_SELECT_MDRRULE_WHERE);
1527    
1528                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
1529    
1530                            if (orderByComparator != null) {
1531                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1532                                            orderByComparator);
1533                            }
1534                            else
1535                             if (pagination) {
1536                                    query.append(MDRRuleModelImpl.ORDER_BY_JPQL);
1537                            }
1538    
1539                            String sql = query.toString();
1540    
1541                            Session session = null;
1542    
1543                            try {
1544                                    session = openSession();
1545    
1546                                    Query q = session.createQuery(sql);
1547    
1548                                    QueryPos qPos = QueryPos.getInstance(q);
1549    
1550                                    qPos.add(ruleGroupId);
1551    
1552                                    if (!pagination) {
1553                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
1554                                                            start, end, false);
1555    
1556                                            Collections.sort(list);
1557    
1558                                            list = Collections.unmodifiableList(list);
1559                                    }
1560                                    else {
1561                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
1562                                                            start, end);
1563                                    }
1564    
1565                                    cacheResult(list);
1566    
1567                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1568                            }
1569                            catch (Exception e) {
1570                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1571    
1572                                    throw processException(e);
1573                            }
1574                            finally {
1575                                    closeSession(session);
1576                            }
1577                    }
1578    
1579                    return list;
1580            }
1581    
1582            /**
1583             * Returns the first m d r rule in the ordered set where ruleGroupId = &#63;.
1584             *
1585             * @param ruleGroupId the rule group ID
1586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1587             * @return the first matching m d r rule
1588             * @throws NoSuchRuleException if a matching m d r rule could not be found
1589             */
1590            @Override
1591            public MDRRule findByRuleGroupId_First(long ruleGroupId,
1592                    OrderByComparator<MDRRule> orderByComparator)
1593                    throws NoSuchRuleException {
1594                    MDRRule mdrRule = fetchByRuleGroupId_First(ruleGroupId,
1595                                    orderByComparator);
1596    
1597                    if (mdrRule != null) {
1598                            return mdrRule;
1599                    }
1600    
1601                    StringBundler msg = new StringBundler(4);
1602    
1603                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1604    
1605                    msg.append("ruleGroupId=");
1606                    msg.append(ruleGroupId);
1607    
1608                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1609    
1610                    throw new NoSuchRuleException(msg.toString());
1611            }
1612    
1613            /**
1614             * Returns the first m d r rule in the ordered set where ruleGroupId = &#63;.
1615             *
1616             * @param ruleGroupId the rule group ID
1617             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1618             * @return the first matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
1619             */
1620            @Override
1621            public MDRRule fetchByRuleGroupId_First(long ruleGroupId,
1622                    OrderByComparator<MDRRule> orderByComparator) {
1623                    List<MDRRule> list = findByRuleGroupId(ruleGroupId, 0, 1,
1624                                    orderByComparator);
1625    
1626                    if (!list.isEmpty()) {
1627                            return list.get(0);
1628                    }
1629    
1630                    return null;
1631            }
1632    
1633            /**
1634             * Returns the last m d r rule in the ordered set where ruleGroupId = &#63;.
1635             *
1636             * @param ruleGroupId the rule group ID
1637             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1638             * @return the last matching m d r rule
1639             * @throws NoSuchRuleException if a matching m d r rule could not be found
1640             */
1641            @Override
1642            public MDRRule findByRuleGroupId_Last(long ruleGroupId,
1643                    OrderByComparator<MDRRule> orderByComparator)
1644                    throws NoSuchRuleException {
1645                    MDRRule mdrRule = fetchByRuleGroupId_Last(ruleGroupId, orderByComparator);
1646    
1647                    if (mdrRule != null) {
1648                            return mdrRule;
1649                    }
1650    
1651                    StringBundler msg = new StringBundler(4);
1652    
1653                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1654    
1655                    msg.append("ruleGroupId=");
1656                    msg.append(ruleGroupId);
1657    
1658                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1659    
1660                    throw new NoSuchRuleException(msg.toString());
1661            }
1662    
1663            /**
1664             * Returns the last m d r rule in the ordered set where ruleGroupId = &#63;.
1665             *
1666             * @param ruleGroupId the rule group ID
1667             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1668             * @return the last matching m d r rule, or <code>null</code> if a matching m d r rule could not be found
1669             */
1670            @Override
1671            public MDRRule fetchByRuleGroupId_Last(long ruleGroupId,
1672                    OrderByComparator<MDRRule> orderByComparator) {
1673                    int count = countByRuleGroupId(ruleGroupId);
1674    
1675                    if (count == 0) {
1676                            return null;
1677                    }
1678    
1679                    List<MDRRule> list = findByRuleGroupId(ruleGroupId, count - 1, count,
1680                                    orderByComparator);
1681    
1682                    if (!list.isEmpty()) {
1683                            return list.get(0);
1684                    }
1685    
1686                    return null;
1687            }
1688    
1689            /**
1690             * Returns the m d r rules before and after the current m d r rule in the ordered set where ruleGroupId = &#63;.
1691             *
1692             * @param ruleId the primary key of the current m d r rule
1693             * @param ruleGroupId the rule group ID
1694             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1695             * @return the previous, current, and next m d r rule
1696             * @throws NoSuchRuleException if a m d r rule with the primary key could not be found
1697             */
1698            @Override
1699            public MDRRule[] findByRuleGroupId_PrevAndNext(long ruleId,
1700                    long ruleGroupId, OrderByComparator<MDRRule> orderByComparator)
1701                    throws NoSuchRuleException {
1702                    MDRRule mdrRule = findByPrimaryKey(ruleId);
1703    
1704                    Session session = null;
1705    
1706                    try {
1707                            session = openSession();
1708    
1709                            MDRRule[] array = new MDRRuleImpl[3];
1710    
1711                            array[0] = getByRuleGroupId_PrevAndNext(session, mdrRule,
1712                                            ruleGroupId, orderByComparator, true);
1713    
1714                            array[1] = mdrRule;
1715    
1716                            array[2] = getByRuleGroupId_PrevAndNext(session, mdrRule,
1717                                            ruleGroupId, orderByComparator, false);
1718    
1719                            return array;
1720                    }
1721                    catch (Exception e) {
1722                            throw processException(e);
1723                    }
1724                    finally {
1725                            closeSession(session);
1726                    }
1727            }
1728    
1729            protected MDRRule getByRuleGroupId_PrevAndNext(Session session,
1730                    MDRRule mdrRule, long ruleGroupId,
1731                    OrderByComparator<MDRRule> orderByComparator, boolean previous) {
1732                    StringBundler query = null;
1733    
1734                    if (orderByComparator != null) {
1735                            query = new StringBundler(6 +
1736                                            (orderByComparator.getOrderByFields().length * 6));
1737                    }
1738                    else {
1739                            query = new StringBundler(3);
1740                    }
1741    
1742                    query.append(_SQL_SELECT_MDRRULE_WHERE);
1743    
1744                    query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
1745    
1746                    if (orderByComparator != null) {
1747                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1748    
1749                            if (orderByConditionFields.length > 0) {
1750                                    query.append(WHERE_AND);
1751                            }
1752    
1753                            for (int i = 0; i < orderByConditionFields.length; i++) {
1754                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1755                                    query.append(orderByConditionFields[i]);
1756    
1757                                    if ((i + 1) < orderByConditionFields.length) {
1758                                            if (orderByComparator.isAscending() ^ previous) {
1759                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1760                                            }
1761                                            else {
1762                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1763                                            }
1764                                    }
1765                                    else {
1766                                            if (orderByComparator.isAscending() ^ previous) {
1767                                                    query.append(WHERE_GREATER_THAN);
1768                                            }
1769                                            else {
1770                                                    query.append(WHERE_LESSER_THAN);
1771                                            }
1772                                    }
1773                            }
1774    
1775                            query.append(ORDER_BY_CLAUSE);
1776    
1777                            String[] orderByFields = orderByComparator.getOrderByFields();
1778    
1779                            for (int i = 0; i < orderByFields.length; i++) {
1780                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1781                                    query.append(orderByFields[i]);
1782    
1783                                    if ((i + 1) < orderByFields.length) {
1784                                            if (orderByComparator.isAscending() ^ previous) {
1785                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1786                                            }
1787                                            else {
1788                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1789                                            }
1790                                    }
1791                                    else {
1792                                            if (orderByComparator.isAscending() ^ previous) {
1793                                                    query.append(ORDER_BY_ASC);
1794                                            }
1795                                            else {
1796                                                    query.append(ORDER_BY_DESC);
1797                                            }
1798                                    }
1799                            }
1800                    }
1801                    else {
1802                            query.append(MDRRuleModelImpl.ORDER_BY_JPQL);
1803                    }
1804    
1805                    String sql = query.toString();
1806    
1807                    Query q = session.createQuery(sql);
1808    
1809                    q.setFirstResult(0);
1810                    q.setMaxResults(2);
1811    
1812                    QueryPos qPos = QueryPos.getInstance(q);
1813    
1814                    qPos.add(ruleGroupId);
1815    
1816                    if (orderByComparator != null) {
1817                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRule);
1818    
1819                            for (Object value : values) {
1820                                    qPos.add(value);
1821                            }
1822                    }
1823    
1824                    List<MDRRule> list = q.list();
1825    
1826                    if (list.size() == 2) {
1827                            return list.get(1);
1828                    }
1829                    else {
1830                            return null;
1831                    }
1832            }
1833    
1834            /**
1835             * Removes all the m d r rules where ruleGroupId = &#63; from the database.
1836             *
1837             * @param ruleGroupId the rule group ID
1838             */
1839            @Override
1840            public void removeByRuleGroupId(long ruleGroupId) {
1841                    for (MDRRule mdrRule : findByRuleGroupId(ruleGroupId,
1842                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1843                            remove(mdrRule);
1844                    }
1845            }
1846    
1847            /**
1848             * Returns the number of m d r rules where ruleGroupId = &#63;.
1849             *
1850             * @param ruleGroupId the rule group ID
1851             * @return the number of matching m d r rules
1852             */
1853            @Override
1854            public int countByRuleGroupId(long ruleGroupId) {
1855                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RULEGROUPID;
1856    
1857                    Object[] finderArgs = new Object[] { ruleGroupId };
1858    
1859                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1860                                    this);
1861    
1862                    if (count == null) {
1863                            StringBundler query = new StringBundler(2);
1864    
1865                            query.append(_SQL_COUNT_MDRRULE_WHERE);
1866    
1867                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
1868    
1869                            String sql = query.toString();
1870    
1871                            Session session = null;
1872    
1873                            try {
1874                                    session = openSession();
1875    
1876                                    Query q = session.createQuery(sql);
1877    
1878                                    QueryPos qPos = QueryPos.getInstance(q);
1879    
1880                                    qPos.add(ruleGroupId);
1881    
1882                                    count = (Long)q.uniqueResult();
1883    
1884                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1885                            }
1886                            catch (Exception e) {
1887                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1888    
1889                                    throw processException(e);
1890                            }
1891                            finally {
1892                                    closeSession(session);
1893                            }
1894                    }
1895    
1896                    return count.intValue();
1897            }
1898    
1899            private static final String _FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2 = "mdrRule.ruleGroupId = ?";
1900    
1901            public MDRRulePersistenceImpl() {
1902                    setModelClass(MDRRule.class);
1903            }
1904    
1905            /**
1906             * Caches the m d r rule in the entity cache if it is enabled.
1907             *
1908             * @param mdrRule the m d r rule
1909             */
1910            @Override
1911            public void cacheResult(MDRRule mdrRule) {
1912                    EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1913                            MDRRuleImpl.class, mdrRule.getPrimaryKey(), mdrRule);
1914    
1915                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1916                            new Object[] { mdrRule.getUuid(), mdrRule.getGroupId() }, mdrRule);
1917    
1918                    mdrRule.resetOriginalValues();
1919            }
1920    
1921            /**
1922             * Caches the m d r rules in the entity cache if it is enabled.
1923             *
1924             * @param mdrRules the m d r rules
1925             */
1926            @Override
1927            public void cacheResult(List<MDRRule> mdrRules) {
1928                    for (MDRRule mdrRule : mdrRules) {
1929                            if (EntityCacheUtil.getResult(
1930                                                    MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1931                                                    MDRRuleImpl.class, mdrRule.getPrimaryKey()) == null) {
1932                                    cacheResult(mdrRule);
1933                            }
1934                            else {
1935                                    mdrRule.resetOriginalValues();
1936                            }
1937                    }
1938            }
1939    
1940            /**
1941             * Clears the cache for all m d r rules.
1942             *
1943             * <p>
1944             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1945             * </p>
1946             */
1947            @Override
1948            public void clearCache() {
1949                    EntityCacheUtil.clearCache(MDRRuleImpl.class);
1950    
1951                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1952                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1953                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1954            }
1955    
1956            /**
1957             * Clears the cache for the m d r rule.
1958             *
1959             * <p>
1960             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1961             * </p>
1962             */
1963            @Override
1964            public void clearCache(MDRRule mdrRule) {
1965                    EntityCacheUtil.removeResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1966                            MDRRuleImpl.class, mdrRule.getPrimaryKey());
1967    
1968                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1969                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1970    
1971                    clearUniqueFindersCache(mdrRule);
1972            }
1973    
1974            @Override
1975            public void clearCache(List<MDRRule> mdrRules) {
1976                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1977                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1978    
1979                    for (MDRRule mdrRule : mdrRules) {
1980                            EntityCacheUtil.removeResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1981                                    MDRRuleImpl.class, mdrRule.getPrimaryKey());
1982    
1983                            clearUniqueFindersCache(mdrRule);
1984                    }
1985            }
1986    
1987            protected void cacheUniqueFindersCache(MDRRule mdrRule) {
1988                    if (mdrRule.isNew()) {
1989                            Object[] args = new Object[] { mdrRule.getUuid(), mdrRule.getGroupId() };
1990    
1991                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
1992                                    Long.valueOf(1));
1993                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args, mdrRule);
1994                    }
1995                    else {
1996                            MDRRuleModelImpl mdrRuleModelImpl = (MDRRuleModelImpl)mdrRule;
1997    
1998                            if ((mdrRuleModelImpl.getColumnBitmask() &
1999                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2000                                    Object[] args = new Object[] {
2001                                                    mdrRule.getUuid(), mdrRule.getGroupId()
2002                                            };
2003    
2004                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2005                                            Long.valueOf(1));
2006                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2007                                            mdrRule);
2008                            }
2009                    }
2010            }
2011    
2012            protected void clearUniqueFindersCache(MDRRule mdrRule) {
2013                    MDRRuleModelImpl mdrRuleModelImpl = (MDRRuleModelImpl)mdrRule;
2014    
2015                    Object[] args = new Object[] { mdrRule.getUuid(), mdrRule.getGroupId() };
2016    
2017                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2018                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2019    
2020                    if ((mdrRuleModelImpl.getColumnBitmask() &
2021                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2022                            args = new Object[] {
2023                                            mdrRuleModelImpl.getOriginalUuid(),
2024                                            mdrRuleModelImpl.getOriginalGroupId()
2025                                    };
2026    
2027                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2028                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2029                    }
2030            }
2031    
2032            /**
2033             * Creates a new m d r rule with the primary key. Does not add the m d r rule to the database.
2034             *
2035             * @param ruleId the primary key for the new m d r rule
2036             * @return the new m d r rule
2037             */
2038            @Override
2039            public MDRRule create(long ruleId) {
2040                    MDRRule mdrRule = new MDRRuleImpl();
2041    
2042                    mdrRule.setNew(true);
2043                    mdrRule.setPrimaryKey(ruleId);
2044    
2045                    String uuid = PortalUUIDUtil.generate();
2046    
2047                    mdrRule.setUuid(uuid);
2048    
2049                    return mdrRule;
2050            }
2051    
2052            /**
2053             * Removes the m d r rule with the primary key from the database. Also notifies the appropriate model listeners.
2054             *
2055             * @param ruleId the primary key of the m d r rule
2056             * @return the m d r rule that was removed
2057             * @throws NoSuchRuleException if a m d r rule with the primary key could not be found
2058             */
2059            @Override
2060            public MDRRule remove(long ruleId) throws NoSuchRuleException {
2061                    return remove((Serializable)ruleId);
2062            }
2063    
2064            /**
2065             * Removes the m d r rule with the primary key from the database. Also notifies the appropriate model listeners.
2066             *
2067             * @param primaryKey the primary key of the m d r rule
2068             * @return the m d r rule that was removed
2069             * @throws NoSuchRuleException if a m d r rule with the primary key could not be found
2070             */
2071            @Override
2072            public MDRRule remove(Serializable primaryKey) throws NoSuchRuleException {
2073                    Session session = null;
2074    
2075                    try {
2076                            session = openSession();
2077    
2078                            MDRRule mdrRule = (MDRRule)session.get(MDRRuleImpl.class, primaryKey);
2079    
2080                            if (mdrRule == null) {
2081                                    if (_log.isWarnEnabled()) {
2082                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2083                                    }
2084    
2085                                    throw new NoSuchRuleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2086                                            primaryKey);
2087                            }
2088    
2089                            return remove(mdrRule);
2090                    }
2091                    catch (NoSuchRuleException nsee) {
2092                            throw nsee;
2093                    }
2094                    catch (Exception e) {
2095                            throw processException(e);
2096                    }
2097                    finally {
2098                            closeSession(session);
2099                    }
2100            }
2101    
2102            @Override
2103            protected MDRRule removeImpl(MDRRule mdrRule) {
2104                    mdrRule = toUnwrappedModel(mdrRule);
2105    
2106                    Session session = null;
2107    
2108                    try {
2109                            session = openSession();
2110    
2111                            if (!session.contains(mdrRule)) {
2112                                    mdrRule = (MDRRule)session.get(MDRRuleImpl.class,
2113                                                    mdrRule.getPrimaryKeyObj());
2114                            }
2115    
2116                            if (mdrRule != null) {
2117                                    session.delete(mdrRule);
2118                            }
2119                    }
2120                    catch (Exception e) {
2121                            throw processException(e);
2122                    }
2123                    finally {
2124                            closeSession(session);
2125                    }
2126    
2127                    if (mdrRule != null) {
2128                            clearCache(mdrRule);
2129                    }
2130    
2131                    return mdrRule;
2132            }
2133    
2134            @Override
2135            public MDRRule updateImpl(MDRRule mdrRule) {
2136                    mdrRule = toUnwrappedModel(mdrRule);
2137    
2138                    boolean isNew = mdrRule.isNew();
2139    
2140                    MDRRuleModelImpl mdrRuleModelImpl = (MDRRuleModelImpl)mdrRule;
2141    
2142                    if (Validator.isNull(mdrRule.getUuid())) {
2143                            String uuid = PortalUUIDUtil.generate();
2144    
2145                            mdrRule.setUuid(uuid);
2146                    }
2147    
2148                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2149    
2150                    Date now = new Date();
2151    
2152                    if (isNew && (mdrRule.getCreateDate() == null)) {
2153                            if (serviceContext == null) {
2154                                    mdrRule.setCreateDate(now);
2155                            }
2156                            else {
2157                                    mdrRule.setCreateDate(serviceContext.getCreateDate(now));
2158                            }
2159                    }
2160    
2161                    if (!mdrRuleModelImpl.hasSetModifiedDate()) {
2162                            if (serviceContext == null) {
2163                                    mdrRule.setModifiedDate(now);
2164                            }
2165                            else {
2166                                    mdrRule.setModifiedDate(serviceContext.getModifiedDate(now));
2167                            }
2168                    }
2169    
2170                    Session session = null;
2171    
2172                    try {
2173                            session = openSession();
2174    
2175                            if (mdrRule.isNew()) {
2176                                    session.save(mdrRule);
2177    
2178                                    mdrRule.setNew(false);
2179                            }
2180                            else {
2181                                    session.merge(mdrRule);
2182                            }
2183                    }
2184                    catch (Exception e) {
2185                            throw processException(e);
2186                    }
2187                    finally {
2188                            closeSession(session);
2189                    }
2190    
2191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2192    
2193                    if (isNew || !MDRRuleModelImpl.COLUMN_BITMASK_ENABLED) {
2194                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2195                    }
2196    
2197                    else {
2198                            if ((mdrRuleModelImpl.getColumnBitmask() &
2199                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2200                                    Object[] args = new Object[] { mdrRuleModelImpl.getOriginalUuid() };
2201    
2202                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2203                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2204                                            args);
2205    
2206                                    args = new Object[] { mdrRuleModelImpl.getUuid() };
2207    
2208                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2209                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2210                                            args);
2211                            }
2212    
2213                            if ((mdrRuleModelImpl.getColumnBitmask() &
2214                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2215                                    Object[] args = new Object[] {
2216                                                    mdrRuleModelImpl.getOriginalUuid(),
2217                                                    mdrRuleModelImpl.getOriginalCompanyId()
2218                                            };
2219    
2220                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2221                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2222                                            args);
2223    
2224                                    args = new Object[] {
2225                                                    mdrRuleModelImpl.getUuid(),
2226                                                    mdrRuleModelImpl.getCompanyId()
2227                                            };
2228    
2229                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2230                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2231                                            args);
2232                            }
2233    
2234                            if ((mdrRuleModelImpl.getColumnBitmask() &
2235                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID.getColumnBitmask()) != 0) {
2236                                    Object[] args = new Object[] {
2237                                                    mdrRuleModelImpl.getOriginalRuleGroupId()
2238                                            };
2239    
2240                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
2241                                            args);
2242                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
2243                                            args);
2244    
2245                                    args = new Object[] { mdrRuleModelImpl.getRuleGroupId() };
2246    
2247                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
2248                                            args);
2249                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
2250                                            args);
2251                            }
2252                    }
2253    
2254                    EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2255                            MDRRuleImpl.class, mdrRule.getPrimaryKey(), mdrRule, false);
2256    
2257                    clearUniqueFindersCache(mdrRule);
2258                    cacheUniqueFindersCache(mdrRule);
2259    
2260                    mdrRule.resetOriginalValues();
2261    
2262                    return mdrRule;
2263            }
2264    
2265            protected MDRRule toUnwrappedModel(MDRRule mdrRule) {
2266                    if (mdrRule instanceof MDRRuleImpl) {
2267                            return mdrRule;
2268                    }
2269    
2270                    MDRRuleImpl mdrRuleImpl = new MDRRuleImpl();
2271    
2272                    mdrRuleImpl.setNew(mdrRule.isNew());
2273                    mdrRuleImpl.setPrimaryKey(mdrRule.getPrimaryKey());
2274    
2275                    mdrRuleImpl.setUuid(mdrRule.getUuid());
2276                    mdrRuleImpl.setRuleId(mdrRule.getRuleId());
2277                    mdrRuleImpl.setGroupId(mdrRule.getGroupId());
2278                    mdrRuleImpl.setCompanyId(mdrRule.getCompanyId());
2279                    mdrRuleImpl.setUserId(mdrRule.getUserId());
2280                    mdrRuleImpl.setUserName(mdrRule.getUserName());
2281                    mdrRuleImpl.setCreateDate(mdrRule.getCreateDate());
2282                    mdrRuleImpl.setModifiedDate(mdrRule.getModifiedDate());
2283                    mdrRuleImpl.setRuleGroupId(mdrRule.getRuleGroupId());
2284                    mdrRuleImpl.setName(mdrRule.getName());
2285                    mdrRuleImpl.setDescription(mdrRule.getDescription());
2286                    mdrRuleImpl.setType(mdrRule.getType());
2287                    mdrRuleImpl.setTypeSettings(mdrRule.getTypeSettings());
2288    
2289                    return mdrRuleImpl;
2290            }
2291    
2292            /**
2293             * Returns the m d r rule with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2294             *
2295             * @param primaryKey the primary key of the m d r rule
2296             * @return the m d r rule
2297             * @throws NoSuchRuleException if a m d r rule with the primary key could not be found
2298             */
2299            @Override
2300            public MDRRule findByPrimaryKey(Serializable primaryKey)
2301                    throws NoSuchRuleException {
2302                    MDRRule mdrRule = fetchByPrimaryKey(primaryKey);
2303    
2304                    if (mdrRule == null) {
2305                            if (_log.isWarnEnabled()) {
2306                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2307                            }
2308    
2309                            throw new NoSuchRuleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2310                                    primaryKey);
2311                    }
2312    
2313                    return mdrRule;
2314            }
2315    
2316            /**
2317             * Returns the m d r rule with the primary key or throws a {@link NoSuchRuleException} if it could not be found.
2318             *
2319             * @param ruleId the primary key of the m d r rule
2320             * @return the m d r rule
2321             * @throws NoSuchRuleException if a m d r rule with the primary key could not be found
2322             */
2323            @Override
2324            public MDRRule findByPrimaryKey(long ruleId) throws NoSuchRuleException {
2325                    return findByPrimaryKey((Serializable)ruleId);
2326            }
2327    
2328            /**
2329             * Returns the m d r rule with the primary key or returns <code>null</code> if it could not be found.
2330             *
2331             * @param primaryKey the primary key of the m d r rule
2332             * @return the m d r rule, or <code>null</code> if a m d r rule with the primary key could not be found
2333             */
2334            @Override
2335            public MDRRule fetchByPrimaryKey(Serializable primaryKey) {
2336                    MDRRule mdrRule = (MDRRule)EntityCacheUtil.getResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2337                                    MDRRuleImpl.class, primaryKey);
2338    
2339                    if (mdrRule == _nullMDRRule) {
2340                            return null;
2341                    }
2342    
2343                    if (mdrRule == null) {
2344                            Session session = null;
2345    
2346                            try {
2347                                    session = openSession();
2348    
2349                                    mdrRule = (MDRRule)session.get(MDRRuleImpl.class, primaryKey);
2350    
2351                                    if (mdrRule != null) {
2352                                            cacheResult(mdrRule);
2353                                    }
2354                                    else {
2355                                            EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2356                                                    MDRRuleImpl.class, primaryKey, _nullMDRRule);
2357                                    }
2358                            }
2359                            catch (Exception e) {
2360                                    EntityCacheUtil.removeResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2361                                            MDRRuleImpl.class, primaryKey);
2362    
2363                                    throw processException(e);
2364                            }
2365                            finally {
2366                                    closeSession(session);
2367                            }
2368                    }
2369    
2370                    return mdrRule;
2371            }
2372    
2373            /**
2374             * Returns the m d r rule with the primary key or returns <code>null</code> if it could not be found.
2375             *
2376             * @param ruleId the primary key of the m d r rule
2377             * @return the m d r rule, or <code>null</code> if a m d r rule with the primary key could not be found
2378             */
2379            @Override
2380            public MDRRule fetchByPrimaryKey(long ruleId) {
2381                    return fetchByPrimaryKey((Serializable)ruleId);
2382            }
2383    
2384            @Override
2385            public Map<Serializable, MDRRule> fetchByPrimaryKeys(
2386                    Set<Serializable> primaryKeys) {
2387                    if (primaryKeys.isEmpty()) {
2388                            return Collections.emptyMap();
2389                    }
2390    
2391                    Map<Serializable, MDRRule> map = new HashMap<Serializable, MDRRule>();
2392    
2393                    if (primaryKeys.size() == 1) {
2394                            Iterator<Serializable> iterator = primaryKeys.iterator();
2395    
2396                            Serializable primaryKey = iterator.next();
2397    
2398                            MDRRule mdrRule = fetchByPrimaryKey(primaryKey);
2399    
2400                            if (mdrRule != null) {
2401                                    map.put(primaryKey, mdrRule);
2402                            }
2403    
2404                            return map;
2405                    }
2406    
2407                    Set<Serializable> uncachedPrimaryKeys = null;
2408    
2409                    for (Serializable primaryKey : primaryKeys) {
2410                            MDRRule mdrRule = (MDRRule)EntityCacheUtil.getResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2411                                            MDRRuleImpl.class, primaryKey);
2412    
2413                            if (mdrRule == null) {
2414                                    if (uncachedPrimaryKeys == null) {
2415                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2416                                    }
2417    
2418                                    uncachedPrimaryKeys.add(primaryKey);
2419                            }
2420                            else {
2421                                    map.put(primaryKey, mdrRule);
2422                            }
2423                    }
2424    
2425                    if (uncachedPrimaryKeys == null) {
2426                            return map;
2427                    }
2428    
2429                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2430                                    1);
2431    
2432                    query.append(_SQL_SELECT_MDRRULE_WHERE_PKS_IN);
2433    
2434                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2435                            query.append(String.valueOf(primaryKey));
2436    
2437                            query.append(StringPool.COMMA);
2438                    }
2439    
2440                    query.setIndex(query.index() - 1);
2441    
2442                    query.append(StringPool.CLOSE_PARENTHESIS);
2443    
2444                    String sql = query.toString();
2445    
2446                    Session session = null;
2447    
2448                    try {
2449                            session = openSession();
2450    
2451                            Query q = session.createQuery(sql);
2452    
2453                            for (MDRRule mdrRule : (List<MDRRule>)q.list()) {
2454                                    map.put(mdrRule.getPrimaryKeyObj(), mdrRule);
2455    
2456                                    cacheResult(mdrRule);
2457    
2458                                    uncachedPrimaryKeys.remove(mdrRule.getPrimaryKeyObj());
2459                            }
2460    
2461                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2462                                    EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2463                                            MDRRuleImpl.class, primaryKey, _nullMDRRule);
2464                            }
2465                    }
2466                    catch (Exception e) {
2467                            throw processException(e);
2468                    }
2469                    finally {
2470                            closeSession(session);
2471                    }
2472    
2473                    return map;
2474            }
2475    
2476            /**
2477             * Returns all the m d r rules.
2478             *
2479             * @return the m d r rules
2480             */
2481            @Override
2482            public List<MDRRule> findAll() {
2483                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2484            }
2485    
2486            /**
2487             * Returns a range of all the m d r rules.
2488             *
2489             * <p>
2490             * 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 MDRRuleModelImpl}. 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.
2491             * </p>
2492             *
2493             * @param start the lower bound of the range of m d r rules
2494             * @param end the upper bound of the range of m d r rules (not inclusive)
2495             * @return the range of m d r rules
2496             */
2497            @Override
2498            public List<MDRRule> findAll(int start, int end) {
2499                    return findAll(start, end, null);
2500            }
2501    
2502            /**
2503             * Returns an ordered range of all the m d r rules.
2504             *
2505             * <p>
2506             * 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 MDRRuleModelImpl}. 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.
2507             * </p>
2508             *
2509             * @param start the lower bound of the range of m d r rules
2510             * @param end the upper bound of the range of m d r rules (not inclusive)
2511             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2512             * @return the ordered range of m d r rules
2513             */
2514            @Override
2515            public List<MDRRule> findAll(int start, int end,
2516                    OrderByComparator<MDRRule> orderByComparator) {
2517                    boolean pagination = true;
2518                    FinderPath finderPath = null;
2519                    Object[] finderArgs = null;
2520    
2521                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2522                                    (orderByComparator == null)) {
2523                            pagination = false;
2524                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2525                            finderArgs = FINDER_ARGS_EMPTY;
2526                    }
2527                    else {
2528                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2529                            finderArgs = new Object[] { start, end, orderByComparator };
2530                    }
2531    
2532                    List<MDRRule> list = (List<MDRRule>)FinderCacheUtil.getResult(finderPath,
2533                                    finderArgs, this);
2534    
2535                    if (list == null) {
2536                            StringBundler query = null;
2537                            String sql = null;
2538    
2539                            if (orderByComparator != null) {
2540                                    query = new StringBundler(2 +
2541                                                    (orderByComparator.getOrderByFields().length * 3));
2542    
2543                                    query.append(_SQL_SELECT_MDRRULE);
2544    
2545                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2546                                            orderByComparator);
2547    
2548                                    sql = query.toString();
2549                            }
2550                            else {
2551                                    sql = _SQL_SELECT_MDRRULE;
2552    
2553                                    if (pagination) {
2554                                            sql = sql.concat(MDRRuleModelImpl.ORDER_BY_JPQL);
2555                                    }
2556                            }
2557    
2558                            Session session = null;
2559    
2560                            try {
2561                                    session = openSession();
2562    
2563                                    Query q = session.createQuery(sql);
2564    
2565                                    if (!pagination) {
2566                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
2567                                                            start, end, false);
2568    
2569                                            Collections.sort(list);
2570    
2571                                            list = Collections.unmodifiableList(list);
2572                                    }
2573                                    else {
2574                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
2575                                                            start, end);
2576                                    }
2577    
2578                                    cacheResult(list);
2579    
2580                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2581                            }
2582                            catch (Exception e) {
2583                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2584    
2585                                    throw processException(e);
2586                            }
2587                            finally {
2588                                    closeSession(session);
2589                            }
2590                    }
2591    
2592                    return list;
2593            }
2594    
2595            /**
2596             * Removes all the m d r rules from the database.
2597             *
2598             */
2599            @Override
2600            public void removeAll() {
2601                    for (MDRRule mdrRule : findAll()) {
2602                            remove(mdrRule);
2603                    }
2604            }
2605    
2606            /**
2607             * Returns the number of m d r rules.
2608             *
2609             * @return the number of m d r rules
2610             */
2611            @Override
2612            public int countAll() {
2613                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2614                                    FINDER_ARGS_EMPTY, this);
2615    
2616                    if (count == null) {
2617                            Session session = null;
2618    
2619                            try {
2620                                    session = openSession();
2621    
2622                                    Query q = session.createQuery(_SQL_COUNT_MDRRULE);
2623    
2624                                    count = (Long)q.uniqueResult();
2625    
2626                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2627                                            FINDER_ARGS_EMPTY, count);
2628                            }
2629                            catch (Exception e) {
2630                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2631                                            FINDER_ARGS_EMPTY);
2632    
2633                                    throw processException(e);
2634                            }
2635                            finally {
2636                                    closeSession(session);
2637                            }
2638                    }
2639    
2640                    return count.intValue();
2641            }
2642    
2643            @Override
2644            protected Set<String> getBadColumnNames() {
2645                    return _badColumnNames;
2646            }
2647    
2648            /**
2649             * Initializes the m d r rule persistence.
2650             */
2651            public void afterPropertiesSet() {
2652            }
2653    
2654            public void destroy() {
2655                    EntityCacheUtil.removeCache(MDRRuleImpl.class.getName());
2656                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2657                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2658                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2659            }
2660    
2661            private static final String _SQL_SELECT_MDRRULE = "SELECT mdrRule FROM MDRRule mdrRule";
2662            private static final String _SQL_SELECT_MDRRULE_WHERE_PKS_IN = "SELECT mdrRule FROM MDRRule mdrRule WHERE ruleId IN (";
2663            private static final String _SQL_SELECT_MDRRULE_WHERE = "SELECT mdrRule FROM MDRRule mdrRule WHERE ";
2664            private static final String _SQL_COUNT_MDRRULE = "SELECT COUNT(mdrRule) FROM MDRRule mdrRule";
2665            private static final String _SQL_COUNT_MDRRULE_WHERE = "SELECT COUNT(mdrRule) FROM MDRRule mdrRule WHERE ";
2666            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRule.";
2667            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRule exists with the primary key ";
2668            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRule exists with the key {";
2669            private static final Log _log = LogFactoryUtil.getLog(MDRRulePersistenceImpl.class);
2670            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2671                                    "uuid", "type"
2672                            });
2673            private static final MDRRule _nullMDRRule = new MDRRuleImpl() {
2674                            @Override
2675                            public Object clone() {
2676                                    return this;
2677                            }
2678    
2679                            @Override
2680                            public CacheModel<MDRRule> toCacheModel() {
2681                                    return _nullMDRRuleCacheModel;
2682                            }
2683                    };
2684    
2685            private static final CacheModel<MDRRule> _nullMDRRuleCacheModel = new CacheModel<MDRRule>() {
2686                            @Override
2687                            public MDRRule toEntityModel() {
2688                                    return _nullMDRRule;
2689                            }
2690                    };
2691    }