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