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