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