001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.mobiledevicerules.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.SetUtil;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.Validator;
035    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
038    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039    
040    import com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException;
041    import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup;
042    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupImpl;
043    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl;
044    import com.liferay.portlet.mobiledevicerules.service.persistence.MDRRuleGroupPersistence;
045    
046    import java.io.Serializable;
047    
048    import java.util.Collections;
049    import java.util.HashMap;
050    import java.util.HashSet;
051    import java.util.Iterator;
052    import java.util.List;
053    import java.util.Map;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the m d r rule group 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 MDRRuleGroupPersistence
065     * @see MDRRuleGroupUtil
066     * @generated
067     */
068    @ProviderType
069    public class MDRRuleGroupPersistenceImpl extends BasePersistenceImpl<MDRRuleGroup>
070            implements MDRRuleGroupPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link MDRRuleGroupUtil} to access the m d r rule group persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = MDRRuleGroupImpl.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(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
082                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.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(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
085                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
088                            MDRRuleGroupModelImpl.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(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
091                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.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(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
100                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102                            new String[] { String.class.getName() },
103                            MDRRuleGroupModelImpl.UUID_COLUMN_BITMASK);
104            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
105                            MDRRuleGroupModelImpl.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 rule groups where uuid = &#63;.
111             *
112             * @param uuid the uuid
113             * @return the matching m d r rule groups
114             */
115            @Override
116            public List<MDRRuleGroup> 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 rule groups 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. 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 rule groups
129             * @param end the upper bound of the range of m d r rule groups (not inclusive)
130             * @return the range of matching m d r rule groups
131             */
132            @Override
133            public List<MDRRuleGroup> 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 rule groups 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. 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 rule groups
146             * @param end the upper bound of the range of m d r rule groups (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 rule groups
149             */
150            @Override
151            public List<MDRRuleGroup> findByUuid(String uuid, int start, int end,
152                    OrderByComparator<MDRRuleGroup> 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<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
169                                    finderArgs, this);
170    
171                    if ((list != null) && !list.isEmpty()) {
172                            for (MDRRuleGroup mdrRuleGroup : list) {
173                                    if (!Validator.equals(uuid, mdrRuleGroup.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_MDRRULEGROUP_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(MDRRuleGroupModelImpl.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<MDRRuleGroup>)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<MDRRuleGroup>)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 group 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 group
268             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
269             */
270            @Override
271            public MDRRuleGroup findByUuid_First(String uuid,
272                    OrderByComparator<MDRRuleGroup> orderByComparator)
273                    throws NoSuchRuleGroupException {
274                    MDRRuleGroup mdrRuleGroup = fetchByUuid_First(uuid, orderByComparator);
275    
276                    if (mdrRuleGroup != null) {
277                            return mdrRuleGroup;
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 NoSuchRuleGroupException(msg.toString());
290            }
291    
292            /**
293             * Returns the first m d r rule group 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 group, or <code>null</code> if a matching m d r rule group could not be found
298             */
299            @Override
300            public MDRRuleGroup fetchByUuid_First(String uuid,
301                    OrderByComparator<MDRRuleGroup> orderByComparator) {
302                    List<MDRRuleGroup> 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 group 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 group
317             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
318             */
319            @Override
320            public MDRRuleGroup findByUuid_Last(String uuid,
321                    OrderByComparator<MDRRuleGroup> orderByComparator)
322                    throws NoSuchRuleGroupException {
323                    MDRRuleGroup mdrRuleGroup = fetchByUuid_Last(uuid, orderByComparator);
324    
325                    if (mdrRuleGroup != null) {
326                            return mdrRuleGroup;
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 NoSuchRuleGroupException(msg.toString());
339            }
340    
341            /**
342             * Returns the last m d r rule group 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 group, or <code>null</code> if a matching m d r rule group could not be found
347             */
348            @Override
349            public MDRRuleGroup fetchByUuid_Last(String uuid,
350                    OrderByComparator<MDRRuleGroup> orderByComparator) {
351                    int count = countByUuid(uuid);
352    
353                    if (count == 0) {
354                            return null;
355                    }
356    
357                    List<MDRRuleGroup> 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 rule groups before and after the current m d r rule group in the ordered set where uuid = &#63;.
369             *
370             * @param ruleGroupId the primary key of the current m d r rule group
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 group
374             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
375             */
376            @Override
377            public MDRRuleGroup[] findByUuid_PrevAndNext(long ruleGroupId, String uuid,
378                    OrderByComparator<MDRRuleGroup> orderByComparator)
379                    throws NoSuchRuleGroupException {
380                    MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
381    
382                    Session session = null;
383    
384                    try {
385                            session = openSession();
386    
387                            MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
388    
389                            array[0] = getByUuid_PrevAndNext(session, mdrRuleGroup, uuid,
390                                            orderByComparator, true);
391    
392                            array[1] = mdrRuleGroup;
393    
394                            array[2] = getByUuid_PrevAndNext(session, mdrRuleGroup, 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 MDRRuleGroup getByUuid_PrevAndNext(Session session,
408                    MDRRuleGroup mdrRuleGroup, String uuid,
409                    OrderByComparator<MDRRuleGroup> orderByComparator, 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_MDRRULEGROUP_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(MDRRuleGroupModelImpl.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(mdrRuleGroup);
510    
511                            for (Object value : values) {
512                                    qPos.add(value);
513                            }
514                    }
515    
516                    List<MDRRuleGroup> list = q.list();
517    
518                    if (list.size() == 2) {
519                            return list.get(1);
520                    }
521                    else {
522                            return null;
523                    }
524            }
525    
526            /**
527             * Removes all the m d r rule groups where uuid = &#63; from the database.
528             *
529             * @param uuid the uuid
530             */
531            @Override
532            public void removeByUuid(String uuid) {
533                    for (MDRRuleGroup mdrRuleGroup : findByUuid(uuid, QueryUtil.ALL_POS,
534                                    QueryUtil.ALL_POS, null)) {
535                            remove(mdrRuleGroup);
536                    }
537            }
538    
539            /**
540             * Returns the number of m d r rule groups where uuid = &#63;.
541             *
542             * @param uuid the uuid
543             * @return the number of matching m d r rule groups
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_MDRRULEGROUP_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 = "mdrRuleGroup.uuid IS NULL";
606            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrRuleGroup.uuid = ?";
607            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrRuleGroup.uuid IS NULL OR mdrRuleGroup.uuid = '')";
608            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
609                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
610                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
611                            new String[] { String.class.getName(), Long.class.getName() },
612                            MDRRuleGroupModelImpl.UUID_COLUMN_BITMASK |
613                            MDRRuleGroupModelImpl.GROUPID_COLUMN_BITMASK);
614            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
615                            MDRRuleGroupModelImpl.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 group where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException} 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 group
625             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
626             */
627            @Override
628            public MDRRuleGroup findByUUID_G(String uuid, long groupId)
629                    throws NoSuchRuleGroupException {
630                    MDRRuleGroup mdrRuleGroup = fetchByUUID_G(uuid, groupId);
631    
632                    if (mdrRuleGroup == 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 NoSuchRuleGroupException(msg.toString());
650                    }
651    
652                    return mdrRuleGroup;
653            }
654    
655            /**
656             * Returns the m d r rule group 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 group, or <code>null</code> if a matching m d r rule group could not be found
661             */
662            @Override
663            public MDRRuleGroup fetchByUUID_G(String uuid, long groupId) {
664                    return fetchByUUID_G(uuid, groupId, true);
665            }
666    
667            /**
668             * Returns the m d r rule group where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
669             *
670             * @param uuid the uuid
671             * @param groupId the group ID
672             * @param retrieveFromCache whether to use the finder cache
673             * @return the matching m d r rule group, or <code>null</code> if a matching m d r rule group could not be found
674             */
675            @Override
676            public MDRRuleGroup 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 MDRRuleGroup) {
688                            MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)result;
689    
690                            if (!Validator.equals(uuid, mdrRuleGroup.getUuid()) ||
691                                            (groupId != mdrRuleGroup.getGroupId())) {
692                                    result = null;
693                            }
694                    }
695    
696                    if (result == null) {
697                            StringBundler query = new StringBundler(4);
698    
699                            query.append(_SQL_SELECT_MDRRULEGROUP_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<MDRRuleGroup> list = q.list();
735    
736                                    if (list.isEmpty()) {
737                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
738                                                    finderArgs, list);
739                                    }
740                                    else {
741                                            MDRRuleGroup mdrRuleGroup = list.get(0);
742    
743                                            result = mdrRuleGroup;
744    
745                                            cacheResult(mdrRuleGroup);
746    
747                                            if ((mdrRuleGroup.getUuid() == null) ||
748                                                            !mdrRuleGroup.getUuid().equals(uuid) ||
749                                                            (mdrRuleGroup.getGroupId() != groupId)) {
750                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
751                                                            finderArgs, mdrRuleGroup);
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 (MDRRuleGroup)result;
771                    }
772            }
773    
774            /**
775             * Removes the m d r rule group 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 group that was removed
780             */
781            @Override
782            public MDRRuleGroup removeByUUID_G(String uuid, long groupId)
783                    throws NoSuchRuleGroupException {
784                    MDRRuleGroup mdrRuleGroup = findByUUID_G(uuid, groupId);
785    
786                    return remove(mdrRuleGroup);
787            }
788    
789            /**
790             * Returns the number of m d r rule groups 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 rule groups
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_MDRRULEGROUP_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 = "mdrRuleGroup.uuid IS NULL AND ";
861            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrRuleGroup.uuid = ? AND ";
862            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrRuleGroup.uuid IS NULL OR mdrRuleGroup.uuid = '') AND ";
863            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrRuleGroup.groupId = ?";
864            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
865                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.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(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
875                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
876                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
877                            new String[] { String.class.getName(), Long.class.getName() },
878                            MDRRuleGroupModelImpl.UUID_COLUMN_BITMASK |
879                            MDRRuleGroupModelImpl.COMPANYID_COLUMN_BITMASK);
880            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
881                            MDRRuleGroupModelImpl.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 rule groups 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 rule groups
891             */
892            @Override
893            public List<MDRRuleGroup> 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 rule groups where uuid = &#63; and companyId = &#63;.
900             *
901             * <p>
902             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
903             * </p>
904             *
905             * @param uuid the uuid
906             * @param companyId the company ID
907             * @param start the lower bound of the range of m d r rule groups
908             * @param end the upper bound of the range of m d r rule groups (not inclusive)
909             * @return the range of matching m d r rule groups
910             */
911            @Override
912            public List<MDRRuleGroup> findByUuid_C(String uuid, long companyId,
913                    int start, 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 rule groups where uuid = &#63; and companyId = &#63;.
919             *
920             * <p>
921             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
922             * </p>
923             *
924             * @param uuid the uuid
925             * @param companyId the company ID
926             * @param start the lower bound of the range of m d r rule groups
927             * @param end the upper bound of the range of m d r rule groups (not inclusive)
928             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
929             * @return the ordered range of matching m d r rule groups
930             */
931            @Override
932            public List<MDRRuleGroup> findByUuid_C(String uuid, long companyId,
933                    int start, int end, OrderByComparator<MDRRuleGroup> 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<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
954                                    finderArgs, this);
955    
956                    if ((list != null) && !list.isEmpty()) {
957                            for (MDRRuleGroup mdrRuleGroup : list) {
958                                    if (!Validator.equals(uuid, mdrRuleGroup.getUuid()) ||
959                                                    (companyId != mdrRuleGroup.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_MDRRULEGROUP_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(MDRRuleGroupModelImpl.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<MDRRuleGroup>)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<MDRRuleGroup>)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 group 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 group
1059             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1060             */
1061            @Override
1062            public MDRRuleGroup findByUuid_C_First(String uuid, long companyId,
1063                    OrderByComparator<MDRRuleGroup> orderByComparator)
1064                    throws NoSuchRuleGroupException {
1065                    MDRRuleGroup mdrRuleGroup = fetchByUuid_C_First(uuid, companyId,
1066                                    orderByComparator);
1067    
1068                    if (mdrRuleGroup != null) {
1069                            return mdrRuleGroup;
1070                    }
1071    
1072                    StringBundler msg = new StringBundler(6);
1073    
1074                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1075    
1076                    msg.append("uuid=");
1077                    msg.append(uuid);
1078    
1079                    msg.append(", companyId=");
1080                    msg.append(companyId);
1081    
1082                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1083    
1084                    throw new NoSuchRuleGroupException(msg.toString());
1085            }
1086    
1087            /**
1088             * Returns the first m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1089             *
1090             * @param uuid the uuid
1091             * @param companyId the company ID
1092             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1093             * @return the first matching m d r rule group, or <code>null</code> if a matching m d r rule group could not be found
1094             */
1095            @Override
1096            public MDRRuleGroup fetchByUuid_C_First(String uuid, long companyId,
1097                    OrderByComparator<MDRRuleGroup> orderByComparator) {
1098                    List<MDRRuleGroup> list = findByUuid_C(uuid, companyId, 0, 1,
1099                                    orderByComparator);
1100    
1101                    if (!list.isEmpty()) {
1102                            return list.get(0);
1103                    }
1104    
1105                    return null;
1106            }
1107    
1108            /**
1109             * Returns the last m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1110             *
1111             * @param uuid the uuid
1112             * @param companyId the company ID
1113             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1114             * @return the last matching m d r rule group
1115             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1116             */
1117            @Override
1118            public MDRRuleGroup findByUuid_C_Last(String uuid, long companyId,
1119                    OrderByComparator<MDRRuleGroup> orderByComparator)
1120                    throws NoSuchRuleGroupException {
1121                    MDRRuleGroup mdrRuleGroup = fetchByUuid_C_Last(uuid, companyId,
1122                                    orderByComparator);
1123    
1124                    if (mdrRuleGroup != null) {
1125                            return mdrRuleGroup;
1126                    }
1127    
1128                    StringBundler msg = new StringBundler(6);
1129    
1130                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1131    
1132                    msg.append("uuid=");
1133                    msg.append(uuid);
1134    
1135                    msg.append(", companyId=");
1136                    msg.append(companyId);
1137    
1138                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1139    
1140                    throw new NoSuchRuleGroupException(msg.toString());
1141            }
1142    
1143            /**
1144             * Returns the last m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1145             *
1146             * @param uuid the uuid
1147             * @param companyId the company ID
1148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1149             * @return the last matching m d r rule group, or <code>null</code> if a matching m d r rule group could not be found
1150             */
1151            @Override
1152            public MDRRuleGroup fetchByUuid_C_Last(String uuid, long companyId,
1153                    OrderByComparator<MDRRuleGroup> orderByComparator) {
1154                    int count = countByUuid_C(uuid, companyId);
1155    
1156                    if (count == 0) {
1157                            return null;
1158                    }
1159    
1160                    List<MDRRuleGroup> list = findByUuid_C(uuid, companyId, count - 1,
1161                                    count, orderByComparator);
1162    
1163                    if (!list.isEmpty()) {
1164                            return list.get(0);
1165                    }
1166    
1167                    return null;
1168            }
1169    
1170            /**
1171             * Returns the m d r rule groups before and after the current m d r rule group in the ordered set where uuid = &#63; and companyId = &#63;.
1172             *
1173             * @param ruleGroupId the primary key of the current m d r rule group
1174             * @param uuid the uuid
1175             * @param companyId the company ID
1176             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1177             * @return the previous, current, and next m d r rule group
1178             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
1179             */
1180            @Override
1181            public MDRRuleGroup[] findByUuid_C_PrevAndNext(long ruleGroupId,
1182                    String uuid, long companyId,
1183                    OrderByComparator<MDRRuleGroup> orderByComparator)
1184                    throws NoSuchRuleGroupException {
1185                    MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
1186    
1187                    Session session = null;
1188    
1189                    try {
1190                            session = openSession();
1191    
1192                            MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
1193    
1194                            array[0] = getByUuid_C_PrevAndNext(session, mdrRuleGroup, uuid,
1195                                            companyId, orderByComparator, true);
1196    
1197                            array[1] = mdrRuleGroup;
1198    
1199                            array[2] = getByUuid_C_PrevAndNext(session, mdrRuleGroup, uuid,
1200                                            companyId, orderByComparator, false);
1201    
1202                            return array;
1203                    }
1204                    catch (Exception e) {
1205                            throw processException(e);
1206                    }
1207                    finally {
1208                            closeSession(session);
1209                    }
1210            }
1211    
1212            protected MDRRuleGroup getByUuid_C_PrevAndNext(Session session,
1213                    MDRRuleGroup mdrRuleGroup, String uuid, long companyId,
1214                    OrderByComparator<MDRRuleGroup> orderByComparator, boolean previous) {
1215                    StringBundler query = null;
1216    
1217                    if (orderByComparator != null) {
1218                            query = new StringBundler(6 +
1219                                            (orderByComparator.getOrderByFields().length * 6));
1220                    }
1221                    else {
1222                            query = new StringBundler(3);
1223                    }
1224    
1225                    query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1226    
1227                    boolean bindUuid = false;
1228    
1229                    if (uuid == null) {
1230                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1231                    }
1232                    else if (uuid.equals(StringPool.BLANK)) {
1233                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1234                    }
1235                    else {
1236                            bindUuid = true;
1237    
1238                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1239                    }
1240    
1241                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1242    
1243                    if (orderByComparator != null) {
1244                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1245    
1246                            if (orderByConditionFields.length > 0) {
1247                                    query.append(WHERE_AND);
1248                            }
1249    
1250                            for (int i = 0; i < orderByConditionFields.length; i++) {
1251                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1252                                    query.append(orderByConditionFields[i]);
1253    
1254                                    if ((i + 1) < orderByConditionFields.length) {
1255                                            if (orderByComparator.isAscending() ^ previous) {
1256                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1257                                            }
1258                                            else {
1259                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1260                                            }
1261                                    }
1262                                    else {
1263                                            if (orderByComparator.isAscending() ^ previous) {
1264                                                    query.append(WHERE_GREATER_THAN);
1265                                            }
1266                                            else {
1267                                                    query.append(WHERE_LESSER_THAN);
1268                                            }
1269                                    }
1270                            }
1271    
1272                            query.append(ORDER_BY_CLAUSE);
1273    
1274                            String[] orderByFields = orderByComparator.getOrderByFields();
1275    
1276                            for (int i = 0; i < orderByFields.length; i++) {
1277                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1278                                    query.append(orderByFields[i]);
1279    
1280                                    if ((i + 1) < orderByFields.length) {
1281                                            if (orderByComparator.isAscending() ^ previous) {
1282                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1283                                            }
1284                                            else {
1285                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1286                                            }
1287                                    }
1288                                    else {
1289                                            if (orderByComparator.isAscending() ^ previous) {
1290                                                    query.append(ORDER_BY_ASC);
1291                                            }
1292                                            else {
1293                                                    query.append(ORDER_BY_DESC);
1294                                            }
1295                                    }
1296                            }
1297                    }
1298                    else {
1299                            query.append(MDRRuleGroupModelImpl.ORDER_BY_JPQL);
1300                    }
1301    
1302                    String sql = query.toString();
1303    
1304                    Query q = session.createQuery(sql);
1305    
1306                    q.setFirstResult(0);
1307                    q.setMaxResults(2);
1308    
1309                    QueryPos qPos = QueryPos.getInstance(q);
1310    
1311                    if (bindUuid) {
1312                            qPos.add(uuid);
1313                    }
1314    
1315                    qPos.add(companyId);
1316    
1317                    if (orderByComparator != null) {
1318                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
1319    
1320                            for (Object value : values) {
1321                                    qPos.add(value);
1322                            }
1323                    }
1324    
1325                    List<MDRRuleGroup> list = q.list();
1326    
1327                    if (list.size() == 2) {
1328                            return list.get(1);
1329                    }
1330                    else {
1331                            return null;
1332                    }
1333            }
1334    
1335            /**
1336             * Removes all the m d r rule groups where uuid = &#63; and companyId = &#63; from the database.
1337             *
1338             * @param uuid the uuid
1339             * @param companyId the company ID
1340             */
1341            @Override
1342            public void removeByUuid_C(String uuid, long companyId) {
1343                    for (MDRRuleGroup mdrRuleGroup : findByUuid_C(uuid, companyId,
1344                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1345                            remove(mdrRuleGroup);
1346                    }
1347            }
1348    
1349            /**
1350             * Returns the number of m d r rule groups where uuid = &#63; and companyId = &#63;.
1351             *
1352             * @param uuid the uuid
1353             * @param companyId the company ID
1354             * @return the number of matching m d r rule groups
1355             */
1356            @Override
1357            public int countByUuid_C(String uuid, long companyId) {
1358                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1359    
1360                    Object[] finderArgs = new Object[] { uuid, companyId };
1361    
1362                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1363                                    this);
1364    
1365                    if (count == null) {
1366                            StringBundler query = new StringBundler(3);
1367    
1368                            query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
1369    
1370                            boolean bindUuid = false;
1371    
1372                            if (uuid == null) {
1373                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1374                            }
1375                            else if (uuid.equals(StringPool.BLANK)) {
1376                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1377                            }
1378                            else {
1379                                    bindUuid = true;
1380    
1381                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1382                            }
1383    
1384                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1385    
1386                            String sql = query.toString();
1387    
1388                            Session session = null;
1389    
1390                            try {
1391                                    session = openSession();
1392    
1393                                    Query q = session.createQuery(sql);
1394    
1395                                    QueryPos qPos = QueryPos.getInstance(q);
1396    
1397                                    if (bindUuid) {
1398                                            qPos.add(uuid);
1399                                    }
1400    
1401                                    qPos.add(companyId);
1402    
1403                                    count = (Long)q.uniqueResult();
1404    
1405                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1406                            }
1407                            catch (Exception e) {
1408                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1409    
1410                                    throw processException(e);
1411                            }
1412                            finally {
1413                                    closeSession(session);
1414                            }
1415                    }
1416    
1417                    return count.intValue();
1418            }
1419    
1420            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mdrRuleGroup.uuid IS NULL AND ";
1421            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mdrRuleGroup.uuid = ? AND ";
1422            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mdrRuleGroup.uuid IS NULL OR mdrRuleGroup.uuid = '') AND ";
1423            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mdrRuleGroup.companyId = ?";
1424            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
1425                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
1426                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1427                            new String[] {
1428                                    Long.class.getName(),
1429                                    
1430                            Integer.class.getName(), Integer.class.getName(),
1431                                    OrderByComparator.class.getName()
1432                            });
1433            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1434                    new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
1435                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, MDRRuleGroupImpl.class,
1436                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1437                            new String[] { Long.class.getName() },
1438                            MDRRuleGroupModelImpl.GROUPID_COLUMN_BITMASK);
1439            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
1440                            MDRRuleGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
1441                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1442                            new String[] { Long.class.getName() });
1443    
1444            /**
1445             * Returns all the m d r rule groups where groupId = &#63;.
1446             *
1447             * @param groupId the group ID
1448             * @return the matching m d r rule groups
1449             */
1450            @Override
1451            public List<MDRRuleGroup> findByGroupId(long groupId) {
1452                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1453            }
1454    
1455            /**
1456             * Returns a range of all the m d r rule groups where groupId = &#63;.
1457             *
1458             * <p>
1459             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. 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.
1460             * </p>
1461             *
1462             * @param groupId the group ID
1463             * @param start the lower bound of the range of m d r rule groups
1464             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1465             * @return the range of matching m d r rule groups
1466             */
1467            @Override
1468            public List<MDRRuleGroup> findByGroupId(long groupId, int start, int end) {
1469                    return findByGroupId(groupId, start, end, null);
1470            }
1471    
1472            /**
1473             * Returns an ordered range of all the m d r rule groups where groupId = &#63;.
1474             *
1475             * <p>
1476             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1477             * </p>
1478             *
1479             * @param groupId the group ID
1480             * @param start the lower bound of the range of m d r rule groups
1481             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1482             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1483             * @return the ordered range of matching m d r rule groups
1484             */
1485            @Override
1486            public List<MDRRuleGroup> findByGroupId(long groupId, int start, int end,
1487                    OrderByComparator<MDRRuleGroup> orderByComparator) {
1488                    boolean pagination = true;
1489                    FinderPath finderPath = null;
1490                    Object[] finderArgs = null;
1491    
1492                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1493                                    (orderByComparator == null)) {
1494                            pagination = false;
1495                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1496                            finderArgs = new Object[] { groupId };
1497                    }
1498                    else {
1499                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1500                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1501                    }
1502    
1503                    List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
1504                                    finderArgs, this);
1505    
1506                    if ((list != null) && !list.isEmpty()) {
1507                            for (MDRRuleGroup mdrRuleGroup : list) {
1508                                    if ((groupId != mdrRuleGroup.getGroupId())) {
1509                                            list = null;
1510    
1511                                            break;
1512                                    }
1513                            }
1514                    }
1515    
1516                    if (list == null) {
1517                            StringBundler query = null;
1518    
1519                            if (orderByComparator != null) {
1520                                    query = new StringBundler(3 +
1521                                                    (orderByComparator.getOrderByFields().length * 3));
1522                            }
1523                            else {
1524                                    query = new StringBundler(3);
1525                            }
1526    
1527                            query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1528    
1529                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1530    
1531                            if (orderByComparator != null) {
1532                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1533                                            orderByComparator);
1534                            }
1535                            else
1536                             if (pagination) {
1537                                    query.append(MDRRuleGroupModelImpl.ORDER_BY_JPQL);
1538                            }
1539    
1540                            String sql = query.toString();
1541    
1542                            Session session = null;
1543    
1544                            try {
1545                                    session = openSession();
1546    
1547                                    Query q = session.createQuery(sql);
1548    
1549                                    QueryPos qPos = QueryPos.getInstance(q);
1550    
1551                                    qPos.add(groupId);
1552    
1553                                    if (!pagination) {
1554                                            list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
1555                                                            start, end, false);
1556    
1557                                            Collections.sort(list);
1558    
1559                                            list = Collections.unmodifiableList(list);
1560                                    }
1561                                    else {
1562                                            list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
1563                                                            start, end);
1564                                    }
1565    
1566                                    cacheResult(list);
1567    
1568                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1569                            }
1570                            catch (Exception e) {
1571                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1572    
1573                                    throw processException(e);
1574                            }
1575                            finally {
1576                                    closeSession(session);
1577                            }
1578                    }
1579    
1580                    return list;
1581            }
1582    
1583            /**
1584             * Returns the first m d r rule group in the ordered set where groupId = &#63;.
1585             *
1586             * @param groupId the group ID
1587             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1588             * @return the first matching m d r rule group
1589             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1590             */
1591            @Override
1592            public MDRRuleGroup findByGroupId_First(long groupId,
1593                    OrderByComparator<MDRRuleGroup> orderByComparator)
1594                    throws NoSuchRuleGroupException {
1595                    MDRRuleGroup mdrRuleGroup = fetchByGroupId_First(groupId,
1596                                    orderByComparator);
1597    
1598                    if (mdrRuleGroup != null) {
1599                            return mdrRuleGroup;
1600                    }
1601    
1602                    StringBundler msg = new StringBundler(4);
1603    
1604                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1605    
1606                    msg.append("groupId=");
1607                    msg.append(groupId);
1608    
1609                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1610    
1611                    throw new NoSuchRuleGroupException(msg.toString());
1612            }
1613    
1614            /**
1615             * Returns the first m d r rule group in the ordered set where groupId = &#63;.
1616             *
1617             * @param groupId the group ID
1618             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1619             * @return the first matching m d r rule group, or <code>null</code> if a matching m d r rule group could not be found
1620             */
1621            @Override
1622            public MDRRuleGroup fetchByGroupId_First(long groupId,
1623                    OrderByComparator<MDRRuleGroup> orderByComparator) {
1624                    List<MDRRuleGroup> list = findByGroupId(groupId, 0, 1, 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 group in the ordered set where groupId = &#63;.
1635             *
1636             * @param groupId the 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 group
1639             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a matching m d r rule group could not be found
1640             */
1641            @Override
1642            public MDRRuleGroup findByGroupId_Last(long groupId,
1643                    OrderByComparator<MDRRuleGroup> orderByComparator)
1644                    throws NoSuchRuleGroupException {
1645                    MDRRuleGroup mdrRuleGroup = fetchByGroupId_Last(groupId,
1646                                    orderByComparator);
1647    
1648                    if (mdrRuleGroup != null) {
1649                            return mdrRuleGroup;
1650                    }
1651    
1652                    StringBundler msg = new StringBundler(4);
1653    
1654                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1655    
1656                    msg.append("groupId=");
1657                    msg.append(groupId);
1658    
1659                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1660    
1661                    throw new NoSuchRuleGroupException(msg.toString());
1662            }
1663    
1664            /**
1665             * Returns the last m d r rule group in the ordered set where groupId = &#63;.
1666             *
1667             * @param groupId the group ID
1668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1669             * @return the last matching m d r rule group, or <code>null</code> if a matching m d r rule group could not be found
1670             */
1671            @Override
1672            public MDRRuleGroup fetchByGroupId_Last(long groupId,
1673                    OrderByComparator<MDRRuleGroup> orderByComparator) {
1674                    int count = countByGroupId(groupId);
1675    
1676                    if (count == 0) {
1677                            return null;
1678                    }
1679    
1680                    List<MDRRuleGroup> list = findByGroupId(groupId, count - 1, count,
1681                                    orderByComparator);
1682    
1683                    if (!list.isEmpty()) {
1684                            return list.get(0);
1685                    }
1686    
1687                    return null;
1688            }
1689    
1690            /**
1691             * Returns the m d r rule groups before and after the current m d r rule group in the ordered set where groupId = &#63;.
1692             *
1693             * @param ruleGroupId the primary key of the current m d r rule group
1694             * @param groupId the group ID
1695             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1696             * @return the previous, current, and next m d r rule group
1697             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
1698             */
1699            @Override
1700            public MDRRuleGroup[] findByGroupId_PrevAndNext(long ruleGroupId,
1701                    long groupId, OrderByComparator<MDRRuleGroup> orderByComparator)
1702                    throws NoSuchRuleGroupException {
1703                    MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
1704    
1705                    Session session = null;
1706    
1707                    try {
1708                            session = openSession();
1709    
1710                            MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
1711    
1712                            array[0] = getByGroupId_PrevAndNext(session, mdrRuleGroup, groupId,
1713                                            orderByComparator, true);
1714    
1715                            array[1] = mdrRuleGroup;
1716    
1717                            array[2] = getByGroupId_PrevAndNext(session, mdrRuleGroup, groupId,
1718                                            orderByComparator, false);
1719    
1720                            return array;
1721                    }
1722                    catch (Exception e) {
1723                            throw processException(e);
1724                    }
1725                    finally {
1726                            closeSession(session);
1727                    }
1728            }
1729    
1730            protected MDRRuleGroup getByGroupId_PrevAndNext(Session session,
1731                    MDRRuleGroup mdrRuleGroup, long groupId,
1732                    OrderByComparator<MDRRuleGroup> orderByComparator, boolean previous) {
1733                    StringBundler query = null;
1734    
1735                    if (orderByComparator != null) {
1736                            query = new StringBundler(6 +
1737                                            (orderByComparator.getOrderByFields().length * 6));
1738                    }
1739                    else {
1740                            query = new StringBundler(3);
1741                    }
1742    
1743                    query.append(_SQL_SELECT_MDRRULEGROUP_WHERE);
1744    
1745                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1746    
1747                    if (orderByComparator != null) {
1748                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1749    
1750                            if (orderByConditionFields.length > 0) {
1751                                    query.append(WHERE_AND);
1752                            }
1753    
1754                            for (int i = 0; i < orderByConditionFields.length; i++) {
1755                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1756                                    query.append(orderByConditionFields[i]);
1757    
1758                                    if ((i + 1) < orderByConditionFields.length) {
1759                                            if (orderByComparator.isAscending() ^ previous) {
1760                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1761                                            }
1762                                            else {
1763                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1764                                            }
1765                                    }
1766                                    else {
1767                                            if (orderByComparator.isAscending() ^ previous) {
1768                                                    query.append(WHERE_GREATER_THAN);
1769                                            }
1770                                            else {
1771                                                    query.append(WHERE_LESSER_THAN);
1772                                            }
1773                                    }
1774                            }
1775    
1776                            query.append(ORDER_BY_CLAUSE);
1777    
1778                            String[] orderByFields = orderByComparator.getOrderByFields();
1779    
1780                            for (int i = 0; i < orderByFields.length; i++) {
1781                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1782                                    query.append(orderByFields[i]);
1783    
1784                                    if ((i + 1) < orderByFields.length) {
1785                                            if (orderByComparator.isAscending() ^ previous) {
1786                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1787                                            }
1788                                            else {
1789                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1790                                            }
1791                                    }
1792                                    else {
1793                                            if (orderByComparator.isAscending() ^ previous) {
1794                                                    query.append(ORDER_BY_ASC);
1795                                            }
1796                                            else {
1797                                                    query.append(ORDER_BY_DESC);
1798                                            }
1799                                    }
1800                            }
1801                    }
1802                    else {
1803                            query.append(MDRRuleGroupModelImpl.ORDER_BY_JPQL);
1804                    }
1805    
1806                    String sql = query.toString();
1807    
1808                    Query q = session.createQuery(sql);
1809    
1810                    q.setFirstResult(0);
1811                    q.setMaxResults(2);
1812    
1813                    QueryPos qPos = QueryPos.getInstance(q);
1814    
1815                    qPos.add(groupId);
1816    
1817                    if (orderByComparator != null) {
1818                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
1819    
1820                            for (Object value : values) {
1821                                    qPos.add(value);
1822                            }
1823                    }
1824    
1825                    List<MDRRuleGroup> list = q.list();
1826    
1827                    if (list.size() == 2) {
1828                            return list.get(1);
1829                    }
1830                    else {
1831                            return null;
1832                    }
1833            }
1834    
1835            /**
1836             * Returns all the m d r rule groups that the user has permission to view where groupId = &#63;.
1837             *
1838             * @param groupId the group ID
1839             * @return the matching m d r rule groups that the user has permission to view
1840             */
1841            @Override
1842            public List<MDRRuleGroup> filterFindByGroupId(long groupId) {
1843                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1844                            QueryUtil.ALL_POS, null);
1845            }
1846    
1847            /**
1848             * Returns a range of all the m d r rule groups that the user has permission to view where groupId = &#63;.
1849             *
1850             * <p>
1851             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. 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.
1852             * </p>
1853             *
1854             * @param groupId the group ID
1855             * @param start the lower bound of the range of m d r rule groups
1856             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1857             * @return the range of matching m d r rule groups that the user has permission to view
1858             */
1859            @Override
1860            public List<MDRRuleGroup> filterFindByGroupId(long groupId, int start,
1861                    int end) {
1862                    return filterFindByGroupId(groupId, start, end, null);
1863            }
1864    
1865            /**
1866             * Returns an ordered range of all the m d r rule groups that the user has permissions to view where groupId = &#63;.
1867             *
1868             * <p>
1869             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. 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.
1870             * </p>
1871             *
1872             * @param groupId the group ID
1873             * @param start the lower bound of the range of m d r rule groups
1874             * @param end the upper bound of the range of m d r rule groups (not inclusive)
1875             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1876             * @return the ordered range of matching m d r rule groups that the user has permission to view
1877             */
1878            @Override
1879            public List<MDRRuleGroup> filterFindByGroupId(long groupId, int start,
1880                    int end, OrderByComparator<MDRRuleGroup> orderByComparator) {
1881                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1882                            return findByGroupId(groupId, start, end, orderByComparator);
1883                    }
1884    
1885                    StringBundler query = null;
1886    
1887                    if (orderByComparator != null) {
1888                            query = new StringBundler(3 +
1889                                            (orderByComparator.getOrderByFields().length * 3));
1890                    }
1891                    else {
1892                            query = new StringBundler(3);
1893                    }
1894    
1895                    if (getDB().isSupportsInlineDistinct()) {
1896                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_WHERE);
1897                    }
1898                    else {
1899                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1);
1900                    }
1901    
1902                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1903    
1904                    if (!getDB().isSupportsInlineDistinct()) {
1905                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2);
1906                    }
1907    
1908                    if (orderByComparator != null) {
1909                            if (getDB().isSupportsInlineDistinct()) {
1910                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1911                                            orderByComparator, true);
1912                            }
1913                            else {
1914                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1915                                            orderByComparator, true);
1916                            }
1917                    }
1918                    else {
1919                            if (getDB().isSupportsInlineDistinct()) {
1920                                    query.append(MDRRuleGroupModelImpl.ORDER_BY_JPQL);
1921                            }
1922                            else {
1923                                    query.append(MDRRuleGroupModelImpl.ORDER_BY_SQL);
1924                            }
1925                    }
1926    
1927                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1928                                    MDRRuleGroup.class.getName(),
1929                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1930    
1931                    Session session = null;
1932    
1933                    try {
1934                            session = openSession();
1935    
1936                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1937    
1938                            if (getDB().isSupportsInlineDistinct()) {
1939                                    q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupImpl.class);
1940                            }
1941                            else {
1942                                    q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupImpl.class);
1943                            }
1944    
1945                            QueryPos qPos = QueryPos.getInstance(q);
1946    
1947                            qPos.add(groupId);
1948    
1949                            return (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(), start,
1950                                    end);
1951                    }
1952                    catch (Exception e) {
1953                            throw processException(e);
1954                    }
1955                    finally {
1956                            closeSession(session);
1957                    }
1958            }
1959    
1960            /**
1961             * Returns the m d r rule groups before and after the current m d r rule group in the ordered set of m d r rule groups that the user has permission to view where groupId = &#63;.
1962             *
1963             * @param ruleGroupId the primary key of the current m d r rule group
1964             * @param groupId the group ID
1965             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1966             * @return the previous, current, and next m d r rule group
1967             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
1968             */
1969            @Override
1970            public MDRRuleGroup[] filterFindByGroupId_PrevAndNext(long ruleGroupId,
1971                    long groupId, OrderByComparator<MDRRuleGroup> orderByComparator)
1972                    throws NoSuchRuleGroupException {
1973                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1974                            return findByGroupId_PrevAndNext(ruleGroupId, groupId,
1975                                    orderByComparator);
1976                    }
1977    
1978                    MDRRuleGroup mdrRuleGroup = findByPrimaryKey(ruleGroupId);
1979    
1980                    Session session = null;
1981    
1982                    try {
1983                            session = openSession();
1984    
1985                            MDRRuleGroup[] array = new MDRRuleGroupImpl[3];
1986    
1987                            array[0] = filterGetByGroupId_PrevAndNext(session, mdrRuleGroup,
1988                                            groupId, orderByComparator, true);
1989    
1990                            array[1] = mdrRuleGroup;
1991    
1992                            array[2] = filterGetByGroupId_PrevAndNext(session, mdrRuleGroup,
1993                                            groupId, orderByComparator, false);
1994    
1995                            return array;
1996                    }
1997                    catch (Exception e) {
1998                            throw processException(e);
1999                    }
2000                    finally {
2001                            closeSession(session);
2002                    }
2003            }
2004    
2005            protected MDRRuleGroup filterGetByGroupId_PrevAndNext(Session session,
2006                    MDRRuleGroup mdrRuleGroup, long groupId,
2007                    OrderByComparator<MDRRuleGroup> orderByComparator, boolean previous) {
2008                    StringBundler query = null;
2009    
2010                    if (orderByComparator != null) {
2011                            query = new StringBundler(6 +
2012                                            (orderByComparator.getOrderByFields().length * 6));
2013                    }
2014                    else {
2015                            query = new StringBundler(3);
2016                    }
2017    
2018                    if (getDB().isSupportsInlineDistinct()) {
2019                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_WHERE);
2020                    }
2021                    else {
2022                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1);
2023                    }
2024    
2025                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2026    
2027                    if (!getDB().isSupportsInlineDistinct()) {
2028                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2);
2029                    }
2030    
2031                    if (orderByComparator != null) {
2032                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2033    
2034                            if (orderByConditionFields.length > 0) {
2035                                    query.append(WHERE_AND);
2036                            }
2037    
2038                            for (int i = 0; i < orderByConditionFields.length; i++) {
2039                                    if (getDB().isSupportsInlineDistinct()) {
2040                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2041                                    }
2042                                    else {
2043                                            query.append(_ORDER_BY_ENTITY_TABLE);
2044                                    }
2045    
2046                                    query.append(orderByConditionFields[i]);
2047    
2048                                    if ((i + 1) < orderByConditionFields.length) {
2049                                            if (orderByComparator.isAscending() ^ previous) {
2050                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2051                                            }
2052                                            else {
2053                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2054                                            }
2055                                    }
2056                                    else {
2057                                            if (orderByComparator.isAscending() ^ previous) {
2058                                                    query.append(WHERE_GREATER_THAN);
2059                                            }
2060                                            else {
2061                                                    query.append(WHERE_LESSER_THAN);
2062                                            }
2063                                    }
2064                            }
2065    
2066                            query.append(ORDER_BY_CLAUSE);
2067    
2068                            String[] orderByFields = orderByComparator.getOrderByFields();
2069    
2070                            for (int i = 0; i < orderByFields.length; i++) {
2071                                    if (getDB().isSupportsInlineDistinct()) {
2072                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2073                                    }
2074                                    else {
2075                                            query.append(_ORDER_BY_ENTITY_TABLE);
2076                                    }
2077    
2078                                    query.append(orderByFields[i]);
2079    
2080                                    if ((i + 1) < orderByFields.length) {
2081                                            if (orderByComparator.isAscending() ^ previous) {
2082                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2083                                            }
2084                                            else {
2085                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2086                                            }
2087                                    }
2088                                    else {
2089                                            if (orderByComparator.isAscending() ^ previous) {
2090                                                    query.append(ORDER_BY_ASC);
2091                                            }
2092                                            else {
2093                                                    query.append(ORDER_BY_DESC);
2094                                            }
2095                                    }
2096                            }
2097                    }
2098                    else {
2099                            if (getDB().isSupportsInlineDistinct()) {
2100                                    query.append(MDRRuleGroupModelImpl.ORDER_BY_JPQL);
2101                            }
2102                            else {
2103                                    query.append(MDRRuleGroupModelImpl.ORDER_BY_SQL);
2104                            }
2105                    }
2106    
2107                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2108                                    MDRRuleGroup.class.getName(),
2109                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2110    
2111                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2112    
2113                    q.setFirstResult(0);
2114                    q.setMaxResults(2);
2115    
2116                    if (getDB().isSupportsInlineDistinct()) {
2117                            q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupImpl.class);
2118                    }
2119                    else {
2120                            q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupImpl.class);
2121                    }
2122    
2123                    QueryPos qPos = QueryPos.getInstance(q);
2124    
2125                    qPos.add(groupId);
2126    
2127                    if (orderByComparator != null) {
2128                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroup);
2129    
2130                            for (Object value : values) {
2131                                    qPos.add(value);
2132                            }
2133                    }
2134    
2135                    List<MDRRuleGroup> list = q.list();
2136    
2137                    if (list.size() == 2) {
2138                            return list.get(1);
2139                    }
2140                    else {
2141                            return null;
2142                    }
2143            }
2144    
2145            /**
2146             * Removes all the m d r rule groups where groupId = &#63; from the database.
2147             *
2148             * @param groupId the group ID
2149             */
2150            @Override
2151            public void removeByGroupId(long groupId) {
2152                    for (MDRRuleGroup mdrRuleGroup : findByGroupId(groupId,
2153                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2154                            remove(mdrRuleGroup);
2155                    }
2156            }
2157    
2158            /**
2159             * Returns the number of m d r rule groups where groupId = &#63;.
2160             *
2161             * @param groupId the group ID
2162             * @return the number of matching m d r rule groups
2163             */
2164            @Override
2165            public int countByGroupId(long groupId) {
2166                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2167    
2168                    Object[] finderArgs = new Object[] { groupId };
2169    
2170                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2171                                    this);
2172    
2173                    if (count == null) {
2174                            StringBundler query = new StringBundler(2);
2175    
2176                            query.append(_SQL_COUNT_MDRRULEGROUP_WHERE);
2177    
2178                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2179    
2180                            String sql = query.toString();
2181    
2182                            Session session = null;
2183    
2184                            try {
2185                                    session = openSession();
2186    
2187                                    Query q = session.createQuery(sql);
2188    
2189                                    QueryPos qPos = QueryPos.getInstance(q);
2190    
2191                                    qPos.add(groupId);
2192    
2193                                    count = (Long)q.uniqueResult();
2194    
2195                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2196                            }
2197                            catch (Exception e) {
2198                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2199    
2200                                    throw processException(e);
2201                            }
2202                            finally {
2203                                    closeSession(session);
2204                            }
2205                    }
2206    
2207                    return count.intValue();
2208            }
2209    
2210            /**
2211             * Returns the number of m d r rule groups that the user has permission to view where groupId = &#63;.
2212             *
2213             * @param groupId the group ID
2214             * @return the number of matching m d r rule groups that the user has permission to view
2215             */
2216            @Override
2217            public int filterCountByGroupId(long groupId) {
2218                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2219                            return countByGroupId(groupId);
2220                    }
2221    
2222                    StringBundler query = new StringBundler(2);
2223    
2224                    query.append(_FILTER_SQL_COUNT_MDRRULEGROUP_WHERE);
2225    
2226                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2227    
2228                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2229                                    MDRRuleGroup.class.getName(),
2230                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2231    
2232                    Session session = null;
2233    
2234                    try {
2235                            session = openSession();
2236    
2237                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2238    
2239                            q.addScalar(COUNT_COLUMN_NAME,
2240                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2241    
2242                            QueryPos qPos = QueryPos.getInstance(q);
2243    
2244                            qPos.add(groupId);
2245    
2246                            Long count = (Long)q.uniqueResult();
2247    
2248                            return count.intValue();
2249                    }
2250                    catch (Exception e) {
2251                            throw processException(e);
2252                    }
2253                    finally {
2254                            closeSession(session);
2255                    }
2256            }
2257    
2258            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mdrRuleGroup.groupId = ?";
2259    
2260            public MDRRuleGroupPersistenceImpl() {
2261                    setModelClass(MDRRuleGroup.class);
2262            }
2263    
2264            /**
2265             * Caches the m d r rule group in the entity cache if it is enabled.
2266             *
2267             * @param mdrRuleGroup the m d r rule group
2268             */
2269            @Override
2270            public void cacheResult(MDRRuleGroup mdrRuleGroup) {
2271                    EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2272                            MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey(), mdrRuleGroup);
2273    
2274                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2275                            new Object[] { mdrRuleGroup.getUuid(), mdrRuleGroup.getGroupId() },
2276                            mdrRuleGroup);
2277    
2278                    mdrRuleGroup.resetOriginalValues();
2279            }
2280    
2281            /**
2282             * Caches the m d r rule groups in the entity cache if it is enabled.
2283             *
2284             * @param mdrRuleGroups the m d r rule groups
2285             */
2286            @Override
2287            public void cacheResult(List<MDRRuleGroup> mdrRuleGroups) {
2288                    for (MDRRuleGroup mdrRuleGroup : mdrRuleGroups) {
2289                            if (EntityCacheUtil.getResult(
2290                                                    MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2291                                                    MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey()) == null) {
2292                                    cacheResult(mdrRuleGroup);
2293                            }
2294                            else {
2295                                    mdrRuleGroup.resetOriginalValues();
2296                            }
2297                    }
2298            }
2299    
2300            /**
2301             * Clears the cache for all m d r rule groups.
2302             *
2303             * <p>
2304             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2305             * </p>
2306             */
2307            @Override
2308            public void clearCache() {
2309                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2310                            CacheRegistryUtil.clear(MDRRuleGroupImpl.class.getName());
2311                    }
2312    
2313                    EntityCacheUtil.clearCache(MDRRuleGroupImpl.class);
2314    
2315                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2316                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2317                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2318            }
2319    
2320            /**
2321             * Clears the cache for the m d r rule group.
2322             *
2323             * <p>
2324             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2325             * </p>
2326             */
2327            @Override
2328            public void clearCache(MDRRuleGroup mdrRuleGroup) {
2329                    EntityCacheUtil.removeResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2330                            MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey());
2331    
2332                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2333                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2334    
2335                    clearUniqueFindersCache(mdrRuleGroup);
2336            }
2337    
2338            @Override
2339            public void clearCache(List<MDRRuleGroup> mdrRuleGroups) {
2340                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2341                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2342    
2343                    for (MDRRuleGroup mdrRuleGroup : mdrRuleGroups) {
2344                            EntityCacheUtil.removeResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2345                                    MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey());
2346    
2347                            clearUniqueFindersCache(mdrRuleGroup);
2348                    }
2349            }
2350    
2351            protected void cacheUniqueFindersCache(MDRRuleGroup mdrRuleGroup) {
2352                    if (mdrRuleGroup.isNew()) {
2353                            Object[] args = new Object[] {
2354                                            mdrRuleGroup.getUuid(), mdrRuleGroup.getGroupId()
2355                                    };
2356    
2357                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2358                                    Long.valueOf(1));
2359                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2360                                    mdrRuleGroup);
2361                    }
2362                    else {
2363                            MDRRuleGroupModelImpl mdrRuleGroupModelImpl = (MDRRuleGroupModelImpl)mdrRuleGroup;
2364    
2365                            if ((mdrRuleGroupModelImpl.getColumnBitmask() &
2366                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2367                                    Object[] args = new Object[] {
2368                                                    mdrRuleGroup.getUuid(), mdrRuleGroup.getGroupId()
2369                                            };
2370    
2371                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2372                                            Long.valueOf(1));
2373                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2374                                            mdrRuleGroup);
2375                            }
2376                    }
2377            }
2378    
2379            protected void clearUniqueFindersCache(MDRRuleGroup mdrRuleGroup) {
2380                    MDRRuleGroupModelImpl mdrRuleGroupModelImpl = (MDRRuleGroupModelImpl)mdrRuleGroup;
2381    
2382                    Object[] args = new Object[] {
2383                                    mdrRuleGroup.getUuid(), mdrRuleGroup.getGroupId()
2384                            };
2385    
2386                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2387                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2388    
2389                    if ((mdrRuleGroupModelImpl.getColumnBitmask() &
2390                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2391                            args = new Object[] {
2392                                            mdrRuleGroupModelImpl.getOriginalUuid(),
2393                                            mdrRuleGroupModelImpl.getOriginalGroupId()
2394                                    };
2395    
2396                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2397                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2398                    }
2399            }
2400    
2401            /**
2402             * Creates a new m d r rule group with the primary key. Does not add the m d r rule group to the database.
2403             *
2404             * @param ruleGroupId the primary key for the new m d r rule group
2405             * @return the new m d r rule group
2406             */
2407            @Override
2408            public MDRRuleGroup create(long ruleGroupId) {
2409                    MDRRuleGroup mdrRuleGroup = new MDRRuleGroupImpl();
2410    
2411                    mdrRuleGroup.setNew(true);
2412                    mdrRuleGroup.setPrimaryKey(ruleGroupId);
2413    
2414                    String uuid = PortalUUIDUtil.generate();
2415    
2416                    mdrRuleGroup.setUuid(uuid);
2417    
2418                    return mdrRuleGroup;
2419            }
2420    
2421            /**
2422             * Removes the m d r rule group with the primary key from the database. Also notifies the appropriate model listeners.
2423             *
2424             * @param ruleGroupId the primary key of the m d r rule group
2425             * @return the m d r rule group that was removed
2426             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
2427             */
2428            @Override
2429            public MDRRuleGroup remove(long ruleGroupId)
2430                    throws NoSuchRuleGroupException {
2431                    return remove((Serializable)ruleGroupId);
2432            }
2433    
2434            /**
2435             * Removes the m d r rule group with the primary key from the database. Also notifies the appropriate model listeners.
2436             *
2437             * @param primaryKey the primary key of the m d r rule group
2438             * @return the m d r rule group that was removed
2439             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
2440             */
2441            @Override
2442            public MDRRuleGroup remove(Serializable primaryKey)
2443                    throws NoSuchRuleGroupException {
2444                    Session session = null;
2445    
2446                    try {
2447                            session = openSession();
2448    
2449                            MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)session.get(MDRRuleGroupImpl.class,
2450                                            primaryKey);
2451    
2452                            if (mdrRuleGroup == null) {
2453                                    if (_log.isWarnEnabled()) {
2454                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2455                                    }
2456    
2457                                    throw new NoSuchRuleGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2458                                            primaryKey);
2459                            }
2460    
2461                            return remove(mdrRuleGroup);
2462                    }
2463                    catch (NoSuchRuleGroupException nsee) {
2464                            throw nsee;
2465                    }
2466                    catch (Exception e) {
2467                            throw processException(e);
2468                    }
2469                    finally {
2470                            closeSession(session);
2471                    }
2472            }
2473    
2474            @Override
2475            protected MDRRuleGroup removeImpl(MDRRuleGroup mdrRuleGroup) {
2476                    mdrRuleGroup = toUnwrappedModel(mdrRuleGroup);
2477    
2478                    Session session = null;
2479    
2480                    try {
2481                            session = openSession();
2482    
2483                            if (!session.contains(mdrRuleGroup)) {
2484                                    mdrRuleGroup = (MDRRuleGroup)session.get(MDRRuleGroupImpl.class,
2485                                                    mdrRuleGroup.getPrimaryKeyObj());
2486                            }
2487    
2488                            if (mdrRuleGroup != null) {
2489                                    session.delete(mdrRuleGroup);
2490                            }
2491                    }
2492                    catch (Exception e) {
2493                            throw processException(e);
2494                    }
2495                    finally {
2496                            closeSession(session);
2497                    }
2498    
2499                    if (mdrRuleGroup != null) {
2500                            clearCache(mdrRuleGroup);
2501                    }
2502    
2503                    return mdrRuleGroup;
2504            }
2505    
2506            @Override
2507            public MDRRuleGroup updateImpl(
2508                    com.liferay.portlet.mobiledevicerules.model.MDRRuleGroup mdrRuleGroup) {
2509                    mdrRuleGroup = toUnwrappedModel(mdrRuleGroup);
2510    
2511                    boolean isNew = mdrRuleGroup.isNew();
2512    
2513                    MDRRuleGroupModelImpl mdrRuleGroupModelImpl = (MDRRuleGroupModelImpl)mdrRuleGroup;
2514    
2515                    if (Validator.isNull(mdrRuleGroup.getUuid())) {
2516                            String uuid = PortalUUIDUtil.generate();
2517    
2518                            mdrRuleGroup.setUuid(uuid);
2519                    }
2520    
2521                    Session session = null;
2522    
2523                    try {
2524                            session = openSession();
2525    
2526                            if (mdrRuleGroup.isNew()) {
2527                                    session.save(mdrRuleGroup);
2528    
2529                                    mdrRuleGroup.setNew(false);
2530                            }
2531                            else {
2532                                    session.merge(mdrRuleGroup);
2533                            }
2534                    }
2535                    catch (Exception e) {
2536                            throw processException(e);
2537                    }
2538                    finally {
2539                            closeSession(session);
2540                    }
2541    
2542                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2543    
2544                    if (isNew || !MDRRuleGroupModelImpl.COLUMN_BITMASK_ENABLED) {
2545                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2546                    }
2547    
2548                    else {
2549                            if ((mdrRuleGroupModelImpl.getColumnBitmask() &
2550                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2551                                    Object[] args = new Object[] {
2552                                                    mdrRuleGroupModelImpl.getOriginalUuid()
2553                                            };
2554    
2555                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2556                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2557                                            args);
2558    
2559                                    args = new Object[] { mdrRuleGroupModelImpl.getUuid() };
2560    
2561                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2562                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2563                                            args);
2564                            }
2565    
2566                            if ((mdrRuleGroupModelImpl.getColumnBitmask() &
2567                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2568                                    Object[] args = new Object[] {
2569                                                    mdrRuleGroupModelImpl.getOriginalUuid(),
2570                                                    mdrRuleGroupModelImpl.getOriginalCompanyId()
2571                                            };
2572    
2573                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2574                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2575                                            args);
2576    
2577                                    args = new Object[] {
2578                                                    mdrRuleGroupModelImpl.getUuid(),
2579                                                    mdrRuleGroupModelImpl.getCompanyId()
2580                                            };
2581    
2582                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2583                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2584                                            args);
2585                            }
2586    
2587                            if ((mdrRuleGroupModelImpl.getColumnBitmask() &
2588                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2589                                    Object[] args = new Object[] {
2590                                                    mdrRuleGroupModelImpl.getOriginalGroupId()
2591                                            };
2592    
2593                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2594                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2595                                            args);
2596    
2597                                    args = new Object[] { mdrRuleGroupModelImpl.getGroupId() };
2598    
2599                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2600                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2601                                            args);
2602                            }
2603                    }
2604    
2605                    EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2606                            MDRRuleGroupImpl.class, mdrRuleGroup.getPrimaryKey(), mdrRuleGroup,
2607                            false);
2608    
2609                    clearUniqueFindersCache(mdrRuleGroup);
2610                    cacheUniqueFindersCache(mdrRuleGroup);
2611    
2612                    mdrRuleGroup.resetOriginalValues();
2613    
2614                    return mdrRuleGroup;
2615            }
2616    
2617            protected MDRRuleGroup toUnwrappedModel(MDRRuleGroup mdrRuleGroup) {
2618                    if (mdrRuleGroup instanceof MDRRuleGroupImpl) {
2619                            return mdrRuleGroup;
2620                    }
2621    
2622                    MDRRuleGroupImpl mdrRuleGroupImpl = new MDRRuleGroupImpl();
2623    
2624                    mdrRuleGroupImpl.setNew(mdrRuleGroup.isNew());
2625                    mdrRuleGroupImpl.setPrimaryKey(mdrRuleGroup.getPrimaryKey());
2626    
2627                    mdrRuleGroupImpl.setUuid(mdrRuleGroup.getUuid());
2628                    mdrRuleGroupImpl.setRuleGroupId(mdrRuleGroup.getRuleGroupId());
2629                    mdrRuleGroupImpl.setGroupId(mdrRuleGroup.getGroupId());
2630                    mdrRuleGroupImpl.setCompanyId(mdrRuleGroup.getCompanyId());
2631                    mdrRuleGroupImpl.setUserId(mdrRuleGroup.getUserId());
2632                    mdrRuleGroupImpl.setUserName(mdrRuleGroup.getUserName());
2633                    mdrRuleGroupImpl.setCreateDate(mdrRuleGroup.getCreateDate());
2634                    mdrRuleGroupImpl.setModifiedDate(mdrRuleGroup.getModifiedDate());
2635                    mdrRuleGroupImpl.setName(mdrRuleGroup.getName());
2636                    mdrRuleGroupImpl.setDescription(mdrRuleGroup.getDescription());
2637    
2638                    return mdrRuleGroupImpl;
2639            }
2640    
2641            /**
2642             * Returns the m d r rule group with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2643             *
2644             * @param primaryKey the primary key of the m d r rule group
2645             * @return the m d r rule group
2646             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
2647             */
2648            @Override
2649            public MDRRuleGroup findByPrimaryKey(Serializable primaryKey)
2650                    throws NoSuchRuleGroupException {
2651                    MDRRuleGroup mdrRuleGroup = fetchByPrimaryKey(primaryKey);
2652    
2653                    if (mdrRuleGroup == null) {
2654                            if (_log.isWarnEnabled()) {
2655                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2656                            }
2657    
2658                            throw new NoSuchRuleGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2659                                    primaryKey);
2660                    }
2661    
2662                    return mdrRuleGroup;
2663            }
2664    
2665            /**
2666             * Returns the m d r rule group with the primary key or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException} if it could not be found.
2667             *
2668             * @param ruleGroupId the primary key of the m d r rule group
2669             * @return the m d r rule group
2670             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupException if a m d r rule group with the primary key could not be found
2671             */
2672            @Override
2673            public MDRRuleGroup findByPrimaryKey(long ruleGroupId)
2674                    throws NoSuchRuleGroupException {
2675                    return findByPrimaryKey((Serializable)ruleGroupId);
2676            }
2677    
2678            /**
2679             * Returns the m d r rule group with the primary key or returns <code>null</code> if it could not be found.
2680             *
2681             * @param primaryKey the primary key of the m d r rule group
2682             * @return the m d r rule group, or <code>null</code> if a m d r rule group with the primary key could not be found
2683             */
2684            @Override
2685            public MDRRuleGroup fetchByPrimaryKey(Serializable primaryKey) {
2686                    MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)EntityCacheUtil.getResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2687                                    MDRRuleGroupImpl.class, primaryKey);
2688    
2689                    if (mdrRuleGroup == _nullMDRRuleGroup) {
2690                            return null;
2691                    }
2692    
2693                    if (mdrRuleGroup == null) {
2694                            Session session = null;
2695    
2696                            try {
2697                                    session = openSession();
2698    
2699                                    mdrRuleGroup = (MDRRuleGroup)session.get(MDRRuleGroupImpl.class,
2700                                                    primaryKey);
2701    
2702                                    if (mdrRuleGroup != null) {
2703                                            cacheResult(mdrRuleGroup);
2704                                    }
2705                                    else {
2706                                            EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2707                                                    MDRRuleGroupImpl.class, primaryKey, _nullMDRRuleGroup);
2708                                    }
2709                            }
2710                            catch (Exception e) {
2711                                    EntityCacheUtil.removeResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2712                                            MDRRuleGroupImpl.class, primaryKey);
2713    
2714                                    throw processException(e);
2715                            }
2716                            finally {
2717                                    closeSession(session);
2718                            }
2719                    }
2720    
2721                    return mdrRuleGroup;
2722            }
2723    
2724            /**
2725             * Returns the m d r rule group with the primary key or returns <code>null</code> if it could not be found.
2726             *
2727             * @param ruleGroupId the primary key of the m d r rule group
2728             * @return the m d r rule group, or <code>null</code> if a m d r rule group with the primary key could not be found
2729             */
2730            @Override
2731            public MDRRuleGroup fetchByPrimaryKey(long ruleGroupId) {
2732                    return fetchByPrimaryKey((Serializable)ruleGroupId);
2733            }
2734    
2735            @Override
2736            public Map<Serializable, MDRRuleGroup> fetchByPrimaryKeys(
2737                    Set<Serializable> primaryKeys) {
2738                    if (primaryKeys.isEmpty()) {
2739                            return Collections.emptyMap();
2740                    }
2741    
2742                    Map<Serializable, MDRRuleGroup> map = new HashMap<Serializable, MDRRuleGroup>();
2743    
2744                    if (primaryKeys.size() == 1) {
2745                            Iterator<Serializable> iterator = primaryKeys.iterator();
2746    
2747                            Serializable primaryKey = iterator.next();
2748    
2749                            MDRRuleGroup mdrRuleGroup = fetchByPrimaryKey(primaryKey);
2750    
2751                            if (mdrRuleGroup != null) {
2752                                    map.put(primaryKey, mdrRuleGroup);
2753                            }
2754    
2755                            return map;
2756                    }
2757    
2758                    Set<Serializable> uncachedPrimaryKeys = null;
2759    
2760                    for (Serializable primaryKey : primaryKeys) {
2761                            MDRRuleGroup mdrRuleGroup = (MDRRuleGroup)EntityCacheUtil.getResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2762                                            MDRRuleGroupImpl.class, primaryKey);
2763    
2764                            if (mdrRuleGroup == null) {
2765                                    if (uncachedPrimaryKeys == null) {
2766                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2767                                    }
2768    
2769                                    uncachedPrimaryKeys.add(primaryKey);
2770                            }
2771                            else {
2772                                    map.put(primaryKey, mdrRuleGroup);
2773                            }
2774                    }
2775    
2776                    if (uncachedPrimaryKeys == null) {
2777                            return map;
2778                    }
2779    
2780                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2781                                    1);
2782    
2783                    query.append(_SQL_SELECT_MDRRULEGROUP_WHERE_PKS_IN);
2784    
2785                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2786                            query.append(String.valueOf(primaryKey));
2787    
2788                            query.append(StringPool.COMMA);
2789                    }
2790    
2791                    query.setIndex(query.index() - 1);
2792    
2793                    query.append(StringPool.CLOSE_PARENTHESIS);
2794    
2795                    String sql = query.toString();
2796    
2797                    Session session = null;
2798    
2799                    try {
2800                            session = openSession();
2801    
2802                            Query q = session.createQuery(sql);
2803    
2804                            for (MDRRuleGroup mdrRuleGroup : (List<MDRRuleGroup>)q.list()) {
2805                                    map.put(mdrRuleGroup.getPrimaryKeyObj(), mdrRuleGroup);
2806    
2807                                    cacheResult(mdrRuleGroup);
2808    
2809                                    uncachedPrimaryKeys.remove(mdrRuleGroup.getPrimaryKeyObj());
2810                            }
2811    
2812                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2813                                    EntityCacheUtil.putResult(MDRRuleGroupModelImpl.ENTITY_CACHE_ENABLED,
2814                                            MDRRuleGroupImpl.class, primaryKey, _nullMDRRuleGroup);
2815                            }
2816                    }
2817                    catch (Exception e) {
2818                            throw processException(e);
2819                    }
2820                    finally {
2821                            closeSession(session);
2822                    }
2823    
2824                    return map;
2825            }
2826    
2827            /**
2828             * Returns all the m d r rule groups.
2829             *
2830             * @return the m d r rule groups
2831             */
2832            @Override
2833            public List<MDRRuleGroup> findAll() {
2834                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2835            }
2836    
2837            /**
2838             * Returns a range of all the m d r rule groups.
2839             *
2840             * <p>
2841             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. 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.
2842             * </p>
2843             *
2844             * @param start the lower bound of the range of m d r rule groups
2845             * @param end the upper bound of the range of m d r rule groups (not inclusive)
2846             * @return the range of m d r rule groups
2847             */
2848            @Override
2849            public List<MDRRuleGroup> findAll(int start, int end) {
2850                    return findAll(start, end, null);
2851            }
2852    
2853            /**
2854             * Returns an ordered range of all the m d r rule groups.
2855             *
2856             * <p>
2857             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupModelImpl}. 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.
2858             * </p>
2859             *
2860             * @param start the lower bound of the range of m d r rule groups
2861             * @param end the upper bound of the range of m d r rule groups (not inclusive)
2862             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2863             * @return the ordered range of m d r rule groups
2864             */
2865            @Override
2866            public List<MDRRuleGroup> findAll(int start, int end,
2867                    OrderByComparator<MDRRuleGroup> orderByComparator) {
2868                    boolean pagination = true;
2869                    FinderPath finderPath = null;
2870                    Object[] finderArgs = null;
2871    
2872                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2873                                    (orderByComparator == null)) {
2874                            pagination = false;
2875                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2876                            finderArgs = FINDER_ARGS_EMPTY;
2877                    }
2878                    else {
2879                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2880                            finderArgs = new Object[] { start, end, orderByComparator };
2881                    }
2882    
2883                    List<MDRRuleGroup> list = (List<MDRRuleGroup>)FinderCacheUtil.getResult(finderPath,
2884                                    finderArgs, this);
2885    
2886                    if (list == null) {
2887                            StringBundler query = null;
2888                            String sql = null;
2889    
2890                            if (orderByComparator != null) {
2891                                    query = new StringBundler(2 +
2892                                                    (orderByComparator.getOrderByFields().length * 3));
2893    
2894                                    query.append(_SQL_SELECT_MDRRULEGROUP);
2895    
2896                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2897                                            orderByComparator);
2898    
2899                                    sql = query.toString();
2900                            }
2901                            else {
2902                                    sql = _SQL_SELECT_MDRRULEGROUP;
2903    
2904                                    if (pagination) {
2905                                            sql = sql.concat(MDRRuleGroupModelImpl.ORDER_BY_JPQL);
2906                                    }
2907                            }
2908    
2909                            Session session = null;
2910    
2911                            try {
2912                                    session = openSession();
2913    
2914                                    Query q = session.createQuery(sql);
2915    
2916                                    if (!pagination) {
2917                                            list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
2918                                                            start, end, false);
2919    
2920                                            Collections.sort(list);
2921    
2922                                            list = Collections.unmodifiableList(list);
2923                                    }
2924                                    else {
2925                                            list = (List<MDRRuleGroup>)QueryUtil.list(q, getDialect(),
2926                                                            start, end);
2927                                    }
2928    
2929                                    cacheResult(list);
2930    
2931                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2932                            }
2933                            catch (Exception e) {
2934                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2935    
2936                                    throw processException(e);
2937                            }
2938                            finally {
2939                                    closeSession(session);
2940                            }
2941                    }
2942    
2943                    return list;
2944            }
2945    
2946            /**
2947             * Removes all the m d r rule groups from the database.
2948             *
2949             */
2950            @Override
2951            public void removeAll() {
2952                    for (MDRRuleGroup mdrRuleGroup : findAll()) {
2953                            remove(mdrRuleGroup);
2954                    }
2955            }
2956    
2957            /**
2958             * Returns the number of m d r rule groups.
2959             *
2960             * @return the number of m d r rule groups
2961             */
2962            @Override
2963            public int countAll() {
2964                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2965                                    FINDER_ARGS_EMPTY, this);
2966    
2967                    if (count == null) {
2968                            Session session = null;
2969    
2970                            try {
2971                                    session = openSession();
2972    
2973                                    Query q = session.createQuery(_SQL_COUNT_MDRRULEGROUP);
2974    
2975                                    count = (Long)q.uniqueResult();
2976    
2977                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2978                                            FINDER_ARGS_EMPTY, count);
2979                            }
2980                            catch (Exception e) {
2981                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2982                                            FINDER_ARGS_EMPTY);
2983    
2984                                    throw processException(e);
2985                            }
2986                            finally {
2987                                    closeSession(session);
2988                            }
2989                    }
2990    
2991                    return count.intValue();
2992            }
2993    
2994            @Override
2995            protected Set<String> getBadColumnNames() {
2996                    return _badColumnNames;
2997            }
2998    
2999            /**
3000             * Initializes the m d r rule group persistence.
3001             */
3002            public void afterPropertiesSet() {
3003            }
3004    
3005            public void destroy() {
3006                    EntityCacheUtil.removeCache(MDRRuleGroupImpl.class.getName());
3007                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3008                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3009                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3010            }
3011    
3012            private static final String _SQL_SELECT_MDRRULEGROUP = "SELECT mdrRuleGroup FROM MDRRuleGroup mdrRuleGroup";
3013            private static final String _SQL_SELECT_MDRRULEGROUP_WHERE_PKS_IN = "SELECT mdrRuleGroup FROM MDRRuleGroup mdrRuleGroup WHERE ruleGroupId IN (";
3014            private static final String _SQL_SELECT_MDRRULEGROUP_WHERE = "SELECT mdrRuleGroup FROM MDRRuleGroup mdrRuleGroup WHERE ";
3015            private static final String _SQL_COUNT_MDRRULEGROUP = "SELECT COUNT(mdrRuleGroup) FROM MDRRuleGroup mdrRuleGroup";
3016            private static final String _SQL_COUNT_MDRRULEGROUP_WHERE = "SELECT COUNT(mdrRuleGroup) FROM MDRRuleGroup mdrRuleGroup WHERE ";
3017            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mdrRuleGroup.ruleGroupId";
3018            private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_WHERE = "SELECT DISTINCT {mdrRuleGroup.*} FROM MDRRuleGroup mdrRuleGroup WHERE ";
3019            private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_1 =
3020                    "SELECT {MDRRuleGroup.*} FROM (SELECT DISTINCT mdrRuleGroup.ruleGroupId FROM MDRRuleGroup mdrRuleGroup WHERE ";
3021            private static final String _FILTER_SQL_SELECT_MDRRULEGROUP_NO_INLINE_DISTINCT_WHERE_2 =
3022                    ") TEMP_TABLE INNER JOIN MDRRuleGroup ON TEMP_TABLE.ruleGroupId = MDRRuleGroup.ruleGroupId";
3023            private static final String _FILTER_SQL_COUNT_MDRRULEGROUP_WHERE = "SELECT COUNT(DISTINCT mdrRuleGroup.ruleGroupId) AS COUNT_VALUE FROM MDRRuleGroup mdrRuleGroup WHERE ";
3024            private static final String _FILTER_ENTITY_ALIAS = "mdrRuleGroup";
3025            private static final String _FILTER_ENTITY_TABLE = "MDRRuleGroup";
3026            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRuleGroup.";
3027            private static final String _ORDER_BY_ENTITY_TABLE = "MDRRuleGroup.";
3028            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRuleGroup exists with the primary key ";
3029            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRuleGroup exists with the key {";
3030            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3031            private static final Log _log = LogFactoryUtil.getLog(MDRRuleGroupPersistenceImpl.class);
3032            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3033                                    "uuid"
3034                            });
3035            private static final MDRRuleGroup _nullMDRRuleGroup = new MDRRuleGroupImpl() {
3036                            @Override
3037                            public Object clone() {
3038                                    return this;
3039                            }
3040    
3041                            @Override
3042                            public CacheModel<MDRRuleGroup> toCacheModel() {
3043                                    return _nullMDRRuleGroupCacheModel;
3044                            }
3045                    };
3046    
3047            private static final CacheModel<MDRRuleGroup> _nullMDRRuleGroupCacheModel = new CacheModel<MDRRuleGroup>() {
3048                            @Override
3049                            public MDRRuleGroup toEntityModel() {
3050                                    return _nullMDRRuleGroup;
3051                            }
3052                    };
3053    }