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