001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.mobiledevicerules.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException;
044    import com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance;
045    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceImpl;
046    import com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl;
047    
048    import java.io.Serializable;
049    
050    import java.util.ArrayList;
051    import java.util.Collections;
052    import java.util.List;
053    
054    /**
055     * The persistence implementation for the m d r rule group instance service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Edward C. Han
062     * @see MDRRuleGroupInstancePersistence
063     * @see MDRRuleGroupInstanceUtil
064     * @generated
065     */
066    public class MDRRuleGroupInstancePersistenceImpl extends BasePersistenceImpl<MDRRuleGroupInstance>
067            implements MDRRuleGroupInstancePersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link MDRRuleGroupInstanceUtil} to access the m d r rule group instance persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = MDRRuleGroupInstanceImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
079                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
080                            MDRRuleGroupInstanceImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
083                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
084                            MDRRuleGroupInstanceImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
087                            MDRRuleGroupInstanceModelImpl.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(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
090                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
091                            MDRRuleGroupInstanceImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
093                            new String[] {
094                                    String.class.getName(),
095                                    
096                            Integer.class.getName(), Integer.class.getName(),
097                                    OrderByComparator.class.getName()
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
100                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
101                            MDRRuleGroupInstanceImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
103                            new String[] { String.class.getName() },
104                            MDRRuleGroupInstanceModelImpl.UUID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
106                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
108                            new String[] { String.class.getName() });
109    
110            /**
111             * Returns all the m d r rule group instances where uuid = &#63;.
112             *
113             * @param uuid the uuid
114             * @return the matching m d r rule group instances
115             * @throws SystemException if a system exception occurred
116             */
117            public List<MDRRuleGroupInstance> findByUuid(String uuid)
118                    throws SystemException {
119                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
120            }
121    
122            /**
123             * Returns a range of all the m d r rule group instances where uuid = &#63;.
124             *
125             * <p>
126             * 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.MDRRuleGroupInstanceModelImpl}. 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.
127             * </p>
128             *
129             * @param uuid the uuid
130             * @param start the lower bound of the range of m d r rule group instances
131             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
132             * @return the range of matching m d r rule group instances
133             * @throws SystemException if a system exception occurred
134             */
135            public List<MDRRuleGroupInstance> findByUuid(String uuid, int start, int end)
136                    throws SystemException {
137                    return findByUuid(uuid, start, end, null);
138            }
139    
140            /**
141             * Returns an ordered range of all the m d r rule group instances where uuid = &#63;.
142             *
143             * <p>
144             * 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.MDRRuleGroupInstanceModelImpl}. 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.
145             * </p>
146             *
147             * @param uuid the uuid
148             * @param start the lower bound of the range of m d r rule group instances
149             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
151             * @return the ordered range of matching m d r rule group instances
152             * @throws SystemException if a system exception occurred
153             */
154            public List<MDRRuleGroupInstance> findByUuid(String uuid, int start,
155                    int end, 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<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
172                                    finderArgs, this);
173    
174                    if ((list != null) && !list.isEmpty()) {
175                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
176                                    if (!Validator.equals(uuid, mdrRuleGroupInstance.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_MDRRULEGROUPINSTANCE_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(MDRRuleGroupInstanceModelImpl.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<MDRRuleGroupInstance>)QueryUtil.list(q,
237                                                            getDialect(), start, end, false);
238    
239                                            Collections.sort(list);
240    
241                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
242                                    }
243                                    else {
244                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
245                                                            getDialect(), 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 instance 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 instance
271             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
272             * @throws SystemException if a system exception occurred
273             */
274            public MDRRuleGroupInstance findByUuid_First(String uuid,
275                    OrderByComparator orderByComparator)
276                    throws NoSuchRuleGroupInstanceException, SystemException {
277                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUuid_First(uuid,
278                                    orderByComparator);
279    
280                    if (mdrRuleGroupInstance != null) {
281                            return mdrRuleGroupInstance;
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 NoSuchRuleGroupInstanceException(msg.toString());
294            }
295    
296            /**
297             * Returns the first m d r rule group instance 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 instance, or <code>null</code> if a matching m d r rule group instance could not be found
302             * @throws SystemException if a system exception occurred
303             */
304            public MDRRuleGroupInstance fetchByUuid_First(String uuid,
305                    OrderByComparator orderByComparator) throws SystemException {
306                    List<MDRRuleGroupInstance> list = findByUuid(uuid, 0, 1,
307                                    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 instance 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 instance
322             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
323             * @throws SystemException if a system exception occurred
324             */
325            public MDRRuleGroupInstance findByUuid_Last(String uuid,
326                    OrderByComparator orderByComparator)
327                    throws NoSuchRuleGroupInstanceException, SystemException {
328                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUuid_Last(uuid,
329                                    orderByComparator);
330    
331                    if (mdrRuleGroupInstance != null) {
332                            return mdrRuleGroupInstance;
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 NoSuchRuleGroupInstanceException(msg.toString());
345            }
346    
347            /**
348             * Returns the last m d r rule group instance 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 instance, or <code>null</code> if a matching m d r rule group instance could not be found
353             * @throws SystemException if a system exception occurred
354             */
355            public MDRRuleGroupInstance fetchByUuid_Last(String uuid,
356                    OrderByComparator orderByComparator) throws SystemException {
357                    int count = countByUuid(uuid);
358    
359                    List<MDRRuleGroupInstance> list = findByUuid(uuid, count - 1, count,
360                                    orderByComparator);
361    
362                    if (!list.isEmpty()) {
363                            return list.get(0);
364                    }
365    
366                    return null;
367            }
368    
369            /**
370             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where uuid = &#63;.
371             *
372             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
373             * @param uuid the uuid
374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
375             * @return the previous, current, and next m d r rule group instance
376             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
377             * @throws SystemException if a system exception occurred
378             */
379            public MDRRuleGroupInstance[] findByUuid_PrevAndNext(
380                    long ruleGroupInstanceId, String uuid,
381                    OrderByComparator orderByComparator)
382                    throws NoSuchRuleGroupInstanceException, SystemException {
383                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
384    
385                    Session session = null;
386    
387                    try {
388                            session = openSession();
389    
390                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
391    
392                            array[0] = getByUuid_PrevAndNext(session, mdrRuleGroupInstance,
393                                            uuid, orderByComparator, true);
394    
395                            array[1] = mdrRuleGroupInstance;
396    
397                            array[2] = getByUuid_PrevAndNext(session, mdrRuleGroupInstance,
398                                            uuid, orderByComparator, false);
399    
400                            return array;
401                    }
402                    catch (Exception e) {
403                            throw processException(e);
404                    }
405                    finally {
406                            closeSession(session);
407                    }
408            }
409    
410            protected MDRRuleGroupInstance getByUuid_PrevAndNext(Session session,
411                    MDRRuleGroupInstance mdrRuleGroupInstance, String uuid,
412                    OrderByComparator orderByComparator, boolean previous) {
413                    StringBundler query = null;
414    
415                    if (orderByComparator != null) {
416                            query = new StringBundler(6 +
417                                            (orderByComparator.getOrderByFields().length * 6));
418                    }
419                    else {
420                            query = new StringBundler(3);
421                    }
422    
423                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
424    
425                    boolean bindUuid = false;
426    
427                    if (uuid == null) {
428                            query.append(_FINDER_COLUMN_UUID_UUID_1);
429                    }
430                    else if (uuid.equals(StringPool.BLANK)) {
431                            query.append(_FINDER_COLUMN_UUID_UUID_3);
432                    }
433                    else {
434                            bindUuid = true;
435    
436                            query.append(_FINDER_COLUMN_UUID_UUID_2);
437                    }
438    
439                    if (orderByComparator != null) {
440                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
441    
442                            if (orderByConditionFields.length > 0) {
443                                    query.append(WHERE_AND);
444                            }
445    
446                            for (int i = 0; i < orderByConditionFields.length; i++) {
447                                    query.append(_ORDER_BY_ENTITY_ALIAS);
448                                    query.append(orderByConditionFields[i]);
449    
450                                    if ((i + 1) < orderByConditionFields.length) {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
453                                            }
454                                            else {
455                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
456                                            }
457                                    }
458                                    else {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(WHERE_GREATER_THAN);
461                                            }
462                                            else {
463                                                    query.append(WHERE_LESSER_THAN);
464                                            }
465                                    }
466                            }
467    
468                            query.append(ORDER_BY_CLAUSE);
469    
470                            String[] orderByFields = orderByComparator.getOrderByFields();
471    
472                            for (int i = 0; i < orderByFields.length; i++) {
473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
474                                    query.append(orderByFields[i]);
475    
476                                    if ((i + 1) < orderByFields.length) {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
479                                            }
480                                            else {
481                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
482                                            }
483                                    }
484                                    else {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(ORDER_BY_ASC);
487                                            }
488                                            else {
489                                                    query.append(ORDER_BY_DESC);
490                                            }
491                                    }
492                            }
493                    }
494                    else {
495                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
496                    }
497    
498                    String sql = query.toString();
499    
500                    Query q = session.createQuery(sql);
501    
502                    q.setFirstResult(0);
503                    q.setMaxResults(2);
504    
505                    QueryPos qPos = QueryPos.getInstance(q);
506    
507                    if (bindUuid) {
508                            qPos.add(uuid);
509                    }
510    
511                    if (orderByComparator != null) {
512                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
513    
514                            for (Object value : values) {
515                                    qPos.add(value);
516                            }
517                    }
518    
519                    List<MDRRuleGroupInstance> list = q.list();
520    
521                    if (list.size() == 2) {
522                            return list.get(1);
523                    }
524                    else {
525                            return null;
526                    }
527            }
528    
529            /**
530             * Removes all the m d r rule group instances where uuid = &#63; from the database.
531             *
532             * @param uuid the uuid
533             * @throws SystemException if a system exception occurred
534             */
535            public void removeByUuid(String uuid) throws SystemException {
536                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByUuid(uuid,
537                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
538                            remove(mdrRuleGroupInstance);
539                    }
540            }
541    
542            /**
543             * Returns the number of m d r rule group instances where uuid = &#63;.
544             *
545             * @param uuid the uuid
546             * @return the number of matching m d r rule group instances
547             * @throws SystemException if a system exception occurred
548             */
549            public int countByUuid(String uuid) throws SystemException {
550                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
551    
552                    Object[] finderArgs = new Object[] { uuid };
553    
554                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
555                                    this);
556    
557                    if (count == null) {
558                            StringBundler query = new StringBundler(2);
559    
560                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
561    
562                            boolean bindUuid = false;
563    
564                            if (uuid == null) {
565                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
566                            }
567                            else if (uuid.equals(StringPool.BLANK)) {
568                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
569                            }
570                            else {
571                                    bindUuid = true;
572    
573                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
574                            }
575    
576                            String sql = query.toString();
577    
578                            Session session = null;
579    
580                            try {
581                                    session = openSession();
582    
583                                    Query q = session.createQuery(sql);
584    
585                                    QueryPos qPos = QueryPos.getInstance(q);
586    
587                                    if (bindUuid) {
588                                            qPos.add(uuid);
589                                    }
590    
591                                    count = (Long)q.uniqueResult();
592    
593                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
594                            }
595                            catch (Exception e) {
596                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
597    
598                                    throw processException(e);
599                            }
600                            finally {
601                                    closeSession(session);
602                            }
603                    }
604    
605                    return count.intValue();
606            }
607    
608            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mdrRuleGroupInstance.uuid IS NULL";
609            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mdrRuleGroupInstance.uuid = ?";
610            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mdrRuleGroupInstance.uuid IS NULL OR mdrRuleGroupInstance.uuid = '')";
611            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
612                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
613                            MDRRuleGroupInstanceImpl.class, FINDER_CLASS_NAME_ENTITY,
614                            "fetchByUUID_G",
615                            new String[] { String.class.getName(), Long.class.getName() },
616                            MDRRuleGroupInstanceModelImpl.UUID_COLUMN_BITMASK |
617                            MDRRuleGroupInstanceModelImpl.GROUPID_COLUMN_BITMASK);
618            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
619                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
620                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
621                            new String[] { String.class.getName(), Long.class.getName() });
622    
623            /**
624             * Returns the m d r rule group instance where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException} if it could not be found.
625             *
626             * @param uuid the uuid
627             * @param groupId the group ID
628             * @return the matching m d r rule group instance
629             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
630             * @throws SystemException if a system exception occurred
631             */
632            public MDRRuleGroupInstance findByUUID_G(String uuid, long groupId)
633                    throws NoSuchRuleGroupInstanceException, SystemException {
634                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUUID_G(uuid, groupId);
635    
636                    if (mdrRuleGroupInstance == null) {
637                            StringBundler msg = new StringBundler(6);
638    
639                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
640    
641                            msg.append("uuid=");
642                            msg.append(uuid);
643    
644                            msg.append(", groupId=");
645                            msg.append(groupId);
646    
647                            msg.append(StringPool.CLOSE_CURLY_BRACE);
648    
649                            if (_log.isWarnEnabled()) {
650                                    _log.warn(msg.toString());
651                            }
652    
653                            throw new NoSuchRuleGroupInstanceException(msg.toString());
654                    }
655    
656                    return mdrRuleGroupInstance;
657            }
658    
659            /**
660             * Returns the m d r rule group instance where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
661             *
662             * @param uuid the uuid
663             * @param groupId the group ID
664             * @return the matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
665             * @throws SystemException if a system exception occurred
666             */
667            public MDRRuleGroupInstance fetchByUUID_G(String uuid, long groupId)
668                    throws SystemException {
669                    return fetchByUUID_G(uuid, groupId, true);
670            }
671    
672            /**
673             * Returns the m d r rule group instance where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
674             *
675             * @param uuid the uuid
676             * @param groupId the group ID
677             * @param retrieveFromCache whether to use the finder cache
678             * @return the matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
679             * @throws SystemException if a system exception occurred
680             */
681            public MDRRuleGroupInstance fetchByUUID_G(String uuid, long groupId,
682                    boolean retrieveFromCache) throws SystemException {
683                    Object[] finderArgs = new Object[] { uuid, groupId };
684    
685                    Object result = null;
686    
687                    if (retrieveFromCache) {
688                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
689                                            finderArgs, this);
690                    }
691    
692                    if (result instanceof MDRRuleGroupInstance) {
693                            MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)result;
694    
695                            if (!Validator.equals(uuid, mdrRuleGroupInstance.getUuid()) ||
696                                            (groupId != mdrRuleGroupInstance.getGroupId())) {
697                                    result = null;
698                            }
699                    }
700    
701                    if (result == null) {
702                            StringBundler query = new StringBundler(4);
703    
704                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
705    
706                            boolean bindUuid = false;
707    
708                            if (uuid == null) {
709                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
710                            }
711                            else if (uuid.equals(StringPool.BLANK)) {
712                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
713                            }
714                            else {
715                                    bindUuid = true;
716    
717                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
718                            }
719    
720                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
721    
722                            String sql = query.toString();
723    
724                            Session session = null;
725    
726                            try {
727                                    session = openSession();
728    
729                                    Query q = session.createQuery(sql);
730    
731                                    QueryPos qPos = QueryPos.getInstance(q);
732    
733                                    if (bindUuid) {
734                                            qPos.add(uuid);
735                                    }
736    
737                                    qPos.add(groupId);
738    
739                                    List<MDRRuleGroupInstance> list = q.list();
740    
741                                    if (list.isEmpty()) {
742                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
743                                                    finderArgs, list);
744                                    }
745                                    else {
746                                            MDRRuleGroupInstance mdrRuleGroupInstance = list.get(0);
747    
748                                            result = mdrRuleGroupInstance;
749    
750                                            cacheResult(mdrRuleGroupInstance);
751    
752                                            if ((mdrRuleGroupInstance.getUuid() == null) ||
753                                                            !mdrRuleGroupInstance.getUuid().equals(uuid) ||
754                                                            (mdrRuleGroupInstance.getGroupId() != groupId)) {
755                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
756                                                            finderArgs, mdrRuleGroupInstance);
757                                            }
758                                    }
759                            }
760                            catch (Exception e) {
761                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
762                                            finderArgs);
763    
764                                    throw processException(e);
765                            }
766                            finally {
767                                    closeSession(session);
768                            }
769                    }
770    
771                    if (result instanceof List<?>) {
772                            return null;
773                    }
774                    else {
775                            return (MDRRuleGroupInstance)result;
776                    }
777            }
778    
779            /**
780             * Removes the m d r rule group instance where uuid = &#63; and groupId = &#63; from the database.
781             *
782             * @param uuid the uuid
783             * @param groupId the group ID
784             * @return the m d r rule group instance that was removed
785             * @throws SystemException if a system exception occurred
786             */
787            public MDRRuleGroupInstance removeByUUID_G(String uuid, long groupId)
788                    throws NoSuchRuleGroupInstanceException, SystemException {
789                    MDRRuleGroupInstance mdrRuleGroupInstance = findByUUID_G(uuid, groupId);
790    
791                    return remove(mdrRuleGroupInstance);
792            }
793    
794            /**
795             * Returns the number of m d r rule group instances where uuid = &#63; and groupId = &#63;.
796             *
797             * @param uuid the uuid
798             * @param groupId the group ID
799             * @return the number of matching m d r rule group instances
800             * @throws SystemException if a system exception occurred
801             */
802            public int countByUUID_G(String uuid, long groupId)
803                    throws SystemException {
804                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
805    
806                    Object[] finderArgs = new Object[] { uuid, groupId };
807    
808                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
809                                    this);
810    
811                    if (count == null) {
812                            StringBundler query = new StringBundler(3);
813    
814                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
815    
816                            boolean bindUuid = false;
817    
818                            if (uuid == null) {
819                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
820                            }
821                            else if (uuid.equals(StringPool.BLANK)) {
822                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
823                            }
824                            else {
825                                    bindUuid = true;
826    
827                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
828                            }
829    
830                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
831    
832                            String sql = query.toString();
833    
834                            Session session = null;
835    
836                            try {
837                                    session = openSession();
838    
839                                    Query q = session.createQuery(sql);
840    
841                                    QueryPos qPos = QueryPos.getInstance(q);
842    
843                                    if (bindUuid) {
844                                            qPos.add(uuid);
845                                    }
846    
847                                    qPos.add(groupId);
848    
849                                    count = (Long)q.uniqueResult();
850    
851                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
852                            }
853                            catch (Exception e) {
854                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
855    
856                                    throw processException(e);
857                            }
858                            finally {
859                                    closeSession(session);
860                            }
861                    }
862    
863                    return count.intValue();
864            }
865    
866            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mdrRuleGroupInstance.uuid IS NULL AND ";
867            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mdrRuleGroupInstance.uuid = ? AND ";
868            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mdrRuleGroupInstance.uuid IS NULL OR mdrRuleGroupInstance.uuid = '') AND ";
869            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mdrRuleGroupInstance.groupId = ?";
870            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
871                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
872                            MDRRuleGroupInstanceImpl.class,
873                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
874                            new String[] {
875                                    String.class.getName(), Long.class.getName(),
876                                    
877                            Integer.class.getName(), Integer.class.getName(),
878                                    OrderByComparator.class.getName()
879                            });
880            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
881                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
882                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
883                            MDRRuleGroupInstanceImpl.class,
884                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
885                            new String[] { String.class.getName(), Long.class.getName() },
886                            MDRRuleGroupInstanceModelImpl.UUID_COLUMN_BITMASK |
887                            MDRRuleGroupInstanceModelImpl.COMPANYID_COLUMN_BITMASK);
888            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
889                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
890                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
891                            new String[] { String.class.getName(), Long.class.getName() });
892    
893            /**
894             * Returns all the m d r rule group instances where uuid = &#63; and companyId = &#63;.
895             *
896             * @param uuid the uuid
897             * @param companyId the company ID
898             * @return the matching m d r rule group instances
899             * @throws SystemException if a system exception occurred
900             */
901            public List<MDRRuleGroupInstance> findByUuid_C(String uuid, long companyId)
902                    throws SystemException {
903                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
904                            QueryUtil.ALL_POS, null);
905            }
906    
907            /**
908             * Returns a range of all the m d r rule group instances where uuid = &#63; and companyId = &#63;.
909             *
910             * <p>
911             * 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.MDRRuleGroupInstanceModelImpl}. 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.
912             * </p>
913             *
914             * @param uuid the uuid
915             * @param companyId the company ID
916             * @param start the lower bound of the range of m d r rule group instances
917             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
918             * @return the range of matching m d r rule group instances
919             * @throws SystemException if a system exception occurred
920             */
921            public List<MDRRuleGroupInstance> findByUuid_C(String uuid, long companyId,
922                    int start, int end) throws SystemException {
923                    return findByUuid_C(uuid, companyId, start, end, null);
924            }
925    
926            /**
927             * Returns an ordered range of all the m d r rule group instances where uuid = &#63; and companyId = &#63;.
928             *
929             * <p>
930             * 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.MDRRuleGroupInstanceModelImpl}. 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.
931             * </p>
932             *
933             * @param uuid the uuid
934             * @param companyId the company ID
935             * @param start the lower bound of the range of m d r rule group instances
936             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
937             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
938             * @return the ordered range of matching m d r rule group instances
939             * @throws SystemException if a system exception occurred
940             */
941            public List<MDRRuleGroupInstance> findByUuid_C(String uuid, long companyId,
942                    int start, int end, OrderByComparator orderByComparator)
943                    throws SystemException {
944                    boolean pagination = true;
945                    FinderPath finderPath = null;
946                    Object[] finderArgs = null;
947    
948                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
949                                    (orderByComparator == null)) {
950                            pagination = false;
951                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
952                            finderArgs = new Object[] { uuid, companyId };
953                    }
954                    else {
955                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
956                            finderArgs = new Object[] {
957                                            uuid, companyId,
958                                            
959                                            start, end, orderByComparator
960                                    };
961                    }
962    
963                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
964                                    finderArgs, this);
965    
966                    if ((list != null) && !list.isEmpty()) {
967                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
968                                    if (!Validator.equals(uuid, mdrRuleGroupInstance.getUuid()) ||
969                                                    (companyId != mdrRuleGroupInstance.getCompanyId())) {
970                                            list = null;
971    
972                                            break;
973                                    }
974                            }
975                    }
976    
977                    if (list == null) {
978                            StringBundler query = null;
979    
980                            if (orderByComparator != null) {
981                                    query = new StringBundler(4 +
982                                                    (orderByComparator.getOrderByFields().length * 3));
983                            }
984                            else {
985                                    query = new StringBundler(4);
986                            }
987    
988                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
989    
990                            boolean bindUuid = false;
991    
992                            if (uuid == null) {
993                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
994                            }
995                            else if (uuid.equals(StringPool.BLANK)) {
996                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
997                            }
998                            else {
999                                    bindUuid = true;
1000    
1001                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1002                            }
1003    
1004                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1005    
1006                            if (orderByComparator != null) {
1007                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1008                                            orderByComparator);
1009                            }
1010                            else
1011                             if (pagination) {
1012                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1013                            }
1014    
1015                            String sql = query.toString();
1016    
1017                            Session session = null;
1018    
1019                            try {
1020                                    session = openSession();
1021    
1022                                    Query q = session.createQuery(sql);
1023    
1024                                    QueryPos qPos = QueryPos.getInstance(q);
1025    
1026                                    if (bindUuid) {
1027                                            qPos.add(uuid);
1028                                    }
1029    
1030                                    qPos.add(companyId);
1031    
1032                                    if (!pagination) {
1033                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1034                                                            getDialect(), start, end, false);
1035    
1036                                            Collections.sort(list);
1037    
1038                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
1039                                    }
1040                                    else {
1041                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1042                                                            getDialect(), start, end);
1043                                    }
1044    
1045                                    cacheResult(list);
1046    
1047                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1048                            }
1049                            catch (Exception e) {
1050                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1051    
1052                                    throw processException(e);
1053                            }
1054                            finally {
1055                                    closeSession(session);
1056                            }
1057                    }
1058    
1059                    return list;
1060            }
1061    
1062            /**
1063             * Returns the first m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1064             *
1065             * @param uuid the uuid
1066             * @param companyId the company ID
1067             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1068             * @return the first matching m d r rule group instance
1069             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1070             * @throws SystemException if a system exception occurred
1071             */
1072            public MDRRuleGroupInstance findByUuid_C_First(String uuid, long companyId,
1073                    OrderByComparator orderByComparator)
1074                    throws NoSuchRuleGroupInstanceException, SystemException {
1075                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUuid_C_First(uuid,
1076                                    companyId, orderByComparator);
1077    
1078                    if (mdrRuleGroupInstance != null) {
1079                            return mdrRuleGroupInstance;
1080                    }
1081    
1082                    StringBundler msg = new StringBundler(6);
1083    
1084                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1085    
1086                    msg.append("uuid=");
1087                    msg.append(uuid);
1088    
1089                    msg.append(", companyId=");
1090                    msg.append(companyId);
1091    
1092                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1093    
1094                    throw new NoSuchRuleGroupInstanceException(msg.toString());
1095            }
1096    
1097            /**
1098             * Returns the first m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1099             *
1100             * @param uuid the uuid
1101             * @param companyId the company ID
1102             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1103             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1104             * @throws SystemException if a system exception occurred
1105             */
1106            public MDRRuleGroupInstance fetchByUuid_C_First(String uuid,
1107                    long companyId, OrderByComparator orderByComparator)
1108                    throws SystemException {
1109                    List<MDRRuleGroupInstance> list = findByUuid_C(uuid, companyId, 0, 1,
1110                                    orderByComparator);
1111    
1112                    if (!list.isEmpty()) {
1113                            return list.get(0);
1114                    }
1115    
1116                    return null;
1117            }
1118    
1119            /**
1120             * Returns the last m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1121             *
1122             * @param uuid the uuid
1123             * @param companyId the company ID
1124             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1125             * @return the last matching m d r rule group instance
1126             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1127             * @throws SystemException if a system exception occurred
1128             */
1129            public MDRRuleGroupInstance findByUuid_C_Last(String uuid, long companyId,
1130                    OrderByComparator orderByComparator)
1131                    throws NoSuchRuleGroupInstanceException, SystemException {
1132                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByUuid_C_Last(uuid,
1133                                    companyId, orderByComparator);
1134    
1135                    if (mdrRuleGroupInstance != null) {
1136                            return mdrRuleGroupInstance;
1137                    }
1138    
1139                    StringBundler msg = new StringBundler(6);
1140    
1141                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1142    
1143                    msg.append("uuid=");
1144                    msg.append(uuid);
1145    
1146                    msg.append(", companyId=");
1147                    msg.append(companyId);
1148    
1149                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1150    
1151                    throw new NoSuchRuleGroupInstanceException(msg.toString());
1152            }
1153    
1154            /**
1155             * Returns the last m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1156             *
1157             * @param uuid the uuid
1158             * @param companyId the company ID
1159             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1160             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1161             * @throws SystemException if a system exception occurred
1162             */
1163            public MDRRuleGroupInstance fetchByUuid_C_Last(String uuid, long companyId,
1164                    OrderByComparator orderByComparator) throws SystemException {
1165                    int count = countByUuid_C(uuid, companyId);
1166    
1167                    List<MDRRuleGroupInstance> list = findByUuid_C(uuid, companyId,
1168                                    count - 1, count, orderByComparator);
1169    
1170                    if (!list.isEmpty()) {
1171                            return list.get(0);
1172                    }
1173    
1174                    return null;
1175            }
1176    
1177            /**
1178             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where uuid = &#63; and companyId = &#63;.
1179             *
1180             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
1181             * @param uuid the uuid
1182             * @param companyId the company ID
1183             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1184             * @return the previous, current, and next m d r rule group instance
1185             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
1186             * @throws SystemException if a system exception occurred
1187             */
1188            public MDRRuleGroupInstance[] findByUuid_C_PrevAndNext(
1189                    long ruleGroupInstanceId, String uuid, long companyId,
1190                    OrderByComparator orderByComparator)
1191                    throws NoSuchRuleGroupInstanceException, SystemException {
1192                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
1193    
1194                    Session session = null;
1195    
1196                    try {
1197                            session = openSession();
1198    
1199                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
1200    
1201                            array[0] = getByUuid_C_PrevAndNext(session, mdrRuleGroupInstance,
1202                                            uuid, companyId, orderByComparator, true);
1203    
1204                            array[1] = mdrRuleGroupInstance;
1205    
1206                            array[2] = getByUuid_C_PrevAndNext(session, mdrRuleGroupInstance,
1207                                            uuid, companyId, orderByComparator, false);
1208    
1209                            return array;
1210                    }
1211                    catch (Exception e) {
1212                            throw processException(e);
1213                    }
1214                    finally {
1215                            closeSession(session);
1216                    }
1217            }
1218    
1219            protected MDRRuleGroupInstance getByUuid_C_PrevAndNext(Session session,
1220                    MDRRuleGroupInstance mdrRuleGroupInstance, String uuid, long companyId,
1221                    OrderByComparator orderByComparator, boolean previous) {
1222                    StringBundler query = null;
1223    
1224                    if (orderByComparator != null) {
1225                            query = new StringBundler(6 +
1226                                            (orderByComparator.getOrderByFields().length * 6));
1227                    }
1228                    else {
1229                            query = new StringBundler(3);
1230                    }
1231    
1232                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1233    
1234                    boolean bindUuid = false;
1235    
1236                    if (uuid == null) {
1237                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1238                    }
1239                    else if (uuid.equals(StringPool.BLANK)) {
1240                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1241                    }
1242                    else {
1243                            bindUuid = true;
1244    
1245                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1246                    }
1247    
1248                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1249    
1250                    if (orderByComparator != null) {
1251                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1252    
1253                            if (orderByConditionFields.length > 0) {
1254                                    query.append(WHERE_AND);
1255                            }
1256    
1257                            for (int i = 0; i < orderByConditionFields.length; i++) {
1258                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1259                                    query.append(orderByConditionFields[i]);
1260    
1261                                    if ((i + 1) < orderByConditionFields.length) {
1262                                            if (orderByComparator.isAscending() ^ previous) {
1263                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1264                                            }
1265                                            else {
1266                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1267                                            }
1268                                    }
1269                                    else {
1270                                            if (orderByComparator.isAscending() ^ previous) {
1271                                                    query.append(WHERE_GREATER_THAN);
1272                                            }
1273                                            else {
1274                                                    query.append(WHERE_LESSER_THAN);
1275                                            }
1276                                    }
1277                            }
1278    
1279                            query.append(ORDER_BY_CLAUSE);
1280    
1281                            String[] orderByFields = orderByComparator.getOrderByFields();
1282    
1283                            for (int i = 0; i < orderByFields.length; i++) {
1284                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1285                                    query.append(orderByFields[i]);
1286    
1287                                    if ((i + 1) < orderByFields.length) {
1288                                            if (orderByComparator.isAscending() ^ previous) {
1289                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1290                                            }
1291                                            else {
1292                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1293                                            }
1294                                    }
1295                                    else {
1296                                            if (orderByComparator.isAscending() ^ previous) {
1297                                                    query.append(ORDER_BY_ASC);
1298                                            }
1299                                            else {
1300                                                    query.append(ORDER_BY_DESC);
1301                                            }
1302                                    }
1303                            }
1304                    }
1305                    else {
1306                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1307                    }
1308    
1309                    String sql = query.toString();
1310    
1311                    Query q = session.createQuery(sql);
1312    
1313                    q.setFirstResult(0);
1314                    q.setMaxResults(2);
1315    
1316                    QueryPos qPos = QueryPos.getInstance(q);
1317    
1318                    if (bindUuid) {
1319                            qPos.add(uuid);
1320                    }
1321    
1322                    qPos.add(companyId);
1323    
1324                    if (orderByComparator != null) {
1325                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
1326    
1327                            for (Object value : values) {
1328                                    qPos.add(value);
1329                            }
1330                    }
1331    
1332                    List<MDRRuleGroupInstance> list = q.list();
1333    
1334                    if (list.size() == 2) {
1335                            return list.get(1);
1336                    }
1337                    else {
1338                            return null;
1339                    }
1340            }
1341    
1342            /**
1343             * Removes all the m d r rule group instances where uuid = &#63; and companyId = &#63; from the database.
1344             *
1345             * @param uuid the uuid
1346             * @param companyId the company ID
1347             * @throws SystemException if a system exception occurred
1348             */
1349            public void removeByUuid_C(String uuid, long companyId)
1350                    throws SystemException {
1351                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByUuid_C(uuid,
1352                                    companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1353                            remove(mdrRuleGroupInstance);
1354                    }
1355            }
1356    
1357            /**
1358             * Returns the number of m d r rule group instances where uuid = &#63; and companyId = &#63;.
1359             *
1360             * @param uuid the uuid
1361             * @param companyId the company ID
1362             * @return the number of matching m d r rule group instances
1363             * @throws SystemException if a system exception occurred
1364             */
1365            public int countByUuid_C(String uuid, long companyId)
1366                    throws SystemException {
1367                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1368    
1369                    Object[] finderArgs = new Object[] { uuid, companyId };
1370    
1371                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1372                                    this);
1373    
1374                    if (count == null) {
1375                            StringBundler query = new StringBundler(3);
1376    
1377                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
1378    
1379                            boolean bindUuid = false;
1380    
1381                            if (uuid == null) {
1382                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1383                            }
1384                            else if (uuid.equals(StringPool.BLANK)) {
1385                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1386                            }
1387                            else {
1388                                    bindUuid = true;
1389    
1390                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1391                            }
1392    
1393                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1394    
1395                            String sql = query.toString();
1396    
1397                            Session session = null;
1398    
1399                            try {
1400                                    session = openSession();
1401    
1402                                    Query q = session.createQuery(sql);
1403    
1404                                    QueryPos qPos = QueryPos.getInstance(q);
1405    
1406                                    if (bindUuid) {
1407                                            qPos.add(uuid);
1408                                    }
1409    
1410                                    qPos.add(companyId);
1411    
1412                                    count = (Long)q.uniqueResult();
1413    
1414                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1415                            }
1416                            catch (Exception e) {
1417                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1418    
1419                                    throw processException(e);
1420                            }
1421                            finally {
1422                                    closeSession(session);
1423                            }
1424                    }
1425    
1426                    return count.intValue();
1427            }
1428    
1429            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mdrRuleGroupInstance.uuid IS NULL AND ";
1430            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mdrRuleGroupInstance.uuid = ? AND ";
1431            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mdrRuleGroupInstance.uuid IS NULL OR mdrRuleGroupInstance.uuid = '') AND ";
1432            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mdrRuleGroupInstance.companyId = ?";
1433            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
1434                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
1435                            MDRRuleGroupInstanceImpl.class,
1436                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1437                            new String[] {
1438                                    Long.class.getName(),
1439                                    
1440                            Integer.class.getName(), Integer.class.getName(),
1441                                    OrderByComparator.class.getName()
1442                            });
1443            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1444                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
1445                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
1446                            MDRRuleGroupInstanceImpl.class,
1447                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1448                            new String[] { Long.class.getName() },
1449                            MDRRuleGroupInstanceModelImpl.GROUPID_COLUMN_BITMASK);
1450            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
1451                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
1452                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1453                            new String[] { Long.class.getName() });
1454    
1455            /**
1456             * Returns all the m d r rule group instances where groupId = &#63;.
1457             *
1458             * @param groupId the group ID
1459             * @return the matching m d r rule group instances
1460             * @throws SystemException if a system exception occurred
1461             */
1462            public List<MDRRuleGroupInstance> findByGroupId(long groupId)
1463                    throws SystemException {
1464                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1465            }
1466    
1467            /**
1468             * Returns a range of all the m d r rule group instances where groupId = &#63;.
1469             *
1470             * <p>
1471             * 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.MDRRuleGroupInstanceModelImpl}. 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.
1472             * </p>
1473             *
1474             * @param groupId the group ID
1475             * @param start the lower bound of the range of m d r rule group instances
1476             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1477             * @return the range of matching m d r rule group instances
1478             * @throws SystemException if a system exception occurred
1479             */
1480            public List<MDRRuleGroupInstance> findByGroupId(long groupId, int start,
1481                    int end) throws SystemException {
1482                    return findByGroupId(groupId, start, end, null);
1483            }
1484    
1485            /**
1486             * Returns an ordered range of all the m d r rule group instances where groupId = &#63;.
1487             *
1488             * <p>
1489             * 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.MDRRuleGroupInstanceModelImpl}. 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.
1490             * </p>
1491             *
1492             * @param groupId the group ID
1493             * @param start the lower bound of the range of m d r rule group instances
1494             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1495             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1496             * @return the ordered range of matching m d r rule group instances
1497             * @throws SystemException if a system exception occurred
1498             */
1499            public List<MDRRuleGroupInstance> findByGroupId(long groupId, int start,
1500                    int end, OrderByComparator orderByComparator) throws SystemException {
1501                    boolean pagination = true;
1502                    FinderPath finderPath = null;
1503                    Object[] finderArgs = null;
1504    
1505                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1506                                    (orderByComparator == null)) {
1507                            pagination = false;
1508                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1509                            finderArgs = new Object[] { groupId };
1510                    }
1511                    else {
1512                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1513                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1514                    }
1515    
1516                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
1517                                    finderArgs, this);
1518    
1519                    if ((list != null) && !list.isEmpty()) {
1520                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
1521                                    if ((groupId != mdrRuleGroupInstance.getGroupId())) {
1522                                            list = null;
1523    
1524                                            break;
1525                                    }
1526                            }
1527                    }
1528    
1529                    if (list == null) {
1530                            StringBundler query = null;
1531    
1532                            if (orderByComparator != null) {
1533                                    query = new StringBundler(3 +
1534                                                    (orderByComparator.getOrderByFields().length * 3));
1535                            }
1536                            else {
1537                                    query = new StringBundler(3);
1538                            }
1539    
1540                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1541    
1542                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1543    
1544                            if (orderByComparator != null) {
1545                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1546                                            orderByComparator);
1547                            }
1548                            else
1549                             if (pagination) {
1550                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1551                            }
1552    
1553                            String sql = query.toString();
1554    
1555                            Session session = null;
1556    
1557                            try {
1558                                    session = openSession();
1559    
1560                                    Query q = session.createQuery(sql);
1561    
1562                                    QueryPos qPos = QueryPos.getInstance(q);
1563    
1564                                    qPos.add(groupId);
1565    
1566                                    if (!pagination) {
1567                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1568                                                            getDialect(), start, end, false);
1569    
1570                                            Collections.sort(list);
1571    
1572                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
1573                                    }
1574                                    else {
1575                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
1576                                                            getDialect(), start, end);
1577                                    }
1578    
1579                                    cacheResult(list);
1580    
1581                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1582                            }
1583                            catch (Exception e) {
1584                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1585    
1586                                    throw processException(e);
1587                            }
1588                            finally {
1589                                    closeSession(session);
1590                            }
1591                    }
1592    
1593                    return list;
1594            }
1595    
1596            /**
1597             * Returns the first m d r rule group instance in the ordered set where groupId = &#63;.
1598             *
1599             * @param groupId the group ID
1600             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1601             * @return the first matching m d r rule group instance
1602             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1603             * @throws SystemException if a system exception occurred
1604             */
1605            public MDRRuleGroupInstance findByGroupId_First(long groupId,
1606                    OrderByComparator orderByComparator)
1607                    throws NoSuchRuleGroupInstanceException, SystemException {
1608                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByGroupId_First(groupId,
1609                                    orderByComparator);
1610    
1611                    if (mdrRuleGroupInstance != null) {
1612                            return mdrRuleGroupInstance;
1613                    }
1614    
1615                    StringBundler msg = new StringBundler(4);
1616    
1617                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1618    
1619                    msg.append("groupId=");
1620                    msg.append(groupId);
1621    
1622                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1623    
1624                    throw new NoSuchRuleGroupInstanceException(msg.toString());
1625            }
1626    
1627            /**
1628             * Returns the first m d r rule group instance in the ordered set where groupId = &#63;.
1629             *
1630             * @param groupId the group ID
1631             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1632             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1633             * @throws SystemException if a system exception occurred
1634             */
1635            public MDRRuleGroupInstance fetchByGroupId_First(long groupId,
1636                    OrderByComparator orderByComparator) throws SystemException {
1637                    List<MDRRuleGroupInstance> list = findByGroupId(groupId, 0, 1,
1638                                    orderByComparator);
1639    
1640                    if (!list.isEmpty()) {
1641                            return list.get(0);
1642                    }
1643    
1644                    return null;
1645            }
1646    
1647            /**
1648             * Returns the last m d r rule group instance in the ordered set where groupId = &#63;.
1649             *
1650             * @param groupId the group ID
1651             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1652             * @return the last matching m d r rule group instance
1653             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
1654             * @throws SystemException if a system exception occurred
1655             */
1656            public MDRRuleGroupInstance findByGroupId_Last(long groupId,
1657                    OrderByComparator orderByComparator)
1658                    throws NoSuchRuleGroupInstanceException, SystemException {
1659                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByGroupId_Last(groupId,
1660                                    orderByComparator);
1661    
1662                    if (mdrRuleGroupInstance != null) {
1663                            return mdrRuleGroupInstance;
1664                    }
1665    
1666                    StringBundler msg = new StringBundler(4);
1667    
1668                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1669    
1670                    msg.append("groupId=");
1671                    msg.append(groupId);
1672    
1673                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1674    
1675                    throw new NoSuchRuleGroupInstanceException(msg.toString());
1676            }
1677    
1678            /**
1679             * Returns the last m d r rule group instance in the ordered set where groupId = &#63;.
1680             *
1681             * @param groupId the group ID
1682             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1683             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
1684             * @throws SystemException if a system exception occurred
1685             */
1686            public MDRRuleGroupInstance fetchByGroupId_Last(long groupId,
1687                    OrderByComparator orderByComparator) throws SystemException {
1688                    int count = countByGroupId(groupId);
1689    
1690                    List<MDRRuleGroupInstance> list = findByGroupId(groupId, count - 1,
1691                                    count, orderByComparator);
1692    
1693                    if (!list.isEmpty()) {
1694                            return list.get(0);
1695                    }
1696    
1697                    return null;
1698            }
1699    
1700            /**
1701             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where groupId = &#63;.
1702             *
1703             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
1704             * @param groupId the group ID
1705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1706             * @return the previous, current, and next m d r rule group instance
1707             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
1708             * @throws SystemException if a system exception occurred
1709             */
1710            public MDRRuleGroupInstance[] findByGroupId_PrevAndNext(
1711                    long ruleGroupInstanceId, long groupId,
1712                    OrderByComparator orderByComparator)
1713                    throws NoSuchRuleGroupInstanceException, SystemException {
1714                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
1715    
1716                    Session session = null;
1717    
1718                    try {
1719                            session = openSession();
1720    
1721                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
1722    
1723                            array[0] = getByGroupId_PrevAndNext(session, mdrRuleGroupInstance,
1724                                            groupId, orderByComparator, true);
1725    
1726                            array[1] = mdrRuleGroupInstance;
1727    
1728                            array[2] = getByGroupId_PrevAndNext(session, mdrRuleGroupInstance,
1729                                            groupId, orderByComparator, false);
1730    
1731                            return array;
1732                    }
1733                    catch (Exception e) {
1734                            throw processException(e);
1735                    }
1736                    finally {
1737                            closeSession(session);
1738                    }
1739            }
1740    
1741            protected MDRRuleGroupInstance getByGroupId_PrevAndNext(Session session,
1742                    MDRRuleGroupInstance mdrRuleGroupInstance, long groupId,
1743                    OrderByComparator orderByComparator, boolean previous) {
1744                    StringBundler query = null;
1745    
1746                    if (orderByComparator != null) {
1747                            query = new StringBundler(6 +
1748                                            (orderByComparator.getOrderByFields().length * 6));
1749                    }
1750                    else {
1751                            query = new StringBundler(3);
1752                    }
1753    
1754                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1755    
1756                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1757    
1758                    if (orderByComparator != null) {
1759                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1760    
1761                            if (orderByConditionFields.length > 0) {
1762                                    query.append(WHERE_AND);
1763                            }
1764    
1765                            for (int i = 0; i < orderByConditionFields.length; i++) {
1766                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1767                                    query.append(orderByConditionFields[i]);
1768    
1769                                    if ((i + 1) < orderByConditionFields.length) {
1770                                            if (orderByComparator.isAscending() ^ previous) {
1771                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1772                                            }
1773                                            else {
1774                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1775                                            }
1776                                    }
1777                                    else {
1778                                            if (orderByComparator.isAscending() ^ previous) {
1779                                                    query.append(WHERE_GREATER_THAN);
1780                                            }
1781                                            else {
1782                                                    query.append(WHERE_LESSER_THAN);
1783                                            }
1784                                    }
1785                            }
1786    
1787                            query.append(ORDER_BY_CLAUSE);
1788    
1789                            String[] orderByFields = orderByComparator.getOrderByFields();
1790    
1791                            for (int i = 0; i < orderByFields.length; i++) {
1792                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1793                                    query.append(orderByFields[i]);
1794    
1795                                    if ((i + 1) < orderByFields.length) {
1796                                            if (orderByComparator.isAscending() ^ previous) {
1797                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1798                                            }
1799                                            else {
1800                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1801                                            }
1802                                    }
1803                                    else {
1804                                            if (orderByComparator.isAscending() ^ previous) {
1805                                                    query.append(ORDER_BY_ASC);
1806                                            }
1807                                            else {
1808                                                    query.append(ORDER_BY_DESC);
1809                                            }
1810                                    }
1811                            }
1812                    }
1813                    else {
1814                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1815                    }
1816    
1817                    String sql = query.toString();
1818    
1819                    Query q = session.createQuery(sql);
1820    
1821                    q.setFirstResult(0);
1822                    q.setMaxResults(2);
1823    
1824                    QueryPos qPos = QueryPos.getInstance(q);
1825    
1826                    qPos.add(groupId);
1827    
1828                    if (orderByComparator != null) {
1829                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
1830    
1831                            for (Object value : values) {
1832                                    qPos.add(value);
1833                            }
1834                    }
1835    
1836                    List<MDRRuleGroupInstance> list = q.list();
1837    
1838                    if (list.size() == 2) {
1839                            return list.get(1);
1840                    }
1841                    else {
1842                            return null;
1843                    }
1844            }
1845    
1846            /**
1847             * Returns all the m d r rule group instances that the user has permission to view where groupId = &#63;.
1848             *
1849             * @param groupId the group ID
1850             * @return the matching m d r rule group instances that the user has permission to view
1851             * @throws SystemException if a system exception occurred
1852             */
1853            public List<MDRRuleGroupInstance> filterFindByGroupId(long groupId)
1854                    throws SystemException {
1855                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1856                            QueryUtil.ALL_POS, null);
1857            }
1858    
1859            /**
1860             * Returns a range of all the m d r rule group instances that the user has permission to view where groupId = &#63;.
1861             *
1862             * <p>
1863             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.mobiledevicerules.model.impl.MDRRuleGroupInstanceModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1864             * </p>
1865             *
1866             * @param groupId the group ID
1867             * @param start the lower bound of the range of m d r rule group instances
1868             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1869             * @return the range of matching m d r rule group instances that the user has permission to view
1870             * @throws SystemException if a system exception occurred
1871             */
1872            public List<MDRRuleGroupInstance> filterFindByGroupId(long groupId,
1873                    int start, int end) throws SystemException {
1874                    return filterFindByGroupId(groupId, start, end, null);
1875            }
1876    
1877            /**
1878             * Returns an ordered range of all the m d r rule group instances that the user has permissions to view where groupId = &#63;.
1879             *
1880             * <p>
1881             * 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.MDRRuleGroupInstanceModelImpl}. 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.
1882             * </p>
1883             *
1884             * @param groupId the group ID
1885             * @param start the lower bound of the range of m d r rule group instances
1886             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
1887             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1888             * @return the ordered range of matching m d r rule group instances that the user has permission to view
1889             * @throws SystemException if a system exception occurred
1890             */
1891            public List<MDRRuleGroupInstance> filterFindByGroupId(long groupId,
1892                    int start, int end, OrderByComparator orderByComparator)
1893                    throws SystemException {
1894                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1895                            return findByGroupId(groupId, start, end, orderByComparator);
1896                    }
1897    
1898                    StringBundler query = null;
1899    
1900                    if (orderByComparator != null) {
1901                            query = new StringBundler(3 +
1902                                            (orderByComparator.getOrderByFields().length * 3));
1903                    }
1904                    else {
1905                            query = new StringBundler(3);
1906                    }
1907    
1908                    if (getDB().isSupportsInlineDistinct()) {
1909                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
1910                    }
1911                    else {
1912                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
1913                    }
1914    
1915                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1916    
1917                    if (!getDB().isSupportsInlineDistinct()) {
1918                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
1919                    }
1920    
1921                    if (orderByComparator != null) {
1922                            if (getDB().isSupportsInlineDistinct()) {
1923                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1924                                            orderByComparator);
1925                            }
1926                            else {
1927                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1928                                            orderByComparator);
1929                            }
1930                    }
1931                    else {
1932                            if (getDB().isSupportsInlineDistinct()) {
1933                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
1934                            }
1935                            else {
1936                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_SQL);
1937                            }
1938                    }
1939    
1940                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1941                                    MDRRuleGroupInstance.class.getName(),
1942                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1943    
1944                    Session session = null;
1945    
1946                    try {
1947                            session = openSession();
1948    
1949                            SQLQuery q = session.createSQLQuery(sql);
1950    
1951                            if (getDB().isSupportsInlineDistinct()) {
1952                                    q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
1953                            }
1954                            else {
1955                                    q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
1956                            }
1957    
1958                            QueryPos qPos = QueryPos.getInstance(q);
1959    
1960                            qPos.add(groupId);
1961    
1962                            return (List<MDRRuleGroupInstance>)QueryUtil.list(q, getDialect(),
1963                                    start, end);
1964                    }
1965                    catch (Exception e) {
1966                            throw processException(e);
1967                    }
1968                    finally {
1969                            closeSession(session);
1970                    }
1971            }
1972    
1973            /**
1974             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set of m d r rule group instances that the user has permission to view where groupId = &#63;.
1975             *
1976             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
1977             * @param groupId the group ID
1978             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1979             * @return the previous, current, and next m d r rule group instance
1980             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
1981             * @throws SystemException if a system exception occurred
1982             */
1983            public MDRRuleGroupInstance[] filterFindByGroupId_PrevAndNext(
1984                    long ruleGroupInstanceId, long groupId,
1985                    OrderByComparator orderByComparator)
1986                    throws NoSuchRuleGroupInstanceException, SystemException {
1987                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1988                            return findByGroupId_PrevAndNext(ruleGroupInstanceId, groupId,
1989                                    orderByComparator);
1990                    }
1991    
1992                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
1993    
1994                    Session session = null;
1995    
1996                    try {
1997                            session = openSession();
1998    
1999                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
2000    
2001                            array[0] = filterGetByGroupId_PrevAndNext(session,
2002                                            mdrRuleGroupInstance, groupId, orderByComparator, true);
2003    
2004                            array[1] = mdrRuleGroupInstance;
2005    
2006                            array[2] = filterGetByGroupId_PrevAndNext(session,
2007                                            mdrRuleGroupInstance, groupId, orderByComparator, false);
2008    
2009                            return array;
2010                    }
2011                    catch (Exception e) {
2012                            throw processException(e);
2013                    }
2014                    finally {
2015                            closeSession(session);
2016                    }
2017            }
2018    
2019            protected MDRRuleGroupInstance filterGetByGroupId_PrevAndNext(
2020                    Session session, MDRRuleGroupInstance mdrRuleGroupInstance,
2021                    long groupId, OrderByComparator orderByComparator, boolean previous) {
2022                    StringBundler query = null;
2023    
2024                    if (orderByComparator != null) {
2025                            query = new StringBundler(6 +
2026                                            (orderByComparator.getOrderByFields().length * 6));
2027                    }
2028                    else {
2029                            query = new StringBundler(3);
2030                    }
2031    
2032                    if (getDB().isSupportsInlineDistinct()) {
2033                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2034                    }
2035                    else {
2036                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
2037                    }
2038    
2039                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2040    
2041                    if (!getDB().isSupportsInlineDistinct()) {
2042                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
2043                    }
2044    
2045                    if (orderByComparator != null) {
2046                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2047    
2048                            if (orderByConditionFields.length > 0) {
2049                                    query.append(WHERE_AND);
2050                            }
2051    
2052                            for (int i = 0; i < orderByConditionFields.length; i++) {
2053                                    if (getDB().isSupportsInlineDistinct()) {
2054                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2055                                    }
2056                                    else {
2057                                            query.append(_ORDER_BY_ENTITY_TABLE);
2058                                    }
2059    
2060                                    query.append(orderByConditionFields[i]);
2061    
2062                                    if ((i + 1) < orderByConditionFields.length) {
2063                                            if (orderByComparator.isAscending() ^ previous) {
2064                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2065                                            }
2066                                            else {
2067                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2068                                            }
2069                                    }
2070                                    else {
2071                                            if (orderByComparator.isAscending() ^ previous) {
2072                                                    query.append(WHERE_GREATER_THAN);
2073                                            }
2074                                            else {
2075                                                    query.append(WHERE_LESSER_THAN);
2076                                            }
2077                                    }
2078                            }
2079    
2080                            query.append(ORDER_BY_CLAUSE);
2081    
2082                            String[] orderByFields = orderByComparator.getOrderByFields();
2083    
2084                            for (int i = 0; i < orderByFields.length; i++) {
2085                                    if (getDB().isSupportsInlineDistinct()) {
2086                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2087                                    }
2088                                    else {
2089                                            query.append(_ORDER_BY_ENTITY_TABLE);
2090                                    }
2091    
2092                                    query.append(orderByFields[i]);
2093    
2094                                    if ((i + 1) < orderByFields.length) {
2095                                            if (orderByComparator.isAscending() ^ previous) {
2096                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2097                                            }
2098                                            else {
2099                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2100                                            }
2101                                    }
2102                                    else {
2103                                            if (orderByComparator.isAscending() ^ previous) {
2104                                                    query.append(ORDER_BY_ASC);
2105                                            }
2106                                            else {
2107                                                    query.append(ORDER_BY_DESC);
2108                                            }
2109                                    }
2110                            }
2111                    }
2112                    else {
2113                            if (getDB().isSupportsInlineDistinct()) {
2114                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
2115                            }
2116                            else {
2117                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_SQL);
2118                            }
2119                    }
2120    
2121                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2122                                    MDRRuleGroupInstance.class.getName(),
2123                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2124    
2125                    SQLQuery q = session.createSQLQuery(sql);
2126    
2127                    q.setFirstResult(0);
2128                    q.setMaxResults(2);
2129    
2130                    if (getDB().isSupportsInlineDistinct()) {
2131                            q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
2132                    }
2133                    else {
2134                            q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
2135                    }
2136    
2137                    QueryPos qPos = QueryPos.getInstance(q);
2138    
2139                    qPos.add(groupId);
2140    
2141                    if (orderByComparator != null) {
2142                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
2143    
2144                            for (Object value : values) {
2145                                    qPos.add(value);
2146                            }
2147                    }
2148    
2149                    List<MDRRuleGroupInstance> list = q.list();
2150    
2151                    if (list.size() == 2) {
2152                            return list.get(1);
2153                    }
2154                    else {
2155                            return null;
2156                    }
2157            }
2158    
2159            /**
2160             * Removes all the m d r rule group instances where groupId = &#63; from the database.
2161             *
2162             * @param groupId the group ID
2163             * @throws SystemException if a system exception occurred
2164             */
2165            public void removeByGroupId(long groupId) throws SystemException {
2166                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByGroupId(
2167                                    groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2168                            remove(mdrRuleGroupInstance);
2169                    }
2170            }
2171    
2172            /**
2173             * Returns the number of m d r rule group instances where groupId = &#63;.
2174             *
2175             * @param groupId the group ID
2176             * @return the number of matching m d r rule group instances
2177             * @throws SystemException if a system exception occurred
2178             */
2179            public int countByGroupId(long groupId) throws SystemException {
2180                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2181    
2182                    Object[] finderArgs = new Object[] { groupId };
2183    
2184                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2185                                    this);
2186    
2187                    if (count == null) {
2188                            StringBundler query = new StringBundler(2);
2189    
2190                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
2191    
2192                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2193    
2194                            String sql = query.toString();
2195    
2196                            Session session = null;
2197    
2198                            try {
2199                                    session = openSession();
2200    
2201                                    Query q = session.createQuery(sql);
2202    
2203                                    QueryPos qPos = QueryPos.getInstance(q);
2204    
2205                                    qPos.add(groupId);
2206    
2207                                    count = (Long)q.uniqueResult();
2208    
2209                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2210                            }
2211                            catch (Exception e) {
2212                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2213    
2214                                    throw processException(e);
2215                            }
2216                            finally {
2217                                    closeSession(session);
2218                            }
2219                    }
2220    
2221                    return count.intValue();
2222            }
2223    
2224            /**
2225             * Returns the number of m d r rule group instances that the user has permission to view where groupId = &#63;.
2226             *
2227             * @param groupId the group ID
2228             * @return the number of matching m d r rule group instances that the user has permission to view
2229             * @throws SystemException if a system exception occurred
2230             */
2231            public int filterCountByGroupId(long groupId) throws SystemException {
2232                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2233                            return countByGroupId(groupId);
2234                    }
2235    
2236                    StringBundler query = new StringBundler(2);
2237    
2238                    query.append(_FILTER_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
2239    
2240                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2241    
2242                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2243                                    MDRRuleGroupInstance.class.getName(),
2244                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2245    
2246                    Session session = null;
2247    
2248                    try {
2249                            session = openSession();
2250    
2251                            SQLQuery q = session.createSQLQuery(sql);
2252    
2253                            q.addScalar(COUNT_COLUMN_NAME,
2254                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2255    
2256                            QueryPos qPos = QueryPos.getInstance(q);
2257    
2258                            qPos.add(groupId);
2259    
2260                            Long count = (Long)q.uniqueResult();
2261    
2262                            return count.intValue();
2263                    }
2264                    catch (Exception e) {
2265                            throw processException(e);
2266                    }
2267                    finally {
2268                            closeSession(session);
2269                    }
2270            }
2271    
2272            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mdrRuleGroupInstance.groupId = ?";
2273            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID =
2274                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2275                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
2276                            MDRRuleGroupInstanceImpl.class,
2277                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRuleGroupId",
2278                            new String[] {
2279                                    Long.class.getName(),
2280                                    
2281                            Integer.class.getName(), Integer.class.getName(),
2282                                    OrderByComparator.class.getName()
2283                            });
2284            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID =
2285                    new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2286                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
2287                            MDRRuleGroupInstanceImpl.class,
2288                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRuleGroupId",
2289                            new String[] { Long.class.getName() },
2290                            MDRRuleGroupInstanceModelImpl.RULEGROUPID_COLUMN_BITMASK);
2291            public static final FinderPath FINDER_PATH_COUNT_BY_RULEGROUPID = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2292                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
2293                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRuleGroupId",
2294                            new String[] { Long.class.getName() });
2295    
2296            /**
2297             * Returns all the m d r rule group instances where ruleGroupId = &#63;.
2298             *
2299             * @param ruleGroupId the rule group ID
2300             * @return the matching m d r rule group instances
2301             * @throws SystemException if a system exception occurred
2302             */
2303            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId)
2304                    throws SystemException {
2305                    return findByRuleGroupId(ruleGroupId, QueryUtil.ALL_POS,
2306                            QueryUtil.ALL_POS, null);
2307            }
2308    
2309            /**
2310             * Returns a range of all the m d r rule group instances where ruleGroupId = &#63;.
2311             *
2312             * <p>
2313             * 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.MDRRuleGroupInstanceModelImpl}. 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.
2314             * </p>
2315             *
2316             * @param ruleGroupId the rule group ID
2317             * @param start the lower bound of the range of m d r rule group instances
2318             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2319             * @return the range of matching m d r rule group instances
2320             * @throws SystemException if a system exception occurred
2321             */
2322            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId,
2323                    int start, int end) throws SystemException {
2324                    return findByRuleGroupId(ruleGroupId, start, end, null);
2325            }
2326    
2327            /**
2328             * Returns an ordered range of all the m d r rule group instances where ruleGroupId = &#63;.
2329             *
2330             * <p>
2331             * 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.MDRRuleGroupInstanceModelImpl}. 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.
2332             * </p>
2333             *
2334             * @param ruleGroupId the rule group ID
2335             * @param start the lower bound of the range of m d r rule group instances
2336             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2337             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2338             * @return the ordered range of matching m d r rule group instances
2339             * @throws SystemException if a system exception occurred
2340             */
2341            public List<MDRRuleGroupInstance> findByRuleGroupId(long ruleGroupId,
2342                    int start, int end, OrderByComparator orderByComparator)
2343                    throws SystemException {
2344                    boolean pagination = true;
2345                    FinderPath finderPath = null;
2346                    Object[] finderArgs = null;
2347    
2348                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2349                                    (orderByComparator == null)) {
2350                            pagination = false;
2351                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID;
2352                            finderArgs = new Object[] { ruleGroupId };
2353                    }
2354                    else {
2355                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RULEGROUPID;
2356                            finderArgs = new Object[] { ruleGroupId, start, end, orderByComparator };
2357                    }
2358    
2359                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
2360                                    finderArgs, this);
2361    
2362                    if ((list != null) && !list.isEmpty()) {
2363                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
2364                                    if ((ruleGroupId != mdrRuleGroupInstance.getRuleGroupId())) {
2365                                            list = null;
2366    
2367                                            break;
2368                                    }
2369                            }
2370                    }
2371    
2372                    if (list == null) {
2373                            StringBundler query = null;
2374    
2375                            if (orderByComparator != null) {
2376                                    query = new StringBundler(3 +
2377                                                    (orderByComparator.getOrderByFields().length * 3));
2378                            }
2379                            else {
2380                                    query = new StringBundler(3);
2381                            }
2382    
2383                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2384    
2385                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
2386    
2387                            if (orderByComparator != null) {
2388                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2389                                            orderByComparator);
2390                            }
2391                            else
2392                             if (pagination) {
2393                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
2394                            }
2395    
2396                            String sql = query.toString();
2397    
2398                            Session session = null;
2399    
2400                            try {
2401                                    session = openSession();
2402    
2403                                    Query q = session.createQuery(sql);
2404    
2405                                    QueryPos qPos = QueryPos.getInstance(q);
2406    
2407                                    qPos.add(ruleGroupId);
2408    
2409                                    if (!pagination) {
2410                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2411                                                            getDialect(), start, end, false);
2412    
2413                                            Collections.sort(list);
2414    
2415                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
2416                                    }
2417                                    else {
2418                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2419                                                            getDialect(), start, end);
2420                                    }
2421    
2422                                    cacheResult(list);
2423    
2424                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2425                            }
2426                            catch (Exception e) {
2427                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2428    
2429                                    throw processException(e);
2430                            }
2431                            finally {
2432                                    closeSession(session);
2433                            }
2434                    }
2435    
2436                    return list;
2437            }
2438    
2439            /**
2440             * Returns the first m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2441             *
2442             * @param ruleGroupId the rule group ID
2443             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2444             * @return the first matching m d r rule group instance
2445             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2446             * @throws SystemException if a system exception occurred
2447             */
2448            public MDRRuleGroupInstance findByRuleGroupId_First(long ruleGroupId,
2449                    OrderByComparator orderByComparator)
2450                    throws NoSuchRuleGroupInstanceException, SystemException {
2451                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByRuleGroupId_First(ruleGroupId,
2452                                    orderByComparator);
2453    
2454                    if (mdrRuleGroupInstance != null) {
2455                            return mdrRuleGroupInstance;
2456                    }
2457    
2458                    StringBundler msg = new StringBundler(4);
2459    
2460                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2461    
2462                    msg.append("ruleGroupId=");
2463                    msg.append(ruleGroupId);
2464    
2465                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2466    
2467                    throw new NoSuchRuleGroupInstanceException(msg.toString());
2468            }
2469    
2470            /**
2471             * Returns the first m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2472             *
2473             * @param ruleGroupId the rule group ID
2474             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2475             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
2476             * @throws SystemException if a system exception occurred
2477             */
2478            public MDRRuleGroupInstance fetchByRuleGroupId_First(long ruleGroupId,
2479                    OrderByComparator orderByComparator) throws SystemException {
2480                    List<MDRRuleGroupInstance> list = findByRuleGroupId(ruleGroupId, 0, 1,
2481                                    orderByComparator);
2482    
2483                    if (!list.isEmpty()) {
2484                            return list.get(0);
2485                    }
2486    
2487                    return null;
2488            }
2489    
2490            /**
2491             * Returns the last m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2492             *
2493             * @param ruleGroupId the rule group ID
2494             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2495             * @return the last matching m d r rule group instance
2496             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2497             * @throws SystemException if a system exception occurred
2498             */
2499            public MDRRuleGroupInstance findByRuleGroupId_Last(long ruleGroupId,
2500                    OrderByComparator orderByComparator)
2501                    throws NoSuchRuleGroupInstanceException, SystemException {
2502                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByRuleGroupId_Last(ruleGroupId,
2503                                    orderByComparator);
2504    
2505                    if (mdrRuleGroupInstance != null) {
2506                            return mdrRuleGroupInstance;
2507                    }
2508    
2509                    StringBundler msg = new StringBundler(4);
2510    
2511                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2512    
2513                    msg.append("ruleGroupId=");
2514                    msg.append(ruleGroupId);
2515    
2516                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2517    
2518                    throw new NoSuchRuleGroupInstanceException(msg.toString());
2519            }
2520    
2521            /**
2522             * Returns the last m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2523             *
2524             * @param ruleGroupId the rule group ID
2525             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2526             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
2527             * @throws SystemException if a system exception occurred
2528             */
2529            public MDRRuleGroupInstance fetchByRuleGroupId_Last(long ruleGroupId,
2530                    OrderByComparator orderByComparator) throws SystemException {
2531                    int count = countByRuleGroupId(ruleGroupId);
2532    
2533                    List<MDRRuleGroupInstance> list = findByRuleGroupId(ruleGroupId,
2534                                    count - 1, count, orderByComparator);
2535    
2536                    if (!list.isEmpty()) {
2537                            return list.get(0);
2538                    }
2539    
2540                    return null;
2541            }
2542    
2543            /**
2544             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where ruleGroupId = &#63;.
2545             *
2546             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
2547             * @param ruleGroupId the rule group ID
2548             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2549             * @return the previous, current, and next m d r rule group instance
2550             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
2551             * @throws SystemException if a system exception occurred
2552             */
2553            public MDRRuleGroupInstance[] findByRuleGroupId_PrevAndNext(
2554                    long ruleGroupInstanceId, long ruleGroupId,
2555                    OrderByComparator orderByComparator)
2556                    throws NoSuchRuleGroupInstanceException, SystemException {
2557                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
2558    
2559                    Session session = null;
2560    
2561                    try {
2562                            session = openSession();
2563    
2564                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
2565    
2566                            array[0] = getByRuleGroupId_PrevAndNext(session,
2567                                            mdrRuleGroupInstance, ruleGroupId, orderByComparator, true);
2568    
2569                            array[1] = mdrRuleGroupInstance;
2570    
2571                            array[2] = getByRuleGroupId_PrevAndNext(session,
2572                                            mdrRuleGroupInstance, ruleGroupId, orderByComparator, false);
2573    
2574                            return array;
2575                    }
2576                    catch (Exception e) {
2577                            throw processException(e);
2578                    }
2579                    finally {
2580                            closeSession(session);
2581                    }
2582            }
2583    
2584            protected MDRRuleGroupInstance getByRuleGroupId_PrevAndNext(
2585                    Session session, MDRRuleGroupInstance mdrRuleGroupInstance,
2586                    long ruleGroupId, OrderByComparator orderByComparator, boolean previous) {
2587                    StringBundler query = null;
2588    
2589                    if (orderByComparator != null) {
2590                            query = new StringBundler(6 +
2591                                            (orderByComparator.getOrderByFields().length * 6));
2592                    }
2593                    else {
2594                            query = new StringBundler(3);
2595                    }
2596    
2597                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2598    
2599                    query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
2600    
2601                    if (orderByComparator != null) {
2602                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2603    
2604                            if (orderByConditionFields.length > 0) {
2605                                    query.append(WHERE_AND);
2606                            }
2607    
2608                            for (int i = 0; i < orderByConditionFields.length; i++) {
2609                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2610                                    query.append(orderByConditionFields[i]);
2611    
2612                                    if ((i + 1) < orderByConditionFields.length) {
2613                                            if (orderByComparator.isAscending() ^ previous) {
2614                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2615                                            }
2616                                            else {
2617                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2618                                            }
2619                                    }
2620                                    else {
2621                                            if (orderByComparator.isAscending() ^ previous) {
2622                                                    query.append(WHERE_GREATER_THAN);
2623                                            }
2624                                            else {
2625                                                    query.append(WHERE_LESSER_THAN);
2626                                            }
2627                                    }
2628                            }
2629    
2630                            query.append(ORDER_BY_CLAUSE);
2631    
2632                            String[] orderByFields = orderByComparator.getOrderByFields();
2633    
2634                            for (int i = 0; i < orderByFields.length; i++) {
2635                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2636                                    query.append(orderByFields[i]);
2637    
2638                                    if ((i + 1) < orderByFields.length) {
2639                                            if (orderByComparator.isAscending() ^ previous) {
2640                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2641                                            }
2642                                            else {
2643                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2644                                            }
2645                                    }
2646                                    else {
2647                                            if (orderByComparator.isAscending() ^ previous) {
2648                                                    query.append(ORDER_BY_ASC);
2649                                            }
2650                                            else {
2651                                                    query.append(ORDER_BY_DESC);
2652                                            }
2653                                    }
2654                            }
2655                    }
2656                    else {
2657                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
2658                    }
2659    
2660                    String sql = query.toString();
2661    
2662                    Query q = session.createQuery(sql);
2663    
2664                    q.setFirstResult(0);
2665                    q.setMaxResults(2);
2666    
2667                    QueryPos qPos = QueryPos.getInstance(q);
2668    
2669                    qPos.add(ruleGroupId);
2670    
2671                    if (orderByComparator != null) {
2672                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
2673    
2674                            for (Object value : values) {
2675                                    qPos.add(value);
2676                            }
2677                    }
2678    
2679                    List<MDRRuleGroupInstance> list = q.list();
2680    
2681                    if (list.size() == 2) {
2682                            return list.get(1);
2683                    }
2684                    else {
2685                            return null;
2686                    }
2687            }
2688    
2689            /**
2690             * Removes all the m d r rule group instances where ruleGroupId = &#63; from the database.
2691             *
2692             * @param ruleGroupId the rule group ID
2693             * @throws SystemException if a system exception occurred
2694             */
2695            public void removeByRuleGroupId(long ruleGroupId) throws SystemException {
2696                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByRuleGroupId(
2697                                    ruleGroupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2698                            remove(mdrRuleGroupInstance);
2699                    }
2700            }
2701    
2702            /**
2703             * Returns the number of m d r rule group instances where ruleGroupId = &#63;.
2704             *
2705             * @param ruleGroupId the rule group ID
2706             * @return the number of matching m d r rule group instances
2707             * @throws SystemException if a system exception occurred
2708             */
2709            public int countByRuleGroupId(long ruleGroupId) throws SystemException {
2710                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RULEGROUPID;
2711    
2712                    Object[] finderArgs = new Object[] { ruleGroupId };
2713    
2714                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2715                                    this);
2716    
2717                    if (count == null) {
2718                            StringBundler query = new StringBundler(2);
2719    
2720                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
2721    
2722                            query.append(_FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2);
2723    
2724                            String sql = query.toString();
2725    
2726                            Session session = null;
2727    
2728                            try {
2729                                    session = openSession();
2730    
2731                                    Query q = session.createQuery(sql);
2732    
2733                                    QueryPos qPos = QueryPos.getInstance(q);
2734    
2735                                    qPos.add(ruleGroupId);
2736    
2737                                    count = (Long)q.uniqueResult();
2738    
2739                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2740                            }
2741                            catch (Exception e) {
2742                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2743    
2744                                    throw processException(e);
2745                            }
2746                            finally {
2747                                    closeSession(session);
2748                            }
2749                    }
2750    
2751                    return count.intValue();
2752            }
2753    
2754            private static final String _FINDER_COLUMN_RULEGROUPID_RULEGROUPID_2 = "mdrRuleGroupInstance.ruleGroupId = ?";
2755            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2756                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
2757                            MDRRuleGroupInstanceImpl.class,
2758                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
2759                            new String[] {
2760                                    Long.class.getName(), Long.class.getName(),
2761                                    
2762                            Integer.class.getName(), Integer.class.getName(),
2763                                    OrderByComparator.class.getName()
2764                            });
2765            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2766                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
2767                            MDRRuleGroupInstanceImpl.class,
2768                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
2769                            new String[] { Long.class.getName(), Long.class.getName() },
2770                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2771                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK);
2772            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
2773                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
2774                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2775                            new String[] { Long.class.getName(), Long.class.getName() });
2776    
2777            /**
2778             * Returns all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
2779             *
2780             * @param classNameId the class name ID
2781             * @param classPK the class p k
2782             * @return the matching m d r rule group instances
2783             * @throws SystemException if a system exception occurred
2784             */
2785            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK)
2786                    throws SystemException {
2787                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
2788                            QueryUtil.ALL_POS, null);
2789            }
2790    
2791            /**
2792             * Returns a range of all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
2793             *
2794             * <p>
2795             * 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.MDRRuleGroupInstanceModelImpl}. 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.
2796             * </p>
2797             *
2798             * @param classNameId the class name ID
2799             * @param classPK the class p k
2800             * @param start the lower bound of the range of m d r rule group instances
2801             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2802             * @return the range of matching m d r rule group instances
2803             * @throws SystemException if a system exception occurred
2804             */
2805            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK,
2806                    int start, int end) throws SystemException {
2807                    return findByC_C(classNameId, classPK, start, end, null);
2808            }
2809    
2810            /**
2811             * Returns an ordered range of all the m d r rule group instances where classNameId = &#63; and classPK = &#63;.
2812             *
2813             * <p>
2814             * 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.MDRRuleGroupInstanceModelImpl}. 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.
2815             * </p>
2816             *
2817             * @param classNameId the class name ID
2818             * @param classPK the class p k
2819             * @param start the lower bound of the range of m d r rule group instances
2820             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
2821             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2822             * @return the ordered range of matching m d r rule group instances
2823             * @throws SystemException if a system exception occurred
2824             */
2825            public List<MDRRuleGroupInstance> findByC_C(long classNameId, long classPK,
2826                    int start, int end, OrderByComparator orderByComparator)
2827                    throws SystemException {
2828                    boolean pagination = true;
2829                    FinderPath finderPath = null;
2830                    Object[] finderArgs = null;
2831    
2832                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2833                                    (orderByComparator == null)) {
2834                            pagination = false;
2835                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
2836                            finderArgs = new Object[] { classNameId, classPK };
2837                    }
2838                    else {
2839                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
2840                            finderArgs = new Object[] {
2841                                            classNameId, classPK,
2842                                            
2843                                            start, end, orderByComparator
2844                                    };
2845                    }
2846    
2847                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
2848                                    finderArgs, this);
2849    
2850                    if ((list != null) && !list.isEmpty()) {
2851                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
2852                                    if ((classNameId != mdrRuleGroupInstance.getClassNameId()) ||
2853                                                    (classPK != mdrRuleGroupInstance.getClassPK())) {
2854                                            list = null;
2855    
2856                                            break;
2857                                    }
2858                            }
2859                    }
2860    
2861                    if (list == null) {
2862                            StringBundler query = null;
2863    
2864                            if (orderByComparator != null) {
2865                                    query = new StringBundler(4 +
2866                                                    (orderByComparator.getOrderByFields().length * 3));
2867                            }
2868                            else {
2869                                    query = new StringBundler(4);
2870                            }
2871    
2872                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
2873    
2874                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2875    
2876                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2877    
2878                            if (orderByComparator != null) {
2879                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2880                                            orderByComparator);
2881                            }
2882                            else
2883                             if (pagination) {
2884                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
2885                            }
2886    
2887                            String sql = query.toString();
2888    
2889                            Session session = null;
2890    
2891                            try {
2892                                    session = openSession();
2893    
2894                                    Query q = session.createQuery(sql);
2895    
2896                                    QueryPos qPos = QueryPos.getInstance(q);
2897    
2898                                    qPos.add(classNameId);
2899    
2900                                    qPos.add(classPK);
2901    
2902                                    if (!pagination) {
2903                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2904                                                            getDialect(), start, end, false);
2905    
2906                                            Collections.sort(list);
2907    
2908                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
2909                                    }
2910                                    else {
2911                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
2912                                                            getDialect(), start, end);
2913                                    }
2914    
2915                                    cacheResult(list);
2916    
2917                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2918                            }
2919                            catch (Exception e) {
2920                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2921    
2922                                    throw processException(e);
2923                            }
2924                            finally {
2925                                    closeSession(session);
2926                            }
2927                    }
2928    
2929                    return list;
2930            }
2931    
2932            /**
2933             * Returns the first m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
2934             *
2935             * @param classNameId the class name ID
2936             * @param classPK the class p k
2937             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2938             * @return the first matching m d r rule group instance
2939             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2940             * @throws SystemException if a system exception occurred
2941             */
2942            public MDRRuleGroupInstance findByC_C_First(long classNameId, long classPK,
2943                    OrderByComparator orderByComparator)
2944                    throws NoSuchRuleGroupInstanceException, SystemException {
2945                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByC_C_First(classNameId,
2946                                    classPK, orderByComparator);
2947    
2948                    if (mdrRuleGroupInstance != null) {
2949                            return mdrRuleGroupInstance;
2950                    }
2951    
2952                    StringBundler msg = new StringBundler(6);
2953    
2954                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2955    
2956                    msg.append("classNameId=");
2957                    msg.append(classNameId);
2958    
2959                    msg.append(", classPK=");
2960                    msg.append(classPK);
2961    
2962                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2963    
2964                    throw new NoSuchRuleGroupInstanceException(msg.toString());
2965            }
2966    
2967            /**
2968             * Returns the first m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
2969             *
2970             * @param classNameId the class name ID
2971             * @param classPK the class p k
2972             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2973             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
2974             * @throws SystemException if a system exception occurred
2975             */
2976            public MDRRuleGroupInstance fetchByC_C_First(long classNameId,
2977                    long classPK, OrderByComparator orderByComparator)
2978                    throws SystemException {
2979                    List<MDRRuleGroupInstance> list = findByC_C(classNameId, classPK, 0, 1,
2980                                    orderByComparator);
2981    
2982                    if (!list.isEmpty()) {
2983                            return list.get(0);
2984                    }
2985    
2986                    return null;
2987            }
2988    
2989            /**
2990             * Returns the last m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
2991             *
2992             * @param classNameId the class name ID
2993             * @param classPK the class p k
2994             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2995             * @return the last matching m d r rule group instance
2996             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
2997             * @throws SystemException if a system exception occurred
2998             */
2999            public MDRRuleGroupInstance findByC_C_Last(long classNameId, long classPK,
3000                    OrderByComparator orderByComparator)
3001                    throws NoSuchRuleGroupInstanceException, SystemException {
3002                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByC_C_Last(classNameId,
3003                                    classPK, orderByComparator);
3004    
3005                    if (mdrRuleGroupInstance != null) {
3006                            return mdrRuleGroupInstance;
3007                    }
3008    
3009                    StringBundler msg = new StringBundler(6);
3010    
3011                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3012    
3013                    msg.append("classNameId=");
3014                    msg.append(classNameId);
3015    
3016                    msg.append(", classPK=");
3017                    msg.append(classPK);
3018    
3019                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3020    
3021                    throw new NoSuchRuleGroupInstanceException(msg.toString());
3022            }
3023    
3024            /**
3025             * Returns the last m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
3026             *
3027             * @param classNameId the class name ID
3028             * @param classPK the class p k
3029             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3030             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
3031             * @throws SystemException if a system exception occurred
3032             */
3033            public MDRRuleGroupInstance fetchByC_C_Last(long classNameId, long classPK,
3034                    OrderByComparator orderByComparator) throws SystemException {
3035                    int count = countByC_C(classNameId, classPK);
3036    
3037                    List<MDRRuleGroupInstance> list = findByC_C(classNameId, classPK,
3038                                    count - 1, count, orderByComparator);
3039    
3040                    if (!list.isEmpty()) {
3041                            return list.get(0);
3042                    }
3043    
3044                    return null;
3045            }
3046    
3047            /**
3048             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where classNameId = &#63; and classPK = &#63;.
3049             *
3050             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
3051             * @param classNameId the class name ID
3052             * @param classPK the class p k
3053             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3054             * @return the previous, current, and next m d r rule group instance
3055             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
3056             * @throws SystemException if a system exception occurred
3057             */
3058            public MDRRuleGroupInstance[] findByC_C_PrevAndNext(
3059                    long ruleGroupInstanceId, long classNameId, long classPK,
3060                    OrderByComparator orderByComparator)
3061                    throws NoSuchRuleGroupInstanceException, SystemException {
3062                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
3063    
3064                    Session session = null;
3065    
3066                    try {
3067                            session = openSession();
3068    
3069                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
3070    
3071                            array[0] = getByC_C_PrevAndNext(session, mdrRuleGroupInstance,
3072                                            classNameId, classPK, orderByComparator, true);
3073    
3074                            array[1] = mdrRuleGroupInstance;
3075    
3076                            array[2] = getByC_C_PrevAndNext(session, mdrRuleGroupInstance,
3077                                            classNameId, classPK, orderByComparator, false);
3078    
3079                            return array;
3080                    }
3081                    catch (Exception e) {
3082                            throw processException(e);
3083                    }
3084                    finally {
3085                            closeSession(session);
3086                    }
3087            }
3088    
3089            protected MDRRuleGroupInstance getByC_C_PrevAndNext(Session session,
3090                    MDRRuleGroupInstance mdrRuleGroupInstance, long classNameId,
3091                    long classPK, OrderByComparator orderByComparator, boolean previous) {
3092                    StringBundler query = null;
3093    
3094                    if (orderByComparator != null) {
3095                            query = new StringBundler(6 +
3096                                            (orderByComparator.getOrderByFields().length * 6));
3097                    }
3098                    else {
3099                            query = new StringBundler(3);
3100                    }
3101    
3102                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3103    
3104                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3105    
3106                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3107    
3108                    if (orderByComparator != null) {
3109                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3110    
3111                            if (orderByConditionFields.length > 0) {
3112                                    query.append(WHERE_AND);
3113                            }
3114    
3115                            for (int i = 0; i < orderByConditionFields.length; i++) {
3116                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3117                                    query.append(orderByConditionFields[i]);
3118    
3119                                    if ((i + 1) < orderByConditionFields.length) {
3120                                            if (orderByComparator.isAscending() ^ previous) {
3121                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3122                                            }
3123                                            else {
3124                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3125                                            }
3126                                    }
3127                                    else {
3128                                            if (orderByComparator.isAscending() ^ previous) {
3129                                                    query.append(WHERE_GREATER_THAN);
3130                                            }
3131                                            else {
3132                                                    query.append(WHERE_LESSER_THAN);
3133                                            }
3134                                    }
3135                            }
3136    
3137                            query.append(ORDER_BY_CLAUSE);
3138    
3139                            String[] orderByFields = orderByComparator.getOrderByFields();
3140    
3141                            for (int i = 0; i < orderByFields.length; i++) {
3142                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3143                                    query.append(orderByFields[i]);
3144    
3145                                    if ((i + 1) < orderByFields.length) {
3146                                            if (orderByComparator.isAscending() ^ previous) {
3147                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3148                                            }
3149                                            else {
3150                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3151                                            }
3152                                    }
3153                                    else {
3154                                            if (orderByComparator.isAscending() ^ previous) {
3155                                                    query.append(ORDER_BY_ASC);
3156                                            }
3157                                            else {
3158                                                    query.append(ORDER_BY_DESC);
3159                                            }
3160                                    }
3161                            }
3162                    }
3163                    else {
3164                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
3165                    }
3166    
3167                    String sql = query.toString();
3168    
3169                    Query q = session.createQuery(sql);
3170    
3171                    q.setFirstResult(0);
3172                    q.setMaxResults(2);
3173    
3174                    QueryPos qPos = QueryPos.getInstance(q);
3175    
3176                    qPos.add(classNameId);
3177    
3178                    qPos.add(classPK);
3179    
3180                    if (orderByComparator != null) {
3181                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
3182    
3183                            for (Object value : values) {
3184                                    qPos.add(value);
3185                            }
3186                    }
3187    
3188                    List<MDRRuleGroupInstance> list = q.list();
3189    
3190                    if (list.size() == 2) {
3191                            return list.get(1);
3192                    }
3193                    else {
3194                            return null;
3195                    }
3196            }
3197    
3198            /**
3199             * Removes all the m d r rule group instances where classNameId = &#63; and classPK = &#63; from the database.
3200             *
3201             * @param classNameId the class name ID
3202             * @param classPK the class p k
3203             * @throws SystemException if a system exception occurred
3204             */
3205            public void removeByC_C(long classNameId, long classPK)
3206                    throws SystemException {
3207                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByC_C(
3208                                    classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3209                            remove(mdrRuleGroupInstance);
3210                    }
3211            }
3212    
3213            /**
3214             * Returns the number of m d r rule group instances where classNameId = &#63; and classPK = &#63;.
3215             *
3216             * @param classNameId the class name ID
3217             * @param classPK the class p k
3218             * @return the number of matching m d r rule group instances
3219             * @throws SystemException if a system exception occurred
3220             */
3221            public int countByC_C(long classNameId, long classPK)
3222                    throws SystemException {
3223                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
3224    
3225                    Object[] finderArgs = new Object[] { classNameId, classPK };
3226    
3227                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3228                                    this);
3229    
3230                    if (count == null) {
3231                            StringBundler query = new StringBundler(3);
3232    
3233                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
3234    
3235                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3236    
3237                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3238    
3239                            String sql = query.toString();
3240    
3241                            Session session = null;
3242    
3243                            try {
3244                                    session = openSession();
3245    
3246                                    Query q = session.createQuery(sql);
3247    
3248                                    QueryPos qPos = QueryPos.getInstance(q);
3249    
3250                                    qPos.add(classNameId);
3251    
3252                                    qPos.add(classPK);
3253    
3254                                    count = (Long)q.uniqueResult();
3255    
3256                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3257                            }
3258                            catch (Exception e) {
3259                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3260    
3261                                    throw processException(e);
3262                            }
3263                            finally {
3264                                    closeSession(session);
3265                            }
3266                    }
3267    
3268                    return count.intValue();
3269            }
3270    
3271            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
3272            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ?";
3273            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
3274                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
3275                            MDRRuleGroupInstanceImpl.class,
3276                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_C",
3277                            new String[] {
3278                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
3279                                    
3280                            Integer.class.getName(), Integer.class.getName(),
3281                                    OrderByComparator.class.getName()
3282                            });
3283            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
3284                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
3285                            MDRRuleGroupInstanceImpl.class,
3286                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C",
3287                            new String[] {
3288                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
3289                            },
3290                            MDRRuleGroupInstanceModelImpl.GROUPID_COLUMN_BITMASK |
3291                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3292                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK);
3293            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
3294                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
3295                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C",
3296                            new String[] {
3297                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
3298                            });
3299    
3300            /**
3301             * Returns all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3302             *
3303             * @param groupId the group ID
3304             * @param classNameId the class name ID
3305             * @param classPK the class p k
3306             * @return the matching m d r rule group instances
3307             * @throws SystemException if a system exception occurred
3308             */
3309            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
3310                    long classNameId, long classPK) throws SystemException {
3311                    return findByG_C_C(groupId, classNameId, classPK, QueryUtil.ALL_POS,
3312                            QueryUtil.ALL_POS, null);
3313            }
3314    
3315            /**
3316             * Returns a range of all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3317             *
3318             * <p>
3319             * 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.MDRRuleGroupInstanceModelImpl}. 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.
3320             * </p>
3321             *
3322             * @param groupId the group ID
3323             * @param classNameId the class name ID
3324             * @param classPK the class p k
3325             * @param start the lower bound of the range of m d r rule group instances
3326             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
3327             * @return the range of matching m d r rule group instances
3328             * @throws SystemException if a system exception occurred
3329             */
3330            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
3331                    long classNameId, long classPK, int start, int end)
3332                    throws SystemException {
3333                    return findByG_C_C(groupId, classNameId, classPK, start, end, null);
3334            }
3335    
3336            /**
3337             * Returns an ordered range of all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3338             *
3339             * <p>
3340             * 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.MDRRuleGroupInstanceModelImpl}. 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.
3341             * </p>
3342             *
3343             * @param groupId the group ID
3344             * @param classNameId the class name ID
3345             * @param classPK the class p k
3346             * @param start the lower bound of the range of m d r rule group instances
3347             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
3348             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3349             * @return the ordered range of matching m d r rule group instances
3350             * @throws SystemException if a system exception occurred
3351             */
3352            public List<MDRRuleGroupInstance> findByG_C_C(long groupId,
3353                    long classNameId, long classPK, int start, int end,
3354                    OrderByComparator orderByComparator) throws SystemException {
3355                    boolean pagination = true;
3356                    FinderPath finderPath = null;
3357                    Object[] finderArgs = null;
3358    
3359                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3360                                    (orderByComparator == null)) {
3361                            pagination = false;
3362                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C;
3363                            finderArgs = new Object[] { groupId, classNameId, classPK };
3364                    }
3365                    else {
3366                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C;
3367                            finderArgs = new Object[] {
3368                                            groupId, classNameId, classPK,
3369                                            
3370                                            start, end, orderByComparator
3371                                    };
3372                    }
3373    
3374                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
3375                                    finderArgs, this);
3376    
3377                    if ((list != null) && !list.isEmpty()) {
3378                            for (MDRRuleGroupInstance mdrRuleGroupInstance : list) {
3379                                    if ((groupId != mdrRuleGroupInstance.getGroupId()) ||
3380                                                    (classNameId != mdrRuleGroupInstance.getClassNameId()) ||
3381                                                    (classPK != mdrRuleGroupInstance.getClassPK())) {
3382                                            list = null;
3383    
3384                                            break;
3385                                    }
3386                            }
3387                    }
3388    
3389                    if (list == null) {
3390                            StringBundler query = null;
3391    
3392                            if (orderByComparator != null) {
3393                                    query = new StringBundler(5 +
3394                                                    (orderByComparator.getOrderByFields().length * 3));
3395                            }
3396                            else {
3397                                    query = new StringBundler(5);
3398                            }
3399    
3400                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3401    
3402                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3403    
3404                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3405    
3406                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3407    
3408                            if (orderByComparator != null) {
3409                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3410                                            orderByComparator);
3411                            }
3412                            else
3413                             if (pagination) {
3414                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
3415                            }
3416    
3417                            String sql = query.toString();
3418    
3419                            Session session = null;
3420    
3421                            try {
3422                                    session = openSession();
3423    
3424                                    Query q = session.createQuery(sql);
3425    
3426                                    QueryPos qPos = QueryPos.getInstance(q);
3427    
3428                                    qPos.add(groupId);
3429    
3430                                    qPos.add(classNameId);
3431    
3432                                    qPos.add(classPK);
3433    
3434                                    if (!pagination) {
3435                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
3436                                                            getDialect(), start, end, false);
3437    
3438                                            Collections.sort(list);
3439    
3440                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
3441                                    }
3442                                    else {
3443                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
3444                                                            getDialect(), start, end);
3445                                    }
3446    
3447                                    cacheResult(list);
3448    
3449                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3450                            }
3451                            catch (Exception e) {
3452                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3453    
3454                                    throw processException(e);
3455                            }
3456                            finally {
3457                                    closeSession(session);
3458                            }
3459                    }
3460    
3461                    return list;
3462            }
3463    
3464            /**
3465             * Returns the first m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3466             *
3467             * @param groupId the group ID
3468             * @param classNameId the class name ID
3469             * @param classPK the class p k
3470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3471             * @return the first matching m d r rule group instance
3472             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
3473             * @throws SystemException if a system exception occurred
3474             */
3475            public MDRRuleGroupInstance findByG_C_C_First(long groupId,
3476                    long classNameId, long classPK, OrderByComparator orderByComparator)
3477                    throws NoSuchRuleGroupInstanceException, SystemException {
3478                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByG_C_C_First(groupId,
3479                                    classNameId, classPK, orderByComparator);
3480    
3481                    if (mdrRuleGroupInstance != null) {
3482                            return mdrRuleGroupInstance;
3483                    }
3484    
3485                    StringBundler msg = new StringBundler(8);
3486    
3487                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3488    
3489                    msg.append("groupId=");
3490                    msg.append(groupId);
3491    
3492                    msg.append(", classNameId=");
3493                    msg.append(classNameId);
3494    
3495                    msg.append(", classPK=");
3496                    msg.append(classPK);
3497    
3498                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3499    
3500                    throw new NoSuchRuleGroupInstanceException(msg.toString());
3501            }
3502    
3503            /**
3504             * Returns the first m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3505             *
3506             * @param groupId the group ID
3507             * @param classNameId the class name ID
3508             * @param classPK the class p k
3509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3510             * @return the first matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
3511             * @throws SystemException if a system exception occurred
3512             */
3513            public MDRRuleGroupInstance fetchByG_C_C_First(long groupId,
3514                    long classNameId, long classPK, OrderByComparator orderByComparator)
3515                    throws SystemException {
3516                    List<MDRRuleGroupInstance> list = findByG_C_C(groupId, classNameId,
3517                                    classPK, 0, 1, orderByComparator);
3518    
3519                    if (!list.isEmpty()) {
3520                            return list.get(0);
3521                    }
3522    
3523                    return null;
3524            }
3525    
3526            /**
3527             * Returns the last m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3528             *
3529             * @param groupId the group ID
3530             * @param classNameId the class name ID
3531             * @param classPK the class p k
3532             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3533             * @return the last matching m d r rule group instance
3534             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
3535             * @throws SystemException if a system exception occurred
3536             */
3537            public MDRRuleGroupInstance findByG_C_C_Last(long groupId,
3538                    long classNameId, long classPK, OrderByComparator orderByComparator)
3539                    throws NoSuchRuleGroupInstanceException, SystemException {
3540                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByG_C_C_Last(groupId,
3541                                    classNameId, classPK, orderByComparator);
3542    
3543                    if (mdrRuleGroupInstance != null) {
3544                            return mdrRuleGroupInstance;
3545                    }
3546    
3547                    StringBundler msg = new StringBundler(8);
3548    
3549                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3550    
3551                    msg.append("groupId=");
3552                    msg.append(groupId);
3553    
3554                    msg.append(", classNameId=");
3555                    msg.append(classNameId);
3556    
3557                    msg.append(", classPK=");
3558                    msg.append(classPK);
3559    
3560                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3561    
3562                    throw new NoSuchRuleGroupInstanceException(msg.toString());
3563            }
3564    
3565            /**
3566             * Returns the last m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3567             *
3568             * @param groupId the group ID
3569             * @param classNameId the class name ID
3570             * @param classPK the class p k
3571             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3572             * @return the last matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
3573             * @throws SystemException if a system exception occurred
3574             */
3575            public MDRRuleGroupInstance fetchByG_C_C_Last(long groupId,
3576                    long classNameId, long classPK, OrderByComparator orderByComparator)
3577                    throws SystemException {
3578                    int count = countByG_C_C(groupId, classNameId, classPK);
3579    
3580                    List<MDRRuleGroupInstance> list = findByG_C_C(groupId, classNameId,
3581                                    classPK, count - 1, count, orderByComparator);
3582    
3583                    if (!list.isEmpty()) {
3584                            return list.get(0);
3585                    }
3586    
3587                    return null;
3588            }
3589    
3590            /**
3591             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3592             *
3593             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
3594             * @param groupId the group ID
3595             * @param classNameId the class name ID
3596             * @param classPK the class p k
3597             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3598             * @return the previous, current, and next m d r rule group instance
3599             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
3600             * @throws SystemException if a system exception occurred
3601             */
3602            public MDRRuleGroupInstance[] findByG_C_C_PrevAndNext(
3603                    long ruleGroupInstanceId, long groupId, long classNameId, long classPK,
3604                    OrderByComparator orderByComparator)
3605                    throws NoSuchRuleGroupInstanceException, SystemException {
3606                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
3607    
3608                    Session session = null;
3609    
3610                    try {
3611                            session = openSession();
3612    
3613                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
3614    
3615                            array[0] = getByG_C_C_PrevAndNext(session, mdrRuleGroupInstance,
3616                                            groupId, classNameId, classPK, orderByComparator, true);
3617    
3618                            array[1] = mdrRuleGroupInstance;
3619    
3620                            array[2] = getByG_C_C_PrevAndNext(session, mdrRuleGroupInstance,
3621                                            groupId, classNameId, classPK, orderByComparator, false);
3622    
3623                            return array;
3624                    }
3625                    catch (Exception e) {
3626                            throw processException(e);
3627                    }
3628                    finally {
3629                            closeSession(session);
3630                    }
3631            }
3632    
3633            protected MDRRuleGroupInstance getByG_C_C_PrevAndNext(Session session,
3634                    MDRRuleGroupInstance mdrRuleGroupInstance, long groupId,
3635                    long classNameId, long classPK, OrderByComparator orderByComparator,
3636                    boolean previous) {
3637                    StringBundler query = null;
3638    
3639                    if (orderByComparator != null) {
3640                            query = new StringBundler(6 +
3641                                            (orderByComparator.getOrderByFields().length * 6));
3642                    }
3643                    else {
3644                            query = new StringBundler(3);
3645                    }
3646    
3647                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3648    
3649                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3650    
3651                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3652    
3653                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3654    
3655                    if (orderByComparator != null) {
3656                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3657    
3658                            if (orderByConditionFields.length > 0) {
3659                                    query.append(WHERE_AND);
3660                            }
3661    
3662                            for (int i = 0; i < orderByConditionFields.length; i++) {
3663                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3664                                    query.append(orderByConditionFields[i]);
3665    
3666                                    if ((i + 1) < orderByConditionFields.length) {
3667                                            if (orderByComparator.isAscending() ^ previous) {
3668                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3669                                            }
3670                                            else {
3671                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3672                                            }
3673                                    }
3674                                    else {
3675                                            if (orderByComparator.isAscending() ^ previous) {
3676                                                    query.append(WHERE_GREATER_THAN);
3677                                            }
3678                                            else {
3679                                                    query.append(WHERE_LESSER_THAN);
3680                                            }
3681                                    }
3682                            }
3683    
3684                            query.append(ORDER_BY_CLAUSE);
3685    
3686                            String[] orderByFields = orderByComparator.getOrderByFields();
3687    
3688                            for (int i = 0; i < orderByFields.length; i++) {
3689                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3690                                    query.append(orderByFields[i]);
3691    
3692                                    if ((i + 1) < orderByFields.length) {
3693                                            if (orderByComparator.isAscending() ^ previous) {
3694                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3695                                            }
3696                                            else {
3697                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3698                                            }
3699                                    }
3700                                    else {
3701                                            if (orderByComparator.isAscending() ^ previous) {
3702                                                    query.append(ORDER_BY_ASC);
3703                                            }
3704                                            else {
3705                                                    query.append(ORDER_BY_DESC);
3706                                            }
3707                                    }
3708                            }
3709                    }
3710                    else {
3711                            query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
3712                    }
3713    
3714                    String sql = query.toString();
3715    
3716                    Query q = session.createQuery(sql);
3717    
3718                    q.setFirstResult(0);
3719                    q.setMaxResults(2);
3720    
3721                    QueryPos qPos = QueryPos.getInstance(q);
3722    
3723                    qPos.add(groupId);
3724    
3725                    qPos.add(classNameId);
3726    
3727                    qPos.add(classPK);
3728    
3729                    if (orderByComparator != null) {
3730                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
3731    
3732                            for (Object value : values) {
3733                                    qPos.add(value);
3734                            }
3735                    }
3736    
3737                    List<MDRRuleGroupInstance> list = q.list();
3738    
3739                    if (list.size() == 2) {
3740                            return list.get(1);
3741                    }
3742                    else {
3743                            return null;
3744                    }
3745            }
3746    
3747            /**
3748             * Returns all the m d r rule group instances that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3749             *
3750             * @param groupId the group ID
3751             * @param classNameId the class name ID
3752             * @param classPK the class p k
3753             * @return the matching m d r rule group instances that the user has permission to view
3754             * @throws SystemException if a system exception occurred
3755             */
3756            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
3757                    long classNameId, long classPK) throws SystemException {
3758                    return filterFindByG_C_C(groupId, classNameId, classPK,
3759                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3760            }
3761    
3762            /**
3763             * Returns a range of all the m d r rule group instances that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3764             *
3765             * <p>
3766             * 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.MDRRuleGroupInstanceModelImpl}. 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.
3767             * </p>
3768             *
3769             * @param groupId the group ID
3770             * @param classNameId the class name ID
3771             * @param classPK the class p k
3772             * @param start the lower bound of the range of m d r rule group instances
3773             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
3774             * @return the range of matching m d r rule group instances that the user has permission to view
3775             * @throws SystemException if a system exception occurred
3776             */
3777            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
3778                    long classNameId, long classPK, int start, int end)
3779                    throws SystemException {
3780                    return filterFindByG_C_C(groupId, classNameId, classPK, start, end, null);
3781            }
3782    
3783            /**
3784             * Returns an ordered range of all the m d r rule group instances that the user has permissions to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3785             *
3786             * <p>
3787             * 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.MDRRuleGroupInstanceModelImpl}. 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.
3788             * </p>
3789             *
3790             * @param groupId the group ID
3791             * @param classNameId the class name ID
3792             * @param classPK the class p k
3793             * @param start the lower bound of the range of m d r rule group instances
3794             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
3795             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3796             * @return the ordered range of matching m d r rule group instances that the user has permission to view
3797             * @throws SystemException if a system exception occurred
3798             */
3799            public List<MDRRuleGroupInstance> filterFindByG_C_C(long groupId,
3800                    long classNameId, long classPK, int start, int end,
3801                    OrderByComparator orderByComparator) throws SystemException {
3802                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3803                            return findByG_C_C(groupId, classNameId, classPK, start, end,
3804                                    orderByComparator);
3805                    }
3806    
3807                    StringBundler query = null;
3808    
3809                    if (orderByComparator != null) {
3810                            query = new StringBundler(5 +
3811                                            (orderByComparator.getOrderByFields().length * 3));
3812                    }
3813                    else {
3814                            query = new StringBundler(5);
3815                    }
3816    
3817                    if (getDB().isSupportsInlineDistinct()) {
3818                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3819                    }
3820                    else {
3821                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
3822                    }
3823    
3824                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3825    
3826                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3827    
3828                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3829    
3830                    if (!getDB().isSupportsInlineDistinct()) {
3831                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
3832                    }
3833    
3834                    if (orderByComparator != null) {
3835                            if (getDB().isSupportsInlineDistinct()) {
3836                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3837                                            orderByComparator);
3838                            }
3839                            else {
3840                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3841                                            orderByComparator);
3842                            }
3843                    }
3844                    else {
3845                            if (getDB().isSupportsInlineDistinct()) {
3846                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
3847                            }
3848                            else {
3849                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_SQL);
3850                            }
3851                    }
3852    
3853                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3854                                    MDRRuleGroupInstance.class.getName(),
3855                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3856    
3857                    Session session = null;
3858    
3859                    try {
3860                            session = openSession();
3861    
3862                            SQLQuery q = session.createSQLQuery(sql);
3863    
3864                            if (getDB().isSupportsInlineDistinct()) {
3865                                    q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
3866                            }
3867                            else {
3868                                    q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
3869                            }
3870    
3871                            QueryPos qPos = QueryPos.getInstance(q);
3872    
3873                            qPos.add(groupId);
3874    
3875                            qPos.add(classNameId);
3876    
3877                            qPos.add(classPK);
3878    
3879                            return (List<MDRRuleGroupInstance>)QueryUtil.list(q, getDialect(),
3880                                    start, end);
3881                    }
3882                    catch (Exception e) {
3883                            throw processException(e);
3884                    }
3885                    finally {
3886                            closeSession(session);
3887                    }
3888            }
3889    
3890            /**
3891             * Returns the m d r rule group instances before and after the current m d r rule group instance in the ordered set of m d r rule group instances that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
3892             *
3893             * @param ruleGroupInstanceId the primary key of the current m d r rule group instance
3894             * @param groupId the group ID
3895             * @param classNameId the class name ID
3896             * @param classPK the class p k
3897             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3898             * @return the previous, current, and next m d r rule group instance
3899             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
3900             * @throws SystemException if a system exception occurred
3901             */
3902            public MDRRuleGroupInstance[] filterFindByG_C_C_PrevAndNext(
3903                    long ruleGroupInstanceId, long groupId, long classNameId, long classPK,
3904                    OrderByComparator orderByComparator)
3905                    throws NoSuchRuleGroupInstanceException, SystemException {
3906                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3907                            return findByG_C_C_PrevAndNext(ruleGroupInstanceId, groupId,
3908                                    classNameId, classPK, orderByComparator);
3909                    }
3910    
3911                    MDRRuleGroupInstance mdrRuleGroupInstance = findByPrimaryKey(ruleGroupInstanceId);
3912    
3913                    Session session = null;
3914    
3915                    try {
3916                            session = openSession();
3917    
3918                            MDRRuleGroupInstance[] array = new MDRRuleGroupInstanceImpl[3];
3919    
3920                            array[0] = filterGetByG_C_C_PrevAndNext(session,
3921                                            mdrRuleGroupInstance, groupId, classNameId, classPK,
3922                                            orderByComparator, true);
3923    
3924                            array[1] = mdrRuleGroupInstance;
3925    
3926                            array[2] = filterGetByG_C_C_PrevAndNext(session,
3927                                            mdrRuleGroupInstance, groupId, classNameId, classPK,
3928                                            orderByComparator, false);
3929    
3930                            return array;
3931                    }
3932                    catch (Exception e) {
3933                            throw processException(e);
3934                    }
3935                    finally {
3936                            closeSession(session);
3937                    }
3938            }
3939    
3940            protected MDRRuleGroupInstance filterGetByG_C_C_PrevAndNext(
3941                    Session session, MDRRuleGroupInstance mdrRuleGroupInstance,
3942                    long groupId, long classNameId, long classPK,
3943                    OrderByComparator orderByComparator, boolean previous) {
3944                    StringBundler query = null;
3945    
3946                    if (orderByComparator != null) {
3947                            query = new StringBundler(6 +
3948                                            (orderByComparator.getOrderByFields().length * 6));
3949                    }
3950                    else {
3951                            query = new StringBundler(3);
3952                    }
3953    
3954                    if (getDB().isSupportsInlineDistinct()) {
3955                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
3956                    }
3957                    else {
3958                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1);
3959                    }
3960    
3961                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
3962    
3963                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
3964    
3965                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
3966    
3967                    if (!getDB().isSupportsInlineDistinct()) {
3968                            query.append(_FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2);
3969                    }
3970    
3971                    if (orderByComparator != null) {
3972                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3973    
3974                            if (orderByConditionFields.length > 0) {
3975                                    query.append(WHERE_AND);
3976                            }
3977    
3978                            for (int i = 0; i < orderByConditionFields.length; i++) {
3979                                    if (getDB().isSupportsInlineDistinct()) {
3980                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3981                                    }
3982                                    else {
3983                                            query.append(_ORDER_BY_ENTITY_TABLE);
3984                                    }
3985    
3986                                    query.append(orderByConditionFields[i]);
3987    
3988                                    if ((i + 1) < orderByConditionFields.length) {
3989                                            if (orderByComparator.isAscending() ^ previous) {
3990                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3991                                            }
3992                                            else {
3993                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3994                                            }
3995                                    }
3996                                    else {
3997                                            if (orderByComparator.isAscending() ^ previous) {
3998                                                    query.append(WHERE_GREATER_THAN);
3999                                            }
4000                                            else {
4001                                                    query.append(WHERE_LESSER_THAN);
4002                                            }
4003                                    }
4004                            }
4005    
4006                            query.append(ORDER_BY_CLAUSE);
4007    
4008                            String[] orderByFields = orderByComparator.getOrderByFields();
4009    
4010                            for (int i = 0; i < orderByFields.length; i++) {
4011                                    if (getDB().isSupportsInlineDistinct()) {
4012                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4013                                    }
4014                                    else {
4015                                            query.append(_ORDER_BY_ENTITY_TABLE);
4016                                    }
4017    
4018                                    query.append(orderByFields[i]);
4019    
4020                                    if ((i + 1) < orderByFields.length) {
4021                                            if (orderByComparator.isAscending() ^ previous) {
4022                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4023                                            }
4024                                            else {
4025                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4026                                            }
4027                                    }
4028                                    else {
4029                                            if (orderByComparator.isAscending() ^ previous) {
4030                                                    query.append(ORDER_BY_ASC);
4031                                            }
4032                                            else {
4033                                                    query.append(ORDER_BY_DESC);
4034                                            }
4035                                    }
4036                            }
4037                    }
4038                    else {
4039                            if (getDB().isSupportsInlineDistinct()) {
4040                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
4041                            }
4042                            else {
4043                                    query.append(MDRRuleGroupInstanceModelImpl.ORDER_BY_SQL);
4044                            }
4045                    }
4046    
4047                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4048                                    MDRRuleGroupInstance.class.getName(),
4049                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4050    
4051                    SQLQuery q = session.createSQLQuery(sql);
4052    
4053                    q.setFirstResult(0);
4054                    q.setMaxResults(2);
4055    
4056                    if (getDB().isSupportsInlineDistinct()) {
4057                            q.addEntity(_FILTER_ENTITY_ALIAS, MDRRuleGroupInstanceImpl.class);
4058                    }
4059                    else {
4060                            q.addEntity(_FILTER_ENTITY_TABLE, MDRRuleGroupInstanceImpl.class);
4061                    }
4062    
4063                    QueryPos qPos = QueryPos.getInstance(q);
4064    
4065                    qPos.add(groupId);
4066    
4067                    qPos.add(classNameId);
4068    
4069                    qPos.add(classPK);
4070    
4071                    if (orderByComparator != null) {
4072                            Object[] values = orderByComparator.getOrderByConditionValues(mdrRuleGroupInstance);
4073    
4074                            for (Object value : values) {
4075                                    qPos.add(value);
4076                            }
4077                    }
4078    
4079                    List<MDRRuleGroupInstance> list = q.list();
4080    
4081                    if (list.size() == 2) {
4082                            return list.get(1);
4083                    }
4084                    else {
4085                            return null;
4086                    }
4087            }
4088    
4089            /**
4090             * Removes all the m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
4091             *
4092             * @param groupId the group ID
4093             * @param classNameId the class name ID
4094             * @param classPK the class p k
4095             * @throws SystemException if a system exception occurred
4096             */
4097            public void removeByG_C_C(long groupId, long classNameId, long classPK)
4098                    throws SystemException {
4099                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findByG_C_C(groupId,
4100                                    classNameId, classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4101                            remove(mdrRuleGroupInstance);
4102                    }
4103            }
4104    
4105            /**
4106             * Returns the number of m d r rule group instances where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4107             *
4108             * @param groupId the group ID
4109             * @param classNameId the class name ID
4110             * @param classPK the class p k
4111             * @return the number of matching m d r rule group instances
4112             * @throws SystemException if a system exception occurred
4113             */
4114            public int countByG_C_C(long groupId, long classNameId, long classPK)
4115                    throws SystemException {
4116                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C;
4117    
4118                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK };
4119    
4120                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4121                                    this);
4122    
4123                    if (count == null) {
4124                            StringBundler query = new StringBundler(4);
4125    
4126                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
4127    
4128                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
4129    
4130                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
4131    
4132                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
4133    
4134                            String sql = query.toString();
4135    
4136                            Session session = null;
4137    
4138                            try {
4139                                    session = openSession();
4140    
4141                                    Query q = session.createQuery(sql);
4142    
4143                                    QueryPos qPos = QueryPos.getInstance(q);
4144    
4145                                    qPos.add(groupId);
4146    
4147                                    qPos.add(classNameId);
4148    
4149                                    qPos.add(classPK);
4150    
4151                                    count = (Long)q.uniqueResult();
4152    
4153                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4154                            }
4155                            catch (Exception e) {
4156                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4157    
4158                                    throw processException(e);
4159                            }
4160                            finally {
4161                                    closeSession(session);
4162                            }
4163                    }
4164    
4165                    return count.intValue();
4166            }
4167    
4168            /**
4169             * Returns the number of m d r rule group instances that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
4170             *
4171             * @param groupId the group ID
4172             * @param classNameId the class name ID
4173             * @param classPK the class p k
4174             * @return the number of matching m d r rule group instances that the user has permission to view
4175             * @throws SystemException if a system exception occurred
4176             */
4177            public int filterCountByG_C_C(long groupId, long classNameId, long classPK)
4178                    throws SystemException {
4179                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4180                            return countByG_C_C(groupId, classNameId, classPK);
4181                    }
4182    
4183                    StringBundler query = new StringBundler(4);
4184    
4185                    query.append(_FILTER_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
4186    
4187                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
4188    
4189                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
4190    
4191                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
4192    
4193                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4194                                    MDRRuleGroupInstance.class.getName(),
4195                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4196    
4197                    Session session = null;
4198    
4199                    try {
4200                            session = openSession();
4201    
4202                            SQLQuery q = session.createSQLQuery(sql);
4203    
4204                            q.addScalar(COUNT_COLUMN_NAME,
4205                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4206    
4207                            QueryPos qPos = QueryPos.getInstance(q);
4208    
4209                            qPos.add(groupId);
4210    
4211                            qPos.add(classNameId);
4212    
4213                            qPos.add(classPK);
4214    
4215                            Long count = (Long)q.uniqueResult();
4216    
4217                            return count.intValue();
4218                    }
4219                    catch (Exception e) {
4220                            throw processException(e);
4221                    }
4222                    finally {
4223                            closeSession(session);
4224                    }
4225            }
4226    
4227            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "mdrRuleGroupInstance.groupId = ? AND ";
4228            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
4229            private static final String _FINDER_COLUMN_G_C_C_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ?";
4230            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_R = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4231                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED,
4232                            MDRRuleGroupInstanceImpl.class, FINDER_CLASS_NAME_ENTITY,
4233                            "fetchByC_C_R",
4234                            new String[] {
4235                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
4236                            },
4237                            MDRRuleGroupInstanceModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4238                            MDRRuleGroupInstanceModelImpl.CLASSPK_COLUMN_BITMASK |
4239                            MDRRuleGroupInstanceModelImpl.RULEGROUPID_COLUMN_BITMASK);
4240            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_R = new FinderPath(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4241                            MDRRuleGroupInstanceModelImpl.FINDER_CACHE_ENABLED, Long.class,
4242                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_R",
4243                            new String[] {
4244                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
4245                            });
4246    
4247            /**
4248             * Returns the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException} if it could not be found.
4249             *
4250             * @param classNameId the class name ID
4251             * @param classPK the class p k
4252             * @param ruleGroupId the rule group ID
4253             * @return the matching m d r rule group instance
4254             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a matching m d r rule group instance could not be found
4255             * @throws SystemException if a system exception occurred
4256             */
4257            public MDRRuleGroupInstance findByC_C_R(long classNameId, long classPK,
4258                    long ruleGroupId)
4259                    throws NoSuchRuleGroupInstanceException, SystemException {
4260                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByC_C_R(classNameId,
4261                                    classPK, ruleGroupId);
4262    
4263                    if (mdrRuleGroupInstance == null) {
4264                            StringBundler msg = new StringBundler(8);
4265    
4266                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4267    
4268                            msg.append("classNameId=");
4269                            msg.append(classNameId);
4270    
4271                            msg.append(", classPK=");
4272                            msg.append(classPK);
4273    
4274                            msg.append(", ruleGroupId=");
4275                            msg.append(ruleGroupId);
4276    
4277                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4278    
4279                            if (_log.isWarnEnabled()) {
4280                                    _log.warn(msg.toString());
4281                            }
4282    
4283                            throw new NoSuchRuleGroupInstanceException(msg.toString());
4284                    }
4285    
4286                    return mdrRuleGroupInstance;
4287            }
4288    
4289            /**
4290             * Returns the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4291             *
4292             * @param classNameId the class name ID
4293             * @param classPK the class p k
4294             * @param ruleGroupId the rule group ID
4295             * @return the matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
4296             * @throws SystemException if a system exception occurred
4297             */
4298            public MDRRuleGroupInstance fetchByC_C_R(long classNameId, long classPK,
4299                    long ruleGroupId) throws SystemException {
4300                    return fetchByC_C_R(classNameId, classPK, ruleGroupId, true);
4301            }
4302    
4303            /**
4304             * Returns the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4305             *
4306             * @param classNameId the class name ID
4307             * @param classPK the class p k
4308             * @param ruleGroupId the rule group ID
4309             * @param retrieveFromCache whether to use the finder cache
4310             * @return the matching m d r rule group instance, or <code>null</code> if a matching m d r rule group instance could not be found
4311             * @throws SystemException if a system exception occurred
4312             */
4313            public MDRRuleGroupInstance fetchByC_C_R(long classNameId, long classPK,
4314                    long ruleGroupId, boolean retrieveFromCache) throws SystemException {
4315                    Object[] finderArgs = new Object[] { classNameId, classPK, ruleGroupId };
4316    
4317                    Object result = null;
4318    
4319                    if (retrieveFromCache) {
4320                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_R,
4321                                            finderArgs, this);
4322                    }
4323    
4324                    if (result instanceof MDRRuleGroupInstance) {
4325                            MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)result;
4326    
4327                            if ((classNameId != mdrRuleGroupInstance.getClassNameId()) ||
4328                                            (classPK != mdrRuleGroupInstance.getClassPK()) ||
4329                                            (ruleGroupId != mdrRuleGroupInstance.getRuleGroupId())) {
4330                                    result = null;
4331                            }
4332                    }
4333    
4334                    if (result == null) {
4335                            StringBundler query = new StringBundler(5);
4336    
4337                            query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE);
4338    
4339                            query.append(_FINDER_COLUMN_C_C_R_CLASSNAMEID_2);
4340    
4341                            query.append(_FINDER_COLUMN_C_C_R_CLASSPK_2);
4342    
4343                            query.append(_FINDER_COLUMN_C_C_R_RULEGROUPID_2);
4344    
4345                            String sql = query.toString();
4346    
4347                            Session session = null;
4348    
4349                            try {
4350                                    session = openSession();
4351    
4352                                    Query q = session.createQuery(sql);
4353    
4354                                    QueryPos qPos = QueryPos.getInstance(q);
4355    
4356                                    qPos.add(classNameId);
4357    
4358                                    qPos.add(classPK);
4359    
4360                                    qPos.add(ruleGroupId);
4361    
4362                                    List<MDRRuleGroupInstance> list = q.list();
4363    
4364                                    if (list.isEmpty()) {
4365                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
4366                                                    finderArgs, list);
4367                                    }
4368                                    else {
4369                                            MDRRuleGroupInstance mdrRuleGroupInstance = list.get(0);
4370    
4371                                            result = mdrRuleGroupInstance;
4372    
4373                                            cacheResult(mdrRuleGroupInstance);
4374    
4375                                            if ((mdrRuleGroupInstance.getClassNameId() != classNameId) ||
4376                                                            (mdrRuleGroupInstance.getClassPK() != classPK) ||
4377                                                            (mdrRuleGroupInstance.getRuleGroupId() != ruleGroupId)) {
4378                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
4379                                                            finderArgs, mdrRuleGroupInstance);
4380                                            }
4381                                    }
4382                            }
4383                            catch (Exception e) {
4384                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R,
4385                                            finderArgs);
4386    
4387                                    throw processException(e);
4388                            }
4389                            finally {
4390                                    closeSession(session);
4391                            }
4392                    }
4393    
4394                    if (result instanceof List<?>) {
4395                            return null;
4396                    }
4397                    else {
4398                            return (MDRRuleGroupInstance)result;
4399                    }
4400            }
4401    
4402            /**
4403             * Removes the m d r rule group instance where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63; from the database.
4404             *
4405             * @param classNameId the class name ID
4406             * @param classPK the class p k
4407             * @param ruleGroupId the rule group ID
4408             * @return the m d r rule group instance that was removed
4409             * @throws SystemException if a system exception occurred
4410             */
4411            public MDRRuleGroupInstance removeByC_C_R(long classNameId, long classPK,
4412                    long ruleGroupId)
4413                    throws NoSuchRuleGroupInstanceException, SystemException {
4414                    MDRRuleGroupInstance mdrRuleGroupInstance = findByC_C_R(classNameId,
4415                                    classPK, ruleGroupId);
4416    
4417                    return remove(mdrRuleGroupInstance);
4418            }
4419    
4420            /**
4421             * Returns the number of m d r rule group instances where classNameId = &#63; and classPK = &#63; and ruleGroupId = &#63;.
4422             *
4423             * @param classNameId the class name ID
4424             * @param classPK the class p k
4425             * @param ruleGroupId the rule group ID
4426             * @return the number of matching m d r rule group instances
4427             * @throws SystemException if a system exception occurred
4428             */
4429            public int countByC_C_R(long classNameId, long classPK, long ruleGroupId)
4430                    throws SystemException {
4431                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_R;
4432    
4433                    Object[] finderArgs = new Object[] { classNameId, classPK, ruleGroupId };
4434    
4435                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4436                                    this);
4437    
4438                    if (count == null) {
4439                            StringBundler query = new StringBundler(4);
4440    
4441                            query.append(_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE);
4442    
4443                            query.append(_FINDER_COLUMN_C_C_R_CLASSNAMEID_2);
4444    
4445                            query.append(_FINDER_COLUMN_C_C_R_CLASSPK_2);
4446    
4447                            query.append(_FINDER_COLUMN_C_C_R_RULEGROUPID_2);
4448    
4449                            String sql = query.toString();
4450    
4451                            Session session = null;
4452    
4453                            try {
4454                                    session = openSession();
4455    
4456                                    Query q = session.createQuery(sql);
4457    
4458                                    QueryPos qPos = QueryPos.getInstance(q);
4459    
4460                                    qPos.add(classNameId);
4461    
4462                                    qPos.add(classPK);
4463    
4464                                    qPos.add(ruleGroupId);
4465    
4466                                    count = (Long)q.uniqueResult();
4467    
4468                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4469                            }
4470                            catch (Exception e) {
4471                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4472    
4473                                    throw processException(e);
4474                            }
4475                            finally {
4476                                    closeSession(session);
4477                            }
4478                    }
4479    
4480                    return count.intValue();
4481            }
4482    
4483            private static final String _FINDER_COLUMN_C_C_R_CLASSNAMEID_2 = "mdrRuleGroupInstance.classNameId = ? AND ";
4484            private static final String _FINDER_COLUMN_C_C_R_CLASSPK_2 = "mdrRuleGroupInstance.classPK = ? AND ";
4485            private static final String _FINDER_COLUMN_C_C_R_RULEGROUPID_2 = "mdrRuleGroupInstance.ruleGroupId = ?";
4486    
4487            /**
4488             * Caches the m d r rule group instance in the entity cache if it is enabled.
4489             *
4490             * @param mdrRuleGroupInstance the m d r rule group instance
4491             */
4492            public void cacheResult(MDRRuleGroupInstance mdrRuleGroupInstance) {
4493                    EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4494                            MDRRuleGroupInstanceImpl.class,
4495                            mdrRuleGroupInstance.getPrimaryKey(), mdrRuleGroupInstance);
4496    
4497                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
4498                            new Object[] {
4499                                    mdrRuleGroupInstance.getUuid(),
4500                                    mdrRuleGroupInstance.getGroupId()
4501                            }, mdrRuleGroupInstance);
4502    
4503                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R,
4504                            new Object[] {
4505                                    mdrRuleGroupInstance.getClassNameId(),
4506                                    mdrRuleGroupInstance.getClassPK(),
4507                                    mdrRuleGroupInstance.getRuleGroupId()
4508                            }, mdrRuleGroupInstance);
4509    
4510                    mdrRuleGroupInstance.resetOriginalValues();
4511            }
4512    
4513            /**
4514             * Caches the m d r rule group instances in the entity cache if it is enabled.
4515             *
4516             * @param mdrRuleGroupInstances the m d r rule group instances
4517             */
4518            public void cacheResult(List<MDRRuleGroupInstance> mdrRuleGroupInstances) {
4519                    for (MDRRuleGroupInstance mdrRuleGroupInstance : mdrRuleGroupInstances) {
4520                            if (EntityCacheUtil.getResult(
4521                                                    MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4522                                                    MDRRuleGroupInstanceImpl.class,
4523                                                    mdrRuleGroupInstance.getPrimaryKey()) == null) {
4524                                    cacheResult(mdrRuleGroupInstance);
4525                            }
4526                            else {
4527                                    mdrRuleGroupInstance.resetOriginalValues();
4528                            }
4529                    }
4530            }
4531    
4532            /**
4533             * Clears the cache for all m d r rule group instances.
4534             *
4535             * <p>
4536             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4537             * </p>
4538             */
4539            @Override
4540            public void clearCache() {
4541                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4542                            CacheRegistryUtil.clear(MDRRuleGroupInstanceImpl.class.getName());
4543                    }
4544    
4545                    EntityCacheUtil.clearCache(MDRRuleGroupInstanceImpl.class.getName());
4546    
4547                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4548                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4549                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4550            }
4551    
4552            /**
4553             * Clears the cache for the m d r rule group instance.
4554             *
4555             * <p>
4556             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4557             * </p>
4558             */
4559            @Override
4560            public void clearCache(MDRRuleGroupInstance mdrRuleGroupInstance) {
4561                    EntityCacheUtil.removeResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4562                            MDRRuleGroupInstanceImpl.class, mdrRuleGroupInstance.getPrimaryKey());
4563    
4564                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4565                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4566    
4567                    clearUniqueFindersCache(mdrRuleGroupInstance);
4568            }
4569    
4570            @Override
4571            public void clearCache(List<MDRRuleGroupInstance> mdrRuleGroupInstances) {
4572                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4573                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4574    
4575                    for (MDRRuleGroupInstance mdrRuleGroupInstance : mdrRuleGroupInstances) {
4576                            EntityCacheUtil.removeResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4577                                    MDRRuleGroupInstanceImpl.class,
4578                                    mdrRuleGroupInstance.getPrimaryKey());
4579    
4580                            clearUniqueFindersCache(mdrRuleGroupInstance);
4581                    }
4582            }
4583    
4584            protected void cacheUniqueFindersCache(
4585                    MDRRuleGroupInstance mdrRuleGroupInstance) {
4586                    if (mdrRuleGroupInstance.isNew()) {
4587                            Object[] args = new Object[] {
4588                                            mdrRuleGroupInstance.getUuid(),
4589                                            mdrRuleGroupInstance.getGroupId()
4590                                    };
4591    
4592                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4593                                    Long.valueOf(1));
4594                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4595                                    mdrRuleGroupInstance);
4596    
4597                            args = new Object[] {
4598                                            mdrRuleGroupInstance.getClassNameId(),
4599                                            mdrRuleGroupInstance.getClassPK(),
4600                                            mdrRuleGroupInstance.getRuleGroupId()
4601                                    };
4602    
4603                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_R, args,
4604                                    Long.valueOf(1));
4605                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R, args,
4606                                    mdrRuleGroupInstance);
4607                    }
4608                    else {
4609                            MDRRuleGroupInstanceModelImpl mdrRuleGroupInstanceModelImpl = (MDRRuleGroupInstanceModelImpl)mdrRuleGroupInstance;
4610    
4611                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4612                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4613                                    Object[] args = new Object[] {
4614                                                    mdrRuleGroupInstance.getUuid(),
4615                                                    mdrRuleGroupInstance.getGroupId()
4616                                            };
4617    
4618                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
4619                                            Long.valueOf(1));
4620                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
4621                                            mdrRuleGroupInstance);
4622                            }
4623    
4624                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4625                                            FINDER_PATH_FETCH_BY_C_C_R.getColumnBitmask()) != 0) {
4626                                    Object[] args = new Object[] {
4627                                                    mdrRuleGroupInstance.getClassNameId(),
4628                                                    mdrRuleGroupInstance.getClassPK(),
4629                                                    mdrRuleGroupInstance.getRuleGroupId()
4630                                            };
4631    
4632                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_R, args,
4633                                            Long.valueOf(1));
4634                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_R, args,
4635                                            mdrRuleGroupInstance);
4636                            }
4637                    }
4638            }
4639    
4640            protected void clearUniqueFindersCache(
4641                    MDRRuleGroupInstance mdrRuleGroupInstance) {
4642                    MDRRuleGroupInstanceModelImpl mdrRuleGroupInstanceModelImpl = (MDRRuleGroupInstanceModelImpl)mdrRuleGroupInstance;
4643    
4644                    Object[] args = new Object[] {
4645                                    mdrRuleGroupInstance.getUuid(),
4646                                    mdrRuleGroupInstance.getGroupId()
4647                            };
4648    
4649                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4650                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4651    
4652                    if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4653                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
4654                            args = new Object[] {
4655                                            mdrRuleGroupInstanceModelImpl.getOriginalUuid(),
4656                                            mdrRuleGroupInstanceModelImpl.getOriginalGroupId()
4657                                    };
4658    
4659                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
4660                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
4661                    }
4662    
4663                    args = new Object[] {
4664                                    mdrRuleGroupInstance.getClassNameId(),
4665                                    mdrRuleGroupInstance.getClassPK(),
4666                                    mdrRuleGroupInstance.getRuleGroupId()
4667                            };
4668    
4669                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_R, args);
4670                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R, args);
4671    
4672                    if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4673                                    FINDER_PATH_FETCH_BY_C_C_R.getColumnBitmask()) != 0) {
4674                            args = new Object[] {
4675                                            mdrRuleGroupInstanceModelImpl.getOriginalClassNameId(),
4676                                            mdrRuleGroupInstanceModelImpl.getOriginalClassPK(),
4677                                            mdrRuleGroupInstanceModelImpl.getOriginalRuleGroupId()
4678                                    };
4679    
4680                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_R, args);
4681                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_R, args);
4682                    }
4683            }
4684    
4685            /**
4686             * Creates a new m d r rule group instance with the primary key. Does not add the m d r rule group instance to the database.
4687             *
4688             * @param ruleGroupInstanceId the primary key for the new m d r rule group instance
4689             * @return the new m d r rule group instance
4690             */
4691            public MDRRuleGroupInstance create(long ruleGroupInstanceId) {
4692                    MDRRuleGroupInstance mdrRuleGroupInstance = new MDRRuleGroupInstanceImpl();
4693    
4694                    mdrRuleGroupInstance.setNew(true);
4695                    mdrRuleGroupInstance.setPrimaryKey(ruleGroupInstanceId);
4696    
4697                    String uuid = PortalUUIDUtil.generate();
4698    
4699                    mdrRuleGroupInstance.setUuid(uuid);
4700    
4701                    return mdrRuleGroupInstance;
4702            }
4703    
4704            /**
4705             * Removes the m d r rule group instance with the primary key from the database. Also notifies the appropriate model listeners.
4706             *
4707             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
4708             * @return the m d r rule group instance that was removed
4709             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
4710             * @throws SystemException if a system exception occurred
4711             */
4712            public MDRRuleGroupInstance remove(long ruleGroupInstanceId)
4713                    throws NoSuchRuleGroupInstanceException, SystemException {
4714                    return remove((Serializable)ruleGroupInstanceId);
4715            }
4716    
4717            /**
4718             * Removes the m d r rule group instance with the primary key from the database. Also notifies the appropriate model listeners.
4719             *
4720             * @param primaryKey the primary key of the m d r rule group instance
4721             * @return the m d r rule group instance that was removed
4722             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
4723             * @throws SystemException if a system exception occurred
4724             */
4725            @Override
4726            public MDRRuleGroupInstance remove(Serializable primaryKey)
4727                    throws NoSuchRuleGroupInstanceException, SystemException {
4728                    Session session = null;
4729    
4730                    try {
4731                            session = openSession();
4732    
4733                            MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)session.get(MDRRuleGroupInstanceImpl.class,
4734                                            primaryKey);
4735    
4736                            if (mdrRuleGroupInstance == null) {
4737                                    if (_log.isWarnEnabled()) {
4738                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4739                                    }
4740    
4741                                    throw new NoSuchRuleGroupInstanceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4742                                            primaryKey);
4743                            }
4744    
4745                            return remove(mdrRuleGroupInstance);
4746                    }
4747                    catch (NoSuchRuleGroupInstanceException nsee) {
4748                            throw nsee;
4749                    }
4750                    catch (Exception e) {
4751                            throw processException(e);
4752                    }
4753                    finally {
4754                            closeSession(session);
4755                    }
4756            }
4757    
4758            @Override
4759            protected MDRRuleGroupInstance removeImpl(
4760                    MDRRuleGroupInstance mdrRuleGroupInstance) throws SystemException {
4761                    mdrRuleGroupInstance = toUnwrappedModel(mdrRuleGroupInstance);
4762    
4763                    Session session = null;
4764    
4765                    try {
4766                            session = openSession();
4767    
4768                            if (!session.contains(mdrRuleGroupInstance)) {
4769                                    mdrRuleGroupInstance = (MDRRuleGroupInstance)session.get(MDRRuleGroupInstanceImpl.class,
4770                                                    mdrRuleGroupInstance.getPrimaryKeyObj());
4771                            }
4772    
4773                            if (mdrRuleGroupInstance != null) {
4774                                    session.delete(mdrRuleGroupInstance);
4775                            }
4776                    }
4777                    catch (Exception e) {
4778                            throw processException(e);
4779                    }
4780                    finally {
4781                            closeSession(session);
4782                    }
4783    
4784                    if (mdrRuleGroupInstance != null) {
4785                            clearCache(mdrRuleGroupInstance);
4786                    }
4787    
4788                    return mdrRuleGroupInstance;
4789            }
4790    
4791            @Override
4792            public MDRRuleGroupInstance updateImpl(
4793                    com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance mdrRuleGroupInstance)
4794                    throws SystemException {
4795                    mdrRuleGroupInstance = toUnwrappedModel(mdrRuleGroupInstance);
4796    
4797                    boolean isNew = mdrRuleGroupInstance.isNew();
4798    
4799                    MDRRuleGroupInstanceModelImpl mdrRuleGroupInstanceModelImpl = (MDRRuleGroupInstanceModelImpl)mdrRuleGroupInstance;
4800    
4801                    if (Validator.isNull(mdrRuleGroupInstance.getUuid())) {
4802                            String uuid = PortalUUIDUtil.generate();
4803    
4804                            mdrRuleGroupInstance.setUuid(uuid);
4805                    }
4806    
4807                    Session session = null;
4808    
4809                    try {
4810                            session = openSession();
4811    
4812                            if (mdrRuleGroupInstance.isNew()) {
4813                                    session.save(mdrRuleGroupInstance);
4814    
4815                                    mdrRuleGroupInstance.setNew(false);
4816                            }
4817                            else {
4818                                    session.merge(mdrRuleGroupInstance);
4819                            }
4820                    }
4821                    catch (Exception e) {
4822                            throw processException(e);
4823                    }
4824                    finally {
4825                            closeSession(session);
4826                    }
4827    
4828                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4829    
4830                    if (isNew || !MDRRuleGroupInstanceModelImpl.COLUMN_BITMASK_ENABLED) {
4831                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4832                    }
4833    
4834                    else {
4835                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4836                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4837                                    Object[] args = new Object[] {
4838                                                    mdrRuleGroupInstanceModelImpl.getOriginalUuid()
4839                                            };
4840    
4841                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4842                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4843                                            args);
4844    
4845                                    args = new Object[] { mdrRuleGroupInstanceModelImpl.getUuid() };
4846    
4847                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4848                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4849                                            args);
4850                            }
4851    
4852                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4853                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4854                                    Object[] args = new Object[] {
4855                                                    mdrRuleGroupInstanceModelImpl.getOriginalUuid(),
4856                                                    mdrRuleGroupInstanceModelImpl.getOriginalCompanyId()
4857                                            };
4858    
4859                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4860                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4861                                            args);
4862    
4863                                    args = new Object[] {
4864                                                    mdrRuleGroupInstanceModelImpl.getUuid(),
4865                                                    mdrRuleGroupInstanceModelImpl.getCompanyId()
4866                                            };
4867    
4868                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4869                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4870                                            args);
4871                            }
4872    
4873                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4874                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
4875                                    Object[] args = new Object[] {
4876                                                    mdrRuleGroupInstanceModelImpl.getOriginalGroupId()
4877                                            };
4878    
4879                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4880                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4881                                            args);
4882    
4883                                    args = new Object[] { mdrRuleGroupInstanceModelImpl.getGroupId() };
4884    
4885                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
4886                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
4887                                            args);
4888                            }
4889    
4890                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4891                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID.getColumnBitmask()) != 0) {
4892                                    Object[] args = new Object[] {
4893                                                    mdrRuleGroupInstanceModelImpl.getOriginalRuleGroupId()
4894                                            };
4895    
4896                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
4897                                            args);
4898                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
4899                                            args);
4900    
4901                                    args = new Object[] {
4902                                                    mdrRuleGroupInstanceModelImpl.getRuleGroupId()
4903                                            };
4904    
4905                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
4906                                            args);
4907                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
4908                                            args);
4909                            }
4910    
4911                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4912                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
4913                                    Object[] args = new Object[] {
4914                                                    mdrRuleGroupInstanceModelImpl.getOriginalClassNameId(),
4915                                                    mdrRuleGroupInstanceModelImpl.getOriginalClassPK()
4916                                            };
4917    
4918                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4919                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4920                                            args);
4921    
4922                                    args = new Object[] {
4923                                                    mdrRuleGroupInstanceModelImpl.getClassNameId(),
4924                                                    mdrRuleGroupInstanceModelImpl.getClassPK()
4925                                            };
4926    
4927                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
4928                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
4929                                            args);
4930                            }
4931    
4932                            if ((mdrRuleGroupInstanceModelImpl.getColumnBitmask() &
4933                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C.getColumnBitmask()) != 0) {
4934                                    Object[] args = new Object[] {
4935                                                    mdrRuleGroupInstanceModelImpl.getOriginalGroupId(),
4936                                                    mdrRuleGroupInstanceModelImpl.getOriginalClassNameId(),
4937                                                    mdrRuleGroupInstanceModelImpl.getOriginalClassPK()
4938                                            };
4939    
4940                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
4941                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
4942                                            args);
4943    
4944                                    args = new Object[] {
4945                                                    mdrRuleGroupInstanceModelImpl.getGroupId(),
4946                                                    mdrRuleGroupInstanceModelImpl.getClassNameId(),
4947                                                    mdrRuleGroupInstanceModelImpl.getClassPK()
4948                                            };
4949    
4950                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
4951                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
4952                                            args);
4953                            }
4954                    }
4955    
4956                    EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
4957                            MDRRuleGroupInstanceImpl.class,
4958                            mdrRuleGroupInstance.getPrimaryKey(), mdrRuleGroupInstance);
4959    
4960                    clearUniqueFindersCache(mdrRuleGroupInstance);
4961                    cacheUniqueFindersCache(mdrRuleGroupInstance);
4962    
4963                    return mdrRuleGroupInstance;
4964            }
4965    
4966            protected MDRRuleGroupInstance toUnwrappedModel(
4967                    MDRRuleGroupInstance mdrRuleGroupInstance) {
4968                    if (mdrRuleGroupInstance instanceof MDRRuleGroupInstanceImpl) {
4969                            return mdrRuleGroupInstance;
4970                    }
4971    
4972                    MDRRuleGroupInstanceImpl mdrRuleGroupInstanceImpl = new MDRRuleGroupInstanceImpl();
4973    
4974                    mdrRuleGroupInstanceImpl.setNew(mdrRuleGroupInstance.isNew());
4975                    mdrRuleGroupInstanceImpl.setPrimaryKey(mdrRuleGroupInstance.getPrimaryKey());
4976    
4977                    mdrRuleGroupInstanceImpl.setUuid(mdrRuleGroupInstance.getUuid());
4978                    mdrRuleGroupInstanceImpl.setRuleGroupInstanceId(mdrRuleGroupInstance.getRuleGroupInstanceId());
4979                    mdrRuleGroupInstanceImpl.setGroupId(mdrRuleGroupInstance.getGroupId());
4980                    mdrRuleGroupInstanceImpl.setCompanyId(mdrRuleGroupInstance.getCompanyId());
4981                    mdrRuleGroupInstanceImpl.setUserId(mdrRuleGroupInstance.getUserId());
4982                    mdrRuleGroupInstanceImpl.setUserName(mdrRuleGroupInstance.getUserName());
4983                    mdrRuleGroupInstanceImpl.setCreateDate(mdrRuleGroupInstance.getCreateDate());
4984                    mdrRuleGroupInstanceImpl.setModifiedDate(mdrRuleGroupInstance.getModifiedDate());
4985                    mdrRuleGroupInstanceImpl.setClassNameId(mdrRuleGroupInstance.getClassNameId());
4986                    mdrRuleGroupInstanceImpl.setClassPK(mdrRuleGroupInstance.getClassPK());
4987                    mdrRuleGroupInstanceImpl.setRuleGroupId(mdrRuleGroupInstance.getRuleGroupId());
4988                    mdrRuleGroupInstanceImpl.setPriority(mdrRuleGroupInstance.getPriority());
4989    
4990                    return mdrRuleGroupInstanceImpl;
4991            }
4992    
4993            /**
4994             * Returns the m d r rule group instance with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4995             *
4996             * @param primaryKey the primary key of the m d r rule group instance
4997             * @return the m d r rule group instance
4998             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
4999             * @throws SystemException if a system exception occurred
5000             */
5001            @Override
5002            public MDRRuleGroupInstance findByPrimaryKey(Serializable primaryKey)
5003                    throws NoSuchRuleGroupInstanceException, SystemException {
5004                    MDRRuleGroupInstance mdrRuleGroupInstance = fetchByPrimaryKey(primaryKey);
5005    
5006                    if (mdrRuleGroupInstance == null) {
5007                            if (_log.isWarnEnabled()) {
5008                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
5009                            }
5010    
5011                            throw new NoSuchRuleGroupInstanceException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
5012                                    primaryKey);
5013                    }
5014    
5015                    return mdrRuleGroupInstance;
5016            }
5017    
5018            /**
5019             * Returns the m d r rule group instance with the primary key or throws a {@link com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException} if it could not be found.
5020             *
5021             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
5022             * @return the m d r rule group instance
5023             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleGroupInstanceException if a m d r rule group instance with the primary key could not be found
5024             * @throws SystemException if a system exception occurred
5025             */
5026            public MDRRuleGroupInstance findByPrimaryKey(long ruleGroupInstanceId)
5027                    throws NoSuchRuleGroupInstanceException, SystemException {
5028                    return findByPrimaryKey((Serializable)ruleGroupInstanceId);
5029            }
5030    
5031            /**
5032             * Returns the m d r rule group instance with the primary key or returns <code>null</code> if it could not be found.
5033             *
5034             * @param primaryKey the primary key of the m d r rule group instance
5035             * @return the m d r rule group instance, or <code>null</code> if a m d r rule group instance with the primary key could not be found
5036             * @throws SystemException if a system exception occurred
5037             */
5038            @Override
5039            public MDRRuleGroupInstance fetchByPrimaryKey(Serializable primaryKey)
5040                    throws SystemException {
5041                    MDRRuleGroupInstance mdrRuleGroupInstance = (MDRRuleGroupInstance)EntityCacheUtil.getResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
5042                                    MDRRuleGroupInstanceImpl.class, primaryKey);
5043    
5044                    if (mdrRuleGroupInstance == _nullMDRRuleGroupInstance) {
5045                            return null;
5046                    }
5047    
5048                    if (mdrRuleGroupInstance == null) {
5049                            Session session = null;
5050    
5051                            try {
5052                                    session = openSession();
5053    
5054                                    mdrRuleGroupInstance = (MDRRuleGroupInstance)session.get(MDRRuleGroupInstanceImpl.class,
5055                                                    primaryKey);
5056    
5057                                    if (mdrRuleGroupInstance != null) {
5058                                            cacheResult(mdrRuleGroupInstance);
5059                                    }
5060                                    else {
5061                                            EntityCacheUtil.putResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
5062                                                    MDRRuleGroupInstanceImpl.class, primaryKey,
5063                                                    _nullMDRRuleGroupInstance);
5064                                    }
5065                            }
5066                            catch (Exception e) {
5067                                    EntityCacheUtil.removeResult(MDRRuleGroupInstanceModelImpl.ENTITY_CACHE_ENABLED,
5068                                            MDRRuleGroupInstanceImpl.class, primaryKey);
5069    
5070                                    throw processException(e);
5071                            }
5072                            finally {
5073                                    closeSession(session);
5074                            }
5075                    }
5076    
5077                    return mdrRuleGroupInstance;
5078            }
5079    
5080            /**
5081             * Returns the m d r rule group instance with the primary key or returns <code>null</code> if it could not be found.
5082             *
5083             * @param ruleGroupInstanceId the primary key of the m d r rule group instance
5084             * @return the m d r rule group instance, or <code>null</code> if a m d r rule group instance with the primary key could not be found
5085             * @throws SystemException if a system exception occurred
5086             */
5087            public MDRRuleGroupInstance fetchByPrimaryKey(long ruleGroupInstanceId)
5088                    throws SystemException {
5089                    return fetchByPrimaryKey((Serializable)ruleGroupInstanceId);
5090            }
5091    
5092            /**
5093             * Returns all the m d r rule group instances.
5094             *
5095             * @return the m d r rule group instances
5096             * @throws SystemException if a system exception occurred
5097             */
5098            public List<MDRRuleGroupInstance> findAll() throws SystemException {
5099                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5100            }
5101    
5102            /**
5103             * Returns a range of all the m d r rule group instances.
5104             *
5105             * <p>
5106             * 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.MDRRuleGroupInstanceModelImpl}. 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.
5107             * </p>
5108             *
5109             * @param start the lower bound of the range of m d r rule group instances
5110             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
5111             * @return the range of m d r rule group instances
5112             * @throws SystemException if a system exception occurred
5113             */
5114            public List<MDRRuleGroupInstance> findAll(int start, int end)
5115                    throws SystemException {
5116                    return findAll(start, end, null);
5117            }
5118    
5119            /**
5120             * Returns an ordered range of all the m d r rule group instances.
5121             *
5122             * <p>
5123             * 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.MDRRuleGroupInstanceModelImpl}. 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.
5124             * </p>
5125             *
5126             * @param start the lower bound of the range of m d r rule group instances
5127             * @param end the upper bound of the range of m d r rule group instances (not inclusive)
5128             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5129             * @return the ordered range of m d r rule group instances
5130             * @throws SystemException if a system exception occurred
5131             */
5132            public List<MDRRuleGroupInstance> findAll(int start, int end,
5133                    OrderByComparator orderByComparator) throws SystemException {
5134                    boolean pagination = true;
5135                    FinderPath finderPath = null;
5136                    Object[] finderArgs = null;
5137    
5138                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5139                                    (orderByComparator == null)) {
5140                            pagination = false;
5141                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5142                            finderArgs = FINDER_ARGS_EMPTY;
5143                    }
5144                    else {
5145                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5146                            finderArgs = new Object[] { start, end, orderByComparator };
5147                    }
5148    
5149                    List<MDRRuleGroupInstance> list = (List<MDRRuleGroupInstance>)FinderCacheUtil.getResult(finderPath,
5150                                    finderArgs, this);
5151    
5152                    if (list == null) {
5153                            StringBundler query = null;
5154                            String sql = null;
5155    
5156                            if (orderByComparator != null) {
5157                                    query = new StringBundler(2 +
5158                                                    (orderByComparator.getOrderByFields().length * 3));
5159    
5160                                    query.append(_SQL_SELECT_MDRRULEGROUPINSTANCE);
5161    
5162                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5163                                            orderByComparator);
5164    
5165                                    sql = query.toString();
5166                            }
5167                            else {
5168                                    sql = _SQL_SELECT_MDRRULEGROUPINSTANCE;
5169    
5170                                    if (pagination) {
5171                                            sql = sql.concat(MDRRuleGroupInstanceModelImpl.ORDER_BY_JPQL);
5172                                    }
5173                            }
5174    
5175                            Session session = null;
5176    
5177                            try {
5178                                    session = openSession();
5179    
5180                                    Query q = session.createQuery(sql);
5181    
5182                                    if (!pagination) {
5183                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
5184                                                            getDialect(), start, end, false);
5185    
5186                                            Collections.sort(list);
5187    
5188                                            list = new UnmodifiableList<MDRRuleGroupInstance>(list);
5189                                    }
5190                                    else {
5191                                            list = (List<MDRRuleGroupInstance>)QueryUtil.list(q,
5192                                                            getDialect(), start, end);
5193                                    }
5194    
5195                                    cacheResult(list);
5196    
5197                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5198                            }
5199                            catch (Exception e) {
5200                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5201    
5202                                    throw processException(e);
5203                            }
5204                            finally {
5205                                    closeSession(session);
5206                            }
5207                    }
5208    
5209                    return list;
5210            }
5211    
5212            /**
5213             * Removes all the m d r rule group instances from the database.
5214             *
5215             * @throws SystemException if a system exception occurred
5216             */
5217            public void removeAll() throws SystemException {
5218                    for (MDRRuleGroupInstance mdrRuleGroupInstance : findAll()) {
5219                            remove(mdrRuleGroupInstance);
5220                    }
5221            }
5222    
5223            /**
5224             * Returns the number of m d r rule group instances.
5225             *
5226             * @return the number of m d r rule group instances
5227             * @throws SystemException if a system exception occurred
5228             */
5229            public int countAll() throws SystemException {
5230                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
5231                                    FINDER_ARGS_EMPTY, this);
5232    
5233                    if (count == null) {
5234                            Session session = null;
5235    
5236                            try {
5237                                    session = openSession();
5238    
5239                                    Query q = session.createQuery(_SQL_COUNT_MDRRULEGROUPINSTANCE);
5240    
5241                                    count = (Long)q.uniqueResult();
5242    
5243                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
5244                                            FINDER_ARGS_EMPTY, count);
5245                            }
5246                            catch (Exception e) {
5247                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
5248                                            FINDER_ARGS_EMPTY);
5249    
5250                                    throw processException(e);
5251                            }
5252                            finally {
5253                                    closeSession(session);
5254                            }
5255                    }
5256    
5257                    return count.intValue();
5258            }
5259    
5260            /**
5261             * Initializes the m d r rule group instance persistence.
5262             */
5263            public void afterPropertiesSet() {
5264                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5265                                            com.liferay.portal.util.PropsUtil.get(
5266                                                    "value.object.listener.com.liferay.portlet.mobiledevicerules.model.MDRRuleGroupInstance")));
5267    
5268                    if (listenerClassNames.length > 0) {
5269                            try {
5270                                    List<ModelListener<MDRRuleGroupInstance>> listenersList = new ArrayList<ModelListener<MDRRuleGroupInstance>>();
5271    
5272                                    for (String listenerClassName : listenerClassNames) {
5273                                            listenersList.add((ModelListener<MDRRuleGroupInstance>)InstanceFactory.newInstance(
5274                                                            listenerClassName));
5275                                    }
5276    
5277                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5278                            }
5279                            catch (Exception e) {
5280                                    _log.error(e);
5281                            }
5282                    }
5283            }
5284    
5285            public void destroy() {
5286                    EntityCacheUtil.removeCache(MDRRuleGroupInstanceImpl.class.getName());
5287                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5288                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5289                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5290            }
5291    
5292            private static final String _SQL_SELECT_MDRRULEGROUPINSTANCE = "SELECT mdrRuleGroupInstance FROM MDRRuleGroupInstance mdrRuleGroupInstance";
5293            private static final String _SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE = "SELECT mdrRuleGroupInstance FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5294            private static final String _SQL_COUNT_MDRRULEGROUPINSTANCE = "SELECT COUNT(mdrRuleGroupInstance) FROM MDRRuleGroupInstance mdrRuleGroupInstance";
5295            private static final String _SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE = "SELECT COUNT(mdrRuleGroupInstance) FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5296            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mdrRuleGroupInstance.ruleGroupInstanceId";
5297            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_WHERE = "SELECT DISTINCT {mdrRuleGroupInstance.*} FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5298            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_1 =
5299                    "SELECT {MDRRuleGroupInstance.*} FROM (SELECT DISTINCT mdrRuleGroupInstance.ruleGroupInstanceId FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5300            private static final String _FILTER_SQL_SELECT_MDRRULEGROUPINSTANCE_NO_INLINE_DISTINCT_WHERE_2 =
5301                    ") TEMP_TABLE INNER JOIN MDRRuleGroupInstance ON TEMP_TABLE.ruleGroupInstanceId = MDRRuleGroupInstance.ruleGroupInstanceId";
5302            private static final String _FILTER_SQL_COUNT_MDRRULEGROUPINSTANCE_WHERE = "SELECT COUNT(DISTINCT mdrRuleGroupInstance.ruleGroupInstanceId) AS COUNT_VALUE FROM MDRRuleGroupInstance mdrRuleGroupInstance WHERE ";
5303            private static final String _FILTER_ENTITY_ALIAS = "mdrRuleGroupInstance";
5304            private static final String _FILTER_ENTITY_TABLE = "MDRRuleGroupInstance";
5305            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRuleGroupInstance.";
5306            private static final String _ORDER_BY_ENTITY_TABLE = "MDRRuleGroupInstance.";
5307            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRuleGroupInstance exists with the primary key ";
5308            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRuleGroupInstance exists with the key {";
5309            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
5310            private static Log _log = LogFactoryUtil.getLog(MDRRuleGroupInstancePersistenceImpl.class);
5311            private static MDRRuleGroupInstance _nullMDRRuleGroupInstance = new MDRRuleGroupInstanceImpl() {
5312                            @Override
5313                            public Object clone() {
5314                                    return this;
5315                            }
5316    
5317                            @Override
5318                            public CacheModel<MDRRuleGroupInstance> toCacheModel() {
5319                                    return _nullMDRRuleGroupInstanceCacheModel;
5320                            }
5321                    };
5322    
5323            private static CacheModel<MDRRuleGroupInstance> _nullMDRRuleGroupInstanceCacheModel =
5324                    new CacheModel<MDRRuleGroupInstance>() {
5325                            public MDRRuleGroupInstance toEntityModel() {
5326                                    return _nullMDRRuleGroupInstance;
5327                            }
5328                    };
5329    }