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            public MDRRulePersistenceImpl() {
1941                    setModelClass(MDRRule.class);
1942            }
1943    
1944            /**
1945             * Caches the m d r rule in the entity cache if it is enabled.
1946             *
1947             * @param mdrRule the m d r rule
1948             */
1949            @Override
1950            public void cacheResult(MDRRule mdrRule) {
1951                    EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1952                            MDRRuleImpl.class, mdrRule.getPrimaryKey(), mdrRule);
1953    
1954                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1955                            new Object[] { mdrRule.getUuid(), mdrRule.getGroupId() }, mdrRule);
1956    
1957                    mdrRule.resetOriginalValues();
1958            }
1959    
1960            /**
1961             * Caches the m d r rules in the entity cache if it is enabled.
1962             *
1963             * @param mdrRules the m d r rules
1964             */
1965            @Override
1966            public void cacheResult(List<MDRRule> mdrRules) {
1967                    for (MDRRule mdrRule : mdrRules) {
1968                            if (EntityCacheUtil.getResult(
1969                                                    MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
1970                                                    MDRRuleImpl.class, mdrRule.getPrimaryKey()) == null) {
1971                                    cacheResult(mdrRule);
1972                            }
1973                            else {
1974                                    mdrRule.resetOriginalValues();
1975                            }
1976                    }
1977            }
1978    
1979            /**
1980             * Clears the cache for all m d r rules.
1981             *
1982             * <p>
1983             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1984             * </p>
1985             */
1986            @Override
1987            public void clearCache() {
1988                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1989                            CacheRegistryUtil.clear(MDRRuleImpl.class.getName());
1990                    }
1991    
1992                    EntityCacheUtil.clearCache(MDRRuleImpl.class.getName());
1993    
1994                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1995                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1996                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1997            }
1998    
1999            /**
2000             * Clears the cache for the m d r rule.
2001             *
2002             * <p>
2003             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2004             * </p>
2005             */
2006            @Override
2007            public void clearCache(MDRRule mdrRule) {
2008                    EntityCacheUtil.removeResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2009                            MDRRuleImpl.class, mdrRule.getPrimaryKey());
2010    
2011                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2012                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2013    
2014                    clearUniqueFindersCache(mdrRule);
2015            }
2016    
2017            @Override
2018            public void clearCache(List<MDRRule> mdrRules) {
2019                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2020                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2021    
2022                    for (MDRRule mdrRule : mdrRules) {
2023                            EntityCacheUtil.removeResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2024                                    MDRRuleImpl.class, mdrRule.getPrimaryKey());
2025    
2026                            clearUniqueFindersCache(mdrRule);
2027                    }
2028            }
2029    
2030            protected void cacheUniqueFindersCache(MDRRule mdrRule) {
2031                    if (mdrRule.isNew()) {
2032                            Object[] args = new Object[] { mdrRule.getUuid(), mdrRule.getGroupId() };
2033    
2034                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2035                                    Long.valueOf(1));
2036                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args, mdrRule);
2037                    }
2038                    else {
2039                            MDRRuleModelImpl mdrRuleModelImpl = (MDRRuleModelImpl)mdrRule;
2040    
2041                            if ((mdrRuleModelImpl.getColumnBitmask() &
2042                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2043                                    Object[] args = new Object[] {
2044                                                    mdrRule.getUuid(), mdrRule.getGroupId()
2045                                            };
2046    
2047                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2048                                            Long.valueOf(1));
2049                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2050                                            mdrRule);
2051                            }
2052                    }
2053            }
2054    
2055            protected void clearUniqueFindersCache(MDRRule mdrRule) {
2056                    MDRRuleModelImpl mdrRuleModelImpl = (MDRRuleModelImpl)mdrRule;
2057    
2058                    Object[] args = new Object[] { mdrRule.getUuid(), mdrRule.getGroupId() };
2059    
2060                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2061                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2062    
2063                    if ((mdrRuleModelImpl.getColumnBitmask() &
2064                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2065                            args = new Object[] {
2066                                            mdrRuleModelImpl.getOriginalUuid(),
2067                                            mdrRuleModelImpl.getOriginalGroupId()
2068                                    };
2069    
2070                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2071                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2072                    }
2073            }
2074    
2075            /**
2076             * Creates a new m d r rule with the primary key. Does not add the m d r rule to the database.
2077             *
2078             * @param ruleId the primary key for the new m d r rule
2079             * @return the new m d r rule
2080             */
2081            @Override
2082            public MDRRule create(long ruleId) {
2083                    MDRRule mdrRule = new MDRRuleImpl();
2084    
2085                    mdrRule.setNew(true);
2086                    mdrRule.setPrimaryKey(ruleId);
2087    
2088                    String uuid = PortalUUIDUtil.generate();
2089    
2090                    mdrRule.setUuid(uuid);
2091    
2092                    return mdrRule;
2093            }
2094    
2095            /**
2096             * Removes the m d r rule with the primary key from the database. Also notifies the appropriate model listeners.
2097             *
2098             * @param ruleId the primary key of the m d r rule
2099             * @return the m d r rule that was removed
2100             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
2101             * @throws SystemException if a system exception occurred
2102             */
2103            @Override
2104            public MDRRule remove(long ruleId)
2105                    throws NoSuchRuleException, SystemException {
2106                    return remove((Serializable)ruleId);
2107            }
2108    
2109            /**
2110             * Removes the m d r rule with the primary key from the database. Also notifies the appropriate model listeners.
2111             *
2112             * @param primaryKey the primary key of the m d r rule
2113             * @return the m d r rule that was removed
2114             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
2115             * @throws SystemException if a system exception occurred
2116             */
2117            @Override
2118            public MDRRule remove(Serializable primaryKey)
2119                    throws NoSuchRuleException, SystemException {
2120                    Session session = null;
2121    
2122                    try {
2123                            session = openSession();
2124    
2125                            MDRRule mdrRule = (MDRRule)session.get(MDRRuleImpl.class, primaryKey);
2126    
2127                            if (mdrRule == null) {
2128                                    if (_log.isWarnEnabled()) {
2129                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2130                                    }
2131    
2132                                    throw new NoSuchRuleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2133                                            primaryKey);
2134                            }
2135    
2136                            return remove(mdrRule);
2137                    }
2138                    catch (NoSuchRuleException nsee) {
2139                            throw nsee;
2140                    }
2141                    catch (Exception e) {
2142                            throw processException(e);
2143                    }
2144                    finally {
2145                            closeSession(session);
2146                    }
2147            }
2148    
2149            @Override
2150            protected MDRRule removeImpl(MDRRule mdrRule) throws SystemException {
2151                    mdrRule = toUnwrappedModel(mdrRule);
2152    
2153                    Session session = null;
2154    
2155                    try {
2156                            session = openSession();
2157    
2158                            if (!session.contains(mdrRule)) {
2159                                    mdrRule = (MDRRule)session.get(MDRRuleImpl.class,
2160                                                    mdrRule.getPrimaryKeyObj());
2161                            }
2162    
2163                            if (mdrRule != null) {
2164                                    session.delete(mdrRule);
2165                            }
2166                    }
2167                    catch (Exception e) {
2168                            throw processException(e);
2169                    }
2170                    finally {
2171                            closeSession(session);
2172                    }
2173    
2174                    if (mdrRule != null) {
2175                            clearCache(mdrRule);
2176                    }
2177    
2178                    return mdrRule;
2179            }
2180    
2181            @Override
2182            public MDRRule updateImpl(
2183                    com.liferay.portlet.mobiledevicerules.model.MDRRule mdrRule)
2184                    throws SystemException {
2185                    mdrRule = toUnwrappedModel(mdrRule);
2186    
2187                    boolean isNew = mdrRule.isNew();
2188    
2189                    MDRRuleModelImpl mdrRuleModelImpl = (MDRRuleModelImpl)mdrRule;
2190    
2191                    if (Validator.isNull(mdrRule.getUuid())) {
2192                            String uuid = PortalUUIDUtil.generate();
2193    
2194                            mdrRule.setUuid(uuid);
2195                    }
2196    
2197                    Session session = null;
2198    
2199                    try {
2200                            session = openSession();
2201    
2202                            if (mdrRule.isNew()) {
2203                                    session.save(mdrRule);
2204    
2205                                    mdrRule.setNew(false);
2206                            }
2207                            else {
2208                                    session.merge(mdrRule);
2209                            }
2210                    }
2211                    catch (Exception e) {
2212                            throw processException(e);
2213                    }
2214                    finally {
2215                            closeSession(session);
2216                    }
2217    
2218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2219    
2220                    if (isNew || !MDRRuleModelImpl.COLUMN_BITMASK_ENABLED) {
2221                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2222                    }
2223    
2224                    else {
2225                            if ((mdrRuleModelImpl.getColumnBitmask() &
2226                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2227                                    Object[] args = new Object[] { mdrRuleModelImpl.getOriginalUuid() };
2228    
2229                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2230                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2231                                            args);
2232    
2233                                    args = new Object[] { mdrRuleModelImpl.getUuid() };
2234    
2235                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2236                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2237                                            args);
2238                            }
2239    
2240                            if ((mdrRuleModelImpl.getColumnBitmask() &
2241                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2242                                    Object[] args = new Object[] {
2243                                                    mdrRuleModelImpl.getOriginalUuid(),
2244                                                    mdrRuleModelImpl.getOriginalCompanyId()
2245                                            };
2246    
2247                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2248                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2249                                            args);
2250    
2251                                    args = new Object[] {
2252                                                    mdrRuleModelImpl.getUuid(),
2253                                                    mdrRuleModelImpl.getCompanyId()
2254                                            };
2255    
2256                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2257                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2258                                            args);
2259                            }
2260    
2261                            if ((mdrRuleModelImpl.getColumnBitmask() &
2262                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID.getColumnBitmask()) != 0) {
2263                                    Object[] args = new Object[] {
2264                                                    mdrRuleModelImpl.getOriginalRuleGroupId()
2265                                            };
2266    
2267                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
2268                                            args);
2269                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
2270                                            args);
2271    
2272                                    args = new Object[] { mdrRuleModelImpl.getRuleGroupId() };
2273    
2274                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RULEGROUPID,
2275                                            args);
2276                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RULEGROUPID,
2277                                            args);
2278                            }
2279                    }
2280    
2281                    EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2282                            MDRRuleImpl.class, mdrRule.getPrimaryKey(), mdrRule);
2283    
2284                    clearUniqueFindersCache(mdrRule);
2285                    cacheUniqueFindersCache(mdrRule);
2286    
2287                    return mdrRule;
2288            }
2289    
2290            protected MDRRule toUnwrappedModel(MDRRule mdrRule) {
2291                    if (mdrRule instanceof MDRRuleImpl) {
2292                            return mdrRule;
2293                    }
2294    
2295                    MDRRuleImpl mdrRuleImpl = new MDRRuleImpl();
2296    
2297                    mdrRuleImpl.setNew(mdrRule.isNew());
2298                    mdrRuleImpl.setPrimaryKey(mdrRule.getPrimaryKey());
2299    
2300                    mdrRuleImpl.setUuid(mdrRule.getUuid());
2301                    mdrRuleImpl.setRuleId(mdrRule.getRuleId());
2302                    mdrRuleImpl.setGroupId(mdrRule.getGroupId());
2303                    mdrRuleImpl.setCompanyId(mdrRule.getCompanyId());
2304                    mdrRuleImpl.setUserId(mdrRule.getUserId());
2305                    mdrRuleImpl.setUserName(mdrRule.getUserName());
2306                    mdrRuleImpl.setCreateDate(mdrRule.getCreateDate());
2307                    mdrRuleImpl.setModifiedDate(mdrRule.getModifiedDate());
2308                    mdrRuleImpl.setRuleGroupId(mdrRule.getRuleGroupId());
2309                    mdrRuleImpl.setName(mdrRule.getName());
2310                    mdrRuleImpl.setDescription(mdrRule.getDescription());
2311                    mdrRuleImpl.setType(mdrRule.getType());
2312                    mdrRuleImpl.setTypeSettings(mdrRule.getTypeSettings());
2313    
2314                    return mdrRuleImpl;
2315            }
2316    
2317            /**
2318             * Returns the m d r rule with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2319             *
2320             * @param primaryKey the primary key of the m d r rule
2321             * @return the m d r rule
2322             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
2323             * @throws SystemException if a system exception occurred
2324             */
2325            @Override
2326            public MDRRule findByPrimaryKey(Serializable primaryKey)
2327                    throws NoSuchRuleException, SystemException {
2328                    MDRRule mdrRule = fetchByPrimaryKey(primaryKey);
2329    
2330                    if (mdrRule == null) {
2331                            if (_log.isWarnEnabled()) {
2332                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2333                            }
2334    
2335                            throw new NoSuchRuleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2336                                    primaryKey);
2337                    }
2338    
2339                    return mdrRule;
2340            }
2341    
2342            /**
2343             * 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.
2344             *
2345             * @param ruleId the primary key of the m d r rule
2346             * @return the m d r rule
2347             * @throws com.liferay.portlet.mobiledevicerules.NoSuchRuleException if a m d r rule with the primary key could not be found
2348             * @throws SystemException if a system exception occurred
2349             */
2350            @Override
2351            public MDRRule findByPrimaryKey(long ruleId)
2352                    throws NoSuchRuleException, SystemException {
2353                    return findByPrimaryKey((Serializable)ruleId);
2354            }
2355    
2356            /**
2357             * Returns the m d r rule with the primary key or returns <code>null</code> if it could not be found.
2358             *
2359             * @param primaryKey the primary key of the m d r rule
2360             * @return the m d r rule, or <code>null</code> if a m d r rule with the primary key could not be found
2361             * @throws SystemException if a system exception occurred
2362             */
2363            @Override
2364            public MDRRule fetchByPrimaryKey(Serializable primaryKey)
2365                    throws SystemException {
2366                    MDRRule mdrRule = (MDRRule)EntityCacheUtil.getResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2367                                    MDRRuleImpl.class, primaryKey);
2368    
2369                    if (mdrRule == _nullMDRRule) {
2370                            return null;
2371                    }
2372    
2373                    if (mdrRule == null) {
2374                            Session session = null;
2375    
2376                            try {
2377                                    session = openSession();
2378    
2379                                    mdrRule = (MDRRule)session.get(MDRRuleImpl.class, primaryKey);
2380    
2381                                    if (mdrRule != null) {
2382                                            cacheResult(mdrRule);
2383                                    }
2384                                    else {
2385                                            EntityCacheUtil.putResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2386                                                    MDRRuleImpl.class, primaryKey, _nullMDRRule);
2387                                    }
2388                            }
2389                            catch (Exception e) {
2390                                    EntityCacheUtil.removeResult(MDRRuleModelImpl.ENTITY_CACHE_ENABLED,
2391                                            MDRRuleImpl.class, primaryKey);
2392    
2393                                    throw processException(e);
2394                            }
2395                            finally {
2396                                    closeSession(session);
2397                            }
2398                    }
2399    
2400                    return mdrRule;
2401            }
2402    
2403            /**
2404             * Returns the m d r rule with the primary key or returns <code>null</code> if it could not be found.
2405             *
2406             * @param ruleId the primary key of the m d r rule
2407             * @return the m d r rule, or <code>null</code> if a m d r rule with the primary key could not be found
2408             * @throws SystemException if a system exception occurred
2409             */
2410            @Override
2411            public MDRRule fetchByPrimaryKey(long ruleId) throws SystemException {
2412                    return fetchByPrimaryKey((Serializable)ruleId);
2413            }
2414    
2415            /**
2416             * Returns all the m d r rules.
2417             *
2418             * @return the m d r rules
2419             * @throws SystemException if a system exception occurred
2420             */
2421            @Override
2422            public List<MDRRule> findAll() throws SystemException {
2423                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2424            }
2425    
2426            /**
2427             * Returns a range of all the m d r rules.
2428             *
2429             * <p>
2430             * 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.
2431             * </p>
2432             *
2433             * @param start the lower bound of the range of m d r rules
2434             * @param end the upper bound of the range of m d r rules (not inclusive)
2435             * @return the range of m d r rules
2436             * @throws SystemException if a system exception occurred
2437             */
2438            @Override
2439            public List<MDRRule> findAll(int start, int end) throws SystemException {
2440                    return findAll(start, end, null);
2441            }
2442    
2443            /**
2444             * Returns an ordered range of all the m d r rules.
2445             *
2446             * <p>
2447             * 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.
2448             * </p>
2449             *
2450             * @param start the lower bound of the range of m d r rules
2451             * @param end the upper bound of the range of m d r rules (not inclusive)
2452             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2453             * @return the ordered range of m d r rules
2454             * @throws SystemException if a system exception occurred
2455             */
2456            @Override
2457            public List<MDRRule> findAll(int start, int end,
2458                    OrderByComparator orderByComparator) throws SystemException {
2459                    boolean pagination = true;
2460                    FinderPath finderPath = null;
2461                    Object[] finderArgs = null;
2462    
2463                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2464                                    (orderByComparator == null)) {
2465                            pagination = false;
2466                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2467                            finderArgs = FINDER_ARGS_EMPTY;
2468                    }
2469                    else {
2470                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2471                            finderArgs = new Object[] { start, end, orderByComparator };
2472                    }
2473    
2474                    List<MDRRule> list = (List<MDRRule>)FinderCacheUtil.getResult(finderPath,
2475                                    finderArgs, this);
2476    
2477                    if (list == null) {
2478                            StringBundler query = null;
2479                            String sql = null;
2480    
2481                            if (orderByComparator != null) {
2482                                    query = new StringBundler(2 +
2483                                                    (orderByComparator.getOrderByFields().length * 3));
2484    
2485                                    query.append(_SQL_SELECT_MDRRULE);
2486    
2487                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2488                                            orderByComparator);
2489    
2490                                    sql = query.toString();
2491                            }
2492                            else {
2493                                    sql = _SQL_SELECT_MDRRULE;
2494    
2495                                    if (pagination) {
2496                                            sql = sql.concat(MDRRuleModelImpl.ORDER_BY_JPQL);
2497                                    }
2498                            }
2499    
2500                            Session session = null;
2501    
2502                            try {
2503                                    session = openSession();
2504    
2505                                    Query q = session.createQuery(sql);
2506    
2507                                    if (!pagination) {
2508                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
2509                                                            start, end, false);
2510    
2511                                            Collections.sort(list);
2512    
2513                                            list = new UnmodifiableList<MDRRule>(list);
2514                                    }
2515                                    else {
2516                                            list = (List<MDRRule>)QueryUtil.list(q, getDialect(),
2517                                                            start, end);
2518                                    }
2519    
2520                                    cacheResult(list);
2521    
2522                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2523                            }
2524                            catch (Exception e) {
2525                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2526    
2527                                    throw processException(e);
2528                            }
2529                            finally {
2530                                    closeSession(session);
2531                            }
2532                    }
2533    
2534                    return list;
2535            }
2536    
2537            /**
2538             * Removes all the m d r rules from the database.
2539             *
2540             * @throws SystemException if a system exception occurred
2541             */
2542            @Override
2543            public void removeAll() throws SystemException {
2544                    for (MDRRule mdrRule : findAll()) {
2545                            remove(mdrRule);
2546                    }
2547            }
2548    
2549            /**
2550             * Returns the number of m d r rules.
2551             *
2552             * @return the number of m d r rules
2553             * @throws SystemException if a system exception occurred
2554             */
2555            @Override
2556            public int countAll() throws SystemException {
2557                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2558                                    FINDER_ARGS_EMPTY, this);
2559    
2560                    if (count == null) {
2561                            Session session = null;
2562    
2563                            try {
2564                                    session = openSession();
2565    
2566                                    Query q = session.createQuery(_SQL_COUNT_MDRRULE);
2567    
2568                                    count = (Long)q.uniqueResult();
2569    
2570                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2571                                            FINDER_ARGS_EMPTY, count);
2572                            }
2573                            catch (Exception e) {
2574                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2575                                            FINDER_ARGS_EMPTY);
2576    
2577                                    throw processException(e);
2578                            }
2579                            finally {
2580                                    closeSession(session);
2581                            }
2582                    }
2583    
2584                    return count.intValue();
2585            }
2586    
2587            @Override
2588            protected Set<String> getBadColumnNames() {
2589                    return _badColumnNames;
2590            }
2591    
2592            /**
2593             * Initializes the m d r rule persistence.
2594             */
2595            public void afterPropertiesSet() {
2596                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2597                                            com.liferay.portal.util.PropsUtil.get(
2598                                                    "value.object.listener.com.liferay.portlet.mobiledevicerules.model.MDRRule")));
2599    
2600                    if (listenerClassNames.length > 0) {
2601                            try {
2602                                    List<ModelListener<MDRRule>> listenersList = new ArrayList<ModelListener<MDRRule>>();
2603    
2604                                    for (String listenerClassName : listenerClassNames) {
2605                                            listenersList.add((ModelListener<MDRRule>)InstanceFactory.newInstance(
2606                                                            getClassLoader(), listenerClassName));
2607                                    }
2608    
2609                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2610                            }
2611                            catch (Exception e) {
2612                                    _log.error(e);
2613                            }
2614                    }
2615            }
2616    
2617            public void destroy() {
2618                    EntityCacheUtil.removeCache(MDRRuleImpl.class.getName());
2619                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2620                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2621                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2622            }
2623    
2624            private static final String _SQL_SELECT_MDRRULE = "SELECT mdrRule FROM MDRRule mdrRule";
2625            private static final String _SQL_SELECT_MDRRULE_WHERE = "SELECT mdrRule FROM MDRRule mdrRule WHERE ";
2626            private static final String _SQL_COUNT_MDRRULE = "SELECT COUNT(mdrRule) FROM MDRRule mdrRule";
2627            private static final String _SQL_COUNT_MDRRULE_WHERE = "SELECT COUNT(mdrRule) FROM MDRRule mdrRule WHERE ";
2628            private static final String _ORDER_BY_ENTITY_ALIAS = "mdrRule.";
2629            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MDRRule exists with the primary key ";
2630            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MDRRule exists with the key {";
2631            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2632            private static Log _log = LogFactoryUtil.getLog(MDRRulePersistenceImpl.class);
2633            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2634                                    "uuid", "type"
2635                            });
2636            private static MDRRule _nullMDRRule = new MDRRuleImpl() {
2637                            @Override
2638                            public Object clone() {
2639                                    return this;
2640                            }
2641    
2642                            @Override
2643                            public CacheModel<MDRRule> toCacheModel() {
2644                                    return _nullMDRRuleCacheModel;
2645                            }
2646                    };
2647    
2648            private static CacheModel<MDRRule> _nullMDRRuleCacheModel = new CacheModel<MDRRule>() {
2649                            @Override
2650                            public MDRRule toEntityModel() {
2651                                    return _nullMDRRule;
2652                            }
2653                    };
2654    }