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