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