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