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