001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchBackgroundTaskException;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.ArrayUtil;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.model.BackgroundTask;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.MVCCModel;
039    import com.liferay.portal.model.impl.BackgroundTaskImpl;
040    import com.liferay.portal.model.impl.BackgroundTaskModelImpl;
041    import com.liferay.portal.service.persistence.BackgroundTaskPersistence;
042    
043    import java.io.Serializable;
044    
045    import java.util.Collections;
046    import java.util.HashMap;
047    import java.util.HashSet;
048    import java.util.Iterator;
049    import java.util.List;
050    import java.util.Map;
051    import java.util.Set;
052    
053    /**
054     * The persistence implementation for the background task service.
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see BackgroundTaskPersistence
062     * @see BackgroundTaskUtil
063     * @generated
064     */
065    @ProviderType
066    public class BackgroundTaskPersistenceImpl extends BasePersistenceImpl<BackgroundTask>
067            implements BackgroundTaskPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link BackgroundTaskUtil} to access the background task persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = BackgroundTaskImpl.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(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
079                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
080                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
081                            "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
083                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
084                            BackgroundTaskImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
087                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
090                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
091                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
092                            "findByGroupId",
093                            new String[] {
094                                    Long.class.getName(),
095                                    
096                            Integer.class.getName(), Integer.class.getName(),
097                                    OrderByComparator.class.getName()
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
100                    new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
101                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
102                            BackgroundTaskImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
104                            new String[] { Long.class.getName() },
105                            BackgroundTaskModelImpl.GROUPID_COLUMN_BITMASK |
106                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
107            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
108                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
110                            new String[] { Long.class.getName() });
111    
112            /**
113             * Returns all the background tasks where groupId = &#63;.
114             *
115             * @param groupId the group ID
116             * @return the matching background tasks
117             */
118            @Override
119            public List<BackgroundTask> findByGroupId(long groupId) {
120                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the background tasks where groupId = &#63;.
125             *
126             * <p>
127             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
128             * </p>
129             *
130             * @param groupId the group ID
131             * @param start the lower bound of the range of background tasks
132             * @param end the upper bound of the range of background tasks (not inclusive)
133             * @return the range of matching background tasks
134             */
135            @Override
136            public List<BackgroundTask> findByGroupId(long groupId, int start, int end) {
137                    return findByGroupId(groupId, start, end, null);
138            }
139    
140            /**
141             * Returns an ordered range of all the background tasks where groupId = &#63;.
142             *
143             * <p>
144             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
145             * </p>
146             *
147             * @param groupId the group ID
148             * @param start the lower bound of the range of background tasks
149             * @param end the upper bound of the range of background tasks (not inclusive)
150             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
151             * @return the ordered range of matching background tasks
152             */
153            @Override
154            public List<BackgroundTask> findByGroupId(long groupId, int start, int end,
155                    OrderByComparator<BackgroundTask> orderByComparator) {
156                    boolean pagination = true;
157                    FinderPath finderPath = null;
158                    Object[] finderArgs = null;
159    
160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161                                    (orderByComparator == null)) {
162                            pagination = false;
163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
164                            finderArgs = new Object[] { groupId };
165                    }
166                    else {
167                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
168                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
169                    }
170    
171                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
172                                    finderArgs, this);
173    
174                    if ((list != null) && !list.isEmpty()) {
175                            for (BackgroundTask backgroundTask : list) {
176                                    if ((groupId != backgroundTask.getGroupId())) {
177                                            list = null;
178    
179                                            break;
180                                    }
181                            }
182                    }
183    
184                    if (list == null) {
185                            StringBundler query = null;
186    
187                            if (orderByComparator != null) {
188                                    query = new StringBundler(3 +
189                                                    (orderByComparator.getOrderByFields().length * 3));
190                            }
191                            else {
192                                    query = new StringBundler(3);
193                            }
194    
195                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
196    
197                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
198    
199                            if (orderByComparator != null) {
200                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
201                                            orderByComparator);
202                            }
203                            else
204                             if (pagination) {
205                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
206                            }
207    
208                            String sql = query.toString();
209    
210                            Session session = null;
211    
212                            try {
213                                    session = openSession();
214    
215                                    Query q = session.createQuery(sql);
216    
217                                    QueryPos qPos = QueryPos.getInstance(q);
218    
219                                    qPos.add(groupId);
220    
221                                    if (!pagination) {
222                                            list = (List<BackgroundTask>)QueryUtil.list(q,
223                                                            getDialect(), start, end, false);
224    
225                                            Collections.sort(list);
226    
227                                            list = Collections.unmodifiableList(list);
228                                    }
229                                    else {
230                                            list = (List<BackgroundTask>)QueryUtil.list(q,
231                                                            getDialect(), start, end);
232                                    }
233    
234                                    cacheResult(list);
235    
236                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
237                            }
238                            catch (Exception e) {
239                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
240    
241                                    throw processException(e);
242                            }
243                            finally {
244                                    closeSession(session);
245                            }
246                    }
247    
248                    return list;
249            }
250    
251            /**
252             * Returns the first background task in the ordered set where groupId = &#63;.
253             *
254             * @param groupId the group ID
255             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
256             * @return the first matching background task
257             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
258             */
259            @Override
260            public BackgroundTask findByGroupId_First(long groupId,
261                    OrderByComparator<BackgroundTask> orderByComparator)
262                    throws NoSuchBackgroundTaskException {
263                    BackgroundTask backgroundTask = fetchByGroupId_First(groupId,
264                                    orderByComparator);
265    
266                    if (backgroundTask != null) {
267                            return backgroundTask;
268                    }
269    
270                    StringBundler msg = new StringBundler(4);
271    
272                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
273    
274                    msg.append("groupId=");
275                    msg.append(groupId);
276    
277                    msg.append(StringPool.CLOSE_CURLY_BRACE);
278    
279                    throw new NoSuchBackgroundTaskException(msg.toString());
280            }
281    
282            /**
283             * Returns the first background task in the ordered set where groupId = &#63;.
284             *
285             * @param groupId the group ID
286             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
287             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
288             */
289            @Override
290            public BackgroundTask fetchByGroupId_First(long groupId,
291                    OrderByComparator<BackgroundTask> orderByComparator) {
292                    List<BackgroundTask> list = findByGroupId(groupId, 0, 1,
293                                    orderByComparator);
294    
295                    if (!list.isEmpty()) {
296                            return list.get(0);
297                    }
298    
299                    return null;
300            }
301    
302            /**
303             * Returns the last background task in the ordered set where groupId = &#63;.
304             *
305             * @param groupId the group ID
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the last matching background task
308             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
309             */
310            @Override
311            public BackgroundTask findByGroupId_Last(long groupId,
312                    OrderByComparator<BackgroundTask> orderByComparator)
313                    throws NoSuchBackgroundTaskException {
314                    BackgroundTask backgroundTask = fetchByGroupId_Last(groupId,
315                                    orderByComparator);
316    
317                    if (backgroundTask != null) {
318                            return backgroundTask;
319                    }
320    
321                    StringBundler msg = new StringBundler(4);
322    
323                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
324    
325                    msg.append("groupId=");
326                    msg.append(groupId);
327    
328                    msg.append(StringPool.CLOSE_CURLY_BRACE);
329    
330                    throw new NoSuchBackgroundTaskException(msg.toString());
331            }
332    
333            /**
334             * Returns the last background task in the ordered set where groupId = &#63;.
335             *
336             * @param groupId the group ID
337             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
338             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
339             */
340            @Override
341            public BackgroundTask fetchByGroupId_Last(long groupId,
342                    OrderByComparator<BackgroundTask> orderByComparator) {
343                    int count = countByGroupId(groupId);
344    
345                    if (count == 0) {
346                            return null;
347                    }
348    
349                    List<BackgroundTask> list = findByGroupId(groupId, count - 1, count,
350                                    orderByComparator);
351    
352                    if (!list.isEmpty()) {
353                            return list.get(0);
354                    }
355    
356                    return null;
357            }
358    
359            /**
360             * Returns the background tasks before and after the current background task in the ordered set where groupId = &#63;.
361             *
362             * @param backgroundTaskId the primary key of the current background task
363             * @param groupId the group ID
364             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
365             * @return the previous, current, and next background task
366             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
367             */
368            @Override
369            public BackgroundTask[] findByGroupId_PrevAndNext(long backgroundTaskId,
370                    long groupId, OrderByComparator<BackgroundTask> orderByComparator)
371                    throws NoSuchBackgroundTaskException {
372                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
373    
374                    Session session = null;
375    
376                    try {
377                            session = openSession();
378    
379                            BackgroundTask[] array = new BackgroundTaskImpl[3];
380    
381                            array[0] = getByGroupId_PrevAndNext(session, backgroundTask,
382                                            groupId, orderByComparator, true);
383    
384                            array[1] = backgroundTask;
385    
386                            array[2] = getByGroupId_PrevAndNext(session, backgroundTask,
387                                            groupId, orderByComparator, false);
388    
389                            return array;
390                    }
391                    catch (Exception e) {
392                            throw processException(e);
393                    }
394                    finally {
395                            closeSession(session);
396                    }
397            }
398    
399            protected BackgroundTask getByGroupId_PrevAndNext(Session session,
400                    BackgroundTask backgroundTask, long groupId,
401                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
402                    StringBundler query = null;
403    
404                    if (orderByComparator != null) {
405                            query = new StringBundler(6 +
406                                            (orderByComparator.getOrderByFields().length * 6));
407                    }
408                    else {
409                            query = new StringBundler(3);
410                    }
411    
412                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
413    
414                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
415    
416                    if (orderByComparator != null) {
417                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
418    
419                            if (orderByConditionFields.length > 0) {
420                                    query.append(WHERE_AND);
421                            }
422    
423                            for (int i = 0; i < orderByConditionFields.length; i++) {
424                                    query.append(_ORDER_BY_ENTITY_ALIAS);
425                                    query.append(orderByConditionFields[i]);
426    
427                                    if ((i + 1) < orderByConditionFields.length) {
428                                            if (orderByComparator.isAscending() ^ previous) {
429                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
430                                            }
431                                            else {
432                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
433                                            }
434                                    }
435                                    else {
436                                            if (orderByComparator.isAscending() ^ previous) {
437                                                    query.append(WHERE_GREATER_THAN);
438                                            }
439                                            else {
440                                                    query.append(WHERE_LESSER_THAN);
441                                            }
442                                    }
443                            }
444    
445                            query.append(ORDER_BY_CLAUSE);
446    
447                            String[] orderByFields = orderByComparator.getOrderByFields();
448    
449                            for (int i = 0; i < orderByFields.length; i++) {
450                                    query.append(_ORDER_BY_ENTITY_ALIAS);
451                                    query.append(orderByFields[i]);
452    
453                                    if ((i + 1) < orderByFields.length) {
454                                            if (orderByComparator.isAscending() ^ previous) {
455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
456                                            }
457                                            else {
458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
459                                            }
460                                    }
461                                    else {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(ORDER_BY_ASC);
464                                            }
465                                            else {
466                                                    query.append(ORDER_BY_DESC);
467                                            }
468                                    }
469                            }
470                    }
471                    else {
472                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
473                    }
474    
475                    String sql = query.toString();
476    
477                    Query q = session.createQuery(sql);
478    
479                    q.setFirstResult(0);
480                    q.setMaxResults(2);
481    
482                    QueryPos qPos = QueryPos.getInstance(q);
483    
484                    qPos.add(groupId);
485    
486                    if (orderByComparator != null) {
487                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
488    
489                            for (Object value : values) {
490                                    qPos.add(value);
491                            }
492                    }
493    
494                    List<BackgroundTask> list = q.list();
495    
496                    if (list.size() == 2) {
497                            return list.get(1);
498                    }
499                    else {
500                            return null;
501                    }
502            }
503    
504            /**
505             * Removes all the background tasks where groupId = &#63; from the database.
506             *
507             * @param groupId the group ID
508             */
509            @Override
510            public void removeByGroupId(long groupId) {
511                    for (BackgroundTask backgroundTask : findByGroupId(groupId,
512                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
513                            remove(backgroundTask);
514                    }
515            }
516    
517            /**
518             * Returns the number of background tasks where groupId = &#63;.
519             *
520             * @param groupId the group ID
521             * @return the number of matching background tasks
522             */
523            @Override
524            public int countByGroupId(long groupId) {
525                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
526    
527                    Object[] finderArgs = new Object[] { groupId };
528    
529                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
530                                    this);
531    
532                    if (count == null) {
533                            StringBundler query = new StringBundler(2);
534    
535                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
536    
537                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
538    
539                            String sql = query.toString();
540    
541                            Session session = null;
542    
543                            try {
544                                    session = openSession();
545    
546                                    Query q = session.createQuery(sql);
547    
548                                    QueryPos qPos = QueryPos.getInstance(q);
549    
550                                    qPos.add(groupId);
551    
552                                    count = (Long)q.uniqueResult();
553    
554                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
555                            }
556                            catch (Exception e) {
557                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
558    
559                                    throw processException(e);
560                            }
561                            finally {
562                                    closeSession(session);
563                            }
564                    }
565    
566                    return count.intValue();
567            }
568    
569            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "backgroundTask.groupId = ?";
570            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
571                    new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
572                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
573                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
574                            "findByCompanyId",
575                            new String[] {
576                                    Long.class.getName(),
577                                    
578                            Integer.class.getName(), Integer.class.getName(),
579                                    OrderByComparator.class.getName()
580                            });
581            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
582                    new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
583                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
584                            BackgroundTaskImpl.class,
585                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
586                            new String[] { Long.class.getName() },
587                            BackgroundTaskModelImpl.COMPANYID_COLUMN_BITMASK |
588                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
589            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
590                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
591                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
592                            new String[] { Long.class.getName() });
593    
594            /**
595             * Returns all the background tasks where companyId = &#63;.
596             *
597             * @param companyId the company ID
598             * @return the matching background tasks
599             */
600            @Override
601            public List<BackgroundTask> findByCompanyId(long companyId) {
602                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
603                            null);
604            }
605    
606            /**
607             * Returns a range of all the background tasks where companyId = &#63;.
608             *
609             * <p>
610             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
611             * </p>
612             *
613             * @param companyId the company ID
614             * @param start the lower bound of the range of background tasks
615             * @param end the upper bound of the range of background tasks (not inclusive)
616             * @return the range of matching background tasks
617             */
618            @Override
619            public List<BackgroundTask> findByCompanyId(long companyId, int start,
620                    int end) {
621                    return findByCompanyId(companyId, start, end, null);
622            }
623    
624            /**
625             * Returns an ordered range of all the background tasks where companyId = &#63;.
626             *
627             * <p>
628             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
629             * </p>
630             *
631             * @param companyId the company ID
632             * @param start the lower bound of the range of background tasks
633             * @param end the upper bound of the range of background tasks (not inclusive)
634             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
635             * @return the ordered range of matching background tasks
636             */
637            @Override
638            public List<BackgroundTask> findByCompanyId(long companyId, int start,
639                    int end, OrderByComparator<BackgroundTask> orderByComparator) {
640                    boolean pagination = true;
641                    FinderPath finderPath = null;
642                    Object[] finderArgs = null;
643    
644                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
645                                    (orderByComparator == null)) {
646                            pagination = false;
647                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
648                            finderArgs = new Object[] { companyId };
649                    }
650                    else {
651                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
652                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
653                    }
654    
655                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
656                                    finderArgs, this);
657    
658                    if ((list != null) && !list.isEmpty()) {
659                            for (BackgroundTask backgroundTask : list) {
660                                    if ((companyId != backgroundTask.getCompanyId())) {
661                                            list = null;
662    
663                                            break;
664                                    }
665                            }
666                    }
667    
668                    if (list == null) {
669                            StringBundler query = null;
670    
671                            if (orderByComparator != null) {
672                                    query = new StringBundler(3 +
673                                                    (orderByComparator.getOrderByFields().length * 3));
674                            }
675                            else {
676                                    query = new StringBundler(3);
677                            }
678    
679                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
680    
681                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
682    
683                            if (orderByComparator != null) {
684                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
685                                            orderByComparator);
686                            }
687                            else
688                             if (pagination) {
689                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
690                            }
691    
692                            String sql = query.toString();
693    
694                            Session session = null;
695    
696                            try {
697                                    session = openSession();
698    
699                                    Query q = session.createQuery(sql);
700    
701                                    QueryPos qPos = QueryPos.getInstance(q);
702    
703                                    qPos.add(companyId);
704    
705                                    if (!pagination) {
706                                            list = (List<BackgroundTask>)QueryUtil.list(q,
707                                                            getDialect(), start, end, false);
708    
709                                            Collections.sort(list);
710    
711                                            list = Collections.unmodifiableList(list);
712                                    }
713                                    else {
714                                            list = (List<BackgroundTask>)QueryUtil.list(q,
715                                                            getDialect(), start, end);
716                                    }
717    
718                                    cacheResult(list);
719    
720                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
721                            }
722                            catch (Exception e) {
723                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
724    
725                                    throw processException(e);
726                            }
727                            finally {
728                                    closeSession(session);
729                            }
730                    }
731    
732                    return list;
733            }
734    
735            /**
736             * Returns the first background task in the ordered set where companyId = &#63;.
737             *
738             * @param companyId the company ID
739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
740             * @return the first matching background task
741             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
742             */
743            @Override
744            public BackgroundTask findByCompanyId_First(long companyId,
745                    OrderByComparator<BackgroundTask> orderByComparator)
746                    throws NoSuchBackgroundTaskException {
747                    BackgroundTask backgroundTask = fetchByCompanyId_First(companyId,
748                                    orderByComparator);
749    
750                    if (backgroundTask != null) {
751                            return backgroundTask;
752                    }
753    
754                    StringBundler msg = new StringBundler(4);
755    
756                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
757    
758                    msg.append("companyId=");
759                    msg.append(companyId);
760    
761                    msg.append(StringPool.CLOSE_CURLY_BRACE);
762    
763                    throw new NoSuchBackgroundTaskException(msg.toString());
764            }
765    
766            /**
767             * Returns the first background task in the ordered set where companyId = &#63;.
768             *
769             * @param companyId the company ID
770             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
771             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
772             */
773            @Override
774            public BackgroundTask fetchByCompanyId_First(long companyId,
775                    OrderByComparator<BackgroundTask> orderByComparator) {
776                    List<BackgroundTask> list = findByCompanyId(companyId, 0, 1,
777                                    orderByComparator);
778    
779                    if (!list.isEmpty()) {
780                            return list.get(0);
781                    }
782    
783                    return null;
784            }
785    
786            /**
787             * Returns the last background task in the ordered set where companyId = &#63;.
788             *
789             * @param companyId the company ID
790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
791             * @return the last matching background task
792             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
793             */
794            @Override
795            public BackgroundTask findByCompanyId_Last(long companyId,
796                    OrderByComparator<BackgroundTask> orderByComparator)
797                    throws NoSuchBackgroundTaskException {
798                    BackgroundTask backgroundTask = fetchByCompanyId_Last(companyId,
799                                    orderByComparator);
800    
801                    if (backgroundTask != null) {
802                            return backgroundTask;
803                    }
804    
805                    StringBundler msg = new StringBundler(4);
806    
807                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
808    
809                    msg.append("companyId=");
810                    msg.append(companyId);
811    
812                    msg.append(StringPool.CLOSE_CURLY_BRACE);
813    
814                    throw new NoSuchBackgroundTaskException(msg.toString());
815            }
816    
817            /**
818             * Returns the last background task in the ordered set where companyId = &#63;.
819             *
820             * @param companyId the company ID
821             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
822             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
823             */
824            @Override
825            public BackgroundTask fetchByCompanyId_Last(long companyId,
826                    OrderByComparator<BackgroundTask> orderByComparator) {
827                    int count = countByCompanyId(companyId);
828    
829                    if (count == 0) {
830                            return null;
831                    }
832    
833                    List<BackgroundTask> list = findByCompanyId(companyId, count - 1,
834                                    count, orderByComparator);
835    
836                    if (!list.isEmpty()) {
837                            return list.get(0);
838                    }
839    
840                    return null;
841            }
842    
843            /**
844             * Returns the background tasks before and after the current background task in the ordered set where companyId = &#63;.
845             *
846             * @param backgroundTaskId the primary key of the current background task
847             * @param companyId the company ID
848             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
849             * @return the previous, current, and next background task
850             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
851             */
852            @Override
853            public BackgroundTask[] findByCompanyId_PrevAndNext(long backgroundTaskId,
854                    long companyId, OrderByComparator<BackgroundTask> orderByComparator)
855                    throws NoSuchBackgroundTaskException {
856                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
857    
858                    Session session = null;
859    
860                    try {
861                            session = openSession();
862    
863                            BackgroundTask[] array = new BackgroundTaskImpl[3];
864    
865                            array[0] = getByCompanyId_PrevAndNext(session, backgroundTask,
866                                            companyId, orderByComparator, true);
867    
868                            array[1] = backgroundTask;
869    
870                            array[2] = getByCompanyId_PrevAndNext(session, backgroundTask,
871                                            companyId, orderByComparator, false);
872    
873                            return array;
874                    }
875                    catch (Exception e) {
876                            throw processException(e);
877                    }
878                    finally {
879                            closeSession(session);
880                    }
881            }
882    
883            protected BackgroundTask getByCompanyId_PrevAndNext(Session session,
884                    BackgroundTask backgroundTask, long companyId,
885                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
886                    StringBundler query = null;
887    
888                    if (orderByComparator != null) {
889                            query = new StringBundler(6 +
890                                            (orderByComparator.getOrderByFields().length * 6));
891                    }
892                    else {
893                            query = new StringBundler(3);
894                    }
895    
896                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
897    
898                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
899    
900                    if (orderByComparator != null) {
901                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
902    
903                            if (orderByConditionFields.length > 0) {
904                                    query.append(WHERE_AND);
905                            }
906    
907                            for (int i = 0; i < orderByConditionFields.length; i++) {
908                                    query.append(_ORDER_BY_ENTITY_ALIAS);
909                                    query.append(orderByConditionFields[i]);
910    
911                                    if ((i + 1) < orderByConditionFields.length) {
912                                            if (orderByComparator.isAscending() ^ previous) {
913                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
914                                            }
915                                            else {
916                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
917                                            }
918                                    }
919                                    else {
920                                            if (orderByComparator.isAscending() ^ previous) {
921                                                    query.append(WHERE_GREATER_THAN);
922                                            }
923                                            else {
924                                                    query.append(WHERE_LESSER_THAN);
925                                            }
926                                    }
927                            }
928    
929                            query.append(ORDER_BY_CLAUSE);
930    
931                            String[] orderByFields = orderByComparator.getOrderByFields();
932    
933                            for (int i = 0; i < orderByFields.length; i++) {
934                                    query.append(_ORDER_BY_ENTITY_ALIAS);
935                                    query.append(orderByFields[i]);
936    
937                                    if ((i + 1) < orderByFields.length) {
938                                            if (orderByComparator.isAscending() ^ previous) {
939                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
940                                            }
941                                            else {
942                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
943                                            }
944                                    }
945                                    else {
946                                            if (orderByComparator.isAscending() ^ previous) {
947                                                    query.append(ORDER_BY_ASC);
948                                            }
949                                            else {
950                                                    query.append(ORDER_BY_DESC);
951                                            }
952                                    }
953                            }
954                    }
955                    else {
956                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
957                    }
958    
959                    String sql = query.toString();
960    
961                    Query q = session.createQuery(sql);
962    
963                    q.setFirstResult(0);
964                    q.setMaxResults(2);
965    
966                    QueryPos qPos = QueryPos.getInstance(q);
967    
968                    qPos.add(companyId);
969    
970                    if (orderByComparator != null) {
971                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
972    
973                            for (Object value : values) {
974                                    qPos.add(value);
975                            }
976                    }
977    
978                    List<BackgroundTask> list = q.list();
979    
980                    if (list.size() == 2) {
981                            return list.get(1);
982                    }
983                    else {
984                            return null;
985                    }
986            }
987    
988            /**
989             * Removes all the background tasks where companyId = &#63; from the database.
990             *
991             * @param companyId the company ID
992             */
993            @Override
994            public void removeByCompanyId(long companyId) {
995                    for (BackgroundTask backgroundTask : findByCompanyId(companyId,
996                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
997                            remove(backgroundTask);
998                    }
999            }
1000    
1001            /**
1002             * Returns the number of background tasks where companyId = &#63;.
1003             *
1004             * @param companyId the company ID
1005             * @return the number of matching background tasks
1006             */
1007            @Override
1008            public int countByCompanyId(long companyId) {
1009                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1010    
1011                    Object[] finderArgs = new Object[] { companyId };
1012    
1013                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1014                                    this);
1015    
1016                    if (count == null) {
1017                            StringBundler query = new StringBundler(2);
1018    
1019                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
1020    
1021                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1022    
1023                            String sql = query.toString();
1024    
1025                            Session session = null;
1026    
1027                            try {
1028                                    session = openSession();
1029    
1030                                    Query q = session.createQuery(sql);
1031    
1032                                    QueryPos qPos = QueryPos.getInstance(q);
1033    
1034                                    qPos.add(companyId);
1035    
1036                                    count = (Long)q.uniqueResult();
1037    
1038                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1039                            }
1040                            catch (Exception e) {
1041                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1042    
1043                                    throw processException(e);
1044                            }
1045                            finally {
1046                                    closeSession(session);
1047                            }
1048                    }
1049    
1050                    return count.intValue();
1051            }
1052    
1053            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "backgroundTask.companyId = ?";
1054            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STATUS = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
1055                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
1056                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1057                            "findByStatus",
1058                            new String[] {
1059                                    Integer.class.getName(),
1060                                    
1061                            Integer.class.getName(), Integer.class.getName(),
1062                                    OrderByComparator.class.getName()
1063                            });
1064            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STATUS =
1065                    new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
1066                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
1067                            BackgroundTaskImpl.class,
1068                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStatus",
1069                            new String[] { Integer.class.getName() },
1070                            BackgroundTaskModelImpl.STATUS_COLUMN_BITMASK |
1071                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
1072            public static final FinderPath FINDER_PATH_COUNT_BY_STATUS = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
1073                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
1074                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStatus",
1075                            new String[] { Integer.class.getName() });
1076    
1077            /**
1078             * Returns all the background tasks where status = &#63;.
1079             *
1080             * @param status the status
1081             * @return the matching background tasks
1082             */
1083            @Override
1084            public List<BackgroundTask> findByStatus(int status) {
1085                    return findByStatus(status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1086            }
1087    
1088            /**
1089             * Returns a range of all the background tasks where status = &#63;.
1090             *
1091             * <p>
1092             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
1093             * </p>
1094             *
1095             * @param status the status
1096             * @param start the lower bound of the range of background tasks
1097             * @param end the upper bound of the range of background tasks (not inclusive)
1098             * @return the range of matching background tasks
1099             */
1100            @Override
1101            public List<BackgroundTask> findByStatus(int status, int start, int end) {
1102                    return findByStatus(status, start, end, null);
1103            }
1104    
1105            /**
1106             * Returns an ordered range of all the background tasks where status = &#63;.
1107             *
1108             * <p>
1109             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
1110             * </p>
1111             *
1112             * @param status the status
1113             * @param start the lower bound of the range of background tasks
1114             * @param end the upper bound of the range of background tasks (not inclusive)
1115             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1116             * @return the ordered range of matching background tasks
1117             */
1118            @Override
1119            public List<BackgroundTask> findByStatus(int status, int start, int end,
1120                    OrderByComparator<BackgroundTask> orderByComparator) {
1121                    boolean pagination = true;
1122                    FinderPath finderPath = null;
1123                    Object[] finderArgs = null;
1124    
1125                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1126                                    (orderByComparator == null)) {
1127                            pagination = false;
1128                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STATUS;
1129                            finderArgs = new Object[] { status };
1130                    }
1131                    else {
1132                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STATUS;
1133                            finderArgs = new Object[] { status, start, end, orderByComparator };
1134                    }
1135    
1136                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
1137                                    finderArgs, this);
1138    
1139                    if ((list != null) && !list.isEmpty()) {
1140                            for (BackgroundTask backgroundTask : list) {
1141                                    if ((status != backgroundTask.getStatus())) {
1142                                            list = null;
1143    
1144                                            break;
1145                                    }
1146                            }
1147                    }
1148    
1149                    if (list == null) {
1150                            StringBundler query = null;
1151    
1152                            if (orderByComparator != null) {
1153                                    query = new StringBundler(3 +
1154                                                    (orderByComparator.getOrderByFields().length * 3));
1155                            }
1156                            else {
1157                                    query = new StringBundler(3);
1158                            }
1159    
1160                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
1161    
1162                            query.append(_FINDER_COLUMN_STATUS_STATUS_2);
1163    
1164                            if (orderByComparator != null) {
1165                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1166                                            orderByComparator);
1167                            }
1168                            else
1169                             if (pagination) {
1170                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
1171                            }
1172    
1173                            String sql = query.toString();
1174    
1175                            Session session = null;
1176    
1177                            try {
1178                                    session = openSession();
1179    
1180                                    Query q = session.createQuery(sql);
1181    
1182                                    QueryPos qPos = QueryPos.getInstance(q);
1183    
1184                                    qPos.add(status);
1185    
1186                                    if (!pagination) {
1187                                            list = (List<BackgroundTask>)QueryUtil.list(q,
1188                                                            getDialect(), start, end, false);
1189    
1190                                            Collections.sort(list);
1191    
1192                                            list = Collections.unmodifiableList(list);
1193                                    }
1194                                    else {
1195                                            list = (List<BackgroundTask>)QueryUtil.list(q,
1196                                                            getDialect(), start, end);
1197                                    }
1198    
1199                                    cacheResult(list);
1200    
1201                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1202                            }
1203                            catch (Exception e) {
1204                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1205    
1206                                    throw processException(e);
1207                            }
1208                            finally {
1209                                    closeSession(session);
1210                            }
1211                    }
1212    
1213                    return list;
1214            }
1215    
1216            /**
1217             * Returns the first background task in the ordered set where status = &#63;.
1218             *
1219             * @param status the status
1220             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1221             * @return the first matching background task
1222             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
1223             */
1224            @Override
1225            public BackgroundTask findByStatus_First(int status,
1226                    OrderByComparator<BackgroundTask> orderByComparator)
1227                    throws NoSuchBackgroundTaskException {
1228                    BackgroundTask backgroundTask = fetchByStatus_First(status,
1229                                    orderByComparator);
1230    
1231                    if (backgroundTask != null) {
1232                            return backgroundTask;
1233                    }
1234    
1235                    StringBundler msg = new StringBundler(4);
1236    
1237                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1238    
1239                    msg.append("status=");
1240                    msg.append(status);
1241    
1242                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1243    
1244                    throw new NoSuchBackgroundTaskException(msg.toString());
1245            }
1246    
1247            /**
1248             * Returns the first background task in the ordered set where status = &#63;.
1249             *
1250             * @param status the status
1251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1252             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
1253             */
1254            @Override
1255            public BackgroundTask fetchByStatus_First(int status,
1256                    OrderByComparator<BackgroundTask> orderByComparator) {
1257                    List<BackgroundTask> list = findByStatus(status, 0, 1, orderByComparator);
1258    
1259                    if (!list.isEmpty()) {
1260                            return list.get(0);
1261                    }
1262    
1263                    return null;
1264            }
1265    
1266            /**
1267             * Returns the last background task in the ordered set where status = &#63;.
1268             *
1269             * @param status the status
1270             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1271             * @return the last matching background task
1272             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
1273             */
1274            @Override
1275            public BackgroundTask findByStatus_Last(int status,
1276                    OrderByComparator<BackgroundTask> orderByComparator)
1277                    throws NoSuchBackgroundTaskException {
1278                    BackgroundTask backgroundTask = fetchByStatus_Last(status,
1279                                    orderByComparator);
1280    
1281                    if (backgroundTask != null) {
1282                            return backgroundTask;
1283                    }
1284    
1285                    StringBundler msg = new StringBundler(4);
1286    
1287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1288    
1289                    msg.append("status=");
1290                    msg.append(status);
1291    
1292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1293    
1294                    throw new NoSuchBackgroundTaskException(msg.toString());
1295            }
1296    
1297            /**
1298             * Returns the last background task in the ordered set where status = &#63;.
1299             *
1300             * @param status the status
1301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1302             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
1303             */
1304            @Override
1305            public BackgroundTask fetchByStatus_Last(int status,
1306                    OrderByComparator<BackgroundTask> orderByComparator) {
1307                    int count = countByStatus(status);
1308    
1309                    if (count == 0) {
1310                            return null;
1311                    }
1312    
1313                    List<BackgroundTask> list = findByStatus(status, count - 1, count,
1314                                    orderByComparator);
1315    
1316                    if (!list.isEmpty()) {
1317                            return list.get(0);
1318                    }
1319    
1320                    return null;
1321            }
1322    
1323            /**
1324             * Returns the background tasks before and after the current background task in the ordered set where status = &#63;.
1325             *
1326             * @param backgroundTaskId the primary key of the current background task
1327             * @param status the status
1328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1329             * @return the previous, current, and next background task
1330             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
1331             */
1332            @Override
1333            public BackgroundTask[] findByStatus_PrevAndNext(long backgroundTaskId,
1334                    int status, OrderByComparator<BackgroundTask> orderByComparator)
1335                    throws NoSuchBackgroundTaskException {
1336                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
1337    
1338                    Session session = null;
1339    
1340                    try {
1341                            session = openSession();
1342    
1343                            BackgroundTask[] array = new BackgroundTaskImpl[3];
1344    
1345                            array[0] = getByStatus_PrevAndNext(session, backgroundTask, status,
1346                                            orderByComparator, true);
1347    
1348                            array[1] = backgroundTask;
1349    
1350                            array[2] = getByStatus_PrevAndNext(session, backgroundTask, status,
1351                                            orderByComparator, false);
1352    
1353                            return array;
1354                    }
1355                    catch (Exception e) {
1356                            throw processException(e);
1357                    }
1358                    finally {
1359                            closeSession(session);
1360                    }
1361            }
1362    
1363            protected BackgroundTask getByStatus_PrevAndNext(Session session,
1364                    BackgroundTask backgroundTask, int status,
1365                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
1366                    StringBundler query = null;
1367    
1368                    if (orderByComparator != null) {
1369                            query = new StringBundler(6 +
1370                                            (orderByComparator.getOrderByFields().length * 6));
1371                    }
1372                    else {
1373                            query = new StringBundler(3);
1374                    }
1375    
1376                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
1377    
1378                    query.append(_FINDER_COLUMN_STATUS_STATUS_2);
1379    
1380                    if (orderByComparator != null) {
1381                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1382    
1383                            if (orderByConditionFields.length > 0) {
1384                                    query.append(WHERE_AND);
1385                            }
1386    
1387                            for (int i = 0; i < orderByConditionFields.length; i++) {
1388                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1389                                    query.append(orderByConditionFields[i]);
1390    
1391                                    if ((i + 1) < orderByConditionFields.length) {
1392                                            if (orderByComparator.isAscending() ^ previous) {
1393                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1394                                            }
1395                                            else {
1396                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1397                                            }
1398                                    }
1399                                    else {
1400                                            if (orderByComparator.isAscending() ^ previous) {
1401                                                    query.append(WHERE_GREATER_THAN);
1402                                            }
1403                                            else {
1404                                                    query.append(WHERE_LESSER_THAN);
1405                                            }
1406                                    }
1407                            }
1408    
1409                            query.append(ORDER_BY_CLAUSE);
1410    
1411                            String[] orderByFields = orderByComparator.getOrderByFields();
1412    
1413                            for (int i = 0; i < orderByFields.length; i++) {
1414                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1415                                    query.append(orderByFields[i]);
1416    
1417                                    if ((i + 1) < orderByFields.length) {
1418                                            if (orderByComparator.isAscending() ^ previous) {
1419                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1420                                            }
1421                                            else {
1422                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1423                                            }
1424                                    }
1425                                    else {
1426                                            if (orderByComparator.isAscending() ^ previous) {
1427                                                    query.append(ORDER_BY_ASC);
1428                                            }
1429                                            else {
1430                                                    query.append(ORDER_BY_DESC);
1431                                            }
1432                                    }
1433                            }
1434                    }
1435                    else {
1436                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
1437                    }
1438    
1439                    String sql = query.toString();
1440    
1441                    Query q = session.createQuery(sql);
1442    
1443                    q.setFirstResult(0);
1444                    q.setMaxResults(2);
1445    
1446                    QueryPos qPos = QueryPos.getInstance(q);
1447    
1448                    qPos.add(status);
1449    
1450                    if (orderByComparator != null) {
1451                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
1452    
1453                            for (Object value : values) {
1454                                    qPos.add(value);
1455                            }
1456                    }
1457    
1458                    List<BackgroundTask> list = q.list();
1459    
1460                    if (list.size() == 2) {
1461                            return list.get(1);
1462                    }
1463                    else {
1464                            return null;
1465                    }
1466            }
1467    
1468            /**
1469             * Removes all the background tasks where status = &#63; from the database.
1470             *
1471             * @param status the status
1472             */
1473            @Override
1474            public void removeByStatus(int status) {
1475                    for (BackgroundTask backgroundTask : findByStatus(status,
1476                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1477                            remove(backgroundTask);
1478                    }
1479            }
1480    
1481            /**
1482             * Returns the number of background tasks where status = &#63;.
1483             *
1484             * @param status the status
1485             * @return the number of matching background tasks
1486             */
1487            @Override
1488            public int countByStatus(int status) {
1489                    FinderPath finderPath = FINDER_PATH_COUNT_BY_STATUS;
1490    
1491                    Object[] finderArgs = new Object[] { status };
1492    
1493                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1494                                    this);
1495    
1496                    if (count == null) {
1497                            StringBundler query = new StringBundler(2);
1498    
1499                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
1500    
1501                            query.append(_FINDER_COLUMN_STATUS_STATUS_2);
1502    
1503                            String sql = query.toString();
1504    
1505                            Session session = null;
1506    
1507                            try {
1508                                    session = openSession();
1509    
1510                                    Query q = session.createQuery(sql);
1511    
1512                                    QueryPos qPos = QueryPos.getInstance(q);
1513    
1514                                    qPos.add(status);
1515    
1516                                    count = (Long)q.uniqueResult();
1517    
1518                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1519                            }
1520                            catch (Exception e) {
1521                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1522    
1523                                    throw processException(e);
1524                            }
1525                            finally {
1526                                    closeSession(session);
1527                            }
1528                    }
1529    
1530                    return count.intValue();
1531            }
1532    
1533            private static final String _FINDER_COLUMN_STATUS_STATUS_2 = "backgroundTask.status = ?";
1534            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
1535                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
1536                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1537                            "findByG_T",
1538                            new String[] {
1539                                    Long.class.getName(), String.class.getName(),
1540                                    
1541                            Integer.class.getName(), Integer.class.getName(),
1542                                    OrderByComparator.class.getName()
1543                            });
1544            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
1545                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
1546                            BackgroundTaskImpl.class,
1547                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_T",
1548                            new String[] { Long.class.getName(), String.class.getName() },
1549                            BackgroundTaskModelImpl.GROUPID_COLUMN_BITMASK |
1550                            BackgroundTaskModelImpl.TASKEXECUTORCLASSNAME_COLUMN_BITMASK |
1551                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
1552            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
1553                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
1554                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T",
1555                            new String[] { Long.class.getName(), String.class.getName() });
1556            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
1557                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
1558                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_T",
1559                            new String[] { Long.class.getName(), String.class.getName() });
1560    
1561            /**
1562             * Returns all the background tasks where groupId = &#63; and taskExecutorClassName = &#63;.
1563             *
1564             * @param groupId the group ID
1565             * @param taskExecutorClassName the task executor class name
1566             * @return the matching background tasks
1567             */
1568            @Override
1569            public List<BackgroundTask> findByG_T(long groupId,
1570                    String taskExecutorClassName) {
1571                    return findByG_T(groupId, taskExecutorClassName, QueryUtil.ALL_POS,
1572                            QueryUtil.ALL_POS, null);
1573            }
1574    
1575            /**
1576             * Returns a range of all the background tasks where groupId = &#63; and taskExecutorClassName = &#63;.
1577             *
1578             * <p>
1579             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
1580             * </p>
1581             *
1582             * @param groupId the group ID
1583             * @param taskExecutorClassName the task executor class name
1584             * @param start the lower bound of the range of background tasks
1585             * @param end the upper bound of the range of background tasks (not inclusive)
1586             * @return the range of matching background tasks
1587             */
1588            @Override
1589            public List<BackgroundTask> findByG_T(long groupId,
1590                    String taskExecutorClassName, int start, int end) {
1591                    return findByG_T(groupId, taskExecutorClassName, start, end, null);
1592            }
1593    
1594            /**
1595             * Returns an ordered range of all the background tasks where groupId = &#63; and taskExecutorClassName = &#63;.
1596             *
1597             * <p>
1598             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
1599             * </p>
1600             *
1601             * @param groupId the group ID
1602             * @param taskExecutorClassName the task executor class name
1603             * @param start the lower bound of the range of background tasks
1604             * @param end the upper bound of the range of background tasks (not inclusive)
1605             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1606             * @return the ordered range of matching background tasks
1607             */
1608            @Override
1609            public List<BackgroundTask> findByG_T(long groupId,
1610                    String taskExecutorClassName, int start, int end,
1611                    OrderByComparator<BackgroundTask> orderByComparator) {
1612                    boolean pagination = true;
1613                    FinderPath finderPath = null;
1614                    Object[] finderArgs = null;
1615    
1616                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1617                                    (orderByComparator == null)) {
1618                            pagination = false;
1619                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T;
1620                            finderArgs = new Object[] { groupId, taskExecutorClassName };
1621                    }
1622                    else {
1623                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T;
1624                            finderArgs = new Object[] {
1625                                            groupId, taskExecutorClassName,
1626                                            
1627                                            start, end, orderByComparator
1628                                    };
1629                    }
1630    
1631                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
1632                                    finderArgs, this);
1633    
1634                    if ((list != null) && !list.isEmpty()) {
1635                            for (BackgroundTask backgroundTask : list) {
1636                                    if ((groupId != backgroundTask.getGroupId()) ||
1637                                                    !Validator.equals(taskExecutorClassName,
1638                                                            backgroundTask.getTaskExecutorClassName())) {
1639                                            list = null;
1640    
1641                                            break;
1642                                    }
1643                            }
1644                    }
1645    
1646                    if (list == null) {
1647                            StringBundler query = null;
1648    
1649                            if (orderByComparator != null) {
1650                                    query = new StringBundler(4 +
1651                                                    (orderByComparator.getOrderByFields().length * 3));
1652                            }
1653                            else {
1654                                    query = new StringBundler(4);
1655                            }
1656    
1657                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
1658    
1659                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
1660    
1661                            boolean bindTaskExecutorClassName = false;
1662    
1663                            if (taskExecutorClassName == null) {
1664                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_1);
1665                            }
1666                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
1667                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_3);
1668                            }
1669                            else {
1670                                    bindTaskExecutorClassName = true;
1671    
1672                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_2);
1673                            }
1674    
1675                            if (orderByComparator != null) {
1676                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1677                                            orderByComparator);
1678                            }
1679                            else
1680                             if (pagination) {
1681                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
1682                            }
1683    
1684                            String sql = query.toString();
1685    
1686                            Session session = null;
1687    
1688                            try {
1689                                    session = openSession();
1690    
1691                                    Query q = session.createQuery(sql);
1692    
1693                                    QueryPos qPos = QueryPos.getInstance(q);
1694    
1695                                    qPos.add(groupId);
1696    
1697                                    if (bindTaskExecutorClassName) {
1698                                            qPos.add(taskExecutorClassName);
1699                                    }
1700    
1701                                    if (!pagination) {
1702                                            list = (List<BackgroundTask>)QueryUtil.list(q,
1703                                                            getDialect(), start, end, false);
1704    
1705                                            Collections.sort(list);
1706    
1707                                            list = Collections.unmodifiableList(list);
1708                                    }
1709                                    else {
1710                                            list = (List<BackgroundTask>)QueryUtil.list(q,
1711                                                            getDialect(), start, end);
1712                                    }
1713    
1714                                    cacheResult(list);
1715    
1716                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1717                            }
1718                            catch (Exception e) {
1719                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1720    
1721                                    throw processException(e);
1722                            }
1723                            finally {
1724                                    closeSession(session);
1725                            }
1726                    }
1727    
1728                    return list;
1729            }
1730    
1731            /**
1732             * Returns the first background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63;.
1733             *
1734             * @param groupId the group ID
1735             * @param taskExecutorClassName the task executor class name
1736             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1737             * @return the first matching background task
1738             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
1739             */
1740            @Override
1741            public BackgroundTask findByG_T_First(long groupId,
1742                    String taskExecutorClassName,
1743                    OrderByComparator<BackgroundTask> orderByComparator)
1744                    throws NoSuchBackgroundTaskException {
1745                    BackgroundTask backgroundTask = fetchByG_T_First(groupId,
1746                                    taskExecutorClassName, orderByComparator);
1747    
1748                    if (backgroundTask != null) {
1749                            return backgroundTask;
1750                    }
1751    
1752                    StringBundler msg = new StringBundler(6);
1753    
1754                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1755    
1756                    msg.append("groupId=");
1757                    msg.append(groupId);
1758    
1759                    msg.append(", taskExecutorClassName=");
1760                    msg.append(taskExecutorClassName);
1761    
1762                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1763    
1764                    throw new NoSuchBackgroundTaskException(msg.toString());
1765            }
1766    
1767            /**
1768             * Returns the first background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63;.
1769             *
1770             * @param groupId the group ID
1771             * @param taskExecutorClassName the task executor class name
1772             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1773             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
1774             */
1775            @Override
1776            public BackgroundTask fetchByG_T_First(long groupId,
1777                    String taskExecutorClassName,
1778                    OrderByComparator<BackgroundTask> orderByComparator) {
1779                    List<BackgroundTask> list = findByG_T(groupId, taskExecutorClassName,
1780                                    0, 1, orderByComparator);
1781    
1782                    if (!list.isEmpty()) {
1783                            return list.get(0);
1784                    }
1785    
1786                    return null;
1787            }
1788    
1789            /**
1790             * Returns the last background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63;.
1791             *
1792             * @param groupId the group ID
1793             * @param taskExecutorClassName the task executor class name
1794             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1795             * @return the last matching background task
1796             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
1797             */
1798            @Override
1799            public BackgroundTask findByG_T_Last(long groupId,
1800                    String taskExecutorClassName,
1801                    OrderByComparator<BackgroundTask> orderByComparator)
1802                    throws NoSuchBackgroundTaskException {
1803                    BackgroundTask backgroundTask = fetchByG_T_Last(groupId,
1804                                    taskExecutorClassName, orderByComparator);
1805    
1806                    if (backgroundTask != null) {
1807                            return backgroundTask;
1808                    }
1809    
1810                    StringBundler msg = new StringBundler(6);
1811    
1812                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1813    
1814                    msg.append("groupId=");
1815                    msg.append(groupId);
1816    
1817                    msg.append(", taskExecutorClassName=");
1818                    msg.append(taskExecutorClassName);
1819    
1820                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1821    
1822                    throw new NoSuchBackgroundTaskException(msg.toString());
1823            }
1824    
1825            /**
1826             * Returns the last background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63;.
1827             *
1828             * @param groupId the group ID
1829             * @param taskExecutorClassName the task executor class name
1830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1831             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
1832             */
1833            @Override
1834            public BackgroundTask fetchByG_T_Last(long groupId,
1835                    String taskExecutorClassName,
1836                    OrderByComparator<BackgroundTask> orderByComparator) {
1837                    int count = countByG_T(groupId, taskExecutorClassName);
1838    
1839                    if (count == 0) {
1840                            return null;
1841                    }
1842    
1843                    List<BackgroundTask> list = findByG_T(groupId, taskExecutorClassName,
1844                                    count - 1, count, orderByComparator);
1845    
1846                    if (!list.isEmpty()) {
1847                            return list.get(0);
1848                    }
1849    
1850                    return null;
1851            }
1852    
1853            /**
1854             * Returns the background tasks before and after the current background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63;.
1855             *
1856             * @param backgroundTaskId the primary key of the current background task
1857             * @param groupId the group ID
1858             * @param taskExecutorClassName the task executor class name
1859             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1860             * @return the previous, current, and next background task
1861             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
1862             */
1863            @Override
1864            public BackgroundTask[] findByG_T_PrevAndNext(long backgroundTaskId,
1865                    long groupId, String taskExecutorClassName,
1866                    OrderByComparator<BackgroundTask> orderByComparator)
1867                    throws NoSuchBackgroundTaskException {
1868                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
1869    
1870                    Session session = null;
1871    
1872                    try {
1873                            session = openSession();
1874    
1875                            BackgroundTask[] array = new BackgroundTaskImpl[3];
1876    
1877                            array[0] = getByG_T_PrevAndNext(session, backgroundTask, groupId,
1878                                            taskExecutorClassName, orderByComparator, true);
1879    
1880                            array[1] = backgroundTask;
1881    
1882                            array[2] = getByG_T_PrevAndNext(session, backgroundTask, groupId,
1883                                            taskExecutorClassName, orderByComparator, false);
1884    
1885                            return array;
1886                    }
1887                    catch (Exception e) {
1888                            throw processException(e);
1889                    }
1890                    finally {
1891                            closeSession(session);
1892                    }
1893            }
1894    
1895            protected BackgroundTask getByG_T_PrevAndNext(Session session,
1896                    BackgroundTask backgroundTask, long groupId,
1897                    String taskExecutorClassName,
1898                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
1899                    StringBundler query = null;
1900    
1901                    if (orderByComparator != null) {
1902                            query = new StringBundler(6 +
1903                                            (orderByComparator.getOrderByFields().length * 6));
1904                    }
1905                    else {
1906                            query = new StringBundler(3);
1907                    }
1908    
1909                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
1910    
1911                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
1912    
1913                    boolean bindTaskExecutorClassName = false;
1914    
1915                    if (taskExecutorClassName == null) {
1916                            query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_1);
1917                    }
1918                    else if (taskExecutorClassName.equals(StringPool.BLANK)) {
1919                            query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_3);
1920                    }
1921                    else {
1922                            bindTaskExecutorClassName = true;
1923    
1924                            query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_2);
1925                    }
1926    
1927                    if (orderByComparator != null) {
1928                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1929    
1930                            if (orderByConditionFields.length > 0) {
1931                                    query.append(WHERE_AND);
1932                            }
1933    
1934                            for (int i = 0; i < orderByConditionFields.length; i++) {
1935                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1936                                    query.append(orderByConditionFields[i]);
1937    
1938                                    if ((i + 1) < orderByConditionFields.length) {
1939                                            if (orderByComparator.isAscending() ^ previous) {
1940                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1941                                            }
1942                                            else {
1943                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1944                                            }
1945                                    }
1946                                    else {
1947                                            if (orderByComparator.isAscending() ^ previous) {
1948                                                    query.append(WHERE_GREATER_THAN);
1949                                            }
1950                                            else {
1951                                                    query.append(WHERE_LESSER_THAN);
1952                                            }
1953                                    }
1954                            }
1955    
1956                            query.append(ORDER_BY_CLAUSE);
1957    
1958                            String[] orderByFields = orderByComparator.getOrderByFields();
1959    
1960                            for (int i = 0; i < orderByFields.length; i++) {
1961                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1962                                    query.append(orderByFields[i]);
1963    
1964                                    if ((i + 1) < orderByFields.length) {
1965                                            if (orderByComparator.isAscending() ^ previous) {
1966                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1967                                            }
1968                                            else {
1969                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1970                                            }
1971                                    }
1972                                    else {
1973                                            if (orderByComparator.isAscending() ^ previous) {
1974                                                    query.append(ORDER_BY_ASC);
1975                                            }
1976                                            else {
1977                                                    query.append(ORDER_BY_DESC);
1978                                            }
1979                                    }
1980                            }
1981                    }
1982                    else {
1983                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
1984                    }
1985    
1986                    String sql = query.toString();
1987    
1988                    Query q = session.createQuery(sql);
1989    
1990                    q.setFirstResult(0);
1991                    q.setMaxResults(2);
1992    
1993                    QueryPos qPos = QueryPos.getInstance(q);
1994    
1995                    qPos.add(groupId);
1996    
1997                    if (bindTaskExecutorClassName) {
1998                            qPos.add(taskExecutorClassName);
1999                    }
2000    
2001                    if (orderByComparator != null) {
2002                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
2003    
2004                            for (Object value : values) {
2005                                    qPos.add(value);
2006                            }
2007                    }
2008    
2009                    List<BackgroundTask> list = q.list();
2010    
2011                    if (list.size() == 2) {
2012                            return list.get(1);
2013                    }
2014                    else {
2015                            return null;
2016                    }
2017            }
2018    
2019            /**
2020             * Returns all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63;.
2021             *
2022             * <p>
2023             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
2024             * </p>
2025             *
2026             * @param groupId the group ID
2027             * @param taskExecutorClassNames the task executor class names
2028             * @return the matching background tasks
2029             */
2030            @Override
2031            public List<BackgroundTask> findByG_T(long groupId,
2032                    String[] taskExecutorClassNames) {
2033                    return findByG_T(groupId, taskExecutorClassNames, QueryUtil.ALL_POS,
2034                            QueryUtil.ALL_POS, null);
2035            }
2036    
2037            /**
2038             * Returns a range of all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63;.
2039             *
2040             * <p>
2041             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
2042             * </p>
2043             *
2044             * @param groupId the group ID
2045             * @param taskExecutorClassNames the task executor class names
2046             * @param start the lower bound of the range of background tasks
2047             * @param end the upper bound of the range of background tasks (not inclusive)
2048             * @return the range of matching background tasks
2049             */
2050            @Override
2051            public List<BackgroundTask> findByG_T(long groupId,
2052                    String[] taskExecutorClassNames, int start, int end) {
2053                    return findByG_T(groupId, taskExecutorClassNames, start, end, null);
2054            }
2055    
2056            /**
2057             * Returns an ordered range of all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63;.
2058             *
2059             * <p>
2060             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
2061             * </p>
2062             *
2063             * @param groupId the group ID
2064             * @param taskExecutorClassNames the task executor class names
2065             * @param start the lower bound of the range of background tasks
2066             * @param end the upper bound of the range of background tasks (not inclusive)
2067             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2068             * @return the ordered range of matching background tasks
2069             */
2070            @Override
2071            public List<BackgroundTask> findByG_T(long groupId,
2072                    String[] taskExecutorClassNames, int start, int end,
2073                    OrderByComparator<BackgroundTask> orderByComparator) {
2074                    if (taskExecutorClassNames == null) {
2075                            taskExecutorClassNames = new String[0];
2076                    }
2077                    else {
2078                            taskExecutorClassNames = ArrayUtil.distinct(taskExecutorClassNames,
2079                                            NULL_SAFE_STRING_COMPARATOR);
2080                    }
2081    
2082                    if (taskExecutorClassNames.length == 1) {
2083                            return findByG_T(groupId, taskExecutorClassNames[0], start, end,
2084                                    orderByComparator);
2085                    }
2086    
2087                    boolean pagination = true;
2088                    Object[] finderArgs = null;
2089    
2090                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2091                                    (orderByComparator == null)) {
2092                            pagination = false;
2093                            finderArgs = new Object[] {
2094                                            groupId, StringUtil.merge(taskExecutorClassNames)
2095                                    };
2096                    }
2097                    else {
2098                            finderArgs = new Object[] {
2099                                            groupId, StringUtil.merge(taskExecutorClassNames),
2100                                            
2101                                            start, end, orderByComparator
2102                                    };
2103                    }
2104    
2105                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T,
2106                                    finderArgs, this);
2107    
2108                    if ((list != null) && !list.isEmpty()) {
2109                            for (BackgroundTask backgroundTask : list) {
2110                                    if ((groupId != backgroundTask.getGroupId()) ||
2111                                                    !ArrayUtil.contains(taskExecutorClassNames,
2112                                                            backgroundTask.getTaskExecutorClassName())) {
2113                                            list = null;
2114    
2115                                            break;
2116                                    }
2117                            }
2118                    }
2119    
2120                    if (list == null) {
2121                            StringBundler query = new StringBundler();
2122    
2123                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
2124    
2125                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2126    
2127                            if (taskExecutorClassNames.length > 0) {
2128                                    query.append(StringPool.OPEN_PARENTHESIS);
2129    
2130                                    for (int i = 0; i < taskExecutorClassNames.length; i++) {
2131                                            String taskExecutorClassName = taskExecutorClassNames[i];
2132    
2133                                            if (taskExecutorClassName == null) {
2134                                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_1);
2135                                            }
2136                                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
2137                                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_3);
2138                                            }
2139                                            else {
2140                                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_2);
2141                                            }
2142    
2143                                            if ((i + 1) < taskExecutorClassNames.length) {
2144                                                    query.append(WHERE_OR);
2145                                            }
2146                                    }
2147    
2148                                    query.append(StringPool.CLOSE_PARENTHESIS);
2149                            }
2150    
2151                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
2152                                                    1)), query.index() - 1);
2153    
2154                            if (orderByComparator != null) {
2155                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2156                                            orderByComparator);
2157                            }
2158                            else
2159                             if (pagination) {
2160                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
2161                            }
2162    
2163                            String sql = query.toString();
2164    
2165                            Session session = null;
2166    
2167                            try {
2168                                    session = openSession();
2169    
2170                                    Query q = session.createQuery(sql);
2171    
2172                                    QueryPos qPos = QueryPos.getInstance(q);
2173    
2174                                    qPos.add(groupId);
2175    
2176                                    for (String taskExecutorClassName : taskExecutorClassNames) {
2177                                            if ((taskExecutorClassName != null) &&
2178                                                            !taskExecutorClassName.isEmpty()) {
2179                                                    qPos.add(taskExecutorClassName);
2180                                            }
2181                                    }
2182    
2183                                    if (!pagination) {
2184                                            list = (List<BackgroundTask>)QueryUtil.list(q,
2185                                                            getDialect(), start, end, false);
2186    
2187                                            Collections.sort(list);
2188    
2189                                            list = Collections.unmodifiableList(list);
2190                                    }
2191                                    else {
2192                                            list = (List<BackgroundTask>)QueryUtil.list(q,
2193                                                            getDialect(), start, end);
2194                                    }
2195    
2196                                    cacheResult(list);
2197    
2198                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T,
2199                                            finderArgs, list);
2200                            }
2201                            catch (Exception e) {
2202                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T,
2203                                            finderArgs);
2204    
2205                                    throw processException(e);
2206                            }
2207                            finally {
2208                                    closeSession(session);
2209                            }
2210                    }
2211    
2212                    return list;
2213            }
2214    
2215            /**
2216             * Removes all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; from the database.
2217             *
2218             * @param groupId the group ID
2219             * @param taskExecutorClassName the task executor class name
2220             */
2221            @Override
2222            public void removeByG_T(long groupId, String taskExecutorClassName) {
2223                    for (BackgroundTask backgroundTask : findByG_T(groupId,
2224                                    taskExecutorClassName, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2225                                    null)) {
2226                            remove(backgroundTask);
2227                    }
2228            }
2229    
2230            /**
2231             * Returns the number of background tasks where groupId = &#63; and taskExecutorClassName = &#63;.
2232             *
2233             * @param groupId the group ID
2234             * @param taskExecutorClassName the task executor class name
2235             * @return the number of matching background tasks
2236             */
2237            @Override
2238            public int countByG_T(long groupId, String taskExecutorClassName) {
2239                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_T;
2240    
2241                    Object[] finderArgs = new Object[] { groupId, taskExecutorClassName };
2242    
2243                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2244                                    this);
2245    
2246                    if (count == null) {
2247                            StringBundler query = new StringBundler(3);
2248    
2249                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
2250    
2251                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2252    
2253                            boolean bindTaskExecutorClassName = false;
2254    
2255                            if (taskExecutorClassName == null) {
2256                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_1);
2257                            }
2258                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
2259                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_3);
2260                            }
2261                            else {
2262                                    bindTaskExecutorClassName = true;
2263    
2264                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_2);
2265                            }
2266    
2267                            String sql = query.toString();
2268    
2269                            Session session = null;
2270    
2271                            try {
2272                                    session = openSession();
2273    
2274                                    Query q = session.createQuery(sql);
2275    
2276                                    QueryPos qPos = QueryPos.getInstance(q);
2277    
2278                                    qPos.add(groupId);
2279    
2280                                    if (bindTaskExecutorClassName) {
2281                                            qPos.add(taskExecutorClassName);
2282                                    }
2283    
2284                                    count = (Long)q.uniqueResult();
2285    
2286                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2287                            }
2288                            catch (Exception e) {
2289                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2290    
2291                                    throw processException(e);
2292                            }
2293                            finally {
2294                                    closeSession(session);
2295                            }
2296                    }
2297    
2298                    return count.intValue();
2299            }
2300    
2301            /**
2302             * Returns the number of background tasks where groupId = &#63; and taskExecutorClassName = any &#63;.
2303             *
2304             * @param groupId the group ID
2305             * @param taskExecutorClassNames the task executor class names
2306             * @return the number of matching background tasks
2307             */
2308            @Override
2309            public int countByG_T(long groupId, String[] taskExecutorClassNames) {
2310                    if (taskExecutorClassNames == null) {
2311                            taskExecutorClassNames = new String[0];
2312                    }
2313                    else {
2314                            taskExecutorClassNames = ArrayUtil.distinct(taskExecutorClassNames,
2315                                            NULL_SAFE_STRING_COMPARATOR);
2316                    }
2317    
2318                    Object[] finderArgs = new Object[] {
2319                                    groupId, StringUtil.merge(taskExecutorClassNames)
2320                            };
2321    
2322                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T,
2323                                    finderArgs, this);
2324    
2325                    if (count == null) {
2326                            StringBundler query = new StringBundler();
2327    
2328                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
2329    
2330                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
2331    
2332                            if (taskExecutorClassNames.length > 0) {
2333                                    query.append(StringPool.OPEN_PARENTHESIS);
2334    
2335                                    for (int i = 0; i < taskExecutorClassNames.length; i++) {
2336                                            String taskExecutorClassName = taskExecutorClassNames[i];
2337    
2338                                            if (taskExecutorClassName == null) {
2339                                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_1);
2340                                            }
2341                                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
2342                                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_3);
2343                                            }
2344                                            else {
2345                                                    query.append(_FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_2);
2346                                            }
2347    
2348                                            if ((i + 1) < taskExecutorClassNames.length) {
2349                                                    query.append(WHERE_OR);
2350                                            }
2351                                    }
2352    
2353                                    query.append(StringPool.CLOSE_PARENTHESIS);
2354                            }
2355    
2356                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
2357                                                    1)), query.index() - 1);
2358    
2359                            String sql = query.toString();
2360    
2361                            Session session = null;
2362    
2363                            try {
2364                                    session = openSession();
2365    
2366                                    Query q = session.createQuery(sql);
2367    
2368                                    QueryPos qPos = QueryPos.getInstance(q);
2369    
2370                                    qPos.add(groupId);
2371    
2372                                    for (String taskExecutorClassName : taskExecutorClassNames) {
2373                                            if ((taskExecutorClassName != null) &&
2374                                                            !taskExecutorClassName.isEmpty()) {
2375                                                    qPos.add(taskExecutorClassName);
2376                                            }
2377                                    }
2378    
2379                                    count = (Long)q.uniqueResult();
2380    
2381                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T,
2382                                            finderArgs, count);
2383                            }
2384                            catch (Exception e) {
2385                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T,
2386                                            finderArgs);
2387    
2388                                    throw processException(e);
2389                            }
2390                            finally {
2391                                    closeSession(session);
2392                            }
2393                    }
2394    
2395                    return count.intValue();
2396            }
2397    
2398            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "backgroundTask.groupId = ? AND ";
2399            private static final String _FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_1 = "backgroundTask.taskExecutorClassName IS NULL";
2400            private static final String _FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_2 = "backgroundTask.taskExecutorClassName = ?";
2401            private static final String _FINDER_COLUMN_G_T_TASKEXECUTORCLASSNAME_3 = "(backgroundTask.taskExecutorClassName IS NULL OR backgroundTask.taskExecutorClassName = '')";
2402            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
2403                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
2404                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2405                            "findByG_S",
2406                            new String[] {
2407                                    Long.class.getName(), Integer.class.getName(),
2408                                    
2409                            Integer.class.getName(), Integer.class.getName(),
2410                                    OrderByComparator.class.getName()
2411                            });
2412            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
2413                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
2414                            BackgroundTaskImpl.class,
2415                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
2416                            new String[] { Long.class.getName(), Integer.class.getName() },
2417                            BackgroundTaskModelImpl.GROUPID_COLUMN_BITMASK |
2418                            BackgroundTaskModelImpl.STATUS_COLUMN_BITMASK |
2419                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
2420            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
2421                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
2422                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
2423                            new String[] { Long.class.getName(), Integer.class.getName() });
2424    
2425            /**
2426             * Returns all the background tasks where groupId = &#63; and status = &#63;.
2427             *
2428             * @param groupId the group ID
2429             * @param status the status
2430             * @return the matching background tasks
2431             */
2432            @Override
2433            public List<BackgroundTask> findByG_S(long groupId, int status) {
2434                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2435                            null);
2436            }
2437    
2438            /**
2439             * Returns a range of all the background tasks where groupId = &#63; and status = &#63;.
2440             *
2441             * <p>
2442             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
2443             * </p>
2444             *
2445             * @param groupId the group ID
2446             * @param status the status
2447             * @param start the lower bound of the range of background tasks
2448             * @param end the upper bound of the range of background tasks (not inclusive)
2449             * @return the range of matching background tasks
2450             */
2451            @Override
2452            public List<BackgroundTask> findByG_S(long groupId, int status, int start,
2453                    int end) {
2454                    return findByG_S(groupId, status, start, end, null);
2455            }
2456    
2457            /**
2458             * Returns an ordered range of all the background tasks where groupId = &#63; and status = &#63;.
2459             *
2460             * <p>
2461             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
2462             * </p>
2463             *
2464             * @param groupId the group ID
2465             * @param status the status
2466             * @param start the lower bound of the range of background tasks
2467             * @param end the upper bound of the range of background tasks (not inclusive)
2468             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2469             * @return the ordered range of matching background tasks
2470             */
2471            @Override
2472            public List<BackgroundTask> findByG_S(long groupId, int status, int start,
2473                    int end, OrderByComparator<BackgroundTask> orderByComparator) {
2474                    boolean pagination = true;
2475                    FinderPath finderPath = null;
2476                    Object[] finderArgs = null;
2477    
2478                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2479                                    (orderByComparator == null)) {
2480                            pagination = false;
2481                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
2482                            finderArgs = new Object[] { groupId, status };
2483                    }
2484                    else {
2485                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
2486                            finderArgs = new Object[] {
2487                                            groupId, status,
2488                                            
2489                                            start, end, orderByComparator
2490                                    };
2491                    }
2492    
2493                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
2494                                    finderArgs, this);
2495    
2496                    if ((list != null) && !list.isEmpty()) {
2497                            for (BackgroundTask backgroundTask : list) {
2498                                    if ((groupId != backgroundTask.getGroupId()) ||
2499                                                    (status != backgroundTask.getStatus())) {
2500                                            list = null;
2501    
2502                                            break;
2503                                    }
2504                            }
2505                    }
2506    
2507                    if (list == null) {
2508                            StringBundler query = null;
2509    
2510                            if (orderByComparator != null) {
2511                                    query = new StringBundler(4 +
2512                                                    (orderByComparator.getOrderByFields().length * 3));
2513                            }
2514                            else {
2515                                    query = new StringBundler(4);
2516                            }
2517    
2518                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
2519    
2520                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2521    
2522                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
2523    
2524                            if (orderByComparator != null) {
2525                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2526                                            orderByComparator);
2527                            }
2528                            else
2529                             if (pagination) {
2530                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
2531                            }
2532    
2533                            String sql = query.toString();
2534    
2535                            Session session = null;
2536    
2537                            try {
2538                                    session = openSession();
2539    
2540                                    Query q = session.createQuery(sql);
2541    
2542                                    QueryPos qPos = QueryPos.getInstance(q);
2543    
2544                                    qPos.add(groupId);
2545    
2546                                    qPos.add(status);
2547    
2548                                    if (!pagination) {
2549                                            list = (List<BackgroundTask>)QueryUtil.list(q,
2550                                                            getDialect(), start, end, false);
2551    
2552                                            Collections.sort(list);
2553    
2554                                            list = Collections.unmodifiableList(list);
2555                                    }
2556                                    else {
2557                                            list = (List<BackgroundTask>)QueryUtil.list(q,
2558                                                            getDialect(), start, end);
2559                                    }
2560    
2561                                    cacheResult(list);
2562    
2563                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2564                            }
2565                            catch (Exception e) {
2566                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2567    
2568                                    throw processException(e);
2569                            }
2570                            finally {
2571                                    closeSession(session);
2572                            }
2573                    }
2574    
2575                    return list;
2576            }
2577    
2578            /**
2579             * Returns the first background task in the ordered set where groupId = &#63; and status = &#63;.
2580             *
2581             * @param groupId the group ID
2582             * @param status the status
2583             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2584             * @return the first matching background task
2585             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
2586             */
2587            @Override
2588            public BackgroundTask findByG_S_First(long groupId, int status,
2589                    OrderByComparator<BackgroundTask> orderByComparator)
2590                    throws NoSuchBackgroundTaskException {
2591                    BackgroundTask backgroundTask = fetchByG_S_First(groupId, status,
2592                                    orderByComparator);
2593    
2594                    if (backgroundTask != null) {
2595                            return backgroundTask;
2596                    }
2597    
2598                    StringBundler msg = new StringBundler(6);
2599    
2600                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2601    
2602                    msg.append("groupId=");
2603                    msg.append(groupId);
2604    
2605                    msg.append(", status=");
2606                    msg.append(status);
2607    
2608                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2609    
2610                    throw new NoSuchBackgroundTaskException(msg.toString());
2611            }
2612    
2613            /**
2614             * Returns the first background task in the ordered set where groupId = &#63; and status = &#63;.
2615             *
2616             * @param groupId the group ID
2617             * @param status the status
2618             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2619             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
2620             */
2621            @Override
2622            public BackgroundTask fetchByG_S_First(long groupId, int status,
2623                    OrderByComparator<BackgroundTask> orderByComparator) {
2624                    List<BackgroundTask> list = findByG_S(groupId, status, 0, 1,
2625                                    orderByComparator);
2626    
2627                    if (!list.isEmpty()) {
2628                            return list.get(0);
2629                    }
2630    
2631                    return null;
2632            }
2633    
2634            /**
2635             * Returns the last background task in the ordered set where groupId = &#63; and status = &#63;.
2636             *
2637             * @param groupId the group ID
2638             * @param status the status
2639             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2640             * @return the last matching background task
2641             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
2642             */
2643            @Override
2644            public BackgroundTask findByG_S_Last(long groupId, int status,
2645                    OrderByComparator<BackgroundTask> orderByComparator)
2646                    throws NoSuchBackgroundTaskException {
2647                    BackgroundTask backgroundTask = fetchByG_S_Last(groupId, status,
2648                                    orderByComparator);
2649    
2650                    if (backgroundTask != null) {
2651                            return backgroundTask;
2652                    }
2653    
2654                    StringBundler msg = new StringBundler(6);
2655    
2656                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2657    
2658                    msg.append("groupId=");
2659                    msg.append(groupId);
2660    
2661                    msg.append(", status=");
2662                    msg.append(status);
2663    
2664                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2665    
2666                    throw new NoSuchBackgroundTaskException(msg.toString());
2667            }
2668    
2669            /**
2670             * Returns the last background task in the ordered set where groupId = &#63; and status = &#63;.
2671             *
2672             * @param groupId the group ID
2673             * @param status the status
2674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2675             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
2676             */
2677            @Override
2678            public BackgroundTask fetchByG_S_Last(long groupId, int status,
2679                    OrderByComparator<BackgroundTask> orderByComparator) {
2680                    int count = countByG_S(groupId, status);
2681    
2682                    if (count == 0) {
2683                            return null;
2684                    }
2685    
2686                    List<BackgroundTask> list = findByG_S(groupId, status, count - 1,
2687                                    count, orderByComparator);
2688    
2689                    if (!list.isEmpty()) {
2690                            return list.get(0);
2691                    }
2692    
2693                    return null;
2694            }
2695    
2696            /**
2697             * Returns the background tasks before and after the current background task in the ordered set where groupId = &#63; and status = &#63;.
2698             *
2699             * @param backgroundTaskId the primary key of the current background task
2700             * @param groupId the group ID
2701             * @param status the status
2702             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2703             * @return the previous, current, and next background task
2704             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
2705             */
2706            @Override
2707            public BackgroundTask[] findByG_S_PrevAndNext(long backgroundTaskId,
2708                    long groupId, int status,
2709                    OrderByComparator<BackgroundTask> orderByComparator)
2710                    throws NoSuchBackgroundTaskException {
2711                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
2712    
2713                    Session session = null;
2714    
2715                    try {
2716                            session = openSession();
2717    
2718                            BackgroundTask[] array = new BackgroundTaskImpl[3];
2719    
2720                            array[0] = getByG_S_PrevAndNext(session, backgroundTask, groupId,
2721                                            status, orderByComparator, true);
2722    
2723                            array[1] = backgroundTask;
2724    
2725                            array[2] = getByG_S_PrevAndNext(session, backgroundTask, groupId,
2726                                            status, orderByComparator, false);
2727    
2728                            return array;
2729                    }
2730                    catch (Exception e) {
2731                            throw processException(e);
2732                    }
2733                    finally {
2734                            closeSession(session);
2735                    }
2736            }
2737    
2738            protected BackgroundTask getByG_S_PrevAndNext(Session session,
2739                    BackgroundTask backgroundTask, long groupId, int status,
2740                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
2741                    StringBundler query = null;
2742    
2743                    if (orderByComparator != null) {
2744                            query = new StringBundler(6 +
2745                                            (orderByComparator.getOrderByFields().length * 6));
2746                    }
2747                    else {
2748                            query = new StringBundler(3);
2749                    }
2750    
2751                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
2752    
2753                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2754    
2755                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
2756    
2757                    if (orderByComparator != null) {
2758                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2759    
2760                            if (orderByConditionFields.length > 0) {
2761                                    query.append(WHERE_AND);
2762                            }
2763    
2764                            for (int i = 0; i < orderByConditionFields.length; i++) {
2765                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2766                                    query.append(orderByConditionFields[i]);
2767    
2768                                    if ((i + 1) < orderByConditionFields.length) {
2769                                            if (orderByComparator.isAscending() ^ previous) {
2770                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2771                                            }
2772                                            else {
2773                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2774                                            }
2775                                    }
2776                                    else {
2777                                            if (orderByComparator.isAscending() ^ previous) {
2778                                                    query.append(WHERE_GREATER_THAN);
2779                                            }
2780                                            else {
2781                                                    query.append(WHERE_LESSER_THAN);
2782                                            }
2783                                    }
2784                            }
2785    
2786                            query.append(ORDER_BY_CLAUSE);
2787    
2788                            String[] orderByFields = orderByComparator.getOrderByFields();
2789    
2790                            for (int i = 0; i < orderByFields.length; i++) {
2791                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2792                                    query.append(orderByFields[i]);
2793    
2794                                    if ((i + 1) < orderByFields.length) {
2795                                            if (orderByComparator.isAscending() ^ previous) {
2796                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2797                                            }
2798                                            else {
2799                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2800                                            }
2801                                    }
2802                                    else {
2803                                            if (orderByComparator.isAscending() ^ previous) {
2804                                                    query.append(ORDER_BY_ASC);
2805                                            }
2806                                            else {
2807                                                    query.append(ORDER_BY_DESC);
2808                                            }
2809                                    }
2810                            }
2811                    }
2812                    else {
2813                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
2814                    }
2815    
2816                    String sql = query.toString();
2817    
2818                    Query q = session.createQuery(sql);
2819    
2820                    q.setFirstResult(0);
2821                    q.setMaxResults(2);
2822    
2823                    QueryPos qPos = QueryPos.getInstance(q);
2824    
2825                    qPos.add(groupId);
2826    
2827                    qPos.add(status);
2828    
2829                    if (orderByComparator != null) {
2830                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
2831    
2832                            for (Object value : values) {
2833                                    qPos.add(value);
2834                            }
2835                    }
2836    
2837                    List<BackgroundTask> list = q.list();
2838    
2839                    if (list.size() == 2) {
2840                            return list.get(1);
2841                    }
2842                    else {
2843                            return null;
2844                    }
2845            }
2846    
2847            /**
2848             * Removes all the background tasks where groupId = &#63; and status = &#63; from the database.
2849             *
2850             * @param groupId the group ID
2851             * @param status the status
2852             */
2853            @Override
2854            public void removeByG_S(long groupId, int status) {
2855                    for (BackgroundTask backgroundTask : findByG_S(groupId, status,
2856                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2857                            remove(backgroundTask);
2858                    }
2859            }
2860    
2861            /**
2862             * Returns the number of background tasks where groupId = &#63; and status = &#63;.
2863             *
2864             * @param groupId the group ID
2865             * @param status the status
2866             * @return the number of matching background tasks
2867             */
2868            @Override
2869            public int countByG_S(long groupId, int status) {
2870                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
2871    
2872                    Object[] finderArgs = new Object[] { groupId, status };
2873    
2874                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2875                                    this);
2876    
2877                    if (count == null) {
2878                            StringBundler query = new StringBundler(3);
2879    
2880                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
2881    
2882                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2883    
2884                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
2885    
2886                            String sql = query.toString();
2887    
2888                            Session session = null;
2889    
2890                            try {
2891                                    session = openSession();
2892    
2893                                    Query q = session.createQuery(sql);
2894    
2895                                    QueryPos qPos = QueryPos.getInstance(q);
2896    
2897                                    qPos.add(groupId);
2898    
2899                                    qPos.add(status);
2900    
2901                                    count = (Long)q.uniqueResult();
2902    
2903                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2904                            }
2905                            catch (Exception e) {
2906                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2907    
2908                                    throw processException(e);
2909                            }
2910                            finally {
2911                                    closeSession(session);
2912                            }
2913                    }
2914    
2915                    return count.intValue();
2916            }
2917    
2918            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "backgroundTask.groupId = ? AND ";
2919            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "backgroundTask.status = ?";
2920            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
2921                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
2922                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2923                            "findByT_S",
2924                            new String[] {
2925                                    String.class.getName(), Integer.class.getName(),
2926                                    
2927                            Integer.class.getName(), Integer.class.getName(),
2928                                    OrderByComparator.class.getName()
2929                            });
2930            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
2931                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
2932                            BackgroundTaskImpl.class,
2933                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
2934                            new String[] { String.class.getName(), Integer.class.getName() },
2935                            BackgroundTaskModelImpl.TASKEXECUTORCLASSNAME_COLUMN_BITMASK |
2936                            BackgroundTaskModelImpl.STATUS_COLUMN_BITMASK |
2937                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
2938            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
2939                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
2940                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
2941                            new String[] { String.class.getName(), Integer.class.getName() });
2942            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
2943                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
2944                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByT_S",
2945                            new String[] { String.class.getName(), Integer.class.getName() });
2946    
2947            /**
2948             * Returns all the background tasks where taskExecutorClassName = &#63; and status = &#63;.
2949             *
2950             * @param taskExecutorClassName the task executor class name
2951             * @param status the status
2952             * @return the matching background tasks
2953             */
2954            @Override
2955            public List<BackgroundTask> findByT_S(String taskExecutorClassName,
2956                    int status) {
2957                    return findByT_S(taskExecutorClassName, status, QueryUtil.ALL_POS,
2958                            QueryUtil.ALL_POS, null);
2959            }
2960    
2961            /**
2962             * Returns a range of all the background tasks where taskExecutorClassName = &#63; and status = &#63;.
2963             *
2964             * <p>
2965             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
2966             * </p>
2967             *
2968             * @param taskExecutorClassName the task executor class name
2969             * @param status the status
2970             * @param start the lower bound of the range of background tasks
2971             * @param end the upper bound of the range of background tasks (not inclusive)
2972             * @return the range of matching background tasks
2973             */
2974            @Override
2975            public List<BackgroundTask> findByT_S(String taskExecutorClassName,
2976                    int status, int start, int end) {
2977                    return findByT_S(taskExecutorClassName, status, start, end, null);
2978            }
2979    
2980            /**
2981             * Returns an ordered range of all the background tasks where taskExecutorClassName = &#63; and status = &#63;.
2982             *
2983             * <p>
2984             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
2985             * </p>
2986             *
2987             * @param taskExecutorClassName the task executor class name
2988             * @param status the status
2989             * @param start the lower bound of the range of background tasks
2990             * @param end the upper bound of the range of background tasks (not inclusive)
2991             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2992             * @return the ordered range of matching background tasks
2993             */
2994            @Override
2995            public List<BackgroundTask> findByT_S(String taskExecutorClassName,
2996                    int status, int start, int end,
2997                    OrderByComparator<BackgroundTask> orderByComparator) {
2998                    boolean pagination = true;
2999                    FinderPath finderPath = null;
3000                    Object[] finderArgs = null;
3001    
3002                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3003                                    (orderByComparator == null)) {
3004                            pagination = false;
3005                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
3006                            finderArgs = new Object[] { taskExecutorClassName, status };
3007                    }
3008                    else {
3009                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
3010                            finderArgs = new Object[] {
3011                                            taskExecutorClassName, status,
3012                                            
3013                                            start, end, orderByComparator
3014                                    };
3015                    }
3016    
3017                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
3018                                    finderArgs, this);
3019    
3020                    if ((list != null) && !list.isEmpty()) {
3021                            for (BackgroundTask backgroundTask : list) {
3022                                    if (!Validator.equals(taskExecutorClassName,
3023                                                            backgroundTask.getTaskExecutorClassName()) ||
3024                                                    (status != backgroundTask.getStatus())) {
3025                                            list = null;
3026    
3027                                            break;
3028                                    }
3029                            }
3030                    }
3031    
3032                    if (list == null) {
3033                            StringBundler query = null;
3034    
3035                            if (orderByComparator != null) {
3036                                    query = new StringBundler(4 +
3037                                                    (orderByComparator.getOrderByFields().length * 3));
3038                            }
3039                            else {
3040                                    query = new StringBundler(4);
3041                            }
3042    
3043                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
3044    
3045                            boolean bindTaskExecutorClassName = false;
3046    
3047                            if (taskExecutorClassName == null) {
3048                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_1);
3049                            }
3050                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
3051                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_3);
3052                            }
3053                            else {
3054                                    bindTaskExecutorClassName = true;
3055    
3056                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_2);
3057                            }
3058    
3059                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
3060    
3061                            if (orderByComparator != null) {
3062                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3063                                            orderByComparator);
3064                            }
3065                            else
3066                             if (pagination) {
3067                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
3068                            }
3069    
3070                            String sql = query.toString();
3071    
3072                            Session session = null;
3073    
3074                            try {
3075                                    session = openSession();
3076    
3077                                    Query q = session.createQuery(sql);
3078    
3079                                    QueryPos qPos = QueryPos.getInstance(q);
3080    
3081                                    if (bindTaskExecutorClassName) {
3082                                            qPos.add(taskExecutorClassName);
3083                                    }
3084    
3085                                    qPos.add(status);
3086    
3087                                    if (!pagination) {
3088                                            list = (List<BackgroundTask>)QueryUtil.list(q,
3089                                                            getDialect(), start, end, false);
3090    
3091                                            Collections.sort(list);
3092    
3093                                            list = Collections.unmodifiableList(list);
3094                                    }
3095                                    else {
3096                                            list = (List<BackgroundTask>)QueryUtil.list(q,
3097                                                            getDialect(), start, end);
3098                                    }
3099    
3100                                    cacheResult(list);
3101    
3102                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3103                            }
3104                            catch (Exception e) {
3105                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3106    
3107                                    throw processException(e);
3108                            }
3109                            finally {
3110                                    closeSession(session);
3111                            }
3112                    }
3113    
3114                    return list;
3115            }
3116    
3117            /**
3118             * Returns the first background task in the ordered set where taskExecutorClassName = &#63; and status = &#63;.
3119             *
3120             * @param taskExecutorClassName the task executor class name
3121             * @param status the status
3122             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3123             * @return the first matching background task
3124             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
3125             */
3126            @Override
3127            public BackgroundTask findByT_S_First(String taskExecutorClassName,
3128                    int status, OrderByComparator<BackgroundTask> orderByComparator)
3129                    throws NoSuchBackgroundTaskException {
3130                    BackgroundTask backgroundTask = fetchByT_S_First(taskExecutorClassName,
3131                                    status, orderByComparator);
3132    
3133                    if (backgroundTask != null) {
3134                            return backgroundTask;
3135                    }
3136    
3137                    StringBundler msg = new StringBundler(6);
3138    
3139                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3140    
3141                    msg.append("taskExecutorClassName=");
3142                    msg.append(taskExecutorClassName);
3143    
3144                    msg.append(", status=");
3145                    msg.append(status);
3146    
3147                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3148    
3149                    throw new NoSuchBackgroundTaskException(msg.toString());
3150            }
3151    
3152            /**
3153             * Returns the first background task in the ordered set where taskExecutorClassName = &#63; and status = &#63;.
3154             *
3155             * @param taskExecutorClassName the task executor class name
3156             * @param status the status
3157             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3158             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
3159             */
3160            @Override
3161            public BackgroundTask fetchByT_S_First(String taskExecutorClassName,
3162                    int status, OrderByComparator<BackgroundTask> orderByComparator) {
3163                    List<BackgroundTask> list = findByT_S(taskExecutorClassName, status, 0,
3164                                    1, orderByComparator);
3165    
3166                    if (!list.isEmpty()) {
3167                            return list.get(0);
3168                    }
3169    
3170                    return null;
3171            }
3172    
3173            /**
3174             * Returns the last background task in the ordered set where taskExecutorClassName = &#63; and status = &#63;.
3175             *
3176             * @param taskExecutorClassName the task executor class name
3177             * @param status the status
3178             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3179             * @return the last matching background task
3180             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
3181             */
3182            @Override
3183            public BackgroundTask findByT_S_Last(String taskExecutorClassName,
3184                    int status, OrderByComparator<BackgroundTask> orderByComparator)
3185                    throws NoSuchBackgroundTaskException {
3186                    BackgroundTask backgroundTask = fetchByT_S_Last(taskExecutorClassName,
3187                                    status, orderByComparator);
3188    
3189                    if (backgroundTask != null) {
3190                            return backgroundTask;
3191                    }
3192    
3193                    StringBundler msg = new StringBundler(6);
3194    
3195                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3196    
3197                    msg.append("taskExecutorClassName=");
3198                    msg.append(taskExecutorClassName);
3199    
3200                    msg.append(", status=");
3201                    msg.append(status);
3202    
3203                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3204    
3205                    throw new NoSuchBackgroundTaskException(msg.toString());
3206            }
3207    
3208            /**
3209             * Returns the last background task in the ordered set where taskExecutorClassName = &#63; and status = &#63;.
3210             *
3211             * @param taskExecutorClassName the task executor class name
3212             * @param status the status
3213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3214             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
3215             */
3216            @Override
3217            public BackgroundTask fetchByT_S_Last(String taskExecutorClassName,
3218                    int status, OrderByComparator<BackgroundTask> orderByComparator) {
3219                    int count = countByT_S(taskExecutorClassName, status);
3220    
3221                    if (count == 0) {
3222                            return null;
3223                    }
3224    
3225                    List<BackgroundTask> list = findByT_S(taskExecutorClassName, status,
3226                                    count - 1, count, orderByComparator);
3227    
3228                    if (!list.isEmpty()) {
3229                            return list.get(0);
3230                    }
3231    
3232                    return null;
3233            }
3234    
3235            /**
3236             * Returns the background tasks before and after the current background task in the ordered set where taskExecutorClassName = &#63; and status = &#63;.
3237             *
3238             * @param backgroundTaskId the primary key of the current background task
3239             * @param taskExecutorClassName the task executor class name
3240             * @param status the status
3241             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3242             * @return the previous, current, and next background task
3243             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
3244             */
3245            @Override
3246            public BackgroundTask[] findByT_S_PrevAndNext(long backgroundTaskId,
3247                    String taskExecutorClassName, int status,
3248                    OrderByComparator<BackgroundTask> orderByComparator)
3249                    throws NoSuchBackgroundTaskException {
3250                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
3251    
3252                    Session session = null;
3253    
3254                    try {
3255                            session = openSession();
3256    
3257                            BackgroundTask[] array = new BackgroundTaskImpl[3];
3258    
3259                            array[0] = getByT_S_PrevAndNext(session, backgroundTask,
3260                                            taskExecutorClassName, status, orderByComparator, true);
3261    
3262                            array[1] = backgroundTask;
3263    
3264                            array[2] = getByT_S_PrevAndNext(session, backgroundTask,
3265                                            taskExecutorClassName, status, orderByComparator, false);
3266    
3267                            return array;
3268                    }
3269                    catch (Exception e) {
3270                            throw processException(e);
3271                    }
3272                    finally {
3273                            closeSession(session);
3274                    }
3275            }
3276    
3277            protected BackgroundTask getByT_S_PrevAndNext(Session session,
3278                    BackgroundTask backgroundTask, String taskExecutorClassName,
3279                    int status, OrderByComparator<BackgroundTask> orderByComparator,
3280                    boolean previous) {
3281                    StringBundler query = null;
3282    
3283                    if (orderByComparator != null) {
3284                            query = new StringBundler(6 +
3285                                            (orderByComparator.getOrderByFields().length * 6));
3286                    }
3287                    else {
3288                            query = new StringBundler(3);
3289                    }
3290    
3291                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
3292    
3293                    boolean bindTaskExecutorClassName = false;
3294    
3295                    if (taskExecutorClassName == null) {
3296                            query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_1);
3297                    }
3298                    else if (taskExecutorClassName.equals(StringPool.BLANK)) {
3299                            query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_3);
3300                    }
3301                    else {
3302                            bindTaskExecutorClassName = true;
3303    
3304                            query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_2);
3305                    }
3306    
3307                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
3308    
3309                    if (orderByComparator != null) {
3310                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3311    
3312                            if (orderByConditionFields.length > 0) {
3313                                    query.append(WHERE_AND);
3314                            }
3315    
3316                            for (int i = 0; i < orderByConditionFields.length; i++) {
3317                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3318                                    query.append(orderByConditionFields[i]);
3319    
3320                                    if ((i + 1) < orderByConditionFields.length) {
3321                                            if (orderByComparator.isAscending() ^ previous) {
3322                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3323                                            }
3324                                            else {
3325                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3326                                            }
3327                                    }
3328                                    else {
3329                                            if (orderByComparator.isAscending() ^ previous) {
3330                                                    query.append(WHERE_GREATER_THAN);
3331                                            }
3332                                            else {
3333                                                    query.append(WHERE_LESSER_THAN);
3334                                            }
3335                                    }
3336                            }
3337    
3338                            query.append(ORDER_BY_CLAUSE);
3339    
3340                            String[] orderByFields = orderByComparator.getOrderByFields();
3341    
3342                            for (int i = 0; i < orderByFields.length; i++) {
3343                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3344                                    query.append(orderByFields[i]);
3345    
3346                                    if ((i + 1) < orderByFields.length) {
3347                                            if (orderByComparator.isAscending() ^ previous) {
3348                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3349                                            }
3350                                            else {
3351                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3352                                            }
3353                                    }
3354                                    else {
3355                                            if (orderByComparator.isAscending() ^ previous) {
3356                                                    query.append(ORDER_BY_ASC);
3357                                            }
3358                                            else {
3359                                                    query.append(ORDER_BY_DESC);
3360                                            }
3361                                    }
3362                            }
3363                    }
3364                    else {
3365                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
3366                    }
3367    
3368                    String sql = query.toString();
3369    
3370                    Query q = session.createQuery(sql);
3371    
3372                    q.setFirstResult(0);
3373                    q.setMaxResults(2);
3374    
3375                    QueryPos qPos = QueryPos.getInstance(q);
3376    
3377                    if (bindTaskExecutorClassName) {
3378                            qPos.add(taskExecutorClassName);
3379                    }
3380    
3381                    qPos.add(status);
3382    
3383                    if (orderByComparator != null) {
3384                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
3385    
3386                            for (Object value : values) {
3387                                    qPos.add(value);
3388                            }
3389                    }
3390    
3391                    List<BackgroundTask> list = q.list();
3392    
3393                    if (list.size() == 2) {
3394                            return list.get(1);
3395                    }
3396                    else {
3397                            return null;
3398                    }
3399            }
3400    
3401            /**
3402             * Returns all the background tasks where taskExecutorClassName = any &#63; and status = &#63;.
3403             *
3404             * <p>
3405             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
3406             * </p>
3407             *
3408             * @param taskExecutorClassNames the task executor class names
3409             * @param status the status
3410             * @return the matching background tasks
3411             */
3412            @Override
3413            public List<BackgroundTask> findByT_S(String[] taskExecutorClassNames,
3414                    int status) {
3415                    return findByT_S(taskExecutorClassNames, status, QueryUtil.ALL_POS,
3416                            QueryUtil.ALL_POS, null);
3417            }
3418    
3419            /**
3420             * Returns a range of all the background tasks where taskExecutorClassName = any &#63; and status = &#63;.
3421             *
3422             * <p>
3423             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
3424             * </p>
3425             *
3426             * @param taskExecutorClassNames the task executor class names
3427             * @param status the status
3428             * @param start the lower bound of the range of background tasks
3429             * @param end the upper bound of the range of background tasks (not inclusive)
3430             * @return the range of matching background tasks
3431             */
3432            @Override
3433            public List<BackgroundTask> findByT_S(String[] taskExecutorClassNames,
3434                    int status, int start, int end) {
3435                    return findByT_S(taskExecutorClassNames, status, start, end, null);
3436            }
3437    
3438            /**
3439             * Returns an ordered range of all the background tasks where taskExecutorClassName = any &#63; and status = &#63;.
3440             *
3441             * <p>
3442             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
3443             * </p>
3444             *
3445             * @param taskExecutorClassNames the task executor class names
3446             * @param status the status
3447             * @param start the lower bound of the range of background tasks
3448             * @param end the upper bound of the range of background tasks (not inclusive)
3449             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3450             * @return the ordered range of matching background tasks
3451             */
3452            @Override
3453            public List<BackgroundTask> findByT_S(String[] taskExecutorClassNames,
3454                    int status, int start, int end,
3455                    OrderByComparator<BackgroundTask> orderByComparator) {
3456                    if (taskExecutorClassNames == null) {
3457                            taskExecutorClassNames = new String[0];
3458                    }
3459                    else {
3460                            taskExecutorClassNames = ArrayUtil.distinct(taskExecutorClassNames,
3461                                            NULL_SAFE_STRING_COMPARATOR);
3462                    }
3463    
3464                    if (taskExecutorClassNames.length == 1) {
3465                            return findByT_S(taskExecutorClassNames[0], status, start, end,
3466                                    orderByComparator);
3467                    }
3468    
3469                    boolean pagination = true;
3470                    Object[] finderArgs = null;
3471    
3472                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3473                                    (orderByComparator == null)) {
3474                            pagination = false;
3475                            finderArgs = new Object[] {
3476                                            StringUtil.merge(taskExecutorClassNames), status
3477                                    };
3478                    }
3479                    else {
3480                            finderArgs = new Object[] {
3481                                            StringUtil.merge(taskExecutorClassNames), status,
3482                                            
3483                                            start, end, orderByComparator
3484                                    };
3485                    }
3486    
3487                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S,
3488                                    finderArgs, this);
3489    
3490                    if ((list != null) && !list.isEmpty()) {
3491                            for (BackgroundTask backgroundTask : list) {
3492                                    if (!ArrayUtil.contains(taskExecutorClassNames,
3493                                                            backgroundTask.getTaskExecutorClassName()) ||
3494                                                    (status != backgroundTask.getStatus())) {
3495                                            list = null;
3496    
3497                                            break;
3498                                    }
3499                            }
3500                    }
3501    
3502                    if (list == null) {
3503                            StringBundler query = new StringBundler();
3504    
3505                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
3506    
3507                            if (taskExecutorClassNames.length > 0) {
3508                                    query.append(StringPool.OPEN_PARENTHESIS);
3509    
3510                                    for (int i = 0; i < taskExecutorClassNames.length; i++) {
3511                                            String taskExecutorClassName = taskExecutorClassNames[i];
3512    
3513                                            if (taskExecutorClassName == null) {
3514                                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_4);
3515                                            }
3516                                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
3517                                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_6);
3518                                            }
3519                                            else {
3520                                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_5);
3521                                            }
3522    
3523                                            if ((i + 1) < taskExecutorClassNames.length) {
3524                                                    query.append(WHERE_OR);
3525                                            }
3526                                    }
3527    
3528                                    query.append(StringPool.CLOSE_PARENTHESIS);
3529    
3530                                    query.append(WHERE_AND);
3531                            }
3532    
3533                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
3534    
3535                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3536                                                    1)), query.index() - 1);
3537    
3538                            if (orderByComparator != null) {
3539                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3540                                            orderByComparator);
3541                            }
3542                            else
3543                             if (pagination) {
3544                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
3545                            }
3546    
3547                            String sql = query.toString();
3548    
3549                            Session session = null;
3550    
3551                            try {
3552                                    session = openSession();
3553    
3554                                    Query q = session.createQuery(sql);
3555    
3556                                    QueryPos qPos = QueryPos.getInstance(q);
3557    
3558                                    for (String taskExecutorClassName : taskExecutorClassNames) {
3559                                            if ((taskExecutorClassName != null) &&
3560                                                            !taskExecutorClassName.isEmpty()) {
3561                                                    qPos.add(taskExecutorClassName);
3562                                            }
3563                                    }
3564    
3565                                    qPos.add(status);
3566    
3567                                    if (!pagination) {
3568                                            list = (List<BackgroundTask>)QueryUtil.list(q,
3569                                                            getDialect(), start, end, false);
3570    
3571                                            Collections.sort(list);
3572    
3573                                            list = Collections.unmodifiableList(list);
3574                                    }
3575                                    else {
3576                                            list = (List<BackgroundTask>)QueryUtil.list(q,
3577                                                            getDialect(), start, end);
3578                                    }
3579    
3580                                    cacheResult(list);
3581    
3582                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S,
3583                                            finderArgs, list);
3584                            }
3585                            catch (Exception e) {
3586                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S,
3587                                            finderArgs);
3588    
3589                                    throw processException(e);
3590                            }
3591                            finally {
3592                                    closeSession(session);
3593                            }
3594                    }
3595    
3596                    return list;
3597            }
3598    
3599            /**
3600             * Removes all the background tasks where taskExecutorClassName = &#63; and status = &#63; from the database.
3601             *
3602             * @param taskExecutorClassName the task executor class name
3603             * @param status the status
3604             */
3605            @Override
3606            public void removeByT_S(String taskExecutorClassName, int status) {
3607                    for (BackgroundTask backgroundTask : findByT_S(taskExecutorClassName,
3608                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3609                            remove(backgroundTask);
3610                    }
3611            }
3612    
3613            /**
3614             * Returns the number of background tasks where taskExecutorClassName = &#63; and status = &#63;.
3615             *
3616             * @param taskExecutorClassName the task executor class name
3617             * @param status the status
3618             * @return the number of matching background tasks
3619             */
3620            @Override
3621            public int countByT_S(String taskExecutorClassName, int status) {
3622                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
3623    
3624                    Object[] finderArgs = new Object[] { taskExecutorClassName, status };
3625    
3626                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3627                                    this);
3628    
3629                    if (count == null) {
3630                            StringBundler query = new StringBundler(3);
3631    
3632                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
3633    
3634                            boolean bindTaskExecutorClassName = false;
3635    
3636                            if (taskExecutorClassName == null) {
3637                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_1);
3638                            }
3639                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
3640                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_3);
3641                            }
3642                            else {
3643                                    bindTaskExecutorClassName = true;
3644    
3645                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_2);
3646                            }
3647    
3648                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
3649    
3650                            String sql = query.toString();
3651    
3652                            Session session = null;
3653    
3654                            try {
3655                                    session = openSession();
3656    
3657                                    Query q = session.createQuery(sql);
3658    
3659                                    QueryPos qPos = QueryPos.getInstance(q);
3660    
3661                                    if (bindTaskExecutorClassName) {
3662                                            qPos.add(taskExecutorClassName);
3663                                    }
3664    
3665                                    qPos.add(status);
3666    
3667                                    count = (Long)q.uniqueResult();
3668    
3669                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3670                            }
3671                            catch (Exception e) {
3672                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3673    
3674                                    throw processException(e);
3675                            }
3676                            finally {
3677                                    closeSession(session);
3678                            }
3679                    }
3680    
3681                    return count.intValue();
3682            }
3683    
3684            /**
3685             * Returns the number of background tasks where taskExecutorClassName = any &#63; and status = &#63;.
3686             *
3687             * @param taskExecutorClassNames the task executor class names
3688             * @param status the status
3689             * @return the number of matching background tasks
3690             */
3691            @Override
3692            public int countByT_S(String[] taskExecutorClassNames, int status) {
3693                    if (taskExecutorClassNames == null) {
3694                            taskExecutorClassNames = new String[0];
3695                    }
3696                    else {
3697                            taskExecutorClassNames = ArrayUtil.distinct(taskExecutorClassNames,
3698                                            NULL_SAFE_STRING_COMPARATOR);
3699                    }
3700    
3701                    Object[] finderArgs = new Object[] {
3702                                    StringUtil.merge(taskExecutorClassNames), status
3703                            };
3704    
3705                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_S,
3706                                    finderArgs, this);
3707    
3708                    if (count == null) {
3709                            StringBundler query = new StringBundler();
3710    
3711                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
3712    
3713                            if (taskExecutorClassNames.length > 0) {
3714                                    query.append(StringPool.OPEN_PARENTHESIS);
3715    
3716                                    for (int i = 0; i < taskExecutorClassNames.length; i++) {
3717                                            String taskExecutorClassName = taskExecutorClassNames[i];
3718    
3719                                            if (taskExecutorClassName == null) {
3720                                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_4);
3721                                            }
3722                                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
3723                                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_6);
3724                                            }
3725                                            else {
3726                                                    query.append(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_5);
3727                                            }
3728    
3729                                            if ((i + 1) < taskExecutorClassNames.length) {
3730                                                    query.append(WHERE_OR);
3731                                            }
3732                                    }
3733    
3734                                    query.append(StringPool.CLOSE_PARENTHESIS);
3735    
3736                                    query.append(WHERE_AND);
3737                            }
3738    
3739                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
3740    
3741                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3742                                                    1)), query.index() - 1);
3743    
3744                            String sql = query.toString();
3745    
3746                            Session session = null;
3747    
3748                            try {
3749                                    session = openSession();
3750    
3751                                    Query q = session.createQuery(sql);
3752    
3753                                    QueryPos qPos = QueryPos.getInstance(q);
3754    
3755                                    for (String taskExecutorClassName : taskExecutorClassNames) {
3756                                            if ((taskExecutorClassName != null) &&
3757                                                            !taskExecutorClassName.isEmpty()) {
3758                                                    qPos.add(taskExecutorClassName);
3759                                            }
3760                                    }
3761    
3762                                    qPos.add(status);
3763    
3764                                    count = (Long)q.uniqueResult();
3765    
3766                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_S,
3767                                            finderArgs, count);
3768                            }
3769                            catch (Exception e) {
3770                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_S,
3771                                            finderArgs);
3772    
3773                                    throw processException(e);
3774                            }
3775                            finally {
3776                                    closeSession(session);
3777                            }
3778                    }
3779    
3780                    return count.intValue();
3781            }
3782    
3783            private static final String _FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_1 = "backgroundTask.taskExecutorClassName IS NULL AND ";
3784            private static final String _FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_2 = "backgroundTask.taskExecutorClassName = ? AND ";
3785            private static final String _FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_3 = "(backgroundTask.taskExecutorClassName IS NULL OR backgroundTask.taskExecutorClassName = '') AND ";
3786            private static final String _FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_4 = "(" +
3787                    removeConjunction(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_1) + ")";
3788            private static final String _FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_5 = "(" +
3789                    removeConjunction(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_2) + ")";
3790            private static final String _FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_6 = "(" +
3791                    removeConjunction(_FINDER_COLUMN_T_S_TASKEXECUTORCLASSNAME_3) + ")";
3792            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "backgroundTask.status = ?";
3793            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
3794                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
3795                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3796                            "findByG_N_T",
3797                            new String[] {
3798                                    Long.class.getName(), String.class.getName(),
3799                                    String.class.getName(),
3800                                    
3801                            Integer.class.getName(), Integer.class.getName(),
3802                                    OrderByComparator.class.getName()
3803                            });
3804            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
3805                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
3806                            BackgroundTaskImpl.class,
3807                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_T",
3808                            new String[] {
3809                                    Long.class.getName(), String.class.getName(),
3810                                    String.class.getName()
3811                            },
3812                            BackgroundTaskModelImpl.GROUPID_COLUMN_BITMASK |
3813                            BackgroundTaskModelImpl.NAME_COLUMN_BITMASK |
3814                            BackgroundTaskModelImpl.TASKEXECUTORCLASSNAME_COLUMN_BITMASK |
3815                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
3816            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_T = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
3817                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
3818                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_T",
3819                            new String[] {
3820                                    Long.class.getName(), String.class.getName(),
3821                                    String.class.getName()
3822                            });
3823    
3824            /**
3825             * Returns all the background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
3826             *
3827             * @param groupId the group ID
3828             * @param name the name
3829             * @param taskExecutorClassName the task executor class name
3830             * @return the matching background tasks
3831             */
3832            @Override
3833            public List<BackgroundTask> findByG_N_T(long groupId, String name,
3834                    String taskExecutorClassName) {
3835                    return findByG_N_T(groupId, name, taskExecutorClassName,
3836                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3837            }
3838    
3839            /**
3840             * Returns a range of all the background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
3841             *
3842             * <p>
3843             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
3844             * </p>
3845             *
3846             * @param groupId the group ID
3847             * @param name the name
3848             * @param taskExecutorClassName the task executor class name
3849             * @param start the lower bound of the range of background tasks
3850             * @param end the upper bound of the range of background tasks (not inclusive)
3851             * @return the range of matching background tasks
3852             */
3853            @Override
3854            public List<BackgroundTask> findByG_N_T(long groupId, String name,
3855                    String taskExecutorClassName, int start, int end) {
3856                    return findByG_N_T(groupId, name, taskExecutorClassName, start, end,
3857                            null);
3858            }
3859    
3860            /**
3861             * Returns an ordered range of all the background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
3862             *
3863             * <p>
3864             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
3865             * </p>
3866             *
3867             * @param groupId the group ID
3868             * @param name the name
3869             * @param taskExecutorClassName the task executor class name
3870             * @param start the lower bound of the range of background tasks
3871             * @param end the upper bound of the range of background tasks (not inclusive)
3872             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3873             * @return the ordered range of matching background tasks
3874             */
3875            @Override
3876            public List<BackgroundTask> findByG_N_T(long groupId, String name,
3877                    String taskExecutorClassName, int start, int end,
3878                    OrderByComparator<BackgroundTask> orderByComparator) {
3879                    boolean pagination = true;
3880                    FinderPath finderPath = null;
3881                    Object[] finderArgs = null;
3882    
3883                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3884                                    (orderByComparator == null)) {
3885                            pagination = false;
3886                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T;
3887                            finderArgs = new Object[] { groupId, name, taskExecutorClassName };
3888                    }
3889                    else {
3890                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T;
3891                            finderArgs = new Object[] {
3892                                            groupId, name, taskExecutorClassName,
3893                                            
3894                                            start, end, orderByComparator
3895                                    };
3896                    }
3897    
3898                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
3899                                    finderArgs, this);
3900    
3901                    if ((list != null) && !list.isEmpty()) {
3902                            for (BackgroundTask backgroundTask : list) {
3903                                    if ((groupId != backgroundTask.getGroupId()) ||
3904                                                    !Validator.equals(name, backgroundTask.getName()) ||
3905                                                    !Validator.equals(taskExecutorClassName,
3906                                                            backgroundTask.getTaskExecutorClassName())) {
3907                                            list = null;
3908    
3909                                            break;
3910                                    }
3911                            }
3912                    }
3913    
3914                    if (list == null) {
3915                            StringBundler query = null;
3916    
3917                            if (orderByComparator != null) {
3918                                    query = new StringBundler(5 +
3919                                                    (orderByComparator.getOrderByFields().length * 3));
3920                            }
3921                            else {
3922                                    query = new StringBundler(5);
3923                            }
3924    
3925                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
3926    
3927                            query.append(_FINDER_COLUMN_G_N_T_GROUPID_2);
3928    
3929                            boolean bindName = false;
3930    
3931                            if (name == null) {
3932                                    query.append(_FINDER_COLUMN_G_N_T_NAME_1);
3933                            }
3934                            else if (name.equals(StringPool.BLANK)) {
3935                                    query.append(_FINDER_COLUMN_G_N_T_NAME_3);
3936                            }
3937                            else {
3938                                    bindName = true;
3939    
3940                                    query.append(_FINDER_COLUMN_G_N_T_NAME_2);
3941                            }
3942    
3943                            boolean bindTaskExecutorClassName = false;
3944    
3945                            if (taskExecutorClassName == null) {
3946                                    query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_1);
3947                            }
3948                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
3949                                    query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_3);
3950                            }
3951                            else {
3952                                    bindTaskExecutorClassName = true;
3953    
3954                                    query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_2);
3955                            }
3956    
3957                            if (orderByComparator != null) {
3958                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3959                                            orderByComparator);
3960                            }
3961                            else
3962                             if (pagination) {
3963                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
3964                            }
3965    
3966                            String sql = query.toString();
3967    
3968                            Session session = null;
3969    
3970                            try {
3971                                    session = openSession();
3972    
3973                                    Query q = session.createQuery(sql);
3974    
3975                                    QueryPos qPos = QueryPos.getInstance(q);
3976    
3977                                    qPos.add(groupId);
3978    
3979                                    if (bindName) {
3980                                            qPos.add(name);
3981                                    }
3982    
3983                                    if (bindTaskExecutorClassName) {
3984                                            qPos.add(taskExecutorClassName);
3985                                    }
3986    
3987                                    if (!pagination) {
3988                                            list = (List<BackgroundTask>)QueryUtil.list(q,
3989                                                            getDialect(), start, end, false);
3990    
3991                                            Collections.sort(list);
3992    
3993                                            list = Collections.unmodifiableList(list);
3994                                    }
3995                                    else {
3996                                            list = (List<BackgroundTask>)QueryUtil.list(q,
3997                                                            getDialect(), start, end);
3998                                    }
3999    
4000                                    cacheResult(list);
4001    
4002                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4003                            }
4004                            catch (Exception e) {
4005                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4006    
4007                                    throw processException(e);
4008                            }
4009                            finally {
4010                                    closeSession(session);
4011                            }
4012                    }
4013    
4014                    return list;
4015            }
4016    
4017            /**
4018             * Returns the first background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
4019             *
4020             * @param groupId the group ID
4021             * @param name the name
4022             * @param taskExecutorClassName the task executor class name
4023             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4024             * @return the first matching background task
4025             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
4026             */
4027            @Override
4028            public BackgroundTask findByG_N_T_First(long groupId, String name,
4029                    String taskExecutorClassName,
4030                    OrderByComparator<BackgroundTask> orderByComparator)
4031                    throws NoSuchBackgroundTaskException {
4032                    BackgroundTask backgroundTask = fetchByG_N_T_First(groupId, name,
4033                                    taskExecutorClassName, orderByComparator);
4034    
4035                    if (backgroundTask != null) {
4036                            return backgroundTask;
4037                    }
4038    
4039                    StringBundler msg = new StringBundler(8);
4040    
4041                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4042    
4043                    msg.append("groupId=");
4044                    msg.append(groupId);
4045    
4046                    msg.append(", name=");
4047                    msg.append(name);
4048    
4049                    msg.append(", taskExecutorClassName=");
4050                    msg.append(taskExecutorClassName);
4051    
4052                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4053    
4054                    throw new NoSuchBackgroundTaskException(msg.toString());
4055            }
4056    
4057            /**
4058             * Returns the first background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
4059             *
4060             * @param groupId the group ID
4061             * @param name the name
4062             * @param taskExecutorClassName the task executor class name
4063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4064             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
4065             */
4066            @Override
4067            public BackgroundTask fetchByG_N_T_First(long groupId, String name,
4068                    String taskExecutorClassName,
4069                    OrderByComparator<BackgroundTask> orderByComparator) {
4070                    List<BackgroundTask> list = findByG_N_T(groupId, name,
4071                                    taskExecutorClassName, 0, 1, orderByComparator);
4072    
4073                    if (!list.isEmpty()) {
4074                            return list.get(0);
4075                    }
4076    
4077                    return null;
4078            }
4079    
4080            /**
4081             * Returns the last background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
4082             *
4083             * @param groupId the group ID
4084             * @param name the name
4085             * @param taskExecutorClassName the task executor class name
4086             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4087             * @return the last matching background task
4088             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
4089             */
4090            @Override
4091            public BackgroundTask findByG_N_T_Last(long groupId, String name,
4092                    String taskExecutorClassName,
4093                    OrderByComparator<BackgroundTask> orderByComparator)
4094                    throws NoSuchBackgroundTaskException {
4095                    BackgroundTask backgroundTask = fetchByG_N_T_Last(groupId, name,
4096                                    taskExecutorClassName, orderByComparator);
4097    
4098                    if (backgroundTask != null) {
4099                            return backgroundTask;
4100                    }
4101    
4102                    StringBundler msg = new StringBundler(8);
4103    
4104                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4105    
4106                    msg.append("groupId=");
4107                    msg.append(groupId);
4108    
4109                    msg.append(", name=");
4110                    msg.append(name);
4111    
4112                    msg.append(", taskExecutorClassName=");
4113                    msg.append(taskExecutorClassName);
4114    
4115                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4116    
4117                    throw new NoSuchBackgroundTaskException(msg.toString());
4118            }
4119    
4120            /**
4121             * Returns the last background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
4122             *
4123             * @param groupId the group ID
4124             * @param name the name
4125             * @param taskExecutorClassName the task executor class name
4126             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4127             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
4128             */
4129            @Override
4130            public BackgroundTask fetchByG_N_T_Last(long groupId, String name,
4131                    String taskExecutorClassName,
4132                    OrderByComparator<BackgroundTask> orderByComparator) {
4133                    int count = countByG_N_T(groupId, name, taskExecutorClassName);
4134    
4135                    if (count == 0) {
4136                            return null;
4137                    }
4138    
4139                    List<BackgroundTask> list = findByG_N_T(groupId, name,
4140                                    taskExecutorClassName, count - 1, count, orderByComparator);
4141    
4142                    if (!list.isEmpty()) {
4143                            return list.get(0);
4144                    }
4145    
4146                    return null;
4147            }
4148    
4149            /**
4150             * Returns the background tasks before and after the current background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
4151             *
4152             * @param backgroundTaskId the primary key of the current background task
4153             * @param groupId the group ID
4154             * @param name the name
4155             * @param taskExecutorClassName the task executor class name
4156             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4157             * @return the previous, current, and next background task
4158             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
4159             */
4160            @Override
4161            public BackgroundTask[] findByG_N_T_PrevAndNext(long backgroundTaskId,
4162                    long groupId, String name, String taskExecutorClassName,
4163                    OrderByComparator<BackgroundTask> orderByComparator)
4164                    throws NoSuchBackgroundTaskException {
4165                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
4166    
4167                    Session session = null;
4168    
4169                    try {
4170                            session = openSession();
4171    
4172                            BackgroundTask[] array = new BackgroundTaskImpl[3];
4173    
4174                            array[0] = getByG_N_T_PrevAndNext(session, backgroundTask, groupId,
4175                                            name, taskExecutorClassName, orderByComparator, true);
4176    
4177                            array[1] = backgroundTask;
4178    
4179                            array[2] = getByG_N_T_PrevAndNext(session, backgroundTask, groupId,
4180                                            name, taskExecutorClassName, orderByComparator, false);
4181    
4182                            return array;
4183                    }
4184                    catch (Exception e) {
4185                            throw processException(e);
4186                    }
4187                    finally {
4188                            closeSession(session);
4189                    }
4190            }
4191    
4192            protected BackgroundTask getByG_N_T_PrevAndNext(Session session,
4193                    BackgroundTask backgroundTask, long groupId, String name,
4194                    String taskExecutorClassName,
4195                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
4196                    StringBundler query = null;
4197    
4198                    if (orderByComparator != null) {
4199                            query = new StringBundler(6 +
4200                                            (orderByComparator.getOrderByFields().length * 6));
4201                    }
4202                    else {
4203                            query = new StringBundler(3);
4204                    }
4205    
4206                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
4207    
4208                    query.append(_FINDER_COLUMN_G_N_T_GROUPID_2);
4209    
4210                    boolean bindName = false;
4211    
4212                    if (name == null) {
4213                            query.append(_FINDER_COLUMN_G_N_T_NAME_1);
4214                    }
4215                    else if (name.equals(StringPool.BLANK)) {
4216                            query.append(_FINDER_COLUMN_G_N_T_NAME_3);
4217                    }
4218                    else {
4219                            bindName = true;
4220    
4221                            query.append(_FINDER_COLUMN_G_N_T_NAME_2);
4222                    }
4223    
4224                    boolean bindTaskExecutorClassName = false;
4225    
4226                    if (taskExecutorClassName == null) {
4227                            query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_1);
4228                    }
4229                    else if (taskExecutorClassName.equals(StringPool.BLANK)) {
4230                            query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_3);
4231                    }
4232                    else {
4233                            bindTaskExecutorClassName = true;
4234    
4235                            query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_2);
4236                    }
4237    
4238                    if (orderByComparator != null) {
4239                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4240    
4241                            if (orderByConditionFields.length > 0) {
4242                                    query.append(WHERE_AND);
4243                            }
4244    
4245                            for (int i = 0; i < orderByConditionFields.length; i++) {
4246                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4247                                    query.append(orderByConditionFields[i]);
4248    
4249                                    if ((i + 1) < orderByConditionFields.length) {
4250                                            if (orderByComparator.isAscending() ^ previous) {
4251                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4252                                            }
4253                                            else {
4254                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4255                                            }
4256                                    }
4257                                    else {
4258                                            if (orderByComparator.isAscending() ^ previous) {
4259                                                    query.append(WHERE_GREATER_THAN);
4260                                            }
4261                                            else {
4262                                                    query.append(WHERE_LESSER_THAN);
4263                                            }
4264                                    }
4265                            }
4266    
4267                            query.append(ORDER_BY_CLAUSE);
4268    
4269                            String[] orderByFields = orderByComparator.getOrderByFields();
4270    
4271                            for (int i = 0; i < orderByFields.length; i++) {
4272                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4273                                    query.append(orderByFields[i]);
4274    
4275                                    if ((i + 1) < orderByFields.length) {
4276                                            if (orderByComparator.isAscending() ^ previous) {
4277                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4278                                            }
4279                                            else {
4280                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4281                                            }
4282                                    }
4283                                    else {
4284                                            if (orderByComparator.isAscending() ^ previous) {
4285                                                    query.append(ORDER_BY_ASC);
4286                                            }
4287                                            else {
4288                                                    query.append(ORDER_BY_DESC);
4289                                            }
4290                                    }
4291                            }
4292                    }
4293                    else {
4294                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
4295                    }
4296    
4297                    String sql = query.toString();
4298    
4299                    Query q = session.createQuery(sql);
4300    
4301                    q.setFirstResult(0);
4302                    q.setMaxResults(2);
4303    
4304                    QueryPos qPos = QueryPos.getInstance(q);
4305    
4306                    qPos.add(groupId);
4307    
4308                    if (bindName) {
4309                            qPos.add(name);
4310                    }
4311    
4312                    if (bindTaskExecutorClassName) {
4313                            qPos.add(taskExecutorClassName);
4314                    }
4315    
4316                    if (orderByComparator != null) {
4317                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
4318    
4319                            for (Object value : values) {
4320                                    qPos.add(value);
4321                            }
4322                    }
4323    
4324                    List<BackgroundTask> list = q.list();
4325    
4326                    if (list.size() == 2) {
4327                            return list.get(1);
4328                    }
4329                    else {
4330                            return null;
4331                    }
4332            }
4333    
4334            /**
4335             * Removes all the background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; from the database.
4336             *
4337             * @param groupId the group ID
4338             * @param name the name
4339             * @param taskExecutorClassName the task executor class name
4340             */
4341            @Override
4342            public void removeByG_N_T(long groupId, String name,
4343                    String taskExecutorClassName) {
4344                    for (BackgroundTask backgroundTask : findByG_N_T(groupId, name,
4345                                    taskExecutorClassName, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4346                                    null)) {
4347                            remove(backgroundTask);
4348                    }
4349            }
4350    
4351            /**
4352             * Returns the number of background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63;.
4353             *
4354             * @param groupId the group ID
4355             * @param name the name
4356             * @param taskExecutorClassName the task executor class name
4357             * @return the number of matching background tasks
4358             */
4359            @Override
4360            public int countByG_N_T(long groupId, String name,
4361                    String taskExecutorClassName) {
4362                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_T;
4363    
4364                    Object[] finderArgs = new Object[] { groupId, name, taskExecutorClassName };
4365    
4366                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4367                                    this);
4368    
4369                    if (count == null) {
4370                            StringBundler query = new StringBundler(4);
4371    
4372                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
4373    
4374                            query.append(_FINDER_COLUMN_G_N_T_GROUPID_2);
4375    
4376                            boolean bindName = false;
4377    
4378                            if (name == null) {
4379                                    query.append(_FINDER_COLUMN_G_N_T_NAME_1);
4380                            }
4381                            else if (name.equals(StringPool.BLANK)) {
4382                                    query.append(_FINDER_COLUMN_G_N_T_NAME_3);
4383                            }
4384                            else {
4385                                    bindName = true;
4386    
4387                                    query.append(_FINDER_COLUMN_G_N_T_NAME_2);
4388                            }
4389    
4390                            boolean bindTaskExecutorClassName = false;
4391    
4392                            if (taskExecutorClassName == null) {
4393                                    query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_1);
4394                            }
4395                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
4396                                    query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_3);
4397                            }
4398                            else {
4399                                    bindTaskExecutorClassName = true;
4400    
4401                                    query.append(_FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_2);
4402                            }
4403    
4404                            String sql = query.toString();
4405    
4406                            Session session = null;
4407    
4408                            try {
4409                                    session = openSession();
4410    
4411                                    Query q = session.createQuery(sql);
4412    
4413                                    QueryPos qPos = QueryPos.getInstance(q);
4414    
4415                                    qPos.add(groupId);
4416    
4417                                    if (bindName) {
4418                                            qPos.add(name);
4419                                    }
4420    
4421                                    if (bindTaskExecutorClassName) {
4422                                            qPos.add(taskExecutorClassName);
4423                                    }
4424    
4425                                    count = (Long)q.uniqueResult();
4426    
4427                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4428                            }
4429                            catch (Exception e) {
4430                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4431    
4432                                    throw processException(e);
4433                            }
4434                            finally {
4435                                    closeSession(session);
4436                            }
4437                    }
4438    
4439                    return count.intValue();
4440            }
4441    
4442            private static final String _FINDER_COLUMN_G_N_T_GROUPID_2 = "backgroundTask.groupId = ? AND ";
4443            private static final String _FINDER_COLUMN_G_N_T_NAME_1 = "backgroundTask.name IS NULL AND ";
4444            private static final String _FINDER_COLUMN_G_N_T_NAME_2 = "backgroundTask.name = ? AND ";
4445            private static final String _FINDER_COLUMN_G_N_T_NAME_3 = "(backgroundTask.name IS NULL OR backgroundTask.name = '') AND ";
4446            private static final String _FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_1 = "backgroundTask.taskExecutorClassName IS NULL";
4447            private static final String _FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_2 = "backgroundTask.taskExecutorClassName = ?";
4448            private static final String _FINDER_COLUMN_G_N_T_TASKEXECUTORCLASSNAME_3 = "(backgroundTask.taskExecutorClassName IS NULL OR backgroundTask.taskExecutorClassName = '')";
4449            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_C = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
4450                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
4451                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4452                            "findByG_T_C",
4453                            new String[] {
4454                                    Long.class.getName(), String.class.getName(),
4455                                    Boolean.class.getName(),
4456                                    
4457                            Integer.class.getName(), Integer.class.getName(),
4458                                    OrderByComparator.class.getName()
4459                            });
4460            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_C = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
4461                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
4462                            BackgroundTaskImpl.class,
4463                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_T_C",
4464                            new String[] {
4465                                    Long.class.getName(), String.class.getName(),
4466                                    Boolean.class.getName()
4467                            },
4468                            BackgroundTaskModelImpl.GROUPID_COLUMN_BITMASK |
4469                            BackgroundTaskModelImpl.TASKEXECUTORCLASSNAME_COLUMN_BITMASK |
4470                            BackgroundTaskModelImpl.COMPLETED_COLUMN_BITMASK |
4471                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
4472            public static final FinderPath FINDER_PATH_COUNT_BY_G_T_C = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
4473                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
4474                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T_C",
4475                            new String[] {
4476                                    Long.class.getName(), String.class.getName(),
4477                                    Boolean.class.getName()
4478                            });
4479            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_C = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
4480                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
4481                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_T_C",
4482                            new String[] {
4483                                    Long.class.getName(), String.class.getName(),
4484                                    Boolean.class.getName()
4485                            });
4486    
4487            /**
4488             * Returns all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
4489             *
4490             * @param groupId the group ID
4491             * @param taskExecutorClassName the task executor class name
4492             * @param completed the completed
4493             * @return the matching background tasks
4494             */
4495            @Override
4496            public List<BackgroundTask> findByG_T_C(long groupId,
4497                    String taskExecutorClassName, boolean completed) {
4498                    return findByG_T_C(groupId, taskExecutorClassName, completed,
4499                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4500            }
4501    
4502            /**
4503             * Returns a range of all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
4504             *
4505             * <p>
4506             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
4507             * </p>
4508             *
4509             * @param groupId the group ID
4510             * @param taskExecutorClassName the task executor class name
4511             * @param completed the completed
4512             * @param start the lower bound of the range of background tasks
4513             * @param end the upper bound of the range of background tasks (not inclusive)
4514             * @return the range of matching background tasks
4515             */
4516            @Override
4517            public List<BackgroundTask> findByG_T_C(long groupId,
4518                    String taskExecutorClassName, boolean completed, int start, int end) {
4519                    return findByG_T_C(groupId, taskExecutorClassName, completed, start,
4520                            end, null);
4521            }
4522    
4523            /**
4524             * Returns an ordered range of all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
4525             *
4526             * <p>
4527             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
4528             * </p>
4529             *
4530             * @param groupId the group ID
4531             * @param taskExecutorClassName the task executor class name
4532             * @param completed the completed
4533             * @param start the lower bound of the range of background tasks
4534             * @param end the upper bound of the range of background tasks (not inclusive)
4535             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4536             * @return the ordered range of matching background tasks
4537             */
4538            @Override
4539            public List<BackgroundTask> findByG_T_C(long groupId,
4540                    String taskExecutorClassName, boolean completed, int start, int end,
4541                    OrderByComparator<BackgroundTask> orderByComparator) {
4542                    boolean pagination = true;
4543                    FinderPath finderPath = null;
4544                    Object[] finderArgs = null;
4545    
4546                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4547                                    (orderByComparator == null)) {
4548                            pagination = false;
4549                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_C;
4550                            finderArgs = new Object[] { groupId, taskExecutorClassName, completed };
4551                    }
4552                    else {
4553                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_C;
4554                            finderArgs = new Object[] {
4555                                            groupId, taskExecutorClassName, completed,
4556                                            
4557                                            start, end, orderByComparator
4558                                    };
4559                    }
4560    
4561                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
4562                                    finderArgs, this);
4563    
4564                    if ((list != null) && !list.isEmpty()) {
4565                            for (BackgroundTask backgroundTask : list) {
4566                                    if ((groupId != backgroundTask.getGroupId()) ||
4567                                                    !Validator.equals(taskExecutorClassName,
4568                                                            backgroundTask.getTaskExecutorClassName()) ||
4569                                                    (completed != backgroundTask.getCompleted())) {
4570                                            list = null;
4571    
4572                                            break;
4573                                    }
4574                            }
4575                    }
4576    
4577                    if (list == null) {
4578                            StringBundler query = null;
4579    
4580                            if (orderByComparator != null) {
4581                                    query = new StringBundler(5 +
4582                                                    (orderByComparator.getOrderByFields().length * 3));
4583                            }
4584                            else {
4585                                    query = new StringBundler(5);
4586                            }
4587    
4588                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
4589    
4590                            query.append(_FINDER_COLUMN_G_T_C_GROUPID_2);
4591    
4592                            boolean bindTaskExecutorClassName = false;
4593    
4594                            if (taskExecutorClassName == null) {
4595                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_1);
4596                            }
4597                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
4598                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_3);
4599                            }
4600                            else {
4601                                    bindTaskExecutorClassName = true;
4602    
4603                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_2);
4604                            }
4605    
4606                            query.append(_FINDER_COLUMN_G_T_C_COMPLETED_2);
4607    
4608                            if (orderByComparator != null) {
4609                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4610                                            orderByComparator);
4611                            }
4612                            else
4613                             if (pagination) {
4614                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
4615                            }
4616    
4617                            String sql = query.toString();
4618    
4619                            Session session = null;
4620    
4621                            try {
4622                                    session = openSession();
4623    
4624                                    Query q = session.createQuery(sql);
4625    
4626                                    QueryPos qPos = QueryPos.getInstance(q);
4627    
4628                                    qPos.add(groupId);
4629    
4630                                    if (bindTaskExecutorClassName) {
4631                                            qPos.add(taskExecutorClassName);
4632                                    }
4633    
4634                                    qPos.add(completed);
4635    
4636                                    if (!pagination) {
4637                                            list = (List<BackgroundTask>)QueryUtil.list(q,
4638                                                            getDialect(), start, end, false);
4639    
4640                                            Collections.sort(list);
4641    
4642                                            list = Collections.unmodifiableList(list);
4643                                    }
4644                                    else {
4645                                            list = (List<BackgroundTask>)QueryUtil.list(q,
4646                                                            getDialect(), start, end);
4647                                    }
4648    
4649                                    cacheResult(list);
4650    
4651                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4652                            }
4653                            catch (Exception e) {
4654                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4655    
4656                                    throw processException(e);
4657                            }
4658                            finally {
4659                                    closeSession(session);
4660                            }
4661                    }
4662    
4663                    return list;
4664            }
4665    
4666            /**
4667             * Returns the first background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
4668             *
4669             * @param groupId the group ID
4670             * @param taskExecutorClassName the task executor class name
4671             * @param completed the completed
4672             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4673             * @return the first matching background task
4674             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
4675             */
4676            @Override
4677            public BackgroundTask findByG_T_C_First(long groupId,
4678                    String taskExecutorClassName, boolean completed,
4679                    OrderByComparator<BackgroundTask> orderByComparator)
4680                    throws NoSuchBackgroundTaskException {
4681                    BackgroundTask backgroundTask = fetchByG_T_C_First(groupId,
4682                                    taskExecutorClassName, completed, orderByComparator);
4683    
4684                    if (backgroundTask != null) {
4685                            return backgroundTask;
4686                    }
4687    
4688                    StringBundler msg = new StringBundler(8);
4689    
4690                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4691    
4692                    msg.append("groupId=");
4693                    msg.append(groupId);
4694    
4695                    msg.append(", taskExecutorClassName=");
4696                    msg.append(taskExecutorClassName);
4697    
4698                    msg.append(", completed=");
4699                    msg.append(completed);
4700    
4701                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4702    
4703                    throw new NoSuchBackgroundTaskException(msg.toString());
4704            }
4705    
4706            /**
4707             * Returns the first background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
4708             *
4709             * @param groupId the group ID
4710             * @param taskExecutorClassName the task executor class name
4711             * @param completed the completed
4712             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4713             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
4714             */
4715            @Override
4716            public BackgroundTask fetchByG_T_C_First(long groupId,
4717                    String taskExecutorClassName, boolean completed,
4718                    OrderByComparator<BackgroundTask> orderByComparator) {
4719                    List<BackgroundTask> list = findByG_T_C(groupId, taskExecutorClassName,
4720                                    completed, 0, 1, orderByComparator);
4721    
4722                    if (!list.isEmpty()) {
4723                            return list.get(0);
4724                    }
4725    
4726                    return null;
4727            }
4728    
4729            /**
4730             * Returns the last background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
4731             *
4732             * @param groupId the group ID
4733             * @param taskExecutorClassName the task executor class name
4734             * @param completed the completed
4735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4736             * @return the last matching background task
4737             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
4738             */
4739            @Override
4740            public BackgroundTask findByG_T_C_Last(long groupId,
4741                    String taskExecutorClassName, boolean completed,
4742                    OrderByComparator<BackgroundTask> orderByComparator)
4743                    throws NoSuchBackgroundTaskException {
4744                    BackgroundTask backgroundTask = fetchByG_T_C_Last(groupId,
4745                                    taskExecutorClassName, completed, orderByComparator);
4746    
4747                    if (backgroundTask != null) {
4748                            return backgroundTask;
4749                    }
4750    
4751                    StringBundler msg = new StringBundler(8);
4752    
4753                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4754    
4755                    msg.append("groupId=");
4756                    msg.append(groupId);
4757    
4758                    msg.append(", taskExecutorClassName=");
4759                    msg.append(taskExecutorClassName);
4760    
4761                    msg.append(", completed=");
4762                    msg.append(completed);
4763    
4764                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4765    
4766                    throw new NoSuchBackgroundTaskException(msg.toString());
4767            }
4768    
4769            /**
4770             * Returns the last background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
4771             *
4772             * @param groupId the group ID
4773             * @param taskExecutorClassName the task executor class name
4774             * @param completed the completed
4775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4776             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
4777             */
4778            @Override
4779            public BackgroundTask fetchByG_T_C_Last(long groupId,
4780                    String taskExecutorClassName, boolean completed,
4781                    OrderByComparator<BackgroundTask> orderByComparator) {
4782                    int count = countByG_T_C(groupId, taskExecutorClassName, completed);
4783    
4784                    if (count == 0) {
4785                            return null;
4786                    }
4787    
4788                    List<BackgroundTask> list = findByG_T_C(groupId, taskExecutorClassName,
4789                                    completed, count - 1, count, orderByComparator);
4790    
4791                    if (!list.isEmpty()) {
4792                            return list.get(0);
4793                    }
4794    
4795                    return null;
4796            }
4797    
4798            /**
4799             * Returns the background tasks before and after the current background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
4800             *
4801             * @param backgroundTaskId the primary key of the current background task
4802             * @param groupId the group ID
4803             * @param taskExecutorClassName the task executor class name
4804             * @param completed the completed
4805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4806             * @return the previous, current, and next background task
4807             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
4808             */
4809            @Override
4810            public BackgroundTask[] findByG_T_C_PrevAndNext(long backgroundTaskId,
4811                    long groupId, String taskExecutorClassName, boolean completed,
4812                    OrderByComparator<BackgroundTask> orderByComparator)
4813                    throws NoSuchBackgroundTaskException {
4814                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
4815    
4816                    Session session = null;
4817    
4818                    try {
4819                            session = openSession();
4820    
4821                            BackgroundTask[] array = new BackgroundTaskImpl[3];
4822    
4823                            array[0] = getByG_T_C_PrevAndNext(session, backgroundTask, groupId,
4824                                            taskExecutorClassName, completed, orderByComparator, true);
4825    
4826                            array[1] = backgroundTask;
4827    
4828                            array[2] = getByG_T_C_PrevAndNext(session, backgroundTask, groupId,
4829                                            taskExecutorClassName, completed, orderByComparator, false);
4830    
4831                            return array;
4832                    }
4833                    catch (Exception e) {
4834                            throw processException(e);
4835                    }
4836                    finally {
4837                            closeSession(session);
4838                    }
4839            }
4840    
4841            protected BackgroundTask getByG_T_C_PrevAndNext(Session session,
4842                    BackgroundTask backgroundTask, long groupId,
4843                    String taskExecutorClassName, boolean completed,
4844                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
4845                    StringBundler query = null;
4846    
4847                    if (orderByComparator != null) {
4848                            query = new StringBundler(6 +
4849                                            (orderByComparator.getOrderByFields().length * 6));
4850                    }
4851                    else {
4852                            query = new StringBundler(3);
4853                    }
4854    
4855                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
4856    
4857                    query.append(_FINDER_COLUMN_G_T_C_GROUPID_2);
4858    
4859                    boolean bindTaskExecutorClassName = false;
4860    
4861                    if (taskExecutorClassName == null) {
4862                            query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_1);
4863                    }
4864                    else if (taskExecutorClassName.equals(StringPool.BLANK)) {
4865                            query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_3);
4866                    }
4867                    else {
4868                            bindTaskExecutorClassName = true;
4869    
4870                            query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_2);
4871                    }
4872    
4873                    query.append(_FINDER_COLUMN_G_T_C_COMPLETED_2);
4874    
4875                    if (orderByComparator != null) {
4876                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4877    
4878                            if (orderByConditionFields.length > 0) {
4879                                    query.append(WHERE_AND);
4880                            }
4881    
4882                            for (int i = 0; i < orderByConditionFields.length; i++) {
4883                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4884                                    query.append(orderByConditionFields[i]);
4885    
4886                                    if ((i + 1) < orderByConditionFields.length) {
4887                                            if (orderByComparator.isAscending() ^ previous) {
4888                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4889                                            }
4890                                            else {
4891                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4892                                            }
4893                                    }
4894                                    else {
4895                                            if (orderByComparator.isAscending() ^ previous) {
4896                                                    query.append(WHERE_GREATER_THAN);
4897                                            }
4898                                            else {
4899                                                    query.append(WHERE_LESSER_THAN);
4900                                            }
4901                                    }
4902                            }
4903    
4904                            query.append(ORDER_BY_CLAUSE);
4905    
4906                            String[] orderByFields = orderByComparator.getOrderByFields();
4907    
4908                            for (int i = 0; i < orderByFields.length; i++) {
4909                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4910                                    query.append(orderByFields[i]);
4911    
4912                                    if ((i + 1) < orderByFields.length) {
4913                                            if (orderByComparator.isAscending() ^ previous) {
4914                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4915                                            }
4916                                            else {
4917                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4918                                            }
4919                                    }
4920                                    else {
4921                                            if (orderByComparator.isAscending() ^ previous) {
4922                                                    query.append(ORDER_BY_ASC);
4923                                            }
4924                                            else {
4925                                                    query.append(ORDER_BY_DESC);
4926                                            }
4927                                    }
4928                            }
4929                    }
4930                    else {
4931                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
4932                    }
4933    
4934                    String sql = query.toString();
4935    
4936                    Query q = session.createQuery(sql);
4937    
4938                    q.setFirstResult(0);
4939                    q.setMaxResults(2);
4940    
4941                    QueryPos qPos = QueryPos.getInstance(q);
4942    
4943                    qPos.add(groupId);
4944    
4945                    if (bindTaskExecutorClassName) {
4946                            qPos.add(taskExecutorClassName);
4947                    }
4948    
4949                    qPos.add(completed);
4950    
4951                    if (orderByComparator != null) {
4952                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
4953    
4954                            for (Object value : values) {
4955                                    qPos.add(value);
4956                            }
4957                    }
4958    
4959                    List<BackgroundTask> list = q.list();
4960    
4961                    if (list.size() == 2) {
4962                            return list.get(1);
4963                    }
4964                    else {
4965                            return null;
4966                    }
4967            }
4968    
4969            /**
4970             * Returns all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63; and completed = &#63;.
4971             *
4972             * <p>
4973             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
4974             * </p>
4975             *
4976             * @param groupId the group ID
4977             * @param taskExecutorClassNames the task executor class names
4978             * @param completed the completed
4979             * @return the matching background tasks
4980             */
4981            @Override
4982            public List<BackgroundTask> findByG_T_C(long groupId,
4983                    String[] taskExecutorClassNames, boolean completed) {
4984                    return findByG_T_C(groupId, taskExecutorClassNames, completed,
4985                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4986            }
4987    
4988            /**
4989             * Returns a range of all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63; and completed = &#63;.
4990             *
4991             * <p>
4992             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
4993             * </p>
4994             *
4995             * @param groupId the group ID
4996             * @param taskExecutorClassNames the task executor class names
4997             * @param completed the completed
4998             * @param start the lower bound of the range of background tasks
4999             * @param end the upper bound of the range of background tasks (not inclusive)
5000             * @return the range of matching background tasks
5001             */
5002            @Override
5003            public List<BackgroundTask> findByG_T_C(long groupId,
5004                    String[] taskExecutorClassNames, boolean completed, int start, int end) {
5005                    return findByG_T_C(groupId, taskExecutorClassNames, completed, start,
5006                            end, null);
5007            }
5008    
5009            /**
5010             * Returns an ordered range of all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63; and completed = &#63;.
5011             *
5012             * <p>
5013             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
5014             * </p>
5015             *
5016             * @param groupId the group ID
5017             * @param taskExecutorClassNames the task executor class names
5018             * @param completed the completed
5019             * @param start the lower bound of the range of background tasks
5020             * @param end the upper bound of the range of background tasks (not inclusive)
5021             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5022             * @return the ordered range of matching background tasks
5023             */
5024            @Override
5025            public List<BackgroundTask> findByG_T_C(long groupId,
5026                    String[] taskExecutorClassNames, boolean completed, int start, int end,
5027                    OrderByComparator<BackgroundTask> orderByComparator) {
5028                    if (taskExecutorClassNames == null) {
5029                            taskExecutorClassNames = new String[0];
5030                    }
5031                    else {
5032                            taskExecutorClassNames = ArrayUtil.distinct(taskExecutorClassNames,
5033                                            NULL_SAFE_STRING_COMPARATOR);
5034                    }
5035    
5036                    if (taskExecutorClassNames.length == 1) {
5037                            return findByG_T_C(groupId, taskExecutorClassNames[0], completed,
5038                                    start, end, orderByComparator);
5039                    }
5040    
5041                    boolean pagination = true;
5042                    Object[] finderArgs = null;
5043    
5044                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5045                                    (orderByComparator == null)) {
5046                            pagination = false;
5047                            finderArgs = new Object[] {
5048                                            groupId, StringUtil.merge(taskExecutorClassNames), completed
5049                                    };
5050                    }
5051                    else {
5052                            finderArgs = new Object[] {
5053                                            groupId, StringUtil.merge(taskExecutorClassNames), completed,
5054                                            
5055                                            start, end, orderByComparator
5056                                    };
5057                    }
5058    
5059                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_C,
5060                                    finderArgs, this);
5061    
5062                    if ((list != null) && !list.isEmpty()) {
5063                            for (BackgroundTask backgroundTask : list) {
5064                                    if ((groupId != backgroundTask.getGroupId()) ||
5065                                                    !ArrayUtil.contains(taskExecutorClassNames,
5066                                                            backgroundTask.getTaskExecutorClassName()) ||
5067                                                    (completed != backgroundTask.getCompleted())) {
5068                                            list = null;
5069    
5070                                            break;
5071                                    }
5072                            }
5073                    }
5074    
5075                    if (list == null) {
5076                            StringBundler query = new StringBundler();
5077    
5078                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
5079    
5080                            query.append(_FINDER_COLUMN_G_T_C_GROUPID_2);
5081    
5082                            if (taskExecutorClassNames.length > 0) {
5083                                    query.append(StringPool.OPEN_PARENTHESIS);
5084    
5085                                    for (int i = 0; i < taskExecutorClassNames.length; i++) {
5086                                            String taskExecutorClassName = taskExecutorClassNames[i];
5087    
5088                                            if (taskExecutorClassName == null) {
5089                                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_4);
5090                                            }
5091                                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
5092                                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_6);
5093                                            }
5094                                            else {
5095                                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_5);
5096                                            }
5097    
5098                                            if ((i + 1) < taskExecutorClassNames.length) {
5099                                                    query.append(WHERE_OR);
5100                                            }
5101                                    }
5102    
5103                                    query.append(StringPool.CLOSE_PARENTHESIS);
5104    
5105                                    query.append(WHERE_AND);
5106                            }
5107    
5108                            query.append(_FINDER_COLUMN_G_T_C_COMPLETED_2);
5109    
5110                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
5111                                                    1)), query.index() - 1);
5112    
5113                            if (orderByComparator != null) {
5114                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5115                                            orderByComparator);
5116                            }
5117                            else
5118                             if (pagination) {
5119                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
5120                            }
5121    
5122                            String sql = query.toString();
5123    
5124                            Session session = null;
5125    
5126                            try {
5127                                    session = openSession();
5128    
5129                                    Query q = session.createQuery(sql);
5130    
5131                                    QueryPos qPos = QueryPos.getInstance(q);
5132    
5133                                    qPos.add(groupId);
5134    
5135                                    for (String taskExecutorClassName : taskExecutorClassNames) {
5136                                            if ((taskExecutorClassName != null) &&
5137                                                            !taskExecutorClassName.isEmpty()) {
5138                                                    qPos.add(taskExecutorClassName);
5139                                            }
5140                                    }
5141    
5142                                    qPos.add(completed);
5143    
5144                                    if (!pagination) {
5145                                            list = (List<BackgroundTask>)QueryUtil.list(q,
5146                                                            getDialect(), start, end, false);
5147    
5148                                            Collections.sort(list);
5149    
5150                                            list = Collections.unmodifiableList(list);
5151                                    }
5152                                    else {
5153                                            list = (List<BackgroundTask>)QueryUtil.list(q,
5154                                                            getDialect(), start, end);
5155                                    }
5156    
5157                                    cacheResult(list);
5158    
5159                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_C,
5160                                            finderArgs, list);
5161                            }
5162                            catch (Exception e) {
5163                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_C,
5164                                            finderArgs);
5165    
5166                                    throw processException(e);
5167                            }
5168                            finally {
5169                                    closeSession(session);
5170                            }
5171                    }
5172    
5173                    return list;
5174            }
5175    
5176            /**
5177             * Removes all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63; from the database.
5178             *
5179             * @param groupId the group ID
5180             * @param taskExecutorClassName the task executor class name
5181             * @param completed the completed
5182             */
5183            @Override
5184            public void removeByG_T_C(long groupId, String taskExecutorClassName,
5185                    boolean completed) {
5186                    for (BackgroundTask backgroundTask : findByG_T_C(groupId,
5187                                    taskExecutorClassName, completed, QueryUtil.ALL_POS,
5188                                    QueryUtil.ALL_POS, null)) {
5189                            remove(backgroundTask);
5190                    }
5191            }
5192    
5193            /**
5194             * Returns the number of background tasks where groupId = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
5195             *
5196             * @param groupId the group ID
5197             * @param taskExecutorClassName the task executor class name
5198             * @param completed the completed
5199             * @return the number of matching background tasks
5200             */
5201            @Override
5202            public int countByG_T_C(long groupId, String taskExecutorClassName,
5203                    boolean completed) {
5204                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_T_C;
5205    
5206                    Object[] finderArgs = new Object[] {
5207                                    groupId, taskExecutorClassName, completed
5208                            };
5209    
5210                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5211                                    this);
5212    
5213                    if (count == null) {
5214                            StringBundler query = new StringBundler(4);
5215    
5216                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
5217    
5218                            query.append(_FINDER_COLUMN_G_T_C_GROUPID_2);
5219    
5220                            boolean bindTaskExecutorClassName = false;
5221    
5222                            if (taskExecutorClassName == null) {
5223                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_1);
5224                            }
5225                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
5226                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_3);
5227                            }
5228                            else {
5229                                    bindTaskExecutorClassName = true;
5230    
5231                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_2);
5232                            }
5233    
5234                            query.append(_FINDER_COLUMN_G_T_C_COMPLETED_2);
5235    
5236                            String sql = query.toString();
5237    
5238                            Session session = null;
5239    
5240                            try {
5241                                    session = openSession();
5242    
5243                                    Query q = session.createQuery(sql);
5244    
5245                                    QueryPos qPos = QueryPos.getInstance(q);
5246    
5247                                    qPos.add(groupId);
5248    
5249                                    if (bindTaskExecutorClassName) {
5250                                            qPos.add(taskExecutorClassName);
5251                                    }
5252    
5253                                    qPos.add(completed);
5254    
5255                                    count = (Long)q.uniqueResult();
5256    
5257                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5258                            }
5259                            catch (Exception e) {
5260                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5261    
5262                                    throw processException(e);
5263                            }
5264                            finally {
5265                                    closeSession(session);
5266                            }
5267                    }
5268    
5269                    return count.intValue();
5270            }
5271    
5272            /**
5273             * Returns the number of background tasks where groupId = &#63; and taskExecutorClassName = any &#63; and completed = &#63;.
5274             *
5275             * @param groupId the group ID
5276             * @param taskExecutorClassNames the task executor class names
5277             * @param completed the completed
5278             * @return the number of matching background tasks
5279             */
5280            @Override
5281            public int countByG_T_C(long groupId, String[] taskExecutorClassNames,
5282                    boolean completed) {
5283                    if (taskExecutorClassNames == null) {
5284                            taskExecutorClassNames = new String[0];
5285                    }
5286                    else {
5287                            taskExecutorClassNames = ArrayUtil.distinct(taskExecutorClassNames,
5288                                            NULL_SAFE_STRING_COMPARATOR);
5289                    }
5290    
5291                    Object[] finderArgs = new Object[] {
5292                                    groupId, StringUtil.merge(taskExecutorClassNames), completed
5293                            };
5294    
5295                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_C,
5296                                    finderArgs, this);
5297    
5298                    if (count == null) {
5299                            StringBundler query = new StringBundler();
5300    
5301                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
5302    
5303                            query.append(_FINDER_COLUMN_G_T_C_GROUPID_2);
5304    
5305                            if (taskExecutorClassNames.length > 0) {
5306                                    query.append(StringPool.OPEN_PARENTHESIS);
5307    
5308                                    for (int i = 0; i < taskExecutorClassNames.length; i++) {
5309                                            String taskExecutorClassName = taskExecutorClassNames[i];
5310    
5311                                            if (taskExecutorClassName == null) {
5312                                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_4);
5313                                            }
5314                                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
5315                                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_6);
5316                                            }
5317                                            else {
5318                                                    query.append(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_5);
5319                                            }
5320    
5321                                            if ((i + 1) < taskExecutorClassNames.length) {
5322                                                    query.append(WHERE_OR);
5323                                            }
5324                                    }
5325    
5326                                    query.append(StringPool.CLOSE_PARENTHESIS);
5327    
5328                                    query.append(WHERE_AND);
5329                            }
5330    
5331                            query.append(_FINDER_COLUMN_G_T_C_COMPLETED_2);
5332    
5333                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
5334                                                    1)), query.index() - 1);
5335    
5336                            String sql = query.toString();
5337    
5338                            Session session = null;
5339    
5340                            try {
5341                                    session = openSession();
5342    
5343                                    Query q = session.createQuery(sql);
5344    
5345                                    QueryPos qPos = QueryPos.getInstance(q);
5346    
5347                                    qPos.add(groupId);
5348    
5349                                    for (String taskExecutorClassName : taskExecutorClassNames) {
5350                                            if ((taskExecutorClassName != null) &&
5351                                                            !taskExecutorClassName.isEmpty()) {
5352                                                    qPos.add(taskExecutorClassName);
5353                                            }
5354                                    }
5355    
5356                                    qPos.add(completed);
5357    
5358                                    count = (Long)q.uniqueResult();
5359    
5360                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_C,
5361                                            finderArgs, count);
5362                            }
5363                            catch (Exception e) {
5364                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_C,
5365                                            finderArgs);
5366    
5367                                    throw processException(e);
5368                            }
5369                            finally {
5370                                    closeSession(session);
5371                            }
5372                    }
5373    
5374                    return count.intValue();
5375            }
5376    
5377            private static final String _FINDER_COLUMN_G_T_C_GROUPID_2 = "backgroundTask.groupId = ? AND ";
5378            private static final String _FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_1 = "backgroundTask.taskExecutorClassName IS NULL AND ";
5379            private static final String _FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_2 = "backgroundTask.taskExecutorClassName = ? AND ";
5380            private static final String _FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_3 = "(backgroundTask.taskExecutorClassName IS NULL OR backgroundTask.taskExecutorClassName = '') AND ";
5381            private static final String _FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_4 = "(" +
5382                    removeConjunction(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_1) + ")";
5383            private static final String _FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_5 = "(" +
5384                    removeConjunction(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_2) + ")";
5385            private static final String _FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_6 = "(" +
5386                    removeConjunction(_FINDER_COLUMN_G_T_C_TASKEXECUTORCLASSNAME_3) + ")";
5387            private static final String _FINDER_COLUMN_G_T_C_COMPLETED_2 = "backgroundTask.completed = ?";
5388            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
5389                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
5390                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5391                            "findByG_T_S",
5392                            new String[] {
5393                                    Long.class.getName(), String.class.getName(),
5394                                    Integer.class.getName(),
5395                                    
5396                            Integer.class.getName(), Integer.class.getName(),
5397                                    OrderByComparator.class.getName()
5398                            });
5399            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
5400                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
5401                            BackgroundTaskImpl.class,
5402                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_T_S",
5403                            new String[] {
5404                                    Long.class.getName(), String.class.getName(),
5405                                    Integer.class.getName()
5406                            },
5407                            BackgroundTaskModelImpl.GROUPID_COLUMN_BITMASK |
5408                            BackgroundTaskModelImpl.TASKEXECUTORCLASSNAME_COLUMN_BITMASK |
5409                            BackgroundTaskModelImpl.STATUS_COLUMN_BITMASK |
5410                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
5411            public static final FinderPath FINDER_PATH_COUNT_BY_G_T_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
5412                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
5413                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T_S",
5414                            new String[] {
5415                                    Long.class.getName(), String.class.getName(),
5416                                    Integer.class.getName()
5417                            });
5418            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_S = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
5419                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
5420                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_T_S",
5421                            new String[] {
5422                                    Long.class.getName(), String.class.getName(),
5423                                    Integer.class.getName()
5424                            });
5425    
5426            /**
5427             * Returns all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
5428             *
5429             * @param groupId the group ID
5430             * @param taskExecutorClassName the task executor class name
5431             * @param status the status
5432             * @return the matching background tasks
5433             */
5434            @Override
5435            public List<BackgroundTask> findByG_T_S(long groupId,
5436                    String taskExecutorClassName, int status) {
5437                    return findByG_T_S(groupId, taskExecutorClassName, status,
5438                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5439            }
5440    
5441            /**
5442             * Returns a range of all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
5443             *
5444             * <p>
5445             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
5446             * </p>
5447             *
5448             * @param groupId the group ID
5449             * @param taskExecutorClassName the task executor class name
5450             * @param status the status
5451             * @param start the lower bound of the range of background tasks
5452             * @param end the upper bound of the range of background tasks (not inclusive)
5453             * @return the range of matching background tasks
5454             */
5455            @Override
5456            public List<BackgroundTask> findByG_T_S(long groupId,
5457                    String taskExecutorClassName, int status, int start, int end) {
5458                    return findByG_T_S(groupId, taskExecutorClassName, status, start, end,
5459                            null);
5460            }
5461    
5462            /**
5463             * Returns an ordered range of all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
5464             *
5465             * <p>
5466             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
5467             * </p>
5468             *
5469             * @param groupId the group ID
5470             * @param taskExecutorClassName the task executor class name
5471             * @param status the status
5472             * @param start the lower bound of the range of background tasks
5473             * @param end the upper bound of the range of background tasks (not inclusive)
5474             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5475             * @return the ordered range of matching background tasks
5476             */
5477            @Override
5478            public List<BackgroundTask> findByG_T_S(long groupId,
5479                    String taskExecutorClassName, int status, int start, int end,
5480                    OrderByComparator<BackgroundTask> orderByComparator) {
5481                    boolean pagination = true;
5482                    FinderPath finderPath = null;
5483                    Object[] finderArgs = null;
5484    
5485                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5486                                    (orderByComparator == null)) {
5487                            pagination = false;
5488                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_S;
5489                            finderArgs = new Object[] { groupId, taskExecutorClassName, status };
5490                    }
5491                    else {
5492                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_S;
5493                            finderArgs = new Object[] {
5494                                            groupId, taskExecutorClassName, status,
5495                                            
5496                                            start, end, orderByComparator
5497                                    };
5498                    }
5499    
5500                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
5501                                    finderArgs, this);
5502    
5503                    if ((list != null) && !list.isEmpty()) {
5504                            for (BackgroundTask backgroundTask : list) {
5505                                    if ((groupId != backgroundTask.getGroupId()) ||
5506                                                    !Validator.equals(taskExecutorClassName,
5507                                                            backgroundTask.getTaskExecutorClassName()) ||
5508                                                    (status != backgroundTask.getStatus())) {
5509                                            list = null;
5510    
5511                                            break;
5512                                    }
5513                            }
5514                    }
5515    
5516                    if (list == null) {
5517                            StringBundler query = null;
5518    
5519                            if (orderByComparator != null) {
5520                                    query = new StringBundler(5 +
5521                                                    (orderByComparator.getOrderByFields().length * 3));
5522                            }
5523                            else {
5524                                    query = new StringBundler(5);
5525                            }
5526    
5527                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
5528    
5529                            query.append(_FINDER_COLUMN_G_T_S_GROUPID_2);
5530    
5531                            boolean bindTaskExecutorClassName = false;
5532    
5533                            if (taskExecutorClassName == null) {
5534                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_1);
5535                            }
5536                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
5537                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_3);
5538                            }
5539                            else {
5540                                    bindTaskExecutorClassName = true;
5541    
5542                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_2);
5543                            }
5544    
5545                            query.append(_FINDER_COLUMN_G_T_S_STATUS_2);
5546    
5547                            if (orderByComparator != null) {
5548                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5549                                            orderByComparator);
5550                            }
5551                            else
5552                             if (pagination) {
5553                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
5554                            }
5555    
5556                            String sql = query.toString();
5557    
5558                            Session session = null;
5559    
5560                            try {
5561                                    session = openSession();
5562    
5563                                    Query q = session.createQuery(sql);
5564    
5565                                    QueryPos qPos = QueryPos.getInstance(q);
5566    
5567                                    qPos.add(groupId);
5568    
5569                                    if (bindTaskExecutorClassName) {
5570                                            qPos.add(taskExecutorClassName);
5571                                    }
5572    
5573                                    qPos.add(status);
5574    
5575                                    if (!pagination) {
5576                                            list = (List<BackgroundTask>)QueryUtil.list(q,
5577                                                            getDialect(), start, end, false);
5578    
5579                                            Collections.sort(list);
5580    
5581                                            list = Collections.unmodifiableList(list);
5582                                    }
5583                                    else {
5584                                            list = (List<BackgroundTask>)QueryUtil.list(q,
5585                                                            getDialect(), start, end);
5586                                    }
5587    
5588                                    cacheResult(list);
5589    
5590                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5591                            }
5592                            catch (Exception e) {
5593                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5594    
5595                                    throw processException(e);
5596                            }
5597                            finally {
5598                                    closeSession(session);
5599                            }
5600                    }
5601    
5602                    return list;
5603            }
5604    
5605            /**
5606             * Returns the first background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
5607             *
5608             * @param groupId the group ID
5609             * @param taskExecutorClassName the task executor class name
5610             * @param status the status
5611             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5612             * @return the first matching background task
5613             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
5614             */
5615            @Override
5616            public BackgroundTask findByG_T_S_First(long groupId,
5617                    String taskExecutorClassName, int status,
5618                    OrderByComparator<BackgroundTask> orderByComparator)
5619                    throws NoSuchBackgroundTaskException {
5620                    BackgroundTask backgroundTask = fetchByG_T_S_First(groupId,
5621                                    taskExecutorClassName, status, orderByComparator);
5622    
5623                    if (backgroundTask != null) {
5624                            return backgroundTask;
5625                    }
5626    
5627                    StringBundler msg = new StringBundler(8);
5628    
5629                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5630    
5631                    msg.append("groupId=");
5632                    msg.append(groupId);
5633    
5634                    msg.append(", taskExecutorClassName=");
5635                    msg.append(taskExecutorClassName);
5636    
5637                    msg.append(", status=");
5638                    msg.append(status);
5639    
5640                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5641    
5642                    throw new NoSuchBackgroundTaskException(msg.toString());
5643            }
5644    
5645            /**
5646             * Returns the first background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
5647             *
5648             * @param groupId the group ID
5649             * @param taskExecutorClassName the task executor class name
5650             * @param status the status
5651             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5652             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
5653             */
5654            @Override
5655            public BackgroundTask fetchByG_T_S_First(long groupId,
5656                    String taskExecutorClassName, int status,
5657                    OrderByComparator<BackgroundTask> orderByComparator) {
5658                    List<BackgroundTask> list = findByG_T_S(groupId, taskExecutorClassName,
5659                                    status, 0, 1, orderByComparator);
5660    
5661                    if (!list.isEmpty()) {
5662                            return list.get(0);
5663                    }
5664    
5665                    return null;
5666            }
5667    
5668            /**
5669             * Returns the last background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
5670             *
5671             * @param groupId the group ID
5672             * @param taskExecutorClassName the task executor class name
5673             * @param status the status
5674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5675             * @return the last matching background task
5676             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
5677             */
5678            @Override
5679            public BackgroundTask findByG_T_S_Last(long groupId,
5680                    String taskExecutorClassName, int status,
5681                    OrderByComparator<BackgroundTask> orderByComparator)
5682                    throws NoSuchBackgroundTaskException {
5683                    BackgroundTask backgroundTask = fetchByG_T_S_Last(groupId,
5684                                    taskExecutorClassName, status, orderByComparator);
5685    
5686                    if (backgroundTask != null) {
5687                            return backgroundTask;
5688                    }
5689    
5690                    StringBundler msg = new StringBundler(8);
5691    
5692                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5693    
5694                    msg.append("groupId=");
5695                    msg.append(groupId);
5696    
5697                    msg.append(", taskExecutorClassName=");
5698                    msg.append(taskExecutorClassName);
5699    
5700                    msg.append(", status=");
5701                    msg.append(status);
5702    
5703                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5704    
5705                    throw new NoSuchBackgroundTaskException(msg.toString());
5706            }
5707    
5708            /**
5709             * Returns the last background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
5710             *
5711             * @param groupId the group ID
5712             * @param taskExecutorClassName the task executor class name
5713             * @param status the status
5714             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5715             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
5716             */
5717            @Override
5718            public BackgroundTask fetchByG_T_S_Last(long groupId,
5719                    String taskExecutorClassName, int status,
5720                    OrderByComparator<BackgroundTask> orderByComparator) {
5721                    int count = countByG_T_S(groupId, taskExecutorClassName, status);
5722    
5723                    if (count == 0) {
5724                            return null;
5725                    }
5726    
5727                    List<BackgroundTask> list = findByG_T_S(groupId, taskExecutorClassName,
5728                                    status, count - 1, count, orderByComparator);
5729    
5730                    if (!list.isEmpty()) {
5731                            return list.get(0);
5732                    }
5733    
5734                    return null;
5735            }
5736    
5737            /**
5738             * Returns the background tasks before and after the current background task in the ordered set where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
5739             *
5740             * @param backgroundTaskId the primary key of the current background task
5741             * @param groupId the group ID
5742             * @param taskExecutorClassName the task executor class name
5743             * @param status the status
5744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5745             * @return the previous, current, and next background task
5746             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
5747             */
5748            @Override
5749            public BackgroundTask[] findByG_T_S_PrevAndNext(long backgroundTaskId,
5750                    long groupId, String taskExecutorClassName, int status,
5751                    OrderByComparator<BackgroundTask> orderByComparator)
5752                    throws NoSuchBackgroundTaskException {
5753                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
5754    
5755                    Session session = null;
5756    
5757                    try {
5758                            session = openSession();
5759    
5760                            BackgroundTask[] array = new BackgroundTaskImpl[3];
5761    
5762                            array[0] = getByG_T_S_PrevAndNext(session, backgroundTask, groupId,
5763                                            taskExecutorClassName, status, orderByComparator, true);
5764    
5765                            array[1] = backgroundTask;
5766    
5767                            array[2] = getByG_T_S_PrevAndNext(session, backgroundTask, groupId,
5768                                            taskExecutorClassName, status, orderByComparator, false);
5769    
5770                            return array;
5771                    }
5772                    catch (Exception e) {
5773                            throw processException(e);
5774                    }
5775                    finally {
5776                            closeSession(session);
5777                    }
5778            }
5779    
5780            protected BackgroundTask getByG_T_S_PrevAndNext(Session session,
5781                    BackgroundTask backgroundTask, long groupId,
5782                    String taskExecutorClassName, int status,
5783                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
5784                    StringBundler query = null;
5785    
5786                    if (orderByComparator != null) {
5787                            query = new StringBundler(6 +
5788                                            (orderByComparator.getOrderByFields().length * 6));
5789                    }
5790                    else {
5791                            query = new StringBundler(3);
5792                    }
5793    
5794                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
5795    
5796                    query.append(_FINDER_COLUMN_G_T_S_GROUPID_2);
5797    
5798                    boolean bindTaskExecutorClassName = false;
5799    
5800                    if (taskExecutorClassName == null) {
5801                            query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_1);
5802                    }
5803                    else if (taskExecutorClassName.equals(StringPool.BLANK)) {
5804                            query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_3);
5805                    }
5806                    else {
5807                            bindTaskExecutorClassName = true;
5808    
5809                            query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_2);
5810                    }
5811    
5812                    query.append(_FINDER_COLUMN_G_T_S_STATUS_2);
5813    
5814                    if (orderByComparator != null) {
5815                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5816    
5817                            if (orderByConditionFields.length > 0) {
5818                                    query.append(WHERE_AND);
5819                            }
5820    
5821                            for (int i = 0; i < orderByConditionFields.length; i++) {
5822                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5823                                    query.append(orderByConditionFields[i]);
5824    
5825                                    if ((i + 1) < orderByConditionFields.length) {
5826                                            if (orderByComparator.isAscending() ^ previous) {
5827                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5828                                            }
5829                                            else {
5830                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5831                                            }
5832                                    }
5833                                    else {
5834                                            if (orderByComparator.isAscending() ^ previous) {
5835                                                    query.append(WHERE_GREATER_THAN);
5836                                            }
5837                                            else {
5838                                                    query.append(WHERE_LESSER_THAN);
5839                                            }
5840                                    }
5841                            }
5842    
5843                            query.append(ORDER_BY_CLAUSE);
5844    
5845                            String[] orderByFields = orderByComparator.getOrderByFields();
5846    
5847                            for (int i = 0; i < orderByFields.length; i++) {
5848                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5849                                    query.append(orderByFields[i]);
5850    
5851                                    if ((i + 1) < orderByFields.length) {
5852                                            if (orderByComparator.isAscending() ^ previous) {
5853                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5854                                            }
5855                                            else {
5856                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5857                                            }
5858                                    }
5859                                    else {
5860                                            if (orderByComparator.isAscending() ^ previous) {
5861                                                    query.append(ORDER_BY_ASC);
5862                                            }
5863                                            else {
5864                                                    query.append(ORDER_BY_DESC);
5865                                            }
5866                                    }
5867                            }
5868                    }
5869                    else {
5870                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
5871                    }
5872    
5873                    String sql = query.toString();
5874    
5875                    Query q = session.createQuery(sql);
5876    
5877                    q.setFirstResult(0);
5878                    q.setMaxResults(2);
5879    
5880                    QueryPos qPos = QueryPos.getInstance(q);
5881    
5882                    qPos.add(groupId);
5883    
5884                    if (bindTaskExecutorClassName) {
5885                            qPos.add(taskExecutorClassName);
5886                    }
5887    
5888                    qPos.add(status);
5889    
5890                    if (orderByComparator != null) {
5891                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
5892    
5893                            for (Object value : values) {
5894                                    qPos.add(value);
5895                            }
5896                    }
5897    
5898                    List<BackgroundTask> list = q.list();
5899    
5900                    if (list.size() == 2) {
5901                            return list.get(1);
5902                    }
5903                    else {
5904                            return null;
5905                    }
5906            }
5907    
5908            /**
5909             * Returns all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63; and status = &#63;.
5910             *
5911             * <p>
5912             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
5913             * </p>
5914             *
5915             * @param groupId the group ID
5916             * @param taskExecutorClassNames the task executor class names
5917             * @param status the status
5918             * @return the matching background tasks
5919             */
5920            @Override
5921            public List<BackgroundTask> findByG_T_S(long groupId,
5922                    String[] taskExecutorClassNames, int status) {
5923                    return findByG_T_S(groupId, taskExecutorClassNames, status,
5924                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5925            }
5926    
5927            /**
5928             * Returns a range of all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63; and status = &#63;.
5929             *
5930             * <p>
5931             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
5932             * </p>
5933             *
5934             * @param groupId the group ID
5935             * @param taskExecutorClassNames the task executor class names
5936             * @param status the status
5937             * @param start the lower bound of the range of background tasks
5938             * @param end the upper bound of the range of background tasks (not inclusive)
5939             * @return the range of matching background tasks
5940             */
5941            @Override
5942            public List<BackgroundTask> findByG_T_S(long groupId,
5943                    String[] taskExecutorClassNames, int status, int start, int end) {
5944                    return findByG_T_S(groupId, taskExecutorClassNames, status, start, end,
5945                            null);
5946            }
5947    
5948            /**
5949             * Returns an ordered range of all the background tasks where groupId = &#63; and taskExecutorClassName = any &#63; and status = &#63;.
5950             *
5951             * <p>
5952             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
5953             * </p>
5954             *
5955             * @param groupId the group ID
5956             * @param taskExecutorClassNames the task executor class names
5957             * @param status the status
5958             * @param start the lower bound of the range of background tasks
5959             * @param end the upper bound of the range of background tasks (not inclusive)
5960             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5961             * @return the ordered range of matching background tasks
5962             */
5963            @Override
5964            public List<BackgroundTask> findByG_T_S(long groupId,
5965                    String[] taskExecutorClassNames, int status, int start, int end,
5966                    OrderByComparator<BackgroundTask> orderByComparator) {
5967                    if (taskExecutorClassNames == null) {
5968                            taskExecutorClassNames = new String[0];
5969                    }
5970                    else {
5971                            taskExecutorClassNames = ArrayUtil.distinct(taskExecutorClassNames,
5972                                            NULL_SAFE_STRING_COMPARATOR);
5973                    }
5974    
5975                    if (taskExecutorClassNames.length == 1) {
5976                            return findByG_T_S(groupId, taskExecutorClassNames[0], status,
5977                                    start, end, orderByComparator);
5978                    }
5979    
5980                    boolean pagination = true;
5981                    Object[] finderArgs = null;
5982    
5983                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5984                                    (orderByComparator == null)) {
5985                            pagination = false;
5986                            finderArgs = new Object[] {
5987                                            groupId, StringUtil.merge(taskExecutorClassNames), status
5988                                    };
5989                    }
5990                    else {
5991                            finderArgs = new Object[] {
5992                                            groupId, StringUtil.merge(taskExecutorClassNames), status,
5993                                            
5994                                            start, end, orderByComparator
5995                                    };
5996                    }
5997    
5998                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_S,
5999                                    finderArgs, this);
6000    
6001                    if ((list != null) && !list.isEmpty()) {
6002                            for (BackgroundTask backgroundTask : list) {
6003                                    if ((groupId != backgroundTask.getGroupId()) ||
6004                                                    !ArrayUtil.contains(taskExecutorClassNames,
6005                                                            backgroundTask.getTaskExecutorClassName()) ||
6006                                                    (status != backgroundTask.getStatus())) {
6007                                            list = null;
6008    
6009                                            break;
6010                                    }
6011                            }
6012                    }
6013    
6014                    if (list == null) {
6015                            StringBundler query = new StringBundler();
6016    
6017                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
6018    
6019                            query.append(_FINDER_COLUMN_G_T_S_GROUPID_2);
6020    
6021                            if (taskExecutorClassNames.length > 0) {
6022                                    query.append(StringPool.OPEN_PARENTHESIS);
6023    
6024                                    for (int i = 0; i < taskExecutorClassNames.length; i++) {
6025                                            String taskExecutorClassName = taskExecutorClassNames[i];
6026    
6027                                            if (taskExecutorClassName == null) {
6028                                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_4);
6029                                            }
6030                                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
6031                                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_6);
6032                                            }
6033                                            else {
6034                                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_5);
6035                                            }
6036    
6037                                            if ((i + 1) < taskExecutorClassNames.length) {
6038                                                    query.append(WHERE_OR);
6039                                            }
6040                                    }
6041    
6042                                    query.append(StringPool.CLOSE_PARENTHESIS);
6043    
6044                                    query.append(WHERE_AND);
6045                            }
6046    
6047                            query.append(_FINDER_COLUMN_G_T_S_STATUS_2);
6048    
6049                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
6050                                                    1)), query.index() - 1);
6051    
6052                            if (orderByComparator != null) {
6053                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6054                                            orderByComparator);
6055                            }
6056                            else
6057                             if (pagination) {
6058                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
6059                            }
6060    
6061                            String sql = query.toString();
6062    
6063                            Session session = null;
6064    
6065                            try {
6066                                    session = openSession();
6067    
6068                                    Query q = session.createQuery(sql);
6069    
6070                                    QueryPos qPos = QueryPos.getInstance(q);
6071    
6072                                    qPos.add(groupId);
6073    
6074                                    for (String taskExecutorClassName : taskExecutorClassNames) {
6075                                            if ((taskExecutorClassName != null) &&
6076                                                            !taskExecutorClassName.isEmpty()) {
6077                                                    qPos.add(taskExecutorClassName);
6078                                            }
6079                                    }
6080    
6081                                    qPos.add(status);
6082    
6083                                    if (!pagination) {
6084                                            list = (List<BackgroundTask>)QueryUtil.list(q,
6085                                                            getDialect(), start, end, false);
6086    
6087                                            Collections.sort(list);
6088    
6089                                            list = Collections.unmodifiableList(list);
6090                                    }
6091                                    else {
6092                                            list = (List<BackgroundTask>)QueryUtil.list(q,
6093                                                            getDialect(), start, end);
6094                                    }
6095    
6096                                    cacheResult(list);
6097    
6098                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_S,
6099                                            finderArgs, list);
6100                            }
6101                            catch (Exception e) {
6102                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T_S,
6103                                            finderArgs);
6104    
6105                                    throw processException(e);
6106                            }
6107                            finally {
6108                                    closeSession(session);
6109                            }
6110                    }
6111    
6112                    return list;
6113            }
6114    
6115            /**
6116             * Removes all the background tasks where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63; from the database.
6117             *
6118             * @param groupId the group ID
6119             * @param taskExecutorClassName the task executor class name
6120             * @param status the status
6121             */
6122            @Override
6123            public void removeByG_T_S(long groupId, String taskExecutorClassName,
6124                    int status) {
6125                    for (BackgroundTask backgroundTask : findByG_T_S(groupId,
6126                                    taskExecutorClassName, status, QueryUtil.ALL_POS,
6127                                    QueryUtil.ALL_POS, null)) {
6128                            remove(backgroundTask);
6129                    }
6130            }
6131    
6132            /**
6133             * Returns the number of background tasks where groupId = &#63; and taskExecutorClassName = &#63; and status = &#63;.
6134             *
6135             * @param groupId the group ID
6136             * @param taskExecutorClassName the task executor class name
6137             * @param status the status
6138             * @return the number of matching background tasks
6139             */
6140            @Override
6141            public int countByG_T_S(long groupId, String taskExecutorClassName,
6142                    int status) {
6143                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_T_S;
6144    
6145                    Object[] finderArgs = new Object[] {
6146                                    groupId, taskExecutorClassName, status
6147                            };
6148    
6149                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6150                                    this);
6151    
6152                    if (count == null) {
6153                            StringBundler query = new StringBundler(4);
6154    
6155                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
6156    
6157                            query.append(_FINDER_COLUMN_G_T_S_GROUPID_2);
6158    
6159                            boolean bindTaskExecutorClassName = false;
6160    
6161                            if (taskExecutorClassName == null) {
6162                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_1);
6163                            }
6164                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
6165                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_3);
6166                            }
6167                            else {
6168                                    bindTaskExecutorClassName = true;
6169    
6170                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_2);
6171                            }
6172    
6173                            query.append(_FINDER_COLUMN_G_T_S_STATUS_2);
6174    
6175                            String sql = query.toString();
6176    
6177                            Session session = null;
6178    
6179                            try {
6180                                    session = openSession();
6181    
6182                                    Query q = session.createQuery(sql);
6183    
6184                                    QueryPos qPos = QueryPos.getInstance(q);
6185    
6186                                    qPos.add(groupId);
6187    
6188                                    if (bindTaskExecutorClassName) {
6189                                            qPos.add(taskExecutorClassName);
6190                                    }
6191    
6192                                    qPos.add(status);
6193    
6194                                    count = (Long)q.uniqueResult();
6195    
6196                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6197                            }
6198                            catch (Exception e) {
6199                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6200    
6201                                    throw processException(e);
6202                            }
6203                            finally {
6204                                    closeSession(session);
6205                            }
6206                    }
6207    
6208                    return count.intValue();
6209            }
6210    
6211            /**
6212             * Returns the number of background tasks where groupId = &#63; and taskExecutorClassName = any &#63; and status = &#63;.
6213             *
6214             * @param groupId the group ID
6215             * @param taskExecutorClassNames the task executor class names
6216             * @param status the status
6217             * @return the number of matching background tasks
6218             */
6219            @Override
6220            public int countByG_T_S(long groupId, String[] taskExecutorClassNames,
6221                    int status) {
6222                    if (taskExecutorClassNames == null) {
6223                            taskExecutorClassNames = new String[0];
6224                    }
6225                    else {
6226                            taskExecutorClassNames = ArrayUtil.distinct(taskExecutorClassNames,
6227                                            NULL_SAFE_STRING_COMPARATOR);
6228                    }
6229    
6230                    Object[] finderArgs = new Object[] {
6231                                    groupId, StringUtil.merge(taskExecutorClassNames), status
6232                            };
6233    
6234                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_S,
6235                                    finderArgs, this);
6236    
6237                    if (count == null) {
6238                            StringBundler query = new StringBundler();
6239    
6240                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
6241    
6242                            query.append(_FINDER_COLUMN_G_T_S_GROUPID_2);
6243    
6244                            if (taskExecutorClassNames.length > 0) {
6245                                    query.append(StringPool.OPEN_PARENTHESIS);
6246    
6247                                    for (int i = 0; i < taskExecutorClassNames.length; i++) {
6248                                            String taskExecutorClassName = taskExecutorClassNames[i];
6249    
6250                                            if (taskExecutorClassName == null) {
6251                                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_4);
6252                                            }
6253                                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
6254                                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_6);
6255                                            }
6256                                            else {
6257                                                    query.append(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_5);
6258                                            }
6259    
6260                                            if ((i + 1) < taskExecutorClassNames.length) {
6261                                                    query.append(WHERE_OR);
6262                                            }
6263                                    }
6264    
6265                                    query.append(StringPool.CLOSE_PARENTHESIS);
6266    
6267                                    query.append(WHERE_AND);
6268                            }
6269    
6270                            query.append(_FINDER_COLUMN_G_T_S_STATUS_2);
6271    
6272                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
6273                                                    1)), query.index() - 1);
6274    
6275                            String sql = query.toString();
6276    
6277                            Session session = null;
6278    
6279                            try {
6280                                    session = openSession();
6281    
6282                                    Query q = session.createQuery(sql);
6283    
6284                                    QueryPos qPos = QueryPos.getInstance(q);
6285    
6286                                    qPos.add(groupId);
6287    
6288                                    for (String taskExecutorClassName : taskExecutorClassNames) {
6289                                            if ((taskExecutorClassName != null) &&
6290                                                            !taskExecutorClassName.isEmpty()) {
6291                                                    qPos.add(taskExecutorClassName);
6292                                            }
6293                                    }
6294    
6295                                    qPos.add(status);
6296    
6297                                    count = (Long)q.uniqueResult();
6298    
6299                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_S,
6300                                            finderArgs, count);
6301                            }
6302                            catch (Exception e) {
6303                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_T_S,
6304                                            finderArgs);
6305    
6306                                    throw processException(e);
6307                            }
6308                            finally {
6309                                    closeSession(session);
6310                            }
6311                    }
6312    
6313                    return count.intValue();
6314            }
6315    
6316            private static final String _FINDER_COLUMN_G_T_S_GROUPID_2 = "backgroundTask.groupId = ? AND ";
6317            private static final String _FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_1 = "backgroundTask.taskExecutorClassName IS NULL AND ";
6318            private static final String _FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_2 = "backgroundTask.taskExecutorClassName = ? AND ";
6319            private static final String _FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_3 = "(backgroundTask.taskExecutorClassName IS NULL OR backgroundTask.taskExecutorClassName = '') AND ";
6320            private static final String _FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_4 = "(" +
6321                    removeConjunction(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_1) + ")";
6322            private static final String _FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_5 = "(" +
6323                    removeConjunction(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_2) + ")";
6324            private static final String _FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_6 = "(" +
6325                    removeConjunction(_FINDER_COLUMN_G_T_S_TASKEXECUTORCLASSNAME_3) + ")";
6326            private static final String _FINDER_COLUMN_G_T_S_STATUS_2 = "backgroundTask.status = ?";
6327            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_C = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
6328                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
6329                            BackgroundTaskImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
6330                            "findByG_N_T_C",
6331                            new String[] {
6332                                    Long.class.getName(), String.class.getName(),
6333                                    String.class.getName(), Boolean.class.getName(),
6334                                    
6335                            Integer.class.getName(), Integer.class.getName(),
6336                                    OrderByComparator.class.getName()
6337                            });
6338            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_C =
6339                    new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
6340                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED,
6341                            BackgroundTaskImpl.class,
6342                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_N_T_C",
6343                            new String[] {
6344                                    Long.class.getName(), String.class.getName(),
6345                                    String.class.getName(), Boolean.class.getName()
6346                            },
6347                            BackgroundTaskModelImpl.GROUPID_COLUMN_BITMASK |
6348                            BackgroundTaskModelImpl.NAME_COLUMN_BITMASK |
6349                            BackgroundTaskModelImpl.TASKEXECUTORCLASSNAME_COLUMN_BITMASK |
6350                            BackgroundTaskModelImpl.COMPLETED_COLUMN_BITMASK |
6351                            BackgroundTaskModelImpl.CREATEDATE_COLUMN_BITMASK);
6352            public static final FinderPath FINDER_PATH_COUNT_BY_G_N_T_C = new FinderPath(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
6353                            BackgroundTaskModelImpl.FINDER_CACHE_ENABLED, Long.class,
6354                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N_T_C",
6355                            new String[] {
6356                                    Long.class.getName(), String.class.getName(),
6357                                    String.class.getName(), Boolean.class.getName()
6358                            });
6359    
6360            /**
6361             * Returns all the background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6362             *
6363             * @param groupId the group ID
6364             * @param name the name
6365             * @param taskExecutorClassName the task executor class name
6366             * @param completed the completed
6367             * @return the matching background tasks
6368             */
6369            @Override
6370            public List<BackgroundTask> findByG_N_T_C(long groupId, String name,
6371                    String taskExecutorClassName, boolean completed) {
6372                    return findByG_N_T_C(groupId, name, taskExecutorClassName, completed,
6373                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6374            }
6375    
6376            /**
6377             * Returns a range of all the background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6378             *
6379             * <p>
6380             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
6381             * </p>
6382             *
6383             * @param groupId the group ID
6384             * @param name the name
6385             * @param taskExecutorClassName the task executor class name
6386             * @param completed the completed
6387             * @param start the lower bound of the range of background tasks
6388             * @param end the upper bound of the range of background tasks (not inclusive)
6389             * @return the range of matching background tasks
6390             */
6391            @Override
6392            public List<BackgroundTask> findByG_N_T_C(long groupId, String name,
6393                    String taskExecutorClassName, boolean completed, int start, int end) {
6394                    return findByG_N_T_C(groupId, name, taskExecutorClassName, completed,
6395                            start, end, null);
6396            }
6397    
6398            /**
6399             * Returns an ordered range of all the background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6400             *
6401             * <p>
6402             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
6403             * </p>
6404             *
6405             * @param groupId the group ID
6406             * @param name the name
6407             * @param taskExecutorClassName the task executor class name
6408             * @param completed the completed
6409             * @param start the lower bound of the range of background tasks
6410             * @param end the upper bound of the range of background tasks (not inclusive)
6411             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6412             * @return the ordered range of matching background tasks
6413             */
6414            @Override
6415            public List<BackgroundTask> findByG_N_T_C(long groupId, String name,
6416                    String taskExecutorClassName, boolean completed, int start, int end,
6417                    OrderByComparator<BackgroundTask> orderByComparator) {
6418                    boolean pagination = true;
6419                    FinderPath finderPath = null;
6420                    Object[] finderArgs = null;
6421    
6422                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6423                                    (orderByComparator == null)) {
6424                            pagination = false;
6425                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_C;
6426                            finderArgs = new Object[] {
6427                                            groupId, name, taskExecutorClassName, completed
6428                                    };
6429                    }
6430                    else {
6431                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_N_T_C;
6432                            finderArgs = new Object[] {
6433                                            groupId, name, taskExecutorClassName, completed,
6434                                            
6435                                            start, end, orderByComparator
6436                                    };
6437                    }
6438    
6439                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
6440                                    finderArgs, this);
6441    
6442                    if ((list != null) && !list.isEmpty()) {
6443                            for (BackgroundTask backgroundTask : list) {
6444                                    if ((groupId != backgroundTask.getGroupId()) ||
6445                                                    !Validator.equals(name, backgroundTask.getName()) ||
6446                                                    !Validator.equals(taskExecutorClassName,
6447                                                            backgroundTask.getTaskExecutorClassName()) ||
6448                                                    (completed != backgroundTask.getCompleted())) {
6449                                            list = null;
6450    
6451                                            break;
6452                                    }
6453                            }
6454                    }
6455    
6456                    if (list == null) {
6457                            StringBundler query = null;
6458    
6459                            if (orderByComparator != null) {
6460                                    query = new StringBundler(6 +
6461                                                    (orderByComparator.getOrderByFields().length * 3));
6462                            }
6463                            else {
6464                                    query = new StringBundler(6);
6465                            }
6466    
6467                            query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
6468    
6469                            query.append(_FINDER_COLUMN_G_N_T_C_GROUPID_2);
6470    
6471                            boolean bindName = false;
6472    
6473                            if (name == null) {
6474                                    query.append(_FINDER_COLUMN_G_N_T_C_NAME_1);
6475                            }
6476                            else if (name.equals(StringPool.BLANK)) {
6477                                    query.append(_FINDER_COLUMN_G_N_T_C_NAME_3);
6478                            }
6479                            else {
6480                                    bindName = true;
6481    
6482                                    query.append(_FINDER_COLUMN_G_N_T_C_NAME_2);
6483                            }
6484    
6485                            boolean bindTaskExecutorClassName = false;
6486    
6487                            if (taskExecutorClassName == null) {
6488                                    query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_1);
6489                            }
6490                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
6491                                    query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_3);
6492                            }
6493                            else {
6494                                    bindTaskExecutorClassName = true;
6495    
6496                                    query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_2);
6497                            }
6498    
6499                            query.append(_FINDER_COLUMN_G_N_T_C_COMPLETED_2);
6500    
6501                            if (orderByComparator != null) {
6502                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6503                                            orderByComparator);
6504                            }
6505                            else
6506                             if (pagination) {
6507                                    query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
6508                            }
6509    
6510                            String sql = query.toString();
6511    
6512                            Session session = null;
6513    
6514                            try {
6515                                    session = openSession();
6516    
6517                                    Query q = session.createQuery(sql);
6518    
6519                                    QueryPos qPos = QueryPos.getInstance(q);
6520    
6521                                    qPos.add(groupId);
6522    
6523                                    if (bindName) {
6524                                            qPos.add(name);
6525                                    }
6526    
6527                                    if (bindTaskExecutorClassName) {
6528                                            qPos.add(taskExecutorClassName);
6529                                    }
6530    
6531                                    qPos.add(completed);
6532    
6533                                    if (!pagination) {
6534                                            list = (List<BackgroundTask>)QueryUtil.list(q,
6535                                                            getDialect(), start, end, false);
6536    
6537                                            Collections.sort(list);
6538    
6539                                            list = Collections.unmodifiableList(list);
6540                                    }
6541                                    else {
6542                                            list = (List<BackgroundTask>)QueryUtil.list(q,
6543                                                            getDialect(), start, end);
6544                                    }
6545    
6546                                    cacheResult(list);
6547    
6548                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6549                            }
6550                            catch (Exception e) {
6551                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6552    
6553                                    throw processException(e);
6554                            }
6555                            finally {
6556                                    closeSession(session);
6557                            }
6558                    }
6559    
6560                    return list;
6561            }
6562    
6563            /**
6564             * Returns the first background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6565             *
6566             * @param groupId the group ID
6567             * @param name the name
6568             * @param taskExecutorClassName the task executor class name
6569             * @param completed the completed
6570             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6571             * @return the first matching background task
6572             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
6573             */
6574            @Override
6575            public BackgroundTask findByG_N_T_C_First(long groupId, String name,
6576                    String taskExecutorClassName, boolean completed,
6577                    OrderByComparator<BackgroundTask> orderByComparator)
6578                    throws NoSuchBackgroundTaskException {
6579                    BackgroundTask backgroundTask = fetchByG_N_T_C_First(groupId, name,
6580                                    taskExecutorClassName, completed, orderByComparator);
6581    
6582                    if (backgroundTask != null) {
6583                            return backgroundTask;
6584                    }
6585    
6586                    StringBundler msg = new StringBundler(10);
6587    
6588                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6589    
6590                    msg.append("groupId=");
6591                    msg.append(groupId);
6592    
6593                    msg.append(", name=");
6594                    msg.append(name);
6595    
6596                    msg.append(", taskExecutorClassName=");
6597                    msg.append(taskExecutorClassName);
6598    
6599                    msg.append(", completed=");
6600                    msg.append(completed);
6601    
6602                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6603    
6604                    throw new NoSuchBackgroundTaskException(msg.toString());
6605            }
6606    
6607            /**
6608             * Returns the first background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6609             *
6610             * @param groupId the group ID
6611             * @param name the name
6612             * @param taskExecutorClassName the task executor class name
6613             * @param completed the completed
6614             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6615             * @return the first matching background task, or <code>null</code> if a matching background task could not be found
6616             */
6617            @Override
6618            public BackgroundTask fetchByG_N_T_C_First(long groupId, String name,
6619                    String taskExecutorClassName, boolean completed,
6620                    OrderByComparator<BackgroundTask> orderByComparator) {
6621                    List<BackgroundTask> list = findByG_N_T_C(groupId, name,
6622                                    taskExecutorClassName, completed, 0, 1, orderByComparator);
6623    
6624                    if (!list.isEmpty()) {
6625                            return list.get(0);
6626                    }
6627    
6628                    return null;
6629            }
6630    
6631            /**
6632             * Returns the last background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6633             *
6634             * @param groupId the group ID
6635             * @param name the name
6636             * @param taskExecutorClassName the task executor class name
6637             * @param completed the completed
6638             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6639             * @return the last matching background task
6640             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a matching background task could not be found
6641             */
6642            @Override
6643            public BackgroundTask findByG_N_T_C_Last(long groupId, String name,
6644                    String taskExecutorClassName, boolean completed,
6645                    OrderByComparator<BackgroundTask> orderByComparator)
6646                    throws NoSuchBackgroundTaskException {
6647                    BackgroundTask backgroundTask = fetchByG_N_T_C_Last(groupId, name,
6648                                    taskExecutorClassName, completed, orderByComparator);
6649    
6650                    if (backgroundTask != null) {
6651                            return backgroundTask;
6652                    }
6653    
6654                    StringBundler msg = new StringBundler(10);
6655    
6656                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6657    
6658                    msg.append("groupId=");
6659                    msg.append(groupId);
6660    
6661                    msg.append(", name=");
6662                    msg.append(name);
6663    
6664                    msg.append(", taskExecutorClassName=");
6665                    msg.append(taskExecutorClassName);
6666    
6667                    msg.append(", completed=");
6668                    msg.append(completed);
6669    
6670                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6671    
6672                    throw new NoSuchBackgroundTaskException(msg.toString());
6673            }
6674    
6675            /**
6676             * Returns the last background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6677             *
6678             * @param groupId the group ID
6679             * @param name the name
6680             * @param taskExecutorClassName the task executor class name
6681             * @param completed the completed
6682             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6683             * @return the last matching background task, or <code>null</code> if a matching background task could not be found
6684             */
6685            @Override
6686            public BackgroundTask fetchByG_N_T_C_Last(long groupId, String name,
6687                    String taskExecutorClassName, boolean completed,
6688                    OrderByComparator<BackgroundTask> orderByComparator) {
6689                    int count = countByG_N_T_C(groupId, name, taskExecutorClassName,
6690                                    completed);
6691    
6692                    if (count == 0) {
6693                            return null;
6694                    }
6695    
6696                    List<BackgroundTask> list = findByG_N_T_C(groupId, name,
6697                                    taskExecutorClassName, completed, count - 1, count,
6698                                    orderByComparator);
6699    
6700                    if (!list.isEmpty()) {
6701                            return list.get(0);
6702                    }
6703    
6704                    return null;
6705            }
6706    
6707            /**
6708             * Returns the background tasks before and after the current background task in the ordered set where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6709             *
6710             * @param backgroundTaskId the primary key of the current background task
6711             * @param groupId the group ID
6712             * @param name the name
6713             * @param taskExecutorClassName the task executor class name
6714             * @param completed the completed
6715             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6716             * @return the previous, current, and next background task
6717             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
6718             */
6719            @Override
6720            public BackgroundTask[] findByG_N_T_C_PrevAndNext(long backgroundTaskId,
6721                    long groupId, String name, String taskExecutorClassName,
6722                    boolean completed, OrderByComparator<BackgroundTask> orderByComparator)
6723                    throws NoSuchBackgroundTaskException {
6724                    BackgroundTask backgroundTask = findByPrimaryKey(backgroundTaskId);
6725    
6726                    Session session = null;
6727    
6728                    try {
6729                            session = openSession();
6730    
6731                            BackgroundTask[] array = new BackgroundTaskImpl[3];
6732    
6733                            array[0] = getByG_N_T_C_PrevAndNext(session, backgroundTask,
6734                                            groupId, name, taskExecutorClassName, completed,
6735                                            orderByComparator, true);
6736    
6737                            array[1] = backgroundTask;
6738    
6739                            array[2] = getByG_N_T_C_PrevAndNext(session, backgroundTask,
6740                                            groupId, name, taskExecutorClassName, completed,
6741                                            orderByComparator, false);
6742    
6743                            return array;
6744                    }
6745                    catch (Exception e) {
6746                            throw processException(e);
6747                    }
6748                    finally {
6749                            closeSession(session);
6750                    }
6751            }
6752    
6753            protected BackgroundTask getByG_N_T_C_PrevAndNext(Session session,
6754                    BackgroundTask backgroundTask, long groupId, String name,
6755                    String taskExecutorClassName, boolean completed,
6756                    OrderByComparator<BackgroundTask> orderByComparator, boolean previous) {
6757                    StringBundler query = null;
6758    
6759                    if (orderByComparator != null) {
6760                            query = new StringBundler(6 +
6761                                            (orderByComparator.getOrderByFields().length * 6));
6762                    }
6763                    else {
6764                            query = new StringBundler(3);
6765                    }
6766    
6767                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE);
6768    
6769                    query.append(_FINDER_COLUMN_G_N_T_C_GROUPID_2);
6770    
6771                    boolean bindName = false;
6772    
6773                    if (name == null) {
6774                            query.append(_FINDER_COLUMN_G_N_T_C_NAME_1);
6775                    }
6776                    else if (name.equals(StringPool.BLANK)) {
6777                            query.append(_FINDER_COLUMN_G_N_T_C_NAME_3);
6778                    }
6779                    else {
6780                            bindName = true;
6781    
6782                            query.append(_FINDER_COLUMN_G_N_T_C_NAME_2);
6783                    }
6784    
6785                    boolean bindTaskExecutorClassName = false;
6786    
6787                    if (taskExecutorClassName == null) {
6788                            query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_1);
6789                    }
6790                    else if (taskExecutorClassName.equals(StringPool.BLANK)) {
6791                            query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_3);
6792                    }
6793                    else {
6794                            bindTaskExecutorClassName = true;
6795    
6796                            query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_2);
6797                    }
6798    
6799                    query.append(_FINDER_COLUMN_G_N_T_C_COMPLETED_2);
6800    
6801                    if (orderByComparator != null) {
6802                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6803    
6804                            if (orderByConditionFields.length > 0) {
6805                                    query.append(WHERE_AND);
6806                            }
6807    
6808                            for (int i = 0; i < orderByConditionFields.length; i++) {
6809                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6810                                    query.append(orderByConditionFields[i]);
6811    
6812                                    if ((i + 1) < orderByConditionFields.length) {
6813                                            if (orderByComparator.isAscending() ^ previous) {
6814                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6815                                            }
6816                                            else {
6817                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6818                                            }
6819                                    }
6820                                    else {
6821                                            if (orderByComparator.isAscending() ^ previous) {
6822                                                    query.append(WHERE_GREATER_THAN);
6823                                            }
6824                                            else {
6825                                                    query.append(WHERE_LESSER_THAN);
6826                                            }
6827                                    }
6828                            }
6829    
6830                            query.append(ORDER_BY_CLAUSE);
6831    
6832                            String[] orderByFields = orderByComparator.getOrderByFields();
6833    
6834                            for (int i = 0; i < orderByFields.length; i++) {
6835                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6836                                    query.append(orderByFields[i]);
6837    
6838                                    if ((i + 1) < orderByFields.length) {
6839                                            if (orderByComparator.isAscending() ^ previous) {
6840                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6841                                            }
6842                                            else {
6843                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6844                                            }
6845                                    }
6846                                    else {
6847                                            if (orderByComparator.isAscending() ^ previous) {
6848                                                    query.append(ORDER_BY_ASC);
6849                                            }
6850                                            else {
6851                                                    query.append(ORDER_BY_DESC);
6852                                            }
6853                                    }
6854                            }
6855                    }
6856                    else {
6857                            query.append(BackgroundTaskModelImpl.ORDER_BY_JPQL);
6858                    }
6859    
6860                    String sql = query.toString();
6861    
6862                    Query q = session.createQuery(sql);
6863    
6864                    q.setFirstResult(0);
6865                    q.setMaxResults(2);
6866    
6867                    QueryPos qPos = QueryPos.getInstance(q);
6868    
6869                    qPos.add(groupId);
6870    
6871                    if (bindName) {
6872                            qPos.add(name);
6873                    }
6874    
6875                    if (bindTaskExecutorClassName) {
6876                            qPos.add(taskExecutorClassName);
6877                    }
6878    
6879                    qPos.add(completed);
6880    
6881                    if (orderByComparator != null) {
6882                            Object[] values = orderByComparator.getOrderByConditionValues(backgroundTask);
6883    
6884                            for (Object value : values) {
6885                                    qPos.add(value);
6886                            }
6887                    }
6888    
6889                    List<BackgroundTask> list = q.list();
6890    
6891                    if (list.size() == 2) {
6892                            return list.get(1);
6893                    }
6894                    else {
6895                            return null;
6896                    }
6897            }
6898    
6899            /**
6900             * Removes all the background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63; from the database.
6901             *
6902             * @param groupId the group ID
6903             * @param name the name
6904             * @param taskExecutorClassName the task executor class name
6905             * @param completed the completed
6906             */
6907            @Override
6908            public void removeByG_N_T_C(long groupId, String name,
6909                    String taskExecutorClassName, boolean completed) {
6910                    for (BackgroundTask backgroundTask : findByG_N_T_C(groupId, name,
6911                                    taskExecutorClassName, completed, QueryUtil.ALL_POS,
6912                                    QueryUtil.ALL_POS, null)) {
6913                            remove(backgroundTask);
6914                    }
6915            }
6916    
6917            /**
6918             * Returns the number of background tasks where groupId = &#63; and name = &#63; and taskExecutorClassName = &#63; and completed = &#63;.
6919             *
6920             * @param groupId the group ID
6921             * @param name the name
6922             * @param taskExecutorClassName the task executor class name
6923             * @param completed the completed
6924             * @return the number of matching background tasks
6925             */
6926            @Override
6927            public int countByG_N_T_C(long groupId, String name,
6928                    String taskExecutorClassName, boolean completed) {
6929                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N_T_C;
6930    
6931                    Object[] finderArgs = new Object[] {
6932                                    groupId, name, taskExecutorClassName, completed
6933                            };
6934    
6935                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6936                                    this);
6937    
6938                    if (count == null) {
6939                            StringBundler query = new StringBundler(5);
6940    
6941                            query.append(_SQL_COUNT_BACKGROUNDTASK_WHERE);
6942    
6943                            query.append(_FINDER_COLUMN_G_N_T_C_GROUPID_2);
6944    
6945                            boolean bindName = false;
6946    
6947                            if (name == null) {
6948                                    query.append(_FINDER_COLUMN_G_N_T_C_NAME_1);
6949                            }
6950                            else if (name.equals(StringPool.BLANK)) {
6951                                    query.append(_FINDER_COLUMN_G_N_T_C_NAME_3);
6952                            }
6953                            else {
6954                                    bindName = true;
6955    
6956                                    query.append(_FINDER_COLUMN_G_N_T_C_NAME_2);
6957                            }
6958    
6959                            boolean bindTaskExecutorClassName = false;
6960    
6961                            if (taskExecutorClassName == null) {
6962                                    query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_1);
6963                            }
6964                            else if (taskExecutorClassName.equals(StringPool.BLANK)) {
6965                                    query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_3);
6966                            }
6967                            else {
6968                                    bindTaskExecutorClassName = true;
6969    
6970                                    query.append(_FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_2);
6971                            }
6972    
6973                            query.append(_FINDER_COLUMN_G_N_T_C_COMPLETED_2);
6974    
6975                            String sql = query.toString();
6976    
6977                            Session session = null;
6978    
6979                            try {
6980                                    session = openSession();
6981    
6982                                    Query q = session.createQuery(sql);
6983    
6984                                    QueryPos qPos = QueryPos.getInstance(q);
6985    
6986                                    qPos.add(groupId);
6987    
6988                                    if (bindName) {
6989                                            qPos.add(name);
6990                                    }
6991    
6992                                    if (bindTaskExecutorClassName) {
6993                                            qPos.add(taskExecutorClassName);
6994                                    }
6995    
6996                                    qPos.add(completed);
6997    
6998                                    count = (Long)q.uniqueResult();
6999    
7000                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7001                            }
7002                            catch (Exception e) {
7003                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7004    
7005                                    throw processException(e);
7006                            }
7007                            finally {
7008                                    closeSession(session);
7009                            }
7010                    }
7011    
7012                    return count.intValue();
7013            }
7014    
7015            private static final String _FINDER_COLUMN_G_N_T_C_GROUPID_2 = "backgroundTask.groupId = ? AND ";
7016            private static final String _FINDER_COLUMN_G_N_T_C_NAME_1 = "backgroundTask.name IS NULL AND ";
7017            private static final String _FINDER_COLUMN_G_N_T_C_NAME_2 = "backgroundTask.name = ? AND ";
7018            private static final String _FINDER_COLUMN_G_N_T_C_NAME_3 = "(backgroundTask.name IS NULL OR backgroundTask.name = '') AND ";
7019            private static final String _FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_1 = "backgroundTask.taskExecutorClassName IS NULL AND ";
7020            private static final String _FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_2 = "backgroundTask.taskExecutorClassName = ? AND ";
7021            private static final String _FINDER_COLUMN_G_N_T_C_TASKEXECUTORCLASSNAME_3 = "(backgroundTask.taskExecutorClassName IS NULL OR backgroundTask.taskExecutorClassName = '') AND ";
7022            private static final String _FINDER_COLUMN_G_N_T_C_COMPLETED_2 = "backgroundTask.completed = ?";
7023    
7024            public BackgroundTaskPersistenceImpl() {
7025                    setModelClass(BackgroundTask.class);
7026            }
7027    
7028            /**
7029             * Caches the background task in the entity cache if it is enabled.
7030             *
7031             * @param backgroundTask the background task
7032             */
7033            @Override
7034            public void cacheResult(BackgroundTask backgroundTask) {
7035                    EntityCacheUtil.putResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7036                            BackgroundTaskImpl.class, backgroundTask.getPrimaryKey(),
7037                            backgroundTask);
7038    
7039                    backgroundTask.resetOriginalValues();
7040            }
7041    
7042            /**
7043             * Caches the background tasks in the entity cache if it is enabled.
7044             *
7045             * @param backgroundTasks the background tasks
7046             */
7047            @Override
7048            public void cacheResult(List<BackgroundTask> backgroundTasks) {
7049                    for (BackgroundTask backgroundTask : backgroundTasks) {
7050                            if (EntityCacheUtil.getResult(
7051                                                    BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7052                                                    BackgroundTaskImpl.class, backgroundTask.getPrimaryKey()) == null) {
7053                                    cacheResult(backgroundTask);
7054                            }
7055                            else {
7056                                    backgroundTask.resetOriginalValues();
7057                            }
7058                    }
7059            }
7060    
7061            /**
7062             * Clears the cache for all background tasks.
7063             *
7064             * <p>
7065             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7066             * </p>
7067             */
7068            @Override
7069            public void clearCache() {
7070                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7071                            CacheRegistryUtil.clear(BackgroundTaskImpl.class.getName());
7072                    }
7073    
7074                    EntityCacheUtil.clearCache(BackgroundTaskImpl.class);
7075    
7076                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7077                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7078                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7079            }
7080    
7081            /**
7082             * Clears the cache for the background task.
7083             *
7084             * <p>
7085             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7086             * </p>
7087             */
7088            @Override
7089            public void clearCache(BackgroundTask backgroundTask) {
7090                    EntityCacheUtil.removeResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7091                            BackgroundTaskImpl.class, backgroundTask.getPrimaryKey());
7092    
7093                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7094                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7095            }
7096    
7097            @Override
7098            public void clearCache(List<BackgroundTask> backgroundTasks) {
7099                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7100                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7101    
7102                    for (BackgroundTask backgroundTask : backgroundTasks) {
7103                            EntityCacheUtil.removeResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7104                                    BackgroundTaskImpl.class, backgroundTask.getPrimaryKey());
7105                    }
7106            }
7107    
7108            /**
7109             * Creates a new background task with the primary key. Does not add the background task to the database.
7110             *
7111             * @param backgroundTaskId the primary key for the new background task
7112             * @return the new background task
7113             */
7114            @Override
7115            public BackgroundTask create(long backgroundTaskId) {
7116                    BackgroundTask backgroundTask = new BackgroundTaskImpl();
7117    
7118                    backgroundTask.setNew(true);
7119                    backgroundTask.setPrimaryKey(backgroundTaskId);
7120    
7121                    return backgroundTask;
7122            }
7123    
7124            /**
7125             * Removes the background task with the primary key from the database. Also notifies the appropriate model listeners.
7126             *
7127             * @param backgroundTaskId the primary key of the background task
7128             * @return the background task that was removed
7129             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
7130             */
7131            @Override
7132            public BackgroundTask remove(long backgroundTaskId)
7133                    throws NoSuchBackgroundTaskException {
7134                    return remove((Serializable)backgroundTaskId);
7135            }
7136    
7137            /**
7138             * Removes the background task with the primary key from the database. Also notifies the appropriate model listeners.
7139             *
7140             * @param primaryKey the primary key of the background task
7141             * @return the background task that was removed
7142             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
7143             */
7144            @Override
7145            public BackgroundTask remove(Serializable primaryKey)
7146                    throws NoSuchBackgroundTaskException {
7147                    Session session = null;
7148    
7149                    try {
7150                            session = openSession();
7151    
7152                            BackgroundTask backgroundTask = (BackgroundTask)session.get(BackgroundTaskImpl.class,
7153                                            primaryKey);
7154    
7155                            if (backgroundTask == null) {
7156                                    if (_log.isWarnEnabled()) {
7157                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7158                                    }
7159    
7160                                    throw new NoSuchBackgroundTaskException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7161                                            primaryKey);
7162                            }
7163    
7164                            return remove(backgroundTask);
7165                    }
7166                    catch (NoSuchBackgroundTaskException nsee) {
7167                            throw nsee;
7168                    }
7169                    catch (Exception e) {
7170                            throw processException(e);
7171                    }
7172                    finally {
7173                            closeSession(session);
7174                    }
7175            }
7176    
7177            @Override
7178            protected BackgroundTask removeImpl(BackgroundTask backgroundTask) {
7179                    backgroundTask = toUnwrappedModel(backgroundTask);
7180    
7181                    Session session = null;
7182    
7183                    try {
7184                            session = openSession();
7185    
7186                            if (!session.contains(backgroundTask)) {
7187                                    backgroundTask = (BackgroundTask)session.get(BackgroundTaskImpl.class,
7188                                                    backgroundTask.getPrimaryKeyObj());
7189                            }
7190    
7191                            if (backgroundTask != null) {
7192                                    session.delete(backgroundTask);
7193                            }
7194                    }
7195                    catch (Exception e) {
7196                            throw processException(e);
7197                    }
7198                    finally {
7199                            closeSession(session);
7200                    }
7201    
7202                    if (backgroundTask != null) {
7203                            clearCache(backgroundTask);
7204                    }
7205    
7206                    return backgroundTask;
7207            }
7208    
7209            @Override
7210            public BackgroundTask updateImpl(
7211                    com.liferay.portal.model.BackgroundTask backgroundTask) {
7212                    backgroundTask = toUnwrappedModel(backgroundTask);
7213    
7214                    boolean isNew = backgroundTask.isNew();
7215    
7216                    BackgroundTaskModelImpl backgroundTaskModelImpl = (BackgroundTaskModelImpl)backgroundTask;
7217    
7218                    Session session = null;
7219    
7220                    try {
7221                            session = openSession();
7222    
7223                            if (backgroundTask.isNew()) {
7224                                    session.save(backgroundTask);
7225    
7226                                    backgroundTask.setNew(false);
7227                            }
7228                            else {
7229                                    session.merge(backgroundTask);
7230                            }
7231                    }
7232                    catch (Exception e) {
7233                            throw processException(e);
7234                    }
7235                    finally {
7236                            closeSession(session);
7237                    }
7238    
7239                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7240    
7241                    if (isNew || !BackgroundTaskModelImpl.COLUMN_BITMASK_ENABLED) {
7242                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7243                    }
7244    
7245                    else {
7246                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7247                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
7248                                    Object[] args = new Object[] {
7249                                                    backgroundTaskModelImpl.getOriginalGroupId()
7250                                            };
7251    
7252                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7253                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7254                                            args);
7255    
7256                                    args = new Object[] { backgroundTaskModelImpl.getGroupId() };
7257    
7258                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7259                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7260                                            args);
7261                            }
7262    
7263                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7264                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7265                                    Object[] args = new Object[] {
7266                                                    backgroundTaskModelImpl.getOriginalCompanyId()
7267                                            };
7268    
7269                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7270                                            args);
7271                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7272                                            args);
7273    
7274                                    args = new Object[] { backgroundTaskModelImpl.getCompanyId() };
7275    
7276                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7277                                            args);
7278                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7279                                            args);
7280                            }
7281    
7282                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7283                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STATUS.getColumnBitmask()) != 0) {
7284                                    Object[] args = new Object[] {
7285                                                    backgroundTaskModelImpl.getOriginalStatus()
7286                                            };
7287    
7288                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STATUS, args);
7289                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STATUS,
7290                                            args);
7291    
7292                                    args = new Object[] { backgroundTaskModelImpl.getStatus() };
7293    
7294                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STATUS, args);
7295                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STATUS,
7296                                            args);
7297                            }
7298    
7299                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7300                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T.getColumnBitmask()) != 0) {
7301                                    Object[] args = new Object[] {
7302                                                    backgroundTaskModelImpl.getOriginalGroupId(),
7303                                                    backgroundTaskModelImpl.getOriginalTaskExecutorClassName()
7304                                            };
7305    
7306                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
7307                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T,
7308                                            args);
7309    
7310                                    args = new Object[] {
7311                                                    backgroundTaskModelImpl.getGroupId(),
7312                                                    backgroundTaskModelImpl.getTaskExecutorClassName()
7313                                            };
7314    
7315                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
7316                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T,
7317                                            args);
7318                            }
7319    
7320                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7321                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
7322                                    Object[] args = new Object[] {
7323                                                    backgroundTaskModelImpl.getOriginalGroupId(),
7324                                                    backgroundTaskModelImpl.getOriginalStatus()
7325                                            };
7326    
7327                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
7328                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
7329                                            args);
7330    
7331                                    args = new Object[] {
7332                                                    backgroundTaskModelImpl.getGroupId(),
7333                                                    backgroundTaskModelImpl.getStatus()
7334                                            };
7335    
7336                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
7337                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
7338                                            args);
7339                            }
7340    
7341                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7342                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
7343                                    Object[] args = new Object[] {
7344                                                    backgroundTaskModelImpl.getOriginalTaskExecutorClassName(),
7345                                                    backgroundTaskModelImpl.getOriginalStatus()
7346                                            };
7347    
7348                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
7349                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
7350                                            args);
7351    
7352                                    args = new Object[] {
7353                                                    backgroundTaskModelImpl.getTaskExecutorClassName(),
7354                                                    backgroundTaskModelImpl.getStatus()
7355                                            };
7356    
7357                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
7358                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
7359                                            args);
7360                            }
7361    
7362                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7363                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T.getColumnBitmask()) != 0) {
7364                                    Object[] args = new Object[] {
7365                                                    backgroundTaskModelImpl.getOriginalGroupId(),
7366                                                    backgroundTaskModelImpl.getOriginalName(),
7367                                                    backgroundTaskModelImpl.getOriginalTaskExecutorClassName()
7368                                            };
7369    
7370                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T, args);
7371                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T,
7372                                            args);
7373    
7374                                    args = new Object[] {
7375                                                    backgroundTaskModelImpl.getGroupId(),
7376                                                    backgroundTaskModelImpl.getName(),
7377                                                    backgroundTaskModelImpl.getTaskExecutorClassName()
7378                                            };
7379    
7380                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T, args);
7381                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T,
7382                                            args);
7383                            }
7384    
7385                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7386                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_C.getColumnBitmask()) != 0) {
7387                                    Object[] args = new Object[] {
7388                                                    backgroundTaskModelImpl.getOriginalGroupId(),
7389                                                    backgroundTaskModelImpl.getOriginalTaskExecutorClassName(),
7390                                                    backgroundTaskModelImpl.getOriginalCompleted()
7391                                            };
7392    
7393                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T_C, args);
7394                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_C,
7395                                            args);
7396    
7397                                    args = new Object[] {
7398                                                    backgroundTaskModelImpl.getGroupId(),
7399                                                    backgroundTaskModelImpl.getTaskExecutorClassName(),
7400                                                    backgroundTaskModelImpl.getCompleted()
7401                                            };
7402    
7403                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T_C, args);
7404                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_C,
7405                                            args);
7406                            }
7407    
7408                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7409                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_S.getColumnBitmask()) != 0) {
7410                                    Object[] args = new Object[] {
7411                                                    backgroundTaskModelImpl.getOriginalGroupId(),
7412                                                    backgroundTaskModelImpl.getOriginalTaskExecutorClassName(),
7413                                                    backgroundTaskModelImpl.getOriginalStatus()
7414                                            };
7415    
7416                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T_S, args);
7417                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_S,
7418                                            args);
7419    
7420                                    args = new Object[] {
7421                                                    backgroundTaskModelImpl.getGroupId(),
7422                                                    backgroundTaskModelImpl.getTaskExecutorClassName(),
7423                                                    backgroundTaskModelImpl.getStatus()
7424                                            };
7425    
7426                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T_S, args);
7427                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T_S,
7428                                            args);
7429                            }
7430    
7431                            if ((backgroundTaskModelImpl.getColumnBitmask() &
7432                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_C.getColumnBitmask()) != 0) {
7433                                    Object[] args = new Object[] {
7434                                                    backgroundTaskModelImpl.getOriginalGroupId(),
7435                                                    backgroundTaskModelImpl.getOriginalName(),
7436                                                    backgroundTaskModelImpl.getOriginalTaskExecutorClassName(),
7437                                                    backgroundTaskModelImpl.getOriginalCompleted()
7438                                            };
7439    
7440                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_C, args);
7441                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_C,
7442                                            args);
7443    
7444                                    args = new Object[] {
7445                                                    backgroundTaskModelImpl.getGroupId(),
7446                                                    backgroundTaskModelImpl.getName(),
7447                                                    backgroundTaskModelImpl.getTaskExecutorClassName(),
7448                                                    backgroundTaskModelImpl.getCompleted()
7449                                            };
7450    
7451                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N_T_C, args);
7452                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_N_T_C,
7453                                            args);
7454                            }
7455                    }
7456    
7457                    EntityCacheUtil.putResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7458                            BackgroundTaskImpl.class, backgroundTask.getPrimaryKey(),
7459                            backgroundTask, false);
7460    
7461                    backgroundTask.resetOriginalValues();
7462    
7463                    return backgroundTask;
7464            }
7465    
7466            protected BackgroundTask toUnwrappedModel(BackgroundTask backgroundTask) {
7467                    if (backgroundTask instanceof BackgroundTaskImpl) {
7468                            return backgroundTask;
7469                    }
7470    
7471                    BackgroundTaskImpl backgroundTaskImpl = new BackgroundTaskImpl();
7472    
7473                    backgroundTaskImpl.setNew(backgroundTask.isNew());
7474                    backgroundTaskImpl.setPrimaryKey(backgroundTask.getPrimaryKey());
7475    
7476                    backgroundTaskImpl.setMvccVersion(backgroundTask.getMvccVersion());
7477                    backgroundTaskImpl.setBackgroundTaskId(backgroundTask.getBackgroundTaskId());
7478                    backgroundTaskImpl.setGroupId(backgroundTask.getGroupId());
7479                    backgroundTaskImpl.setCompanyId(backgroundTask.getCompanyId());
7480                    backgroundTaskImpl.setUserId(backgroundTask.getUserId());
7481                    backgroundTaskImpl.setUserName(backgroundTask.getUserName());
7482                    backgroundTaskImpl.setCreateDate(backgroundTask.getCreateDate());
7483                    backgroundTaskImpl.setModifiedDate(backgroundTask.getModifiedDate());
7484                    backgroundTaskImpl.setName(backgroundTask.getName());
7485                    backgroundTaskImpl.setServletContextNames(backgroundTask.getServletContextNames());
7486                    backgroundTaskImpl.setTaskExecutorClassName(backgroundTask.getTaskExecutorClassName());
7487                    backgroundTaskImpl.setTaskContextMap(backgroundTask.getTaskContextMap());
7488                    backgroundTaskImpl.setCompleted(backgroundTask.isCompleted());
7489                    backgroundTaskImpl.setCompletionDate(backgroundTask.getCompletionDate());
7490                    backgroundTaskImpl.setStatus(backgroundTask.getStatus());
7491                    backgroundTaskImpl.setStatusMessage(backgroundTask.getStatusMessage());
7492    
7493                    return backgroundTaskImpl;
7494            }
7495    
7496            /**
7497             * Returns the background task with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
7498             *
7499             * @param primaryKey the primary key of the background task
7500             * @return the background task
7501             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
7502             */
7503            @Override
7504            public BackgroundTask findByPrimaryKey(Serializable primaryKey)
7505                    throws NoSuchBackgroundTaskException {
7506                    BackgroundTask backgroundTask = fetchByPrimaryKey(primaryKey);
7507    
7508                    if (backgroundTask == null) {
7509                            if (_log.isWarnEnabled()) {
7510                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7511                            }
7512    
7513                            throw new NoSuchBackgroundTaskException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7514                                    primaryKey);
7515                    }
7516    
7517                    return backgroundTask;
7518            }
7519    
7520            /**
7521             * Returns the background task with the primary key or throws a {@link com.liferay.portal.NoSuchBackgroundTaskException} if it could not be found.
7522             *
7523             * @param backgroundTaskId the primary key of the background task
7524             * @return the background task
7525             * @throws com.liferay.portal.NoSuchBackgroundTaskException if a background task with the primary key could not be found
7526             */
7527            @Override
7528            public BackgroundTask findByPrimaryKey(long backgroundTaskId)
7529                    throws NoSuchBackgroundTaskException {
7530                    return findByPrimaryKey((Serializable)backgroundTaskId);
7531            }
7532    
7533            /**
7534             * Returns the background task with the primary key or returns <code>null</code> if it could not be found.
7535             *
7536             * @param primaryKey the primary key of the background task
7537             * @return the background task, or <code>null</code> if a background task with the primary key could not be found
7538             */
7539            @Override
7540            public BackgroundTask fetchByPrimaryKey(Serializable primaryKey) {
7541                    BackgroundTask backgroundTask = (BackgroundTask)EntityCacheUtil.getResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7542                                    BackgroundTaskImpl.class, primaryKey);
7543    
7544                    if (backgroundTask == _nullBackgroundTask) {
7545                            return null;
7546                    }
7547    
7548                    if (backgroundTask == null) {
7549                            Session session = null;
7550    
7551                            try {
7552                                    session = openSession();
7553    
7554                                    backgroundTask = (BackgroundTask)session.get(BackgroundTaskImpl.class,
7555                                                    primaryKey);
7556    
7557                                    if (backgroundTask != null) {
7558                                            cacheResult(backgroundTask);
7559                                    }
7560                                    else {
7561                                            EntityCacheUtil.putResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7562                                                    BackgroundTaskImpl.class, primaryKey,
7563                                                    _nullBackgroundTask);
7564                                    }
7565                            }
7566                            catch (Exception e) {
7567                                    EntityCacheUtil.removeResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7568                                            BackgroundTaskImpl.class, primaryKey);
7569    
7570                                    throw processException(e);
7571                            }
7572                            finally {
7573                                    closeSession(session);
7574                            }
7575                    }
7576    
7577                    return backgroundTask;
7578            }
7579    
7580            /**
7581             * Returns the background task with the primary key or returns <code>null</code> if it could not be found.
7582             *
7583             * @param backgroundTaskId the primary key of the background task
7584             * @return the background task, or <code>null</code> if a background task with the primary key could not be found
7585             */
7586            @Override
7587            public BackgroundTask fetchByPrimaryKey(long backgroundTaskId) {
7588                    return fetchByPrimaryKey((Serializable)backgroundTaskId);
7589            }
7590    
7591            @Override
7592            public Map<Serializable, BackgroundTask> fetchByPrimaryKeys(
7593                    Set<Serializable> primaryKeys) {
7594                    if (primaryKeys.isEmpty()) {
7595                            return Collections.emptyMap();
7596                    }
7597    
7598                    Map<Serializable, BackgroundTask> map = new HashMap<Serializable, BackgroundTask>();
7599    
7600                    if (primaryKeys.size() == 1) {
7601                            Iterator<Serializable> iterator = primaryKeys.iterator();
7602    
7603                            Serializable primaryKey = iterator.next();
7604    
7605                            BackgroundTask backgroundTask = fetchByPrimaryKey(primaryKey);
7606    
7607                            if (backgroundTask != null) {
7608                                    map.put(primaryKey, backgroundTask);
7609                            }
7610    
7611                            return map;
7612                    }
7613    
7614                    Set<Serializable> uncachedPrimaryKeys = null;
7615    
7616                    for (Serializable primaryKey : primaryKeys) {
7617                            BackgroundTask backgroundTask = (BackgroundTask)EntityCacheUtil.getResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7618                                            BackgroundTaskImpl.class, primaryKey);
7619    
7620                            if (backgroundTask == null) {
7621                                    if (uncachedPrimaryKeys == null) {
7622                                            uncachedPrimaryKeys = new HashSet<Serializable>();
7623                                    }
7624    
7625                                    uncachedPrimaryKeys.add(primaryKey);
7626                            }
7627                            else {
7628                                    map.put(primaryKey, backgroundTask);
7629                            }
7630                    }
7631    
7632                    if (uncachedPrimaryKeys == null) {
7633                            return map;
7634                    }
7635    
7636                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
7637                                    1);
7638    
7639                    query.append(_SQL_SELECT_BACKGROUNDTASK_WHERE_PKS_IN);
7640    
7641                    for (Serializable primaryKey : uncachedPrimaryKeys) {
7642                            query.append(String.valueOf(primaryKey));
7643    
7644                            query.append(StringPool.COMMA);
7645                    }
7646    
7647                    query.setIndex(query.index() - 1);
7648    
7649                    query.append(StringPool.CLOSE_PARENTHESIS);
7650    
7651                    String sql = query.toString();
7652    
7653                    Session session = null;
7654    
7655                    try {
7656                            session = openSession();
7657    
7658                            Query q = session.createQuery(sql);
7659    
7660                            for (BackgroundTask backgroundTask : (List<BackgroundTask>)q.list()) {
7661                                    map.put(backgroundTask.getPrimaryKeyObj(), backgroundTask);
7662    
7663                                    cacheResult(backgroundTask);
7664    
7665                                    uncachedPrimaryKeys.remove(backgroundTask.getPrimaryKeyObj());
7666                            }
7667    
7668                            for (Serializable primaryKey : uncachedPrimaryKeys) {
7669                                    EntityCacheUtil.putResult(BackgroundTaskModelImpl.ENTITY_CACHE_ENABLED,
7670                                            BackgroundTaskImpl.class, primaryKey, _nullBackgroundTask);
7671                            }
7672                    }
7673                    catch (Exception e) {
7674                            throw processException(e);
7675                    }
7676                    finally {
7677                            closeSession(session);
7678                    }
7679    
7680                    return map;
7681            }
7682    
7683            /**
7684             * Returns all the background tasks.
7685             *
7686             * @return the background tasks
7687             */
7688            @Override
7689            public List<BackgroundTask> findAll() {
7690                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7691            }
7692    
7693            /**
7694             * Returns a range of all the background tasks.
7695             *
7696             * <p>
7697             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
7698             * </p>
7699             *
7700             * @param start the lower bound of the range of background tasks
7701             * @param end the upper bound of the range of background tasks (not inclusive)
7702             * @return the range of background tasks
7703             */
7704            @Override
7705            public List<BackgroundTask> findAll(int start, int end) {
7706                    return findAll(start, end, null);
7707            }
7708    
7709            /**
7710             * Returns an ordered range of all the background tasks.
7711             *
7712             * <p>
7713             * 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.portal.model.impl.BackgroundTaskModelImpl}. 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.
7714             * </p>
7715             *
7716             * @param start the lower bound of the range of background tasks
7717             * @param end the upper bound of the range of background tasks (not inclusive)
7718             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7719             * @return the ordered range of background tasks
7720             */
7721            @Override
7722            public List<BackgroundTask> findAll(int start, int end,
7723                    OrderByComparator<BackgroundTask> orderByComparator) {
7724                    boolean pagination = true;
7725                    FinderPath finderPath = null;
7726                    Object[] finderArgs = null;
7727    
7728                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7729                                    (orderByComparator == null)) {
7730                            pagination = false;
7731                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7732                            finderArgs = FINDER_ARGS_EMPTY;
7733                    }
7734                    else {
7735                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7736                            finderArgs = new Object[] { start, end, orderByComparator };
7737                    }
7738    
7739                    List<BackgroundTask> list = (List<BackgroundTask>)FinderCacheUtil.getResult(finderPath,
7740                                    finderArgs, this);
7741    
7742                    if (list == null) {
7743                            StringBundler query = null;
7744                            String sql = null;
7745    
7746                            if (orderByComparator != null) {
7747                                    query = new StringBundler(2 +
7748                                                    (orderByComparator.getOrderByFields().length * 3));
7749    
7750                                    query.append(_SQL_SELECT_BACKGROUNDTASK);
7751    
7752                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7753                                            orderByComparator);
7754    
7755                                    sql = query.toString();
7756                            }
7757                            else {
7758                                    sql = _SQL_SELECT_BACKGROUNDTASK;
7759    
7760                                    if (pagination) {
7761                                            sql = sql.concat(BackgroundTaskModelImpl.ORDER_BY_JPQL);
7762                                    }
7763                            }
7764    
7765                            Session session = null;
7766    
7767                            try {
7768                                    session = openSession();
7769    
7770                                    Query q = session.createQuery(sql);
7771    
7772                                    if (!pagination) {
7773                                            list = (List<BackgroundTask>)QueryUtil.list(q,
7774                                                            getDialect(), start, end, false);
7775    
7776                                            Collections.sort(list);
7777    
7778                                            list = Collections.unmodifiableList(list);
7779                                    }
7780                                    else {
7781                                            list = (List<BackgroundTask>)QueryUtil.list(q,
7782                                                            getDialect(), start, end);
7783                                    }
7784    
7785                                    cacheResult(list);
7786    
7787                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7788                            }
7789                            catch (Exception e) {
7790                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7791    
7792                                    throw processException(e);
7793                            }
7794                            finally {
7795                                    closeSession(session);
7796                            }
7797                    }
7798    
7799                    return list;
7800            }
7801    
7802            /**
7803             * Removes all the background tasks from the database.
7804             *
7805             */
7806            @Override
7807            public void removeAll() {
7808                    for (BackgroundTask backgroundTask : findAll()) {
7809                            remove(backgroundTask);
7810                    }
7811            }
7812    
7813            /**
7814             * Returns the number of background tasks.
7815             *
7816             * @return the number of background tasks
7817             */
7818            @Override
7819            public int countAll() {
7820                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7821                                    FINDER_ARGS_EMPTY, this);
7822    
7823                    if (count == null) {
7824                            Session session = null;
7825    
7826                            try {
7827                                    session = openSession();
7828    
7829                                    Query q = session.createQuery(_SQL_COUNT_BACKGROUNDTASK);
7830    
7831                                    count = (Long)q.uniqueResult();
7832    
7833                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7834                                            FINDER_ARGS_EMPTY, count);
7835                            }
7836                            catch (Exception e) {
7837                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7838                                            FINDER_ARGS_EMPTY);
7839    
7840                                    throw processException(e);
7841                            }
7842                            finally {
7843                                    closeSession(session);
7844                            }
7845                    }
7846    
7847                    return count.intValue();
7848            }
7849    
7850            /**
7851             * Initializes the background task persistence.
7852             */
7853            public void afterPropertiesSet() {
7854            }
7855    
7856            public void destroy() {
7857                    EntityCacheUtil.removeCache(BackgroundTaskImpl.class.getName());
7858                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7859                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7860                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7861            }
7862    
7863            private static final String _SQL_SELECT_BACKGROUNDTASK = "SELECT backgroundTask FROM BackgroundTask backgroundTask";
7864            private static final String _SQL_SELECT_BACKGROUNDTASK_WHERE_PKS_IN = "SELECT backgroundTask FROM BackgroundTask backgroundTask WHERE backgroundTaskId IN (";
7865            private static final String _SQL_SELECT_BACKGROUNDTASK_WHERE = "SELECT backgroundTask FROM BackgroundTask backgroundTask WHERE ";
7866            private static final String _SQL_COUNT_BACKGROUNDTASK = "SELECT COUNT(backgroundTask) FROM BackgroundTask backgroundTask";
7867            private static final String _SQL_COUNT_BACKGROUNDTASK_WHERE = "SELECT COUNT(backgroundTask) FROM BackgroundTask backgroundTask WHERE ";
7868            private static final String _ORDER_BY_ENTITY_ALIAS = "backgroundTask.";
7869            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BackgroundTask exists with the primary key ";
7870            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BackgroundTask exists with the key {";
7871            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7872            private static final Log _log = LogFactoryUtil.getLog(BackgroundTaskPersistenceImpl.class);
7873            private static final BackgroundTask _nullBackgroundTask = new BackgroundTaskImpl() {
7874                            @Override
7875                            public Object clone() {
7876                                    return this;
7877                            }
7878    
7879                            @Override
7880                            public CacheModel<BackgroundTask> toCacheModel() {
7881                                    return _nullBackgroundTaskCacheModel;
7882                            }
7883                    };
7884    
7885            private static final CacheModel<BackgroundTask> _nullBackgroundTaskCacheModel =
7886                    new NullCacheModel();
7887    
7888            private static class NullCacheModel implements CacheModel<BackgroundTask>,
7889                    MVCCModel {
7890                    @Override
7891                    public long getMvccVersion() {
7892                            return -1;
7893                    }
7894    
7895                    @Override
7896                    public void setMvccVersion(long mvccVersion) {
7897                    }
7898    
7899                    @Override
7900                    public BackgroundTask toEntityModel() {
7901                            return _nullBackgroundTask;
7902                    }
7903            }
7904    }