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