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