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