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