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