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