001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.journal.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.CalendarUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.SetUtil;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.kernel.util.UnmodifiableList;
039    import com.liferay.portal.kernel.util.Validator;
040    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
041    import com.liferay.portal.model.CacheModel;
042    import com.liferay.portal.model.ModelListener;
043    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import com.liferay.portlet.journal.NoSuchArticleException;
047    import com.liferay.portlet.journal.model.JournalArticle;
048    import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
049    import com.liferay.portlet.journal.model.impl.JournalArticleModelImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Collections;
055    import java.util.Date;
056    import java.util.List;
057    import java.util.Set;
058    
059    /**
060     * The persistence implementation for the journal article service.
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see JournalArticlePersistence
068     * @see JournalArticleUtil
069     * @generated
070     */
071    public class JournalArticlePersistenceImpl extends BasePersistenceImpl<JournalArticle>
072            implements JournalArticlePersistence {
073            /*
074             * NOTE FOR DEVELOPERS:
075             *
076             * Never modify or reference this class directly. Always use {@link JournalArticleUtil} to access the journal article persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
077             */
078            public static final String FINDER_CLASS_NAME_ENTITY = JournalArticleImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List1";
081            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List2";
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
084                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
085                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
086                            "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
088                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
089                            JournalArticleImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
092                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
095                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
096                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
097                            "findByUuid",
098                            new String[] {
099                                    String.class.getName(),
100                                    
101                            Integer.class.getName(), Integer.class.getName(),
102                                    OrderByComparator.class.getName()
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
105                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
106                            JournalArticleImpl.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
108                            new String[] { String.class.getName() },
109                            JournalArticleModelImpl.UUID_COLUMN_BITMASK |
110                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
111                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
112            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
113                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
115                            new String[] { String.class.getName() });
116    
117            /**
118             * Returns all the journal articles where uuid = &#63;.
119             *
120             * @param uuid the uuid
121             * @return the matching journal articles
122             * @throws SystemException if a system exception occurred
123             */
124            @Override
125            public List<JournalArticle> findByUuid(String uuid)
126                    throws SystemException {
127                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
128            }
129    
130            /**
131             * Returns a range of all the journal articles where uuid = &#63;.
132             *
133             * <p>
134             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
135             * </p>
136             *
137             * @param uuid the uuid
138             * @param start the lower bound of the range of journal articles
139             * @param end the upper bound of the range of journal articles (not inclusive)
140             * @return the range of matching journal articles
141             * @throws SystemException if a system exception occurred
142             */
143            @Override
144            public List<JournalArticle> findByUuid(String uuid, int start, int end)
145                    throws SystemException {
146                    return findByUuid(uuid, start, end, null);
147            }
148    
149            /**
150             * Returns an ordered range of all the journal articles where uuid = &#63;.
151             *
152             * <p>
153             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
154             * </p>
155             *
156             * @param uuid the uuid
157             * @param start the lower bound of the range of journal articles
158             * @param end the upper bound of the range of journal articles (not inclusive)
159             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
160             * @return the ordered range of matching journal articles
161             * @throws SystemException if a system exception occurred
162             */
163            @Override
164            public List<JournalArticle> findByUuid(String uuid, int start, int end,
165                    OrderByComparator orderByComparator) throws SystemException {
166                    boolean pagination = true;
167                    FinderPath finderPath = null;
168                    Object[] finderArgs = null;
169    
170                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
171                                    (orderByComparator == null)) {
172                            pagination = false;
173                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
174                            finderArgs = new Object[] { uuid };
175                    }
176                    else {
177                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
178                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
179                    }
180    
181                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
182                                    finderArgs, this);
183    
184                    if ((list != null) && !list.isEmpty()) {
185                            for (JournalArticle journalArticle : list) {
186                                    if (!Validator.equals(uuid, journalArticle.getUuid())) {
187                                            list = null;
188    
189                                            break;
190                                    }
191                            }
192                    }
193    
194                    if (list == null) {
195                            StringBundler query = null;
196    
197                            if (orderByComparator != null) {
198                                    query = new StringBundler(3 +
199                                                    (orderByComparator.getOrderByFields().length * 3));
200                            }
201                            else {
202                                    query = new StringBundler(3);
203                            }
204    
205                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
206    
207                            boolean bindUuid = false;
208    
209                            if (uuid == null) {
210                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
211                            }
212                            else if (uuid.equals(StringPool.BLANK)) {
213                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
214                            }
215                            else {
216                                    bindUuid = true;
217    
218                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
219                            }
220    
221                            if (orderByComparator != null) {
222                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
223                                            orderByComparator);
224                            }
225                            else
226                             if (pagination) {
227                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
228                            }
229    
230                            String sql = query.toString();
231    
232                            Session session = null;
233    
234                            try {
235                                    session = openSession();
236    
237                                    Query q = session.createQuery(sql);
238    
239                                    QueryPos qPos = QueryPos.getInstance(q);
240    
241                                    if (bindUuid) {
242                                            qPos.add(uuid);
243                                    }
244    
245                                    if (!pagination) {
246                                            list = (List<JournalArticle>)QueryUtil.list(q,
247                                                            getDialect(), start, end, false);
248    
249                                            Collections.sort(list);
250    
251                                            list = new UnmodifiableList<JournalArticle>(list);
252                                    }
253                                    else {
254                                            list = (List<JournalArticle>)QueryUtil.list(q,
255                                                            getDialect(), start, end);
256                                    }
257    
258                                    cacheResult(list);
259    
260                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
261                            }
262                            catch (Exception e) {
263                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
264    
265                                    throw processException(e);
266                            }
267                            finally {
268                                    closeSession(session);
269                            }
270                    }
271    
272                    return list;
273            }
274    
275            /**
276             * Returns the first journal article in the ordered set where uuid = &#63;.
277             *
278             * @param uuid the uuid
279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
280             * @return the first matching journal article
281             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
282             * @throws SystemException if a system exception occurred
283             */
284            @Override
285            public JournalArticle findByUuid_First(String uuid,
286                    OrderByComparator orderByComparator)
287                    throws NoSuchArticleException, SystemException {
288                    JournalArticle journalArticle = fetchByUuid_First(uuid,
289                                    orderByComparator);
290    
291                    if (journalArticle != null) {
292                            return journalArticle;
293                    }
294    
295                    StringBundler msg = new StringBundler(4);
296    
297                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
298    
299                    msg.append("uuid=");
300                    msg.append(uuid);
301    
302                    msg.append(StringPool.CLOSE_CURLY_BRACE);
303    
304                    throw new NoSuchArticleException(msg.toString());
305            }
306    
307            /**
308             * Returns the first journal article in the ordered set where uuid = &#63;.
309             *
310             * @param uuid the uuid
311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
312             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
313             * @throws SystemException if a system exception occurred
314             */
315            @Override
316            public JournalArticle fetchByUuid_First(String uuid,
317                    OrderByComparator orderByComparator) throws SystemException {
318                    List<JournalArticle> list = findByUuid(uuid, 0, 1, orderByComparator);
319    
320                    if (!list.isEmpty()) {
321                            return list.get(0);
322                    }
323    
324                    return null;
325            }
326    
327            /**
328             * Returns the last journal article in the ordered set where uuid = &#63;.
329             *
330             * @param uuid the uuid
331             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
332             * @return the last matching journal article
333             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
334             * @throws SystemException if a system exception occurred
335             */
336            @Override
337            public JournalArticle findByUuid_Last(String uuid,
338                    OrderByComparator orderByComparator)
339                    throws NoSuchArticleException, SystemException {
340                    JournalArticle journalArticle = fetchByUuid_Last(uuid, orderByComparator);
341    
342                    if (journalArticle != null) {
343                            return journalArticle;
344                    }
345    
346                    StringBundler msg = new StringBundler(4);
347    
348                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
349    
350                    msg.append("uuid=");
351                    msg.append(uuid);
352    
353                    msg.append(StringPool.CLOSE_CURLY_BRACE);
354    
355                    throw new NoSuchArticleException(msg.toString());
356            }
357    
358            /**
359             * Returns the last journal article in the ordered set where uuid = &#63;.
360             *
361             * @param uuid the uuid
362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
363             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
364             * @throws SystemException if a system exception occurred
365             */
366            @Override
367            public JournalArticle fetchByUuid_Last(String uuid,
368                    OrderByComparator orderByComparator) throws SystemException {
369                    int count = countByUuid(uuid);
370    
371                    if (count == 0) {
372                            return null;
373                    }
374    
375                    List<JournalArticle> list = findByUuid(uuid, count - 1, count,
376                                    orderByComparator);
377    
378                    if (!list.isEmpty()) {
379                            return list.get(0);
380                    }
381    
382                    return null;
383            }
384    
385            /**
386             * Returns the journal articles before and after the current journal article in the ordered set where uuid = &#63;.
387             *
388             * @param id the primary key of the current journal article
389             * @param uuid the uuid
390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
391             * @return the previous, current, and next journal article
392             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
393             * @throws SystemException if a system exception occurred
394             */
395            @Override
396            public JournalArticle[] findByUuid_PrevAndNext(long id, String uuid,
397                    OrderByComparator orderByComparator)
398                    throws NoSuchArticleException, SystemException {
399                    JournalArticle journalArticle = findByPrimaryKey(id);
400    
401                    Session session = null;
402    
403                    try {
404                            session = openSession();
405    
406                            JournalArticle[] array = new JournalArticleImpl[3];
407    
408                            array[0] = getByUuid_PrevAndNext(session, journalArticle, uuid,
409                                            orderByComparator, true);
410    
411                            array[1] = journalArticle;
412    
413                            array[2] = getByUuid_PrevAndNext(session, journalArticle, uuid,
414                                            orderByComparator, false);
415    
416                            return array;
417                    }
418                    catch (Exception e) {
419                            throw processException(e);
420                    }
421                    finally {
422                            closeSession(session);
423                    }
424            }
425    
426            protected JournalArticle getByUuid_PrevAndNext(Session session,
427                    JournalArticle journalArticle, String uuid,
428                    OrderByComparator orderByComparator, boolean previous) {
429                    StringBundler query = null;
430    
431                    if (orderByComparator != null) {
432                            query = new StringBundler(6 +
433                                            (orderByComparator.getOrderByFields().length * 6));
434                    }
435                    else {
436                            query = new StringBundler(3);
437                    }
438    
439                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
440    
441                    boolean bindUuid = false;
442    
443                    if (uuid == null) {
444                            query.append(_FINDER_COLUMN_UUID_UUID_1);
445                    }
446                    else if (uuid.equals(StringPool.BLANK)) {
447                            query.append(_FINDER_COLUMN_UUID_UUID_3);
448                    }
449                    else {
450                            bindUuid = true;
451    
452                            query.append(_FINDER_COLUMN_UUID_UUID_2);
453                    }
454    
455                    if (orderByComparator != null) {
456                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
457    
458                            if (orderByConditionFields.length > 0) {
459                                    query.append(WHERE_AND);
460                            }
461    
462                            for (int i = 0; i < orderByConditionFields.length; i++) {
463                                    query.append(_ORDER_BY_ENTITY_ALIAS);
464                                    query.append(orderByConditionFields[i]);
465    
466                                    if ((i + 1) < orderByConditionFields.length) {
467                                            if (orderByComparator.isAscending() ^ previous) {
468                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
469                                            }
470                                            else {
471                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
472                                            }
473                                    }
474                                    else {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(WHERE_GREATER_THAN);
477                                            }
478                                            else {
479                                                    query.append(WHERE_LESSER_THAN);
480                                            }
481                                    }
482                            }
483    
484                            query.append(ORDER_BY_CLAUSE);
485    
486                            String[] orderByFields = orderByComparator.getOrderByFields();
487    
488                            for (int i = 0; i < orderByFields.length; i++) {
489                                    query.append(_ORDER_BY_ENTITY_ALIAS);
490                                    query.append(orderByFields[i]);
491    
492                                    if ((i + 1) < orderByFields.length) {
493                                            if (orderByComparator.isAscending() ^ previous) {
494                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
495                                            }
496                                            else {
497                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
498                                            }
499                                    }
500                                    else {
501                                            if (orderByComparator.isAscending() ^ previous) {
502                                                    query.append(ORDER_BY_ASC);
503                                            }
504                                            else {
505                                                    query.append(ORDER_BY_DESC);
506                                            }
507                                    }
508                            }
509                    }
510                    else {
511                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
512                    }
513    
514                    String sql = query.toString();
515    
516                    Query q = session.createQuery(sql);
517    
518                    q.setFirstResult(0);
519                    q.setMaxResults(2);
520    
521                    QueryPos qPos = QueryPos.getInstance(q);
522    
523                    if (bindUuid) {
524                            qPos.add(uuid);
525                    }
526    
527                    if (orderByComparator != null) {
528                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
529    
530                            for (Object value : values) {
531                                    qPos.add(value);
532                            }
533                    }
534    
535                    List<JournalArticle> list = q.list();
536    
537                    if (list.size() == 2) {
538                            return list.get(1);
539                    }
540                    else {
541                            return null;
542                    }
543            }
544    
545            /**
546             * Removes all the journal articles where uuid = &#63; from the database.
547             *
548             * @param uuid the uuid
549             * @throws SystemException if a system exception occurred
550             */
551            @Override
552            public void removeByUuid(String uuid) throws SystemException {
553                    for (JournalArticle journalArticle : findByUuid(uuid,
554                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
555                            remove(journalArticle);
556                    }
557            }
558    
559            /**
560             * Returns the number of journal articles where uuid = &#63;.
561             *
562             * @param uuid the uuid
563             * @return the number of matching journal articles
564             * @throws SystemException if a system exception occurred
565             */
566            @Override
567            public int countByUuid(String uuid) throws SystemException {
568                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
569    
570                    Object[] finderArgs = new Object[] { uuid };
571    
572                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
573                                    this);
574    
575                    if (count == null) {
576                            StringBundler query = new StringBundler(2);
577    
578                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
579    
580                            boolean bindUuid = false;
581    
582                            if (uuid == null) {
583                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
584                            }
585                            else if (uuid.equals(StringPool.BLANK)) {
586                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
587                            }
588                            else {
589                                    bindUuid = true;
590    
591                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
592                            }
593    
594                            String sql = query.toString();
595    
596                            Session session = null;
597    
598                            try {
599                                    session = openSession();
600    
601                                    Query q = session.createQuery(sql);
602    
603                                    QueryPos qPos = QueryPos.getInstance(q);
604    
605                                    if (bindUuid) {
606                                            qPos.add(uuid);
607                                    }
608    
609                                    count = (Long)q.uniqueResult();
610    
611                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
612                            }
613                            catch (Exception e) {
614                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
615    
616                                    throw processException(e);
617                            }
618                            finally {
619                                    closeSession(session);
620                            }
621                    }
622    
623                    return count.intValue();
624            }
625    
626            private static final String _FINDER_COLUMN_UUID_UUID_1 = "journalArticle.uuid IS NULL";
627            private static final String _FINDER_COLUMN_UUID_UUID_2 = "journalArticle.uuid = ?";
628            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(journalArticle.uuid IS NULL OR journalArticle.uuid = '')";
629            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
630                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
631                            JournalArticleImpl.class, FINDER_CLASS_NAME_ENTITY,
632                            "fetchByUUID_G",
633                            new String[] { String.class.getName(), Long.class.getName() },
634                            JournalArticleModelImpl.UUID_COLUMN_BITMASK |
635                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK);
636            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
637                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
638                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
639                            new String[] { String.class.getName(), Long.class.getName() });
640    
641            /**
642             * Returns the journal article where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchArticleException} if it could not be found.
643             *
644             * @param uuid the uuid
645             * @param groupId the group ID
646             * @return the matching journal article
647             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
648             * @throws SystemException if a system exception occurred
649             */
650            @Override
651            public JournalArticle findByUUID_G(String uuid, long groupId)
652                    throws NoSuchArticleException, SystemException {
653                    JournalArticle journalArticle = fetchByUUID_G(uuid, groupId);
654    
655                    if (journalArticle == null) {
656                            StringBundler msg = new StringBundler(6);
657    
658                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
659    
660                            msg.append("uuid=");
661                            msg.append(uuid);
662    
663                            msg.append(", groupId=");
664                            msg.append(groupId);
665    
666                            msg.append(StringPool.CLOSE_CURLY_BRACE);
667    
668                            if (_log.isWarnEnabled()) {
669                                    _log.warn(msg.toString());
670                            }
671    
672                            throw new NoSuchArticleException(msg.toString());
673                    }
674    
675                    return journalArticle;
676            }
677    
678            /**
679             * Returns the journal article where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
680             *
681             * @param uuid the uuid
682             * @param groupId the group ID
683             * @return the matching journal article, or <code>null</code> if a matching journal article could not be found
684             * @throws SystemException if a system exception occurred
685             */
686            @Override
687            public JournalArticle fetchByUUID_G(String uuid, long groupId)
688                    throws SystemException {
689                    return fetchByUUID_G(uuid, groupId, true);
690            }
691    
692            /**
693             * Returns the journal article where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
694             *
695             * @param uuid the uuid
696             * @param groupId the group ID
697             * @param retrieveFromCache whether to use the finder cache
698             * @return the matching journal article, or <code>null</code> if a matching journal article could not be found
699             * @throws SystemException if a system exception occurred
700             */
701            @Override
702            public JournalArticle fetchByUUID_G(String uuid, long groupId,
703                    boolean retrieveFromCache) throws SystemException {
704                    Object[] finderArgs = new Object[] { uuid, groupId };
705    
706                    Object result = null;
707    
708                    if (retrieveFromCache) {
709                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
710                                            finderArgs, this);
711                    }
712    
713                    if (result instanceof JournalArticle) {
714                            JournalArticle journalArticle = (JournalArticle)result;
715    
716                            if (!Validator.equals(uuid, journalArticle.getUuid()) ||
717                                            (groupId != journalArticle.getGroupId())) {
718                                    result = null;
719                            }
720                    }
721    
722                    if (result == null) {
723                            StringBundler query = new StringBundler(4);
724    
725                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
726    
727                            boolean bindUuid = false;
728    
729                            if (uuid == null) {
730                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
731                            }
732                            else if (uuid.equals(StringPool.BLANK)) {
733                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
734                            }
735                            else {
736                                    bindUuid = true;
737    
738                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
739                            }
740    
741                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
742    
743                            String sql = query.toString();
744    
745                            Session session = null;
746    
747                            try {
748                                    session = openSession();
749    
750                                    Query q = session.createQuery(sql);
751    
752                                    QueryPos qPos = QueryPos.getInstance(q);
753    
754                                    if (bindUuid) {
755                                            qPos.add(uuid);
756                                    }
757    
758                                    qPos.add(groupId);
759    
760                                    List<JournalArticle> list = q.list();
761    
762                                    if (list.isEmpty()) {
763                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
764                                                    finderArgs, list);
765                                    }
766                                    else {
767                                            JournalArticle journalArticle = list.get(0);
768    
769                                            result = journalArticle;
770    
771                                            cacheResult(journalArticle);
772    
773                                            if ((journalArticle.getUuid() == null) ||
774                                                            !journalArticle.getUuid().equals(uuid) ||
775                                                            (journalArticle.getGroupId() != groupId)) {
776                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
777                                                            finderArgs, journalArticle);
778                                            }
779                                    }
780                            }
781                            catch (Exception e) {
782                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
783                                            finderArgs);
784    
785                                    throw processException(e);
786                            }
787                            finally {
788                                    closeSession(session);
789                            }
790                    }
791    
792                    if (result instanceof List<?>) {
793                            return null;
794                    }
795                    else {
796                            return (JournalArticle)result;
797                    }
798            }
799    
800            /**
801             * Removes the journal article where uuid = &#63; and groupId = &#63; from the database.
802             *
803             * @param uuid the uuid
804             * @param groupId the group ID
805             * @return the journal article that was removed
806             * @throws SystemException if a system exception occurred
807             */
808            @Override
809            public JournalArticle removeByUUID_G(String uuid, long groupId)
810                    throws NoSuchArticleException, SystemException {
811                    JournalArticle journalArticle = findByUUID_G(uuid, groupId);
812    
813                    return remove(journalArticle);
814            }
815    
816            /**
817             * Returns the number of journal articles where uuid = &#63; and groupId = &#63;.
818             *
819             * @param uuid the uuid
820             * @param groupId the group ID
821             * @return the number of matching journal articles
822             * @throws SystemException if a system exception occurred
823             */
824            @Override
825            public int countByUUID_G(String uuid, long groupId)
826                    throws SystemException {
827                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
828    
829                    Object[] finderArgs = new Object[] { uuid, groupId };
830    
831                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
832                                    this);
833    
834                    if (count == null) {
835                            StringBundler query = new StringBundler(3);
836    
837                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
838    
839                            boolean bindUuid = false;
840    
841                            if (uuid == null) {
842                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
843                            }
844                            else if (uuid.equals(StringPool.BLANK)) {
845                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
846                            }
847                            else {
848                                    bindUuid = true;
849    
850                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
851                            }
852    
853                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
854    
855                            String sql = query.toString();
856    
857                            Session session = null;
858    
859                            try {
860                                    session = openSession();
861    
862                                    Query q = session.createQuery(sql);
863    
864                                    QueryPos qPos = QueryPos.getInstance(q);
865    
866                                    if (bindUuid) {
867                                            qPos.add(uuid);
868                                    }
869    
870                                    qPos.add(groupId);
871    
872                                    count = (Long)q.uniqueResult();
873    
874                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
875                            }
876                            catch (Exception e) {
877                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
878    
879                                    throw processException(e);
880                            }
881                            finally {
882                                    closeSession(session);
883                            }
884                    }
885    
886                    return count.intValue();
887            }
888    
889            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "journalArticle.uuid IS NULL AND ";
890            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "journalArticle.uuid = ? AND ";
891            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(journalArticle.uuid IS NULL OR journalArticle.uuid = '') AND ";
892            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "journalArticle.groupId = ?";
893            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
894                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
895                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
896                            "findByUuid_C",
897                            new String[] {
898                                    String.class.getName(), Long.class.getName(),
899                                    
900                            Integer.class.getName(), Integer.class.getName(),
901                                    OrderByComparator.class.getName()
902                            });
903            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
904                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
905                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
906                            JournalArticleImpl.class,
907                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
908                            new String[] { String.class.getName(), Long.class.getName() },
909                            JournalArticleModelImpl.UUID_COLUMN_BITMASK |
910                            JournalArticleModelImpl.COMPANYID_COLUMN_BITMASK |
911                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
912                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
913            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
914                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
915                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
916                            new String[] { String.class.getName(), Long.class.getName() });
917    
918            /**
919             * Returns all the journal articles where uuid = &#63; and companyId = &#63;.
920             *
921             * @param uuid the uuid
922             * @param companyId the company ID
923             * @return the matching journal articles
924             * @throws SystemException if a system exception occurred
925             */
926            @Override
927            public List<JournalArticle> findByUuid_C(String uuid, long companyId)
928                    throws SystemException {
929                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
930                            QueryUtil.ALL_POS, null);
931            }
932    
933            /**
934             * Returns a range of all the journal articles where uuid = &#63; and companyId = &#63;.
935             *
936             * <p>
937             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
938             * </p>
939             *
940             * @param uuid the uuid
941             * @param companyId the company ID
942             * @param start the lower bound of the range of journal articles
943             * @param end the upper bound of the range of journal articles (not inclusive)
944             * @return the range of matching journal articles
945             * @throws SystemException if a system exception occurred
946             */
947            @Override
948            public List<JournalArticle> findByUuid_C(String uuid, long companyId,
949                    int start, int end) throws SystemException {
950                    return findByUuid_C(uuid, companyId, start, end, null);
951            }
952    
953            /**
954             * Returns an ordered range of all the journal articles where uuid = &#63; and companyId = &#63;.
955             *
956             * <p>
957             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
958             * </p>
959             *
960             * @param uuid the uuid
961             * @param companyId the company ID
962             * @param start the lower bound of the range of journal articles
963             * @param end the upper bound of the range of journal articles (not inclusive)
964             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
965             * @return the ordered range of matching journal articles
966             * @throws SystemException if a system exception occurred
967             */
968            @Override
969            public List<JournalArticle> findByUuid_C(String uuid, long companyId,
970                    int start, int end, OrderByComparator orderByComparator)
971                    throws SystemException {
972                    boolean pagination = true;
973                    FinderPath finderPath = null;
974                    Object[] finderArgs = null;
975    
976                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
977                                    (orderByComparator == null)) {
978                            pagination = false;
979                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
980                            finderArgs = new Object[] { uuid, companyId };
981                    }
982                    else {
983                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
984                            finderArgs = new Object[] {
985                                            uuid, companyId,
986                                            
987                                            start, end, orderByComparator
988                                    };
989                    }
990    
991                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
992                                    finderArgs, this);
993    
994                    if ((list != null) && !list.isEmpty()) {
995                            for (JournalArticle journalArticle : list) {
996                                    if (!Validator.equals(uuid, journalArticle.getUuid()) ||
997                                                    (companyId != journalArticle.getCompanyId())) {
998                                            list = null;
999    
1000                                            break;
1001                                    }
1002                            }
1003                    }
1004    
1005                    if (list == null) {
1006                            StringBundler query = null;
1007    
1008                            if (orderByComparator != null) {
1009                                    query = new StringBundler(4 +
1010                                                    (orderByComparator.getOrderByFields().length * 3));
1011                            }
1012                            else {
1013                                    query = new StringBundler(4);
1014                            }
1015    
1016                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
1017    
1018                            boolean bindUuid = false;
1019    
1020                            if (uuid == null) {
1021                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1022                            }
1023                            else if (uuid.equals(StringPool.BLANK)) {
1024                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1025                            }
1026                            else {
1027                                    bindUuid = true;
1028    
1029                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1030                            }
1031    
1032                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1033    
1034                            if (orderByComparator != null) {
1035                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1036                                            orderByComparator);
1037                            }
1038                            else
1039                             if (pagination) {
1040                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
1041                            }
1042    
1043                            String sql = query.toString();
1044    
1045                            Session session = null;
1046    
1047                            try {
1048                                    session = openSession();
1049    
1050                                    Query q = session.createQuery(sql);
1051    
1052                                    QueryPos qPos = QueryPos.getInstance(q);
1053    
1054                                    if (bindUuid) {
1055                                            qPos.add(uuid);
1056                                    }
1057    
1058                                    qPos.add(companyId);
1059    
1060                                    if (!pagination) {
1061                                            list = (List<JournalArticle>)QueryUtil.list(q,
1062                                                            getDialect(), start, end, false);
1063    
1064                                            Collections.sort(list);
1065    
1066                                            list = new UnmodifiableList<JournalArticle>(list);
1067                                    }
1068                                    else {
1069                                            list = (List<JournalArticle>)QueryUtil.list(q,
1070                                                            getDialect(), start, end);
1071                                    }
1072    
1073                                    cacheResult(list);
1074    
1075                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1076                            }
1077                            catch (Exception e) {
1078                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1079    
1080                                    throw processException(e);
1081                            }
1082                            finally {
1083                                    closeSession(session);
1084                            }
1085                    }
1086    
1087                    return list;
1088            }
1089    
1090            /**
1091             * Returns the first journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1092             *
1093             * @param uuid the uuid
1094             * @param companyId the company ID
1095             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1096             * @return the first matching journal article
1097             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
1098             * @throws SystemException if a system exception occurred
1099             */
1100            @Override
1101            public JournalArticle findByUuid_C_First(String uuid, long companyId,
1102                    OrderByComparator orderByComparator)
1103                    throws NoSuchArticleException, SystemException {
1104                    JournalArticle journalArticle = fetchByUuid_C_First(uuid, companyId,
1105                                    orderByComparator);
1106    
1107                    if (journalArticle != null) {
1108                            return journalArticle;
1109                    }
1110    
1111                    StringBundler msg = new StringBundler(6);
1112    
1113                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1114    
1115                    msg.append("uuid=");
1116                    msg.append(uuid);
1117    
1118                    msg.append(", companyId=");
1119                    msg.append(companyId);
1120    
1121                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1122    
1123                    throw new NoSuchArticleException(msg.toString());
1124            }
1125    
1126            /**
1127             * Returns the first journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1128             *
1129             * @param uuid the uuid
1130             * @param companyId the company ID
1131             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1132             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
1133             * @throws SystemException if a system exception occurred
1134             */
1135            @Override
1136            public JournalArticle fetchByUuid_C_First(String uuid, long companyId,
1137                    OrderByComparator orderByComparator) throws SystemException {
1138                    List<JournalArticle> list = findByUuid_C(uuid, companyId, 0, 1,
1139                                    orderByComparator);
1140    
1141                    if (!list.isEmpty()) {
1142                            return list.get(0);
1143                    }
1144    
1145                    return null;
1146            }
1147    
1148            /**
1149             * Returns the last journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1150             *
1151             * @param uuid the uuid
1152             * @param companyId the company ID
1153             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1154             * @return the last matching journal article
1155             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
1156             * @throws SystemException if a system exception occurred
1157             */
1158            @Override
1159            public JournalArticle findByUuid_C_Last(String uuid, long companyId,
1160                    OrderByComparator orderByComparator)
1161                    throws NoSuchArticleException, SystemException {
1162                    JournalArticle journalArticle = fetchByUuid_C_Last(uuid, companyId,
1163                                    orderByComparator);
1164    
1165                    if (journalArticle != null) {
1166                            return journalArticle;
1167                    }
1168    
1169                    StringBundler msg = new StringBundler(6);
1170    
1171                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1172    
1173                    msg.append("uuid=");
1174                    msg.append(uuid);
1175    
1176                    msg.append(", companyId=");
1177                    msg.append(companyId);
1178    
1179                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1180    
1181                    throw new NoSuchArticleException(msg.toString());
1182            }
1183    
1184            /**
1185             * Returns the last journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1186             *
1187             * @param uuid the uuid
1188             * @param companyId the company ID
1189             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1190             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
1191             * @throws SystemException if a system exception occurred
1192             */
1193            @Override
1194            public JournalArticle fetchByUuid_C_Last(String uuid, long companyId,
1195                    OrderByComparator orderByComparator) throws SystemException {
1196                    int count = countByUuid_C(uuid, companyId);
1197    
1198                    if (count == 0) {
1199                            return null;
1200                    }
1201    
1202                    List<JournalArticle> list = findByUuid_C(uuid, companyId, count - 1,
1203                                    count, orderByComparator);
1204    
1205                    if (!list.isEmpty()) {
1206                            return list.get(0);
1207                    }
1208    
1209                    return null;
1210            }
1211    
1212            /**
1213             * Returns the journal articles before and after the current journal article in the ordered set where uuid = &#63; and companyId = &#63;.
1214             *
1215             * @param id the primary key of the current journal article
1216             * @param uuid the uuid
1217             * @param companyId the company ID
1218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1219             * @return the previous, current, and next journal article
1220             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
1221             * @throws SystemException if a system exception occurred
1222             */
1223            @Override
1224            public JournalArticle[] findByUuid_C_PrevAndNext(long id, String uuid,
1225                    long companyId, OrderByComparator orderByComparator)
1226                    throws NoSuchArticleException, SystemException {
1227                    JournalArticle journalArticle = findByPrimaryKey(id);
1228    
1229                    Session session = null;
1230    
1231                    try {
1232                            session = openSession();
1233    
1234                            JournalArticle[] array = new JournalArticleImpl[3];
1235    
1236                            array[0] = getByUuid_C_PrevAndNext(session, journalArticle, uuid,
1237                                            companyId, orderByComparator, true);
1238    
1239                            array[1] = journalArticle;
1240    
1241                            array[2] = getByUuid_C_PrevAndNext(session, journalArticle, uuid,
1242                                            companyId, orderByComparator, false);
1243    
1244                            return array;
1245                    }
1246                    catch (Exception e) {
1247                            throw processException(e);
1248                    }
1249                    finally {
1250                            closeSession(session);
1251                    }
1252            }
1253    
1254            protected JournalArticle getByUuid_C_PrevAndNext(Session session,
1255                    JournalArticle journalArticle, String uuid, long companyId,
1256                    OrderByComparator orderByComparator, boolean previous) {
1257                    StringBundler query = null;
1258    
1259                    if (orderByComparator != null) {
1260                            query = new StringBundler(6 +
1261                                            (orderByComparator.getOrderByFields().length * 6));
1262                    }
1263                    else {
1264                            query = new StringBundler(3);
1265                    }
1266    
1267                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
1268    
1269                    boolean bindUuid = false;
1270    
1271                    if (uuid == null) {
1272                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1273                    }
1274                    else if (uuid.equals(StringPool.BLANK)) {
1275                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1276                    }
1277                    else {
1278                            bindUuid = true;
1279    
1280                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1281                    }
1282    
1283                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1284    
1285                    if (orderByComparator != null) {
1286                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1287    
1288                            if (orderByConditionFields.length > 0) {
1289                                    query.append(WHERE_AND);
1290                            }
1291    
1292                            for (int i = 0; i < orderByConditionFields.length; i++) {
1293                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1294                                    query.append(orderByConditionFields[i]);
1295    
1296                                    if ((i + 1) < orderByConditionFields.length) {
1297                                            if (orderByComparator.isAscending() ^ previous) {
1298                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1299                                            }
1300                                            else {
1301                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1302                                            }
1303                                    }
1304                                    else {
1305                                            if (orderByComparator.isAscending() ^ previous) {
1306                                                    query.append(WHERE_GREATER_THAN);
1307                                            }
1308                                            else {
1309                                                    query.append(WHERE_LESSER_THAN);
1310                                            }
1311                                    }
1312                            }
1313    
1314                            query.append(ORDER_BY_CLAUSE);
1315    
1316                            String[] orderByFields = orderByComparator.getOrderByFields();
1317    
1318                            for (int i = 0; i < orderByFields.length; i++) {
1319                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1320                                    query.append(orderByFields[i]);
1321    
1322                                    if ((i + 1) < orderByFields.length) {
1323                                            if (orderByComparator.isAscending() ^ previous) {
1324                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1325                                            }
1326                                            else {
1327                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1328                                            }
1329                                    }
1330                                    else {
1331                                            if (orderByComparator.isAscending() ^ previous) {
1332                                                    query.append(ORDER_BY_ASC);
1333                                            }
1334                                            else {
1335                                                    query.append(ORDER_BY_DESC);
1336                                            }
1337                                    }
1338                            }
1339                    }
1340                    else {
1341                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
1342                    }
1343    
1344                    String sql = query.toString();
1345    
1346                    Query q = session.createQuery(sql);
1347    
1348                    q.setFirstResult(0);
1349                    q.setMaxResults(2);
1350    
1351                    QueryPos qPos = QueryPos.getInstance(q);
1352    
1353                    if (bindUuid) {
1354                            qPos.add(uuid);
1355                    }
1356    
1357                    qPos.add(companyId);
1358    
1359                    if (orderByComparator != null) {
1360                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
1361    
1362                            for (Object value : values) {
1363                                    qPos.add(value);
1364                            }
1365                    }
1366    
1367                    List<JournalArticle> list = q.list();
1368    
1369                    if (list.size() == 2) {
1370                            return list.get(1);
1371                    }
1372                    else {
1373                            return null;
1374                    }
1375            }
1376    
1377            /**
1378             * Removes all the journal articles where uuid = &#63; and companyId = &#63; from the database.
1379             *
1380             * @param uuid the uuid
1381             * @param companyId the company ID
1382             * @throws SystemException if a system exception occurred
1383             */
1384            @Override
1385            public void removeByUuid_C(String uuid, long companyId)
1386                    throws SystemException {
1387                    for (JournalArticle journalArticle : findByUuid_C(uuid, companyId,
1388                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1389                            remove(journalArticle);
1390                    }
1391            }
1392    
1393            /**
1394             * Returns the number of journal articles where uuid = &#63; and companyId = &#63;.
1395             *
1396             * @param uuid the uuid
1397             * @param companyId the company ID
1398             * @return the number of matching journal articles
1399             * @throws SystemException if a system exception occurred
1400             */
1401            @Override
1402            public int countByUuid_C(String uuid, long companyId)
1403                    throws SystemException {
1404                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1405    
1406                    Object[] finderArgs = new Object[] { uuid, companyId };
1407    
1408                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1409                                    this);
1410    
1411                    if (count == null) {
1412                            StringBundler query = new StringBundler(3);
1413    
1414                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
1415    
1416                            boolean bindUuid = false;
1417    
1418                            if (uuid == null) {
1419                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1420                            }
1421                            else if (uuid.equals(StringPool.BLANK)) {
1422                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1423                            }
1424                            else {
1425                                    bindUuid = true;
1426    
1427                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1428                            }
1429    
1430                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1431    
1432                            String sql = query.toString();
1433    
1434                            Session session = null;
1435    
1436                            try {
1437                                    session = openSession();
1438    
1439                                    Query q = session.createQuery(sql);
1440    
1441                                    QueryPos qPos = QueryPos.getInstance(q);
1442    
1443                                    if (bindUuid) {
1444                                            qPos.add(uuid);
1445                                    }
1446    
1447                                    qPos.add(companyId);
1448    
1449                                    count = (Long)q.uniqueResult();
1450    
1451                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1452                            }
1453                            catch (Exception e) {
1454                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1455    
1456                                    throw processException(e);
1457                            }
1458                            finally {
1459                                    closeSession(session);
1460                            }
1461                    }
1462    
1463                    return count.intValue();
1464            }
1465    
1466            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "journalArticle.uuid IS NULL AND ";
1467            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "journalArticle.uuid = ? AND ";
1468            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(journalArticle.uuid IS NULL OR journalArticle.uuid = '') AND ";
1469            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "journalArticle.companyId = ?";
1470            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEPRIMKEY =
1471                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1472                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
1473                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1474                            "findByResourcePrimKey",
1475                            new String[] {
1476                                    Long.class.getName(),
1477                                    
1478                            Integer.class.getName(), Integer.class.getName(),
1479                                    OrderByComparator.class.getName()
1480                            });
1481            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY =
1482                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1483                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
1484                            JournalArticleImpl.class,
1485                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByResourcePrimKey",
1486                            new String[] { Long.class.getName() },
1487                            JournalArticleModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
1488                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
1489                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
1490            public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1491                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1492                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1493                            "countByResourcePrimKey", new String[] { Long.class.getName() });
1494    
1495            /**
1496             * Returns all the journal articles where resourcePrimKey = &#63;.
1497             *
1498             * @param resourcePrimKey the resource prim key
1499             * @return the matching journal articles
1500             * @throws SystemException if a system exception occurred
1501             */
1502            @Override
1503            public List<JournalArticle> findByResourcePrimKey(long resourcePrimKey)
1504                    throws SystemException {
1505                    return findByResourcePrimKey(resourcePrimKey, QueryUtil.ALL_POS,
1506                            QueryUtil.ALL_POS, null);
1507            }
1508    
1509            /**
1510             * Returns a range of all the journal articles where resourcePrimKey = &#63;.
1511             *
1512             * <p>
1513             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
1514             * </p>
1515             *
1516             * @param resourcePrimKey the resource prim key
1517             * @param start the lower bound of the range of journal articles
1518             * @param end the upper bound of the range of journal articles (not inclusive)
1519             * @return the range of matching journal articles
1520             * @throws SystemException if a system exception occurred
1521             */
1522            @Override
1523            public List<JournalArticle> findByResourcePrimKey(long resourcePrimKey,
1524                    int start, int end) throws SystemException {
1525                    return findByResourcePrimKey(resourcePrimKey, start, end, null);
1526            }
1527    
1528            /**
1529             * Returns an ordered range of all the journal articles where resourcePrimKey = &#63;.
1530             *
1531             * <p>
1532             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
1533             * </p>
1534             *
1535             * @param resourcePrimKey the resource prim key
1536             * @param start the lower bound of the range of journal articles
1537             * @param end the upper bound of the range of journal articles (not inclusive)
1538             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1539             * @return the ordered range of matching journal articles
1540             * @throws SystemException if a system exception occurred
1541             */
1542            @Override
1543            public List<JournalArticle> findByResourcePrimKey(long resourcePrimKey,
1544                    int start, int end, OrderByComparator orderByComparator)
1545                    throws SystemException {
1546                    boolean pagination = true;
1547                    FinderPath finderPath = null;
1548                    Object[] finderArgs = null;
1549    
1550                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1551                                    (orderByComparator == null)) {
1552                            pagination = false;
1553                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY;
1554                            finderArgs = new Object[] { resourcePrimKey };
1555                    }
1556                    else {
1557                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEPRIMKEY;
1558                            finderArgs = new Object[] {
1559                                            resourcePrimKey,
1560                                            
1561                                            start, end, orderByComparator
1562                                    };
1563                    }
1564    
1565                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
1566                                    finderArgs, this);
1567    
1568                    if ((list != null) && !list.isEmpty()) {
1569                            for (JournalArticle journalArticle : list) {
1570                                    if ((resourcePrimKey != journalArticle.getResourcePrimKey())) {
1571                                            list = null;
1572    
1573                                            break;
1574                                    }
1575                            }
1576                    }
1577    
1578                    if (list == null) {
1579                            StringBundler query = null;
1580    
1581                            if (orderByComparator != null) {
1582                                    query = new StringBundler(3 +
1583                                                    (orderByComparator.getOrderByFields().length * 3));
1584                            }
1585                            else {
1586                                    query = new StringBundler(3);
1587                            }
1588    
1589                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
1590    
1591                            query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1592    
1593                            if (orderByComparator != null) {
1594                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1595                                            orderByComparator);
1596                            }
1597                            else
1598                             if (pagination) {
1599                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
1600                            }
1601    
1602                            String sql = query.toString();
1603    
1604                            Session session = null;
1605    
1606                            try {
1607                                    session = openSession();
1608    
1609                                    Query q = session.createQuery(sql);
1610    
1611                                    QueryPos qPos = QueryPos.getInstance(q);
1612    
1613                                    qPos.add(resourcePrimKey);
1614    
1615                                    if (!pagination) {
1616                                            list = (List<JournalArticle>)QueryUtil.list(q,
1617                                                            getDialect(), start, end, false);
1618    
1619                                            Collections.sort(list);
1620    
1621                                            list = new UnmodifiableList<JournalArticle>(list);
1622                                    }
1623                                    else {
1624                                            list = (List<JournalArticle>)QueryUtil.list(q,
1625                                                            getDialect(), start, end);
1626                                    }
1627    
1628                                    cacheResult(list);
1629    
1630                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1631                            }
1632                            catch (Exception e) {
1633                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1634    
1635                                    throw processException(e);
1636                            }
1637                            finally {
1638                                    closeSession(session);
1639                            }
1640                    }
1641    
1642                    return list;
1643            }
1644    
1645            /**
1646             * Returns the first journal article in the ordered set where resourcePrimKey = &#63;.
1647             *
1648             * @param resourcePrimKey the resource prim key
1649             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1650             * @return the first matching journal article
1651             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
1652             * @throws SystemException if a system exception occurred
1653             */
1654            @Override
1655            public JournalArticle findByResourcePrimKey_First(long resourcePrimKey,
1656                    OrderByComparator orderByComparator)
1657                    throws NoSuchArticleException, SystemException {
1658                    JournalArticle journalArticle = fetchByResourcePrimKey_First(resourcePrimKey,
1659                                    orderByComparator);
1660    
1661                    if (journalArticle != null) {
1662                            return journalArticle;
1663                    }
1664    
1665                    StringBundler msg = new StringBundler(4);
1666    
1667                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1668    
1669                    msg.append("resourcePrimKey=");
1670                    msg.append(resourcePrimKey);
1671    
1672                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1673    
1674                    throw new NoSuchArticleException(msg.toString());
1675            }
1676    
1677            /**
1678             * Returns the first journal article in the ordered set where resourcePrimKey = &#63;.
1679             *
1680             * @param resourcePrimKey the resource prim key
1681             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1682             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
1683             * @throws SystemException if a system exception occurred
1684             */
1685            @Override
1686            public JournalArticle fetchByResourcePrimKey_First(long resourcePrimKey,
1687                    OrderByComparator orderByComparator) throws SystemException {
1688                    List<JournalArticle> list = findByResourcePrimKey(resourcePrimKey, 0,
1689                                    1, orderByComparator);
1690    
1691                    if (!list.isEmpty()) {
1692                            return list.get(0);
1693                    }
1694    
1695                    return null;
1696            }
1697    
1698            /**
1699             * Returns the last journal article in the ordered set where resourcePrimKey = &#63;.
1700             *
1701             * @param resourcePrimKey the resource prim key
1702             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1703             * @return the last matching journal article
1704             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
1705             * @throws SystemException if a system exception occurred
1706             */
1707            @Override
1708            public JournalArticle findByResourcePrimKey_Last(long resourcePrimKey,
1709                    OrderByComparator orderByComparator)
1710                    throws NoSuchArticleException, SystemException {
1711                    JournalArticle journalArticle = fetchByResourcePrimKey_Last(resourcePrimKey,
1712                                    orderByComparator);
1713    
1714                    if (journalArticle != null) {
1715                            return journalArticle;
1716                    }
1717    
1718                    StringBundler msg = new StringBundler(4);
1719    
1720                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1721    
1722                    msg.append("resourcePrimKey=");
1723                    msg.append(resourcePrimKey);
1724    
1725                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1726    
1727                    throw new NoSuchArticleException(msg.toString());
1728            }
1729    
1730            /**
1731             * Returns the last journal article in the ordered set where resourcePrimKey = &#63;.
1732             *
1733             * @param resourcePrimKey the resource prim key
1734             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1735             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
1736             * @throws SystemException if a system exception occurred
1737             */
1738            @Override
1739            public JournalArticle fetchByResourcePrimKey_Last(long resourcePrimKey,
1740                    OrderByComparator orderByComparator) throws SystemException {
1741                    int count = countByResourcePrimKey(resourcePrimKey);
1742    
1743                    if (count == 0) {
1744                            return null;
1745                    }
1746    
1747                    List<JournalArticle> list = findByResourcePrimKey(resourcePrimKey,
1748                                    count - 1, count, orderByComparator);
1749    
1750                    if (!list.isEmpty()) {
1751                            return list.get(0);
1752                    }
1753    
1754                    return null;
1755            }
1756    
1757            /**
1758             * Returns the journal articles before and after the current journal article in the ordered set where resourcePrimKey = &#63;.
1759             *
1760             * @param id the primary key of the current journal article
1761             * @param resourcePrimKey the resource prim key
1762             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1763             * @return the previous, current, and next journal article
1764             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
1765             * @throws SystemException if a system exception occurred
1766             */
1767            @Override
1768            public JournalArticle[] findByResourcePrimKey_PrevAndNext(long id,
1769                    long resourcePrimKey, OrderByComparator orderByComparator)
1770                    throws NoSuchArticleException, SystemException {
1771                    JournalArticle journalArticle = findByPrimaryKey(id);
1772    
1773                    Session session = null;
1774    
1775                    try {
1776                            session = openSession();
1777    
1778                            JournalArticle[] array = new JournalArticleImpl[3];
1779    
1780                            array[0] = getByResourcePrimKey_PrevAndNext(session,
1781                                            journalArticle, resourcePrimKey, orderByComparator, true);
1782    
1783                            array[1] = journalArticle;
1784    
1785                            array[2] = getByResourcePrimKey_PrevAndNext(session,
1786                                            journalArticle, resourcePrimKey, orderByComparator, false);
1787    
1788                            return array;
1789                    }
1790                    catch (Exception e) {
1791                            throw processException(e);
1792                    }
1793                    finally {
1794                            closeSession(session);
1795                    }
1796            }
1797    
1798            protected JournalArticle getByResourcePrimKey_PrevAndNext(Session session,
1799                    JournalArticle journalArticle, long resourcePrimKey,
1800                    OrderByComparator orderByComparator, boolean previous) {
1801                    StringBundler query = null;
1802    
1803                    if (orderByComparator != null) {
1804                            query = new StringBundler(6 +
1805                                            (orderByComparator.getOrderByFields().length * 6));
1806                    }
1807                    else {
1808                            query = new StringBundler(3);
1809                    }
1810    
1811                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
1812    
1813                    query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1814    
1815                    if (orderByComparator != null) {
1816                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1817    
1818                            if (orderByConditionFields.length > 0) {
1819                                    query.append(WHERE_AND);
1820                            }
1821    
1822                            for (int i = 0; i < orderByConditionFields.length; i++) {
1823                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1824                                    query.append(orderByConditionFields[i]);
1825    
1826                                    if ((i + 1) < orderByConditionFields.length) {
1827                                            if (orderByComparator.isAscending() ^ previous) {
1828                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1829                                            }
1830                                            else {
1831                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1832                                            }
1833                                    }
1834                                    else {
1835                                            if (orderByComparator.isAscending() ^ previous) {
1836                                                    query.append(WHERE_GREATER_THAN);
1837                                            }
1838                                            else {
1839                                                    query.append(WHERE_LESSER_THAN);
1840                                            }
1841                                    }
1842                            }
1843    
1844                            query.append(ORDER_BY_CLAUSE);
1845    
1846                            String[] orderByFields = orderByComparator.getOrderByFields();
1847    
1848                            for (int i = 0; i < orderByFields.length; i++) {
1849                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1850                                    query.append(orderByFields[i]);
1851    
1852                                    if ((i + 1) < orderByFields.length) {
1853                                            if (orderByComparator.isAscending() ^ previous) {
1854                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1855                                            }
1856                                            else {
1857                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1858                                            }
1859                                    }
1860                                    else {
1861                                            if (orderByComparator.isAscending() ^ previous) {
1862                                                    query.append(ORDER_BY_ASC);
1863                                            }
1864                                            else {
1865                                                    query.append(ORDER_BY_DESC);
1866                                            }
1867                                    }
1868                            }
1869                    }
1870                    else {
1871                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
1872                    }
1873    
1874                    String sql = query.toString();
1875    
1876                    Query q = session.createQuery(sql);
1877    
1878                    q.setFirstResult(0);
1879                    q.setMaxResults(2);
1880    
1881                    QueryPos qPos = QueryPos.getInstance(q);
1882    
1883                    qPos.add(resourcePrimKey);
1884    
1885                    if (orderByComparator != null) {
1886                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
1887    
1888                            for (Object value : values) {
1889                                    qPos.add(value);
1890                            }
1891                    }
1892    
1893                    List<JournalArticle> list = q.list();
1894    
1895                    if (list.size() == 2) {
1896                            return list.get(1);
1897                    }
1898                    else {
1899                            return null;
1900                    }
1901            }
1902    
1903            /**
1904             * Removes all the journal articles where resourcePrimKey = &#63; from the database.
1905             *
1906             * @param resourcePrimKey the resource prim key
1907             * @throws SystemException if a system exception occurred
1908             */
1909            @Override
1910            public void removeByResourcePrimKey(long resourcePrimKey)
1911                    throws SystemException {
1912                    for (JournalArticle journalArticle : findByResourcePrimKey(
1913                                    resourcePrimKey, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1914                            remove(journalArticle);
1915                    }
1916            }
1917    
1918            /**
1919             * Returns the number of journal articles where resourcePrimKey = &#63;.
1920             *
1921             * @param resourcePrimKey the resource prim key
1922             * @return the number of matching journal articles
1923             * @throws SystemException if a system exception occurred
1924             */
1925            @Override
1926            public int countByResourcePrimKey(long resourcePrimKey)
1927                    throws SystemException {
1928                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY;
1929    
1930                    Object[] finderArgs = new Object[] { resourcePrimKey };
1931    
1932                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1933                                    this);
1934    
1935                    if (count == null) {
1936                            StringBundler query = new StringBundler(2);
1937    
1938                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
1939    
1940                            query.append(_FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2);
1941    
1942                            String sql = query.toString();
1943    
1944                            Session session = null;
1945    
1946                            try {
1947                                    session = openSession();
1948    
1949                                    Query q = session.createQuery(sql);
1950    
1951                                    QueryPos qPos = QueryPos.getInstance(q);
1952    
1953                                    qPos.add(resourcePrimKey);
1954    
1955                                    count = (Long)q.uniqueResult();
1956    
1957                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1958                            }
1959                            catch (Exception e) {
1960                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1961    
1962                                    throw processException(e);
1963                            }
1964                            finally {
1965                                    closeSession(session);
1966                            }
1967                    }
1968    
1969                    return count.intValue();
1970            }
1971    
1972            private static final String _FINDER_COLUMN_RESOURCEPRIMKEY_RESOURCEPRIMKEY_2 =
1973                    "journalArticle.resourcePrimKey = ?";
1974            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1975                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
1976                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1977                            "findByGroupId",
1978                            new String[] {
1979                                    Long.class.getName(),
1980                                    
1981                            Integer.class.getName(), Integer.class.getName(),
1982                                    OrderByComparator.class.getName()
1983                            });
1984            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1985                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1986                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
1987                            JournalArticleImpl.class,
1988                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1989                            new String[] { Long.class.getName() },
1990                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
1991                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
1992                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
1993            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
1994                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1995                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1996                            new String[] { Long.class.getName() });
1997    
1998            /**
1999             * Returns all the journal articles where groupId = &#63;.
2000             *
2001             * @param groupId the group ID
2002             * @return the matching journal articles
2003             * @throws SystemException if a system exception occurred
2004             */
2005            @Override
2006            public List<JournalArticle> findByGroupId(long groupId)
2007                    throws SystemException {
2008                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2009            }
2010    
2011            /**
2012             * Returns a range of all the journal articles where groupId = &#63;.
2013             *
2014             * <p>
2015             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
2016             * </p>
2017             *
2018             * @param groupId the group ID
2019             * @param start the lower bound of the range of journal articles
2020             * @param end the upper bound of the range of journal articles (not inclusive)
2021             * @return the range of matching journal articles
2022             * @throws SystemException if a system exception occurred
2023             */
2024            @Override
2025            public List<JournalArticle> findByGroupId(long groupId, int start, int end)
2026                    throws SystemException {
2027                    return findByGroupId(groupId, start, end, null);
2028            }
2029    
2030            /**
2031             * Returns an ordered range of all the journal articles where groupId = &#63;.
2032             *
2033             * <p>
2034             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
2035             * </p>
2036             *
2037             * @param groupId the group ID
2038             * @param start the lower bound of the range of journal articles
2039             * @param end the upper bound of the range of journal articles (not inclusive)
2040             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2041             * @return the ordered range of matching journal articles
2042             * @throws SystemException if a system exception occurred
2043             */
2044            @Override
2045            public List<JournalArticle> findByGroupId(long groupId, int start, int end,
2046                    OrderByComparator orderByComparator) throws SystemException {
2047                    boolean pagination = true;
2048                    FinderPath finderPath = null;
2049                    Object[] finderArgs = null;
2050    
2051                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2052                                    (orderByComparator == null)) {
2053                            pagination = false;
2054                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
2055                            finderArgs = new Object[] { groupId };
2056                    }
2057                    else {
2058                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
2059                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
2060                    }
2061    
2062                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
2063                                    finderArgs, this);
2064    
2065                    if ((list != null) && !list.isEmpty()) {
2066                            for (JournalArticle journalArticle : list) {
2067                                    if ((groupId != journalArticle.getGroupId())) {
2068                                            list = null;
2069    
2070                                            break;
2071                                    }
2072                            }
2073                    }
2074    
2075                    if (list == null) {
2076                            StringBundler query = null;
2077    
2078                            if (orderByComparator != null) {
2079                                    query = new StringBundler(3 +
2080                                                    (orderByComparator.getOrderByFields().length * 3));
2081                            }
2082                            else {
2083                                    query = new StringBundler(3);
2084                            }
2085    
2086                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
2087    
2088                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2089    
2090                            if (orderByComparator != null) {
2091                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2092                                            orderByComparator);
2093                            }
2094                            else
2095                             if (pagination) {
2096                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2097                            }
2098    
2099                            String sql = query.toString();
2100    
2101                            Session session = null;
2102    
2103                            try {
2104                                    session = openSession();
2105    
2106                                    Query q = session.createQuery(sql);
2107    
2108                                    QueryPos qPos = QueryPos.getInstance(q);
2109    
2110                                    qPos.add(groupId);
2111    
2112                                    if (!pagination) {
2113                                            list = (List<JournalArticle>)QueryUtil.list(q,
2114                                                            getDialect(), start, end, false);
2115    
2116                                            Collections.sort(list);
2117    
2118                                            list = new UnmodifiableList<JournalArticle>(list);
2119                                    }
2120                                    else {
2121                                            list = (List<JournalArticle>)QueryUtil.list(q,
2122                                                            getDialect(), start, end);
2123                                    }
2124    
2125                                    cacheResult(list);
2126    
2127                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2128                            }
2129                            catch (Exception e) {
2130                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2131    
2132                                    throw processException(e);
2133                            }
2134                            finally {
2135                                    closeSession(session);
2136                            }
2137                    }
2138    
2139                    return list;
2140            }
2141    
2142            /**
2143             * Returns the first journal article in the ordered set where groupId = &#63;.
2144             *
2145             * @param groupId the group ID
2146             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2147             * @return the first matching journal article
2148             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
2149             * @throws SystemException if a system exception occurred
2150             */
2151            @Override
2152            public JournalArticle findByGroupId_First(long groupId,
2153                    OrderByComparator orderByComparator)
2154                    throws NoSuchArticleException, SystemException {
2155                    JournalArticle journalArticle = fetchByGroupId_First(groupId,
2156                                    orderByComparator);
2157    
2158                    if (journalArticle != null) {
2159                            return journalArticle;
2160                    }
2161    
2162                    StringBundler msg = new StringBundler(4);
2163    
2164                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2165    
2166                    msg.append("groupId=");
2167                    msg.append(groupId);
2168    
2169                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2170    
2171                    throw new NoSuchArticleException(msg.toString());
2172            }
2173    
2174            /**
2175             * Returns the first journal article in the ordered set where groupId = &#63;.
2176             *
2177             * @param groupId the group ID
2178             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2179             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
2180             * @throws SystemException if a system exception occurred
2181             */
2182            @Override
2183            public JournalArticle fetchByGroupId_First(long groupId,
2184                    OrderByComparator orderByComparator) throws SystemException {
2185                    List<JournalArticle> list = findByGroupId(groupId, 0, 1,
2186                                    orderByComparator);
2187    
2188                    if (!list.isEmpty()) {
2189                            return list.get(0);
2190                    }
2191    
2192                    return null;
2193            }
2194    
2195            /**
2196             * Returns the last journal article in the ordered set where groupId = &#63;.
2197             *
2198             * @param groupId the group ID
2199             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2200             * @return the last matching journal article
2201             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
2202             * @throws SystemException if a system exception occurred
2203             */
2204            @Override
2205            public JournalArticle findByGroupId_Last(long groupId,
2206                    OrderByComparator orderByComparator)
2207                    throws NoSuchArticleException, SystemException {
2208                    JournalArticle journalArticle = fetchByGroupId_Last(groupId,
2209                                    orderByComparator);
2210    
2211                    if (journalArticle != null) {
2212                            return journalArticle;
2213                    }
2214    
2215                    StringBundler msg = new StringBundler(4);
2216    
2217                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2218    
2219                    msg.append("groupId=");
2220                    msg.append(groupId);
2221    
2222                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2223    
2224                    throw new NoSuchArticleException(msg.toString());
2225            }
2226    
2227            /**
2228             * Returns the last journal article in the ordered set where groupId = &#63;.
2229             *
2230             * @param groupId the group ID
2231             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2232             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
2233             * @throws SystemException if a system exception occurred
2234             */
2235            @Override
2236            public JournalArticle fetchByGroupId_Last(long groupId,
2237                    OrderByComparator orderByComparator) throws SystemException {
2238                    int count = countByGroupId(groupId);
2239    
2240                    if (count == 0) {
2241                            return null;
2242                    }
2243    
2244                    List<JournalArticle> list = findByGroupId(groupId, count - 1, count,
2245                                    orderByComparator);
2246    
2247                    if (!list.isEmpty()) {
2248                            return list.get(0);
2249                    }
2250    
2251                    return null;
2252            }
2253    
2254            /**
2255             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63;.
2256             *
2257             * @param id the primary key of the current journal article
2258             * @param groupId the group ID
2259             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2260             * @return the previous, current, and next journal article
2261             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
2262             * @throws SystemException if a system exception occurred
2263             */
2264            @Override
2265            public JournalArticle[] findByGroupId_PrevAndNext(long id, long groupId,
2266                    OrderByComparator orderByComparator)
2267                    throws NoSuchArticleException, SystemException {
2268                    JournalArticle journalArticle = findByPrimaryKey(id);
2269    
2270                    Session session = null;
2271    
2272                    try {
2273                            session = openSession();
2274    
2275                            JournalArticle[] array = new JournalArticleImpl[3];
2276    
2277                            array[0] = getByGroupId_PrevAndNext(session, journalArticle,
2278                                            groupId, orderByComparator, true);
2279    
2280                            array[1] = journalArticle;
2281    
2282                            array[2] = getByGroupId_PrevAndNext(session, journalArticle,
2283                                            groupId, orderByComparator, false);
2284    
2285                            return array;
2286                    }
2287                    catch (Exception e) {
2288                            throw processException(e);
2289                    }
2290                    finally {
2291                            closeSession(session);
2292                    }
2293            }
2294    
2295            protected JournalArticle getByGroupId_PrevAndNext(Session session,
2296                    JournalArticle journalArticle, long groupId,
2297                    OrderByComparator orderByComparator, boolean previous) {
2298                    StringBundler query = null;
2299    
2300                    if (orderByComparator != null) {
2301                            query = new StringBundler(6 +
2302                                            (orderByComparator.getOrderByFields().length * 6));
2303                    }
2304                    else {
2305                            query = new StringBundler(3);
2306                    }
2307    
2308                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
2309    
2310                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2311    
2312                    if (orderByComparator != null) {
2313                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2314    
2315                            if (orderByConditionFields.length > 0) {
2316                                    query.append(WHERE_AND);
2317                            }
2318    
2319                            for (int i = 0; i < orderByConditionFields.length; i++) {
2320                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2321                                    query.append(orderByConditionFields[i]);
2322    
2323                                    if ((i + 1) < orderByConditionFields.length) {
2324                                            if (orderByComparator.isAscending() ^ previous) {
2325                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2326                                            }
2327                                            else {
2328                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2329                                            }
2330                                    }
2331                                    else {
2332                                            if (orderByComparator.isAscending() ^ previous) {
2333                                                    query.append(WHERE_GREATER_THAN);
2334                                            }
2335                                            else {
2336                                                    query.append(WHERE_LESSER_THAN);
2337                                            }
2338                                    }
2339                            }
2340    
2341                            query.append(ORDER_BY_CLAUSE);
2342    
2343                            String[] orderByFields = orderByComparator.getOrderByFields();
2344    
2345                            for (int i = 0; i < orderByFields.length; i++) {
2346                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2347                                    query.append(orderByFields[i]);
2348    
2349                                    if ((i + 1) < orderByFields.length) {
2350                                            if (orderByComparator.isAscending() ^ previous) {
2351                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2352                                            }
2353                                            else {
2354                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2355                                            }
2356                                    }
2357                                    else {
2358                                            if (orderByComparator.isAscending() ^ previous) {
2359                                                    query.append(ORDER_BY_ASC);
2360                                            }
2361                                            else {
2362                                                    query.append(ORDER_BY_DESC);
2363                                            }
2364                                    }
2365                            }
2366                    }
2367                    else {
2368                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2369                    }
2370    
2371                    String sql = query.toString();
2372    
2373                    Query q = session.createQuery(sql);
2374    
2375                    q.setFirstResult(0);
2376                    q.setMaxResults(2);
2377    
2378                    QueryPos qPos = QueryPos.getInstance(q);
2379    
2380                    qPos.add(groupId);
2381    
2382                    if (orderByComparator != null) {
2383                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
2384    
2385                            for (Object value : values) {
2386                                    qPos.add(value);
2387                            }
2388                    }
2389    
2390                    List<JournalArticle> list = q.list();
2391    
2392                    if (list.size() == 2) {
2393                            return list.get(1);
2394                    }
2395                    else {
2396                            return null;
2397                    }
2398            }
2399    
2400            /**
2401             * Returns all the journal articles that the user has permission to view where groupId = &#63;.
2402             *
2403             * @param groupId the group ID
2404             * @return the matching journal articles that the user has permission to view
2405             * @throws SystemException if a system exception occurred
2406             */
2407            @Override
2408            public List<JournalArticle> filterFindByGroupId(long groupId)
2409                    throws SystemException {
2410                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2411                            QueryUtil.ALL_POS, null);
2412            }
2413    
2414            /**
2415             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63;.
2416             *
2417             * <p>
2418             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
2419             * </p>
2420             *
2421             * @param groupId the group ID
2422             * @param start the lower bound of the range of journal articles
2423             * @param end the upper bound of the range of journal articles (not inclusive)
2424             * @return the range of matching journal articles that the user has permission to view
2425             * @throws SystemException if a system exception occurred
2426             */
2427            @Override
2428            public List<JournalArticle> filterFindByGroupId(long groupId, int start,
2429                    int end) throws SystemException {
2430                    return filterFindByGroupId(groupId, start, end, null);
2431            }
2432    
2433            /**
2434             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63;.
2435             *
2436             * <p>
2437             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
2438             * </p>
2439             *
2440             * @param groupId the group ID
2441             * @param start the lower bound of the range of journal articles
2442             * @param end the upper bound of the range of journal articles (not inclusive)
2443             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2444             * @return the ordered range of matching journal articles that the user has permission to view
2445             * @throws SystemException if a system exception occurred
2446             */
2447            @Override
2448            public List<JournalArticle> filterFindByGroupId(long groupId, int start,
2449                    int end, OrderByComparator orderByComparator) throws SystemException {
2450                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2451                            return findByGroupId(groupId, start, end, orderByComparator);
2452                    }
2453    
2454                    StringBundler query = null;
2455    
2456                    if (orderByComparator != null) {
2457                            query = new StringBundler(3 +
2458                                            (orderByComparator.getOrderByFields().length * 3));
2459                    }
2460                    else {
2461                            query = new StringBundler(3);
2462                    }
2463    
2464                    if (getDB().isSupportsInlineDistinct()) {
2465                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
2466                    }
2467                    else {
2468                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
2469                    }
2470    
2471                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2472    
2473                    if (!getDB().isSupportsInlineDistinct()) {
2474                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
2475                    }
2476    
2477                    if (orderByComparator != null) {
2478                            if (getDB().isSupportsInlineDistinct()) {
2479                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2480                                            orderByComparator, true);
2481                            }
2482                            else {
2483                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2484                                            orderByComparator, true);
2485                            }
2486                    }
2487                    else {
2488                            if (getDB().isSupportsInlineDistinct()) {
2489                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2490                            }
2491                            else {
2492                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
2493                            }
2494                    }
2495    
2496                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2497                                    JournalArticle.class.getName(),
2498                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2499    
2500                    Session session = null;
2501    
2502                    try {
2503                            session = openSession();
2504    
2505                            SQLQuery q = session.createSQLQuery(sql);
2506    
2507                            if (getDB().isSupportsInlineDistinct()) {
2508                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
2509                            }
2510                            else {
2511                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
2512                            }
2513    
2514                            QueryPos qPos = QueryPos.getInstance(q);
2515    
2516                            qPos.add(groupId);
2517    
2518                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
2519                                    end);
2520                    }
2521                    catch (Exception e) {
2522                            throw processException(e);
2523                    }
2524                    finally {
2525                            closeSession(session);
2526                    }
2527            }
2528    
2529            /**
2530             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63;.
2531             *
2532             * @param id the primary key of the current journal article
2533             * @param groupId the group ID
2534             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2535             * @return the previous, current, and next journal article
2536             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
2537             * @throws SystemException if a system exception occurred
2538             */
2539            @Override
2540            public JournalArticle[] filterFindByGroupId_PrevAndNext(long id,
2541                    long groupId, OrderByComparator orderByComparator)
2542                    throws NoSuchArticleException, SystemException {
2543                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2544                            return findByGroupId_PrevAndNext(id, groupId, orderByComparator);
2545                    }
2546    
2547                    JournalArticle journalArticle = findByPrimaryKey(id);
2548    
2549                    Session session = null;
2550    
2551                    try {
2552                            session = openSession();
2553    
2554                            JournalArticle[] array = new JournalArticleImpl[3];
2555    
2556                            array[0] = filterGetByGroupId_PrevAndNext(session, journalArticle,
2557                                            groupId, orderByComparator, true);
2558    
2559                            array[1] = journalArticle;
2560    
2561                            array[2] = filterGetByGroupId_PrevAndNext(session, journalArticle,
2562                                            groupId, orderByComparator, false);
2563    
2564                            return array;
2565                    }
2566                    catch (Exception e) {
2567                            throw processException(e);
2568                    }
2569                    finally {
2570                            closeSession(session);
2571                    }
2572            }
2573    
2574            protected JournalArticle filterGetByGroupId_PrevAndNext(Session session,
2575                    JournalArticle journalArticle, long groupId,
2576                    OrderByComparator orderByComparator, boolean previous) {
2577                    StringBundler query = null;
2578    
2579                    if (orderByComparator != null) {
2580                            query = new StringBundler(6 +
2581                                            (orderByComparator.getOrderByFields().length * 6));
2582                    }
2583                    else {
2584                            query = new StringBundler(3);
2585                    }
2586    
2587                    if (getDB().isSupportsInlineDistinct()) {
2588                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
2589                    }
2590                    else {
2591                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
2592                    }
2593    
2594                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2595    
2596                    if (!getDB().isSupportsInlineDistinct()) {
2597                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
2598                    }
2599    
2600                    if (orderByComparator != null) {
2601                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2602    
2603                            if (orderByConditionFields.length > 0) {
2604                                    query.append(WHERE_AND);
2605                            }
2606    
2607                            for (int i = 0; i < orderByConditionFields.length; i++) {
2608                                    if (getDB().isSupportsInlineDistinct()) {
2609                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2610                                    }
2611                                    else {
2612                                            query.append(_ORDER_BY_ENTITY_TABLE);
2613                                    }
2614    
2615                                    query.append(orderByConditionFields[i]);
2616    
2617                                    if ((i + 1) < orderByConditionFields.length) {
2618                                            if (orderByComparator.isAscending() ^ previous) {
2619                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2620                                            }
2621                                            else {
2622                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2623                                            }
2624                                    }
2625                                    else {
2626                                            if (orderByComparator.isAscending() ^ previous) {
2627                                                    query.append(WHERE_GREATER_THAN);
2628                                            }
2629                                            else {
2630                                                    query.append(WHERE_LESSER_THAN);
2631                                            }
2632                                    }
2633                            }
2634    
2635                            query.append(ORDER_BY_CLAUSE);
2636    
2637                            String[] orderByFields = orderByComparator.getOrderByFields();
2638    
2639                            for (int i = 0; i < orderByFields.length; i++) {
2640                                    if (getDB().isSupportsInlineDistinct()) {
2641                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2642                                    }
2643                                    else {
2644                                            query.append(_ORDER_BY_ENTITY_TABLE);
2645                                    }
2646    
2647                                    query.append(orderByFields[i]);
2648    
2649                                    if ((i + 1) < orderByFields.length) {
2650                                            if (orderByComparator.isAscending() ^ previous) {
2651                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2652                                            }
2653                                            else {
2654                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2655                                            }
2656                                    }
2657                                    else {
2658                                            if (orderByComparator.isAscending() ^ previous) {
2659                                                    query.append(ORDER_BY_ASC);
2660                                            }
2661                                            else {
2662                                                    query.append(ORDER_BY_DESC);
2663                                            }
2664                                    }
2665                            }
2666                    }
2667                    else {
2668                            if (getDB().isSupportsInlineDistinct()) {
2669                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2670                            }
2671                            else {
2672                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
2673                            }
2674                    }
2675    
2676                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2677                                    JournalArticle.class.getName(),
2678                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2679    
2680                    SQLQuery q = session.createSQLQuery(sql);
2681    
2682                    q.setFirstResult(0);
2683                    q.setMaxResults(2);
2684    
2685                    if (getDB().isSupportsInlineDistinct()) {
2686                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
2687                    }
2688                    else {
2689                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
2690                    }
2691    
2692                    QueryPos qPos = QueryPos.getInstance(q);
2693    
2694                    qPos.add(groupId);
2695    
2696                    if (orderByComparator != null) {
2697                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
2698    
2699                            for (Object value : values) {
2700                                    qPos.add(value);
2701                            }
2702                    }
2703    
2704                    List<JournalArticle> list = q.list();
2705    
2706                    if (list.size() == 2) {
2707                            return list.get(1);
2708                    }
2709                    else {
2710                            return null;
2711                    }
2712            }
2713    
2714            /**
2715             * Removes all the journal articles where groupId = &#63; from the database.
2716             *
2717             * @param groupId the group ID
2718             * @throws SystemException if a system exception occurred
2719             */
2720            @Override
2721            public void removeByGroupId(long groupId) throws SystemException {
2722                    for (JournalArticle journalArticle : findByGroupId(groupId,
2723                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2724                            remove(journalArticle);
2725                    }
2726            }
2727    
2728            /**
2729             * Returns the number of journal articles where groupId = &#63;.
2730             *
2731             * @param groupId the group ID
2732             * @return the number of matching journal articles
2733             * @throws SystemException if a system exception occurred
2734             */
2735            @Override
2736            public int countByGroupId(long groupId) throws SystemException {
2737                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2738    
2739                    Object[] finderArgs = new Object[] { groupId };
2740    
2741                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2742                                    this);
2743    
2744                    if (count == null) {
2745                            StringBundler query = new StringBundler(2);
2746    
2747                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
2748    
2749                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2750    
2751                            String sql = query.toString();
2752    
2753                            Session session = null;
2754    
2755                            try {
2756                                    session = openSession();
2757    
2758                                    Query q = session.createQuery(sql);
2759    
2760                                    QueryPos qPos = QueryPos.getInstance(q);
2761    
2762                                    qPos.add(groupId);
2763    
2764                                    count = (Long)q.uniqueResult();
2765    
2766                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2767                            }
2768                            catch (Exception e) {
2769                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2770    
2771                                    throw processException(e);
2772                            }
2773                            finally {
2774                                    closeSession(session);
2775                            }
2776                    }
2777    
2778                    return count.intValue();
2779            }
2780    
2781            /**
2782             * Returns the number of journal articles that the user has permission to view where groupId = &#63;.
2783             *
2784             * @param groupId the group ID
2785             * @return the number of matching journal articles that the user has permission to view
2786             * @throws SystemException if a system exception occurred
2787             */
2788            @Override
2789            public int filterCountByGroupId(long groupId) throws SystemException {
2790                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2791                            return countByGroupId(groupId);
2792                    }
2793    
2794                    StringBundler query = new StringBundler(2);
2795    
2796                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
2797    
2798                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2799    
2800                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2801                                    JournalArticle.class.getName(),
2802                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2803    
2804                    Session session = null;
2805    
2806                    try {
2807                            session = openSession();
2808    
2809                            SQLQuery q = session.createSQLQuery(sql);
2810    
2811                            q.addScalar(COUNT_COLUMN_NAME,
2812                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2813    
2814                            QueryPos qPos = QueryPos.getInstance(q);
2815    
2816                            qPos.add(groupId);
2817    
2818                            Long count = (Long)q.uniqueResult();
2819    
2820                            return count.intValue();
2821                    }
2822                    catch (Exception e) {
2823                            throw processException(e);
2824                    }
2825                    finally {
2826                            closeSession(session);
2827                    }
2828            }
2829    
2830            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "journalArticle.groupId = ?";
2831            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2832                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
2833                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
2834                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2835                            "findByCompanyId",
2836                            new String[] {
2837                                    Long.class.getName(),
2838                                    
2839                            Integer.class.getName(), Integer.class.getName(),
2840                                    OrderByComparator.class.getName()
2841                            });
2842            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2843                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
2844                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
2845                            JournalArticleImpl.class,
2846                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2847                            new String[] { Long.class.getName() },
2848                            JournalArticleModelImpl.COMPANYID_COLUMN_BITMASK |
2849                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
2850                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
2851            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
2852                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2853                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2854                            new String[] { Long.class.getName() });
2855    
2856            /**
2857             * Returns all the journal articles where companyId = &#63;.
2858             *
2859             * @param companyId the company ID
2860             * @return the matching journal articles
2861             * @throws SystemException if a system exception occurred
2862             */
2863            @Override
2864            public List<JournalArticle> findByCompanyId(long companyId)
2865                    throws SystemException {
2866                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2867                            null);
2868            }
2869    
2870            /**
2871             * Returns a range of all the journal articles where companyId = &#63;.
2872             *
2873             * <p>
2874             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
2875             * </p>
2876             *
2877             * @param companyId the company ID
2878             * @param start the lower bound of the range of journal articles
2879             * @param end the upper bound of the range of journal articles (not inclusive)
2880             * @return the range of matching journal articles
2881             * @throws SystemException if a system exception occurred
2882             */
2883            @Override
2884            public List<JournalArticle> findByCompanyId(long companyId, int start,
2885                    int end) throws SystemException {
2886                    return findByCompanyId(companyId, start, end, null);
2887            }
2888    
2889            /**
2890             * Returns an ordered range of all the journal articles where companyId = &#63;.
2891             *
2892             * <p>
2893             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
2894             * </p>
2895             *
2896             * @param companyId the company ID
2897             * @param start the lower bound of the range of journal articles
2898             * @param end the upper bound of the range of journal articles (not inclusive)
2899             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2900             * @return the ordered range of matching journal articles
2901             * @throws SystemException if a system exception occurred
2902             */
2903            @Override
2904            public List<JournalArticle> findByCompanyId(long companyId, int start,
2905                    int end, OrderByComparator orderByComparator) throws SystemException {
2906                    boolean pagination = true;
2907                    FinderPath finderPath = null;
2908                    Object[] finderArgs = null;
2909    
2910                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2911                                    (orderByComparator == null)) {
2912                            pagination = false;
2913                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2914                            finderArgs = new Object[] { companyId };
2915                    }
2916                    else {
2917                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2918                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2919                    }
2920    
2921                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
2922                                    finderArgs, this);
2923    
2924                    if ((list != null) && !list.isEmpty()) {
2925                            for (JournalArticle journalArticle : list) {
2926                                    if ((companyId != journalArticle.getCompanyId())) {
2927                                            list = null;
2928    
2929                                            break;
2930                                    }
2931                            }
2932                    }
2933    
2934                    if (list == null) {
2935                            StringBundler query = null;
2936    
2937                            if (orderByComparator != null) {
2938                                    query = new StringBundler(3 +
2939                                                    (orderByComparator.getOrderByFields().length * 3));
2940                            }
2941                            else {
2942                                    query = new StringBundler(3);
2943                            }
2944    
2945                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
2946    
2947                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2948    
2949                            if (orderByComparator != null) {
2950                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2951                                            orderByComparator);
2952                            }
2953                            else
2954                             if (pagination) {
2955                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
2956                            }
2957    
2958                            String sql = query.toString();
2959    
2960                            Session session = null;
2961    
2962                            try {
2963                                    session = openSession();
2964    
2965                                    Query q = session.createQuery(sql);
2966    
2967                                    QueryPos qPos = QueryPos.getInstance(q);
2968    
2969                                    qPos.add(companyId);
2970    
2971                                    if (!pagination) {
2972                                            list = (List<JournalArticle>)QueryUtil.list(q,
2973                                                            getDialect(), start, end, false);
2974    
2975                                            Collections.sort(list);
2976    
2977                                            list = new UnmodifiableList<JournalArticle>(list);
2978                                    }
2979                                    else {
2980                                            list = (List<JournalArticle>)QueryUtil.list(q,
2981                                                            getDialect(), start, end);
2982                                    }
2983    
2984                                    cacheResult(list);
2985    
2986                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2987                            }
2988                            catch (Exception e) {
2989                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2990    
2991                                    throw processException(e);
2992                            }
2993                            finally {
2994                                    closeSession(session);
2995                            }
2996                    }
2997    
2998                    return list;
2999            }
3000    
3001            /**
3002             * Returns the first journal article in the ordered set where companyId = &#63;.
3003             *
3004             * @param companyId the company ID
3005             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3006             * @return the first matching journal article
3007             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
3008             * @throws SystemException if a system exception occurred
3009             */
3010            @Override
3011            public JournalArticle findByCompanyId_First(long companyId,
3012                    OrderByComparator orderByComparator)
3013                    throws NoSuchArticleException, SystemException {
3014                    JournalArticle journalArticle = fetchByCompanyId_First(companyId,
3015                                    orderByComparator);
3016    
3017                    if (journalArticle != null) {
3018                            return journalArticle;
3019                    }
3020    
3021                    StringBundler msg = new StringBundler(4);
3022    
3023                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3024    
3025                    msg.append("companyId=");
3026                    msg.append(companyId);
3027    
3028                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3029    
3030                    throw new NoSuchArticleException(msg.toString());
3031            }
3032    
3033            /**
3034             * Returns the first journal article in the ordered set where companyId = &#63;.
3035             *
3036             * @param companyId the company ID
3037             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3038             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
3039             * @throws SystemException if a system exception occurred
3040             */
3041            @Override
3042            public JournalArticle fetchByCompanyId_First(long companyId,
3043                    OrderByComparator orderByComparator) throws SystemException {
3044                    List<JournalArticle> list = findByCompanyId(companyId, 0, 1,
3045                                    orderByComparator);
3046    
3047                    if (!list.isEmpty()) {
3048                            return list.get(0);
3049                    }
3050    
3051                    return null;
3052            }
3053    
3054            /**
3055             * Returns the last journal article in the ordered set where companyId = &#63;.
3056             *
3057             * @param companyId the company ID
3058             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3059             * @return the last matching journal article
3060             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
3061             * @throws SystemException if a system exception occurred
3062             */
3063            @Override
3064            public JournalArticle findByCompanyId_Last(long companyId,
3065                    OrderByComparator orderByComparator)
3066                    throws NoSuchArticleException, SystemException {
3067                    JournalArticle journalArticle = fetchByCompanyId_Last(companyId,
3068                                    orderByComparator);
3069    
3070                    if (journalArticle != null) {
3071                            return journalArticle;
3072                    }
3073    
3074                    StringBundler msg = new StringBundler(4);
3075    
3076                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3077    
3078                    msg.append("companyId=");
3079                    msg.append(companyId);
3080    
3081                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3082    
3083                    throw new NoSuchArticleException(msg.toString());
3084            }
3085    
3086            /**
3087             * Returns the last journal article in the ordered set where companyId = &#63;.
3088             *
3089             * @param companyId the company ID
3090             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3091             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
3092             * @throws SystemException if a system exception occurred
3093             */
3094            @Override
3095            public JournalArticle fetchByCompanyId_Last(long companyId,
3096                    OrderByComparator orderByComparator) throws SystemException {
3097                    int count = countByCompanyId(companyId);
3098    
3099                    if (count == 0) {
3100                            return null;
3101                    }
3102    
3103                    List<JournalArticle> list = findByCompanyId(companyId, count - 1,
3104                                    count, orderByComparator);
3105    
3106                    if (!list.isEmpty()) {
3107                            return list.get(0);
3108                    }
3109    
3110                    return null;
3111            }
3112    
3113            /**
3114             * Returns the journal articles before and after the current journal article in the ordered set where companyId = &#63;.
3115             *
3116             * @param id the primary key of the current journal article
3117             * @param companyId the company ID
3118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3119             * @return the previous, current, and next journal article
3120             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
3121             * @throws SystemException if a system exception occurred
3122             */
3123            @Override
3124            public JournalArticle[] findByCompanyId_PrevAndNext(long id,
3125                    long companyId, OrderByComparator orderByComparator)
3126                    throws NoSuchArticleException, SystemException {
3127                    JournalArticle journalArticle = findByPrimaryKey(id);
3128    
3129                    Session session = null;
3130    
3131                    try {
3132                            session = openSession();
3133    
3134                            JournalArticle[] array = new JournalArticleImpl[3];
3135    
3136                            array[0] = getByCompanyId_PrevAndNext(session, journalArticle,
3137                                            companyId, orderByComparator, true);
3138    
3139                            array[1] = journalArticle;
3140    
3141                            array[2] = getByCompanyId_PrevAndNext(session, journalArticle,
3142                                            companyId, orderByComparator, false);
3143    
3144                            return array;
3145                    }
3146                    catch (Exception e) {
3147                            throw processException(e);
3148                    }
3149                    finally {
3150                            closeSession(session);
3151                    }
3152            }
3153    
3154            protected JournalArticle getByCompanyId_PrevAndNext(Session session,
3155                    JournalArticle journalArticle, long companyId,
3156                    OrderByComparator orderByComparator, boolean previous) {
3157                    StringBundler query = null;
3158    
3159                    if (orderByComparator != null) {
3160                            query = new StringBundler(6 +
3161                                            (orderByComparator.getOrderByFields().length * 6));
3162                    }
3163                    else {
3164                            query = new StringBundler(3);
3165                    }
3166    
3167                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
3168    
3169                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3170    
3171                    if (orderByComparator != null) {
3172                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3173    
3174                            if (orderByConditionFields.length > 0) {
3175                                    query.append(WHERE_AND);
3176                            }
3177    
3178                            for (int i = 0; i < orderByConditionFields.length; i++) {
3179                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3180                                    query.append(orderByConditionFields[i]);
3181    
3182                                    if ((i + 1) < orderByConditionFields.length) {
3183                                            if (orderByComparator.isAscending() ^ previous) {
3184                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3185                                            }
3186                                            else {
3187                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3188                                            }
3189                                    }
3190                                    else {
3191                                            if (orderByComparator.isAscending() ^ previous) {
3192                                                    query.append(WHERE_GREATER_THAN);
3193                                            }
3194                                            else {
3195                                                    query.append(WHERE_LESSER_THAN);
3196                                            }
3197                                    }
3198                            }
3199    
3200                            query.append(ORDER_BY_CLAUSE);
3201    
3202                            String[] orderByFields = orderByComparator.getOrderByFields();
3203    
3204                            for (int i = 0; i < orderByFields.length; i++) {
3205                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3206                                    query.append(orderByFields[i]);
3207    
3208                                    if ((i + 1) < orderByFields.length) {
3209                                            if (orderByComparator.isAscending() ^ previous) {
3210                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3211                                            }
3212                                            else {
3213                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3214                                            }
3215                                    }
3216                                    else {
3217                                            if (orderByComparator.isAscending() ^ previous) {
3218                                                    query.append(ORDER_BY_ASC);
3219                                            }
3220                                            else {
3221                                                    query.append(ORDER_BY_DESC);
3222                                            }
3223                                    }
3224                            }
3225                    }
3226                    else {
3227                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
3228                    }
3229    
3230                    String sql = query.toString();
3231    
3232                    Query q = session.createQuery(sql);
3233    
3234                    q.setFirstResult(0);
3235                    q.setMaxResults(2);
3236    
3237                    QueryPos qPos = QueryPos.getInstance(q);
3238    
3239                    qPos.add(companyId);
3240    
3241                    if (orderByComparator != null) {
3242                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
3243    
3244                            for (Object value : values) {
3245                                    qPos.add(value);
3246                            }
3247                    }
3248    
3249                    List<JournalArticle> list = q.list();
3250    
3251                    if (list.size() == 2) {
3252                            return list.get(1);
3253                    }
3254                    else {
3255                            return null;
3256                    }
3257            }
3258    
3259            /**
3260             * Removes all the journal articles where companyId = &#63; from the database.
3261             *
3262             * @param companyId the company ID
3263             * @throws SystemException if a system exception occurred
3264             */
3265            @Override
3266            public void removeByCompanyId(long companyId) throws SystemException {
3267                    for (JournalArticle journalArticle : findByCompanyId(companyId,
3268                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3269                            remove(journalArticle);
3270                    }
3271            }
3272    
3273            /**
3274             * Returns the number of journal articles where companyId = &#63;.
3275             *
3276             * @param companyId the company ID
3277             * @return the number of matching journal articles
3278             * @throws SystemException if a system exception occurred
3279             */
3280            @Override
3281            public int countByCompanyId(long companyId) throws SystemException {
3282                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
3283    
3284                    Object[] finderArgs = new Object[] { companyId };
3285    
3286                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3287                                    this);
3288    
3289                    if (count == null) {
3290                            StringBundler query = new StringBundler(2);
3291    
3292                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
3293    
3294                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3295    
3296                            String sql = query.toString();
3297    
3298                            Session session = null;
3299    
3300                            try {
3301                                    session = openSession();
3302    
3303                                    Query q = session.createQuery(sql);
3304    
3305                                    QueryPos qPos = QueryPos.getInstance(q);
3306    
3307                                    qPos.add(companyId);
3308    
3309                                    count = (Long)q.uniqueResult();
3310    
3311                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3312                            }
3313                            catch (Exception e) {
3314                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3315    
3316                                    throw processException(e);
3317                            }
3318                            finally {
3319                                    closeSession(session);
3320                            }
3321                    }
3322    
3323                    return count.intValue();
3324            }
3325    
3326            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "journalArticle.companyId = ?";
3327            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID =
3328                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
3329                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
3330                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3331                            "findByStructureId",
3332                            new String[] {
3333                                    String.class.getName(),
3334                                    
3335                            Integer.class.getName(), Integer.class.getName(),
3336                                    OrderByComparator.class.getName()
3337                            });
3338            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID =
3339                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
3340                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
3341                            JournalArticleImpl.class,
3342                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByStructureId",
3343                            new String[] { String.class.getName() },
3344                            JournalArticleModelImpl.STRUCTUREID_COLUMN_BITMASK |
3345                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
3346                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
3347            public static final FinderPath FINDER_PATH_COUNT_BY_STRUCTUREID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
3348                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3349                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByStructureId",
3350                            new String[] { String.class.getName() });
3351            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_STRUCTUREID =
3352                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
3353                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3354                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByStructureId",
3355                            new String[] { String.class.getName() });
3356    
3357            /**
3358             * Returns all the journal articles where structureId = &#63;.
3359             *
3360             * @param structureId the structure ID
3361             * @return the matching journal articles
3362             * @throws SystemException if a system exception occurred
3363             */
3364            @Override
3365            public List<JournalArticle> findByStructureId(String structureId)
3366                    throws SystemException {
3367                    return findByStructureId(structureId, QueryUtil.ALL_POS,
3368                            QueryUtil.ALL_POS, null);
3369            }
3370    
3371            /**
3372             * Returns a range of all the journal articles where structureId = &#63;.
3373             *
3374             * <p>
3375             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
3376             * </p>
3377             *
3378             * @param structureId the structure ID
3379             * @param start the lower bound of the range of journal articles
3380             * @param end the upper bound of the range of journal articles (not inclusive)
3381             * @return the range of matching journal articles
3382             * @throws SystemException if a system exception occurred
3383             */
3384            @Override
3385            public List<JournalArticle> findByStructureId(String structureId,
3386                    int start, int end) throws SystemException {
3387                    return findByStructureId(structureId, start, end, null);
3388            }
3389    
3390            /**
3391             * Returns an ordered range of all the journal articles where structureId = &#63;.
3392             *
3393             * <p>
3394             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
3395             * </p>
3396             *
3397             * @param structureId the structure ID
3398             * @param start the lower bound of the range of journal articles
3399             * @param end the upper bound of the range of journal articles (not inclusive)
3400             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3401             * @return the ordered range of matching journal articles
3402             * @throws SystemException if a system exception occurred
3403             */
3404            @Override
3405            public List<JournalArticle> findByStructureId(String structureId,
3406                    int start, int end, OrderByComparator orderByComparator)
3407                    throws SystemException {
3408                    boolean pagination = true;
3409                    FinderPath finderPath = null;
3410                    Object[] finderArgs = null;
3411    
3412                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3413                                    (orderByComparator == null)) {
3414                            pagination = false;
3415                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID;
3416                            finderArgs = new Object[] { structureId };
3417                    }
3418                    else {
3419                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID;
3420                            finderArgs = new Object[] { structureId, start, end, orderByComparator };
3421                    }
3422    
3423                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
3424                                    finderArgs, this);
3425    
3426                    if ((list != null) && !list.isEmpty()) {
3427                            for (JournalArticle journalArticle : list) {
3428                                    if (!Validator.equals(structureId,
3429                                                            journalArticle.getStructureId())) {
3430                                            list = null;
3431    
3432                                            break;
3433                                    }
3434                            }
3435                    }
3436    
3437                    if (list == null) {
3438                            StringBundler query = null;
3439    
3440                            if (orderByComparator != null) {
3441                                    query = new StringBundler(3 +
3442                                                    (orderByComparator.getOrderByFields().length * 3));
3443                            }
3444                            else {
3445                                    query = new StringBundler(3);
3446                            }
3447    
3448                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
3449    
3450                            boolean bindStructureId = false;
3451    
3452                            if (structureId == null) {
3453                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
3454                            }
3455                            else if (structureId.equals(StringPool.BLANK)) {
3456                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
3457                            }
3458                            else {
3459                                    bindStructureId = true;
3460    
3461                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3462                            }
3463    
3464                            if (orderByComparator != null) {
3465                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3466                                            orderByComparator);
3467                            }
3468                            else
3469                             if (pagination) {
3470                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
3471                            }
3472    
3473                            String sql = query.toString();
3474    
3475                            Session session = null;
3476    
3477                            try {
3478                                    session = openSession();
3479    
3480                                    Query q = session.createQuery(sql);
3481    
3482                                    QueryPos qPos = QueryPos.getInstance(q);
3483    
3484                                    if (bindStructureId) {
3485                                            qPos.add(structureId);
3486                                    }
3487    
3488                                    if (!pagination) {
3489                                            list = (List<JournalArticle>)QueryUtil.list(q,
3490                                                            getDialect(), start, end, false);
3491    
3492                                            Collections.sort(list);
3493    
3494                                            list = new UnmodifiableList<JournalArticle>(list);
3495                                    }
3496                                    else {
3497                                            list = (List<JournalArticle>)QueryUtil.list(q,
3498                                                            getDialect(), start, end);
3499                                    }
3500    
3501                                    cacheResult(list);
3502    
3503                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3504                            }
3505                            catch (Exception e) {
3506                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3507    
3508                                    throw processException(e);
3509                            }
3510                            finally {
3511                                    closeSession(session);
3512                            }
3513                    }
3514    
3515                    return list;
3516            }
3517    
3518            /**
3519             * Returns the first journal article in the ordered set where structureId = &#63;.
3520             *
3521             * @param structureId the structure ID
3522             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3523             * @return the first matching journal article
3524             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
3525             * @throws SystemException if a system exception occurred
3526             */
3527            @Override
3528            public JournalArticle findByStructureId_First(String structureId,
3529                    OrderByComparator orderByComparator)
3530                    throws NoSuchArticleException, SystemException {
3531                    JournalArticle journalArticle = fetchByStructureId_First(structureId,
3532                                    orderByComparator);
3533    
3534                    if (journalArticle != null) {
3535                            return journalArticle;
3536                    }
3537    
3538                    StringBundler msg = new StringBundler(4);
3539    
3540                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3541    
3542                    msg.append("structureId=");
3543                    msg.append(structureId);
3544    
3545                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3546    
3547                    throw new NoSuchArticleException(msg.toString());
3548            }
3549    
3550            /**
3551             * Returns the first journal article in the ordered set where structureId = &#63;.
3552             *
3553             * @param structureId the structure ID
3554             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3555             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
3556             * @throws SystemException if a system exception occurred
3557             */
3558            @Override
3559            public JournalArticle fetchByStructureId_First(String structureId,
3560                    OrderByComparator orderByComparator) throws SystemException {
3561                    List<JournalArticle> list = findByStructureId(structureId, 0, 1,
3562                                    orderByComparator);
3563    
3564                    if (!list.isEmpty()) {
3565                            return list.get(0);
3566                    }
3567    
3568                    return null;
3569            }
3570    
3571            /**
3572             * Returns the last journal article in the ordered set where structureId = &#63;.
3573             *
3574             * @param structureId the structure ID
3575             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3576             * @return the last matching journal article
3577             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
3578             * @throws SystemException if a system exception occurred
3579             */
3580            @Override
3581            public JournalArticle findByStructureId_Last(String structureId,
3582                    OrderByComparator orderByComparator)
3583                    throws NoSuchArticleException, SystemException {
3584                    JournalArticle journalArticle = fetchByStructureId_Last(structureId,
3585                                    orderByComparator);
3586    
3587                    if (journalArticle != null) {
3588                            return journalArticle;
3589                    }
3590    
3591                    StringBundler msg = new StringBundler(4);
3592    
3593                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3594    
3595                    msg.append("structureId=");
3596                    msg.append(structureId);
3597    
3598                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3599    
3600                    throw new NoSuchArticleException(msg.toString());
3601            }
3602    
3603            /**
3604             * Returns the last journal article in the ordered set where structureId = &#63;.
3605             *
3606             * @param structureId the structure ID
3607             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3608             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
3609             * @throws SystemException if a system exception occurred
3610             */
3611            @Override
3612            public JournalArticle fetchByStructureId_Last(String structureId,
3613                    OrderByComparator orderByComparator) throws SystemException {
3614                    int count = countByStructureId(structureId);
3615    
3616                    if (count == 0) {
3617                            return null;
3618                    }
3619    
3620                    List<JournalArticle> list = findByStructureId(structureId, count - 1,
3621                                    count, orderByComparator);
3622    
3623                    if (!list.isEmpty()) {
3624                            return list.get(0);
3625                    }
3626    
3627                    return null;
3628            }
3629    
3630            /**
3631             * Returns the journal articles before and after the current journal article in the ordered set where structureId = &#63;.
3632             *
3633             * @param id the primary key of the current journal article
3634             * @param structureId the structure ID
3635             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3636             * @return the previous, current, and next journal article
3637             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
3638             * @throws SystemException if a system exception occurred
3639             */
3640            @Override
3641            public JournalArticle[] findByStructureId_PrevAndNext(long id,
3642                    String structureId, OrderByComparator orderByComparator)
3643                    throws NoSuchArticleException, SystemException {
3644                    JournalArticle journalArticle = findByPrimaryKey(id);
3645    
3646                    Session session = null;
3647    
3648                    try {
3649                            session = openSession();
3650    
3651                            JournalArticle[] array = new JournalArticleImpl[3];
3652    
3653                            array[0] = getByStructureId_PrevAndNext(session, journalArticle,
3654                                            structureId, orderByComparator, true);
3655    
3656                            array[1] = journalArticle;
3657    
3658                            array[2] = getByStructureId_PrevAndNext(session, journalArticle,
3659                                            structureId, orderByComparator, false);
3660    
3661                            return array;
3662                    }
3663                    catch (Exception e) {
3664                            throw processException(e);
3665                    }
3666                    finally {
3667                            closeSession(session);
3668                    }
3669            }
3670    
3671            protected JournalArticle getByStructureId_PrevAndNext(Session session,
3672                    JournalArticle journalArticle, String structureId,
3673                    OrderByComparator orderByComparator, boolean previous) {
3674                    StringBundler query = null;
3675    
3676                    if (orderByComparator != null) {
3677                            query = new StringBundler(6 +
3678                                            (orderByComparator.getOrderByFields().length * 6));
3679                    }
3680                    else {
3681                            query = new StringBundler(3);
3682                    }
3683    
3684                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
3685    
3686                    boolean bindStructureId = false;
3687    
3688                    if (structureId == null) {
3689                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
3690                    }
3691                    else if (structureId.equals(StringPool.BLANK)) {
3692                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
3693                    }
3694                    else {
3695                            bindStructureId = true;
3696    
3697                            query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
3698                    }
3699    
3700                    if (orderByComparator != null) {
3701                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3702    
3703                            if (orderByConditionFields.length > 0) {
3704                                    query.append(WHERE_AND);
3705                            }
3706    
3707                            for (int i = 0; i < orderByConditionFields.length; i++) {
3708                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3709                                    query.append(orderByConditionFields[i]);
3710    
3711                                    if ((i + 1) < orderByConditionFields.length) {
3712                                            if (orderByComparator.isAscending() ^ previous) {
3713                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3714                                            }
3715                                            else {
3716                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3717                                            }
3718                                    }
3719                                    else {
3720                                            if (orderByComparator.isAscending() ^ previous) {
3721                                                    query.append(WHERE_GREATER_THAN);
3722                                            }
3723                                            else {
3724                                                    query.append(WHERE_LESSER_THAN);
3725                                            }
3726                                    }
3727                            }
3728    
3729                            query.append(ORDER_BY_CLAUSE);
3730    
3731                            String[] orderByFields = orderByComparator.getOrderByFields();
3732    
3733                            for (int i = 0; i < orderByFields.length; i++) {
3734                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3735                                    query.append(orderByFields[i]);
3736    
3737                                    if ((i + 1) < orderByFields.length) {
3738                                            if (orderByComparator.isAscending() ^ previous) {
3739                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3740                                            }
3741                                            else {
3742                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3743                                            }
3744                                    }
3745                                    else {
3746                                            if (orderByComparator.isAscending() ^ previous) {
3747                                                    query.append(ORDER_BY_ASC);
3748                                            }
3749                                            else {
3750                                                    query.append(ORDER_BY_DESC);
3751                                            }
3752                                    }
3753                            }
3754                    }
3755                    else {
3756                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
3757                    }
3758    
3759                    String sql = query.toString();
3760    
3761                    Query q = session.createQuery(sql);
3762    
3763                    q.setFirstResult(0);
3764                    q.setMaxResults(2);
3765    
3766                    QueryPos qPos = QueryPos.getInstance(q);
3767    
3768                    if (bindStructureId) {
3769                            qPos.add(structureId);
3770                    }
3771    
3772                    if (orderByComparator != null) {
3773                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
3774    
3775                            for (Object value : values) {
3776                                    qPos.add(value);
3777                            }
3778                    }
3779    
3780                    List<JournalArticle> list = q.list();
3781    
3782                    if (list.size() == 2) {
3783                            return list.get(1);
3784                    }
3785                    else {
3786                            return null;
3787                    }
3788            }
3789    
3790            /**
3791             * Returns all the journal articles where structureId = any &#63;.
3792             *
3793             * <p>
3794             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
3795             * </p>
3796             *
3797             * @param structureIds the structure IDs
3798             * @return the matching journal articles
3799             * @throws SystemException if a system exception occurred
3800             */
3801            @Override
3802            public List<JournalArticle> findByStructureId(String[] structureIds)
3803                    throws SystemException {
3804                    return findByStructureId(structureIds, QueryUtil.ALL_POS,
3805                            QueryUtil.ALL_POS, null);
3806            }
3807    
3808            /**
3809             * Returns a range of all the journal articles where structureId = any &#63;.
3810             *
3811             * <p>
3812             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
3813             * </p>
3814             *
3815             * @param structureIds the structure IDs
3816             * @param start the lower bound of the range of journal articles
3817             * @param end the upper bound of the range of journal articles (not inclusive)
3818             * @return the range of matching journal articles
3819             * @throws SystemException if a system exception occurred
3820             */
3821            @Override
3822            public List<JournalArticle> findByStructureId(String[] structureIds,
3823                    int start, int end) throws SystemException {
3824                    return findByStructureId(structureIds, start, end, null);
3825            }
3826    
3827            /**
3828             * Returns an ordered range of all the journal articles where structureId = any &#63;.
3829             *
3830             * <p>
3831             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
3832             * </p>
3833             *
3834             * @param structureIds the structure IDs
3835             * @param start the lower bound of the range of journal articles
3836             * @param end the upper bound of the range of journal articles (not inclusive)
3837             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3838             * @return the ordered range of matching journal articles
3839             * @throws SystemException if a system exception occurred
3840             */
3841            @Override
3842            public List<JournalArticle> findByStructureId(String[] structureIds,
3843                    int start, int end, OrderByComparator orderByComparator)
3844                    throws SystemException {
3845                    if ((structureIds != null) && (structureIds.length == 1)) {
3846                            return findByStructureId(structureIds[0], start, end,
3847                                    orderByComparator);
3848                    }
3849    
3850                    boolean pagination = true;
3851                    Object[] finderArgs = null;
3852    
3853                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3854                                    (orderByComparator == null)) {
3855                            pagination = false;
3856                            finderArgs = new Object[] { StringUtil.merge(structureIds) };
3857                    }
3858                    else {
3859                            finderArgs = new Object[] {
3860                                            StringUtil.merge(structureIds),
3861                                            
3862                                            start, end, orderByComparator
3863                                    };
3864                    }
3865    
3866                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID,
3867                                    finderArgs, this);
3868    
3869                    if ((list != null) && !list.isEmpty()) {
3870                            for (JournalArticle journalArticle : list) {
3871                                    if (!ArrayUtil.contains(structureIds,
3872                                                            journalArticle.getStructureId())) {
3873                                            list = null;
3874    
3875                                            break;
3876                                    }
3877                            }
3878                    }
3879    
3880                    if (list == null) {
3881                            StringBundler query = new StringBundler();
3882    
3883                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
3884    
3885                            boolean conjunctionable = false;
3886    
3887                            if ((structureIds == null) || (structureIds.length > 0)) {
3888                                    if (conjunctionable) {
3889                                            query.append(WHERE_AND);
3890                                    }
3891    
3892                                    query.append(StringPool.OPEN_PARENTHESIS);
3893    
3894                                    for (int i = 0; i < structureIds.length; i++) {
3895                                            String structureId = structureIds[i];
3896    
3897                                            if (structureId == null) {
3898                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_4);
3899                                            }
3900                                            else if (structureId.equals(StringPool.BLANK)) {
3901                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_6);
3902                                            }
3903                                            else {
3904                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_5);
3905                                            }
3906    
3907                                            if ((i + 1) < structureIds.length) {
3908                                                    query.append(WHERE_OR);
3909                                            }
3910                                    }
3911    
3912                                    query.append(StringPool.CLOSE_PARENTHESIS);
3913    
3914                                    conjunctionable = true;
3915                            }
3916    
3917                            if (orderByComparator != null) {
3918                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3919                                            orderByComparator);
3920                            }
3921                            else
3922                             if (pagination) {
3923                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
3924                            }
3925    
3926                            String sql = query.toString();
3927    
3928                            Session session = null;
3929    
3930                            try {
3931                                    session = openSession();
3932    
3933                                    Query q = session.createQuery(sql);
3934    
3935                                    QueryPos qPos = QueryPos.getInstance(q);
3936    
3937                                    if (structureIds != null) {
3938                                            qPos.add(structureIds);
3939                                    }
3940    
3941                                    if (!pagination) {
3942                                            list = (List<JournalArticle>)QueryUtil.list(q,
3943                                                            getDialect(), start, end, false);
3944    
3945                                            Collections.sort(list);
3946    
3947                                            list = new UnmodifiableList<JournalArticle>(list);
3948                                    }
3949                                    else {
3950                                            list = (List<JournalArticle>)QueryUtil.list(q,
3951                                                            getDialect(), start, end);
3952                                    }
3953    
3954                                    cacheResult(list);
3955    
3956                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID,
3957                                            finderArgs, list);
3958                            }
3959                            catch (Exception e) {
3960                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_STRUCTUREID,
3961                                            finderArgs);
3962    
3963                                    throw processException(e);
3964                            }
3965                            finally {
3966                                    closeSession(session);
3967                            }
3968                    }
3969    
3970                    return list;
3971            }
3972    
3973            /**
3974             * Removes all the journal articles where structureId = &#63; from the database.
3975             *
3976             * @param structureId the structure ID
3977             * @throws SystemException if a system exception occurred
3978             */
3979            @Override
3980            public void removeByStructureId(String structureId)
3981                    throws SystemException {
3982                    for (JournalArticle journalArticle : findByStructureId(structureId,
3983                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3984                            remove(journalArticle);
3985                    }
3986            }
3987    
3988            /**
3989             * Returns the number of journal articles where structureId = &#63;.
3990             *
3991             * @param structureId the structure ID
3992             * @return the number of matching journal articles
3993             * @throws SystemException if a system exception occurred
3994             */
3995            @Override
3996            public int countByStructureId(String structureId) throws SystemException {
3997                    FinderPath finderPath = FINDER_PATH_COUNT_BY_STRUCTUREID;
3998    
3999                    Object[] finderArgs = new Object[] { structureId };
4000    
4001                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4002                                    this);
4003    
4004                    if (count == null) {
4005                            StringBundler query = new StringBundler(2);
4006    
4007                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
4008    
4009                            boolean bindStructureId = false;
4010    
4011                            if (structureId == null) {
4012                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1);
4013                            }
4014                            else if (structureId.equals(StringPool.BLANK)) {
4015                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3);
4016                            }
4017                            else {
4018                                    bindStructureId = true;
4019    
4020                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2);
4021                            }
4022    
4023                            String sql = query.toString();
4024    
4025                            Session session = null;
4026    
4027                            try {
4028                                    session = openSession();
4029    
4030                                    Query q = session.createQuery(sql);
4031    
4032                                    QueryPos qPos = QueryPos.getInstance(q);
4033    
4034                                    if (bindStructureId) {
4035                                            qPos.add(structureId);
4036                                    }
4037    
4038                                    count = (Long)q.uniqueResult();
4039    
4040                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4041                            }
4042                            catch (Exception e) {
4043                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4044    
4045                                    throw processException(e);
4046                            }
4047                            finally {
4048                                    closeSession(session);
4049                            }
4050                    }
4051    
4052                    return count.intValue();
4053            }
4054    
4055            /**
4056             * Returns the number of journal articles where structureId = any &#63;.
4057             *
4058             * @param structureIds the structure IDs
4059             * @return the number of matching journal articles
4060             * @throws SystemException if a system exception occurred
4061             */
4062            @Override
4063            public int countByStructureId(String[] structureIds)
4064                    throws SystemException {
4065                    Object[] finderArgs = new Object[] { StringUtil.merge(structureIds) };
4066    
4067                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_STRUCTUREID,
4068                                    finderArgs, this);
4069    
4070                    if (count == null) {
4071                            StringBundler query = new StringBundler();
4072    
4073                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
4074    
4075                            boolean conjunctionable = false;
4076    
4077                            if ((structureIds == null) || (structureIds.length > 0)) {
4078                                    if (conjunctionable) {
4079                                            query.append(WHERE_AND);
4080                                    }
4081    
4082                                    query.append(StringPool.OPEN_PARENTHESIS);
4083    
4084                                    for (int i = 0; i < structureIds.length; i++) {
4085                                            String structureId = structureIds[i];
4086    
4087                                            if (structureId == null) {
4088                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_4);
4089                                            }
4090                                            else if (structureId.equals(StringPool.BLANK)) {
4091                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_6);
4092                                            }
4093                                            else {
4094                                                    query.append(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_5);
4095                                            }
4096    
4097                                            if ((i + 1) < structureIds.length) {
4098                                                    query.append(WHERE_OR);
4099                                            }
4100                                    }
4101    
4102                                    query.append(StringPool.CLOSE_PARENTHESIS);
4103    
4104                                    conjunctionable = true;
4105                            }
4106    
4107                            String sql = query.toString();
4108    
4109                            Session session = null;
4110    
4111                            try {
4112                                    session = openSession();
4113    
4114                                    Query q = session.createQuery(sql);
4115    
4116                                    QueryPos qPos = QueryPos.getInstance(q);
4117    
4118                                    if (structureIds != null) {
4119                                            qPos.add(structureIds);
4120                                    }
4121    
4122                                    count = (Long)q.uniqueResult();
4123    
4124                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_STRUCTUREID,
4125                                            finderArgs, count);
4126                            }
4127                            catch (Exception e) {
4128                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_STRUCTUREID,
4129                                            finderArgs);
4130    
4131                                    throw processException(e);
4132                            }
4133                            finally {
4134                                    closeSession(session);
4135                            }
4136                    }
4137    
4138                    return count.intValue();
4139            }
4140    
4141            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1 = "journalArticle.structureId IS NULL";
4142            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2 = "journalArticle.structureId = ?";
4143            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3 = "(journalArticle.structureId IS NULL OR journalArticle.structureId = '')";
4144            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_4 = "(" +
4145                    removeConjunction(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_1) + ")";
4146            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_5 = "(" +
4147                    removeConjunction(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_2) + ")";
4148            private static final String _FINDER_COLUMN_STRUCTUREID_STRUCTUREID_6 = "(" +
4149                    removeConjunction(_FINDER_COLUMN_STRUCTUREID_STRUCTUREID_3) + ")";
4150            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID =
4151                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4152                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
4153                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4154                            "findByTemplateId",
4155                            new String[] {
4156                                    String.class.getName(),
4157                                    
4158                            Integer.class.getName(), Integer.class.getName(),
4159                                    OrderByComparator.class.getName()
4160                            });
4161            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID =
4162                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4163                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
4164                            JournalArticleImpl.class,
4165                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTemplateId",
4166                            new String[] { String.class.getName() },
4167                            JournalArticleModelImpl.TEMPLATEID_COLUMN_BITMASK |
4168                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
4169                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
4170            public static final FinderPath FINDER_PATH_COUNT_BY_TEMPLATEID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4171                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4172                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTemplateId",
4173                            new String[] { String.class.getName() });
4174    
4175            /**
4176             * Returns all the journal articles where templateId = &#63;.
4177             *
4178             * @param templateId the template ID
4179             * @return the matching journal articles
4180             * @throws SystemException if a system exception occurred
4181             */
4182            @Override
4183            public List<JournalArticle> findByTemplateId(String templateId)
4184                    throws SystemException {
4185                    return findByTemplateId(templateId, QueryUtil.ALL_POS,
4186                            QueryUtil.ALL_POS, null);
4187            }
4188    
4189            /**
4190             * Returns a range of all the journal articles where templateId = &#63;.
4191             *
4192             * <p>
4193             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
4194             * </p>
4195             *
4196             * @param templateId the template ID
4197             * @param start the lower bound of the range of journal articles
4198             * @param end the upper bound of the range of journal articles (not inclusive)
4199             * @return the range of matching journal articles
4200             * @throws SystemException if a system exception occurred
4201             */
4202            @Override
4203            public List<JournalArticle> findByTemplateId(String templateId, int start,
4204                    int end) throws SystemException {
4205                    return findByTemplateId(templateId, start, end, null);
4206            }
4207    
4208            /**
4209             * Returns an ordered range of all the journal articles where templateId = &#63;.
4210             *
4211             * <p>
4212             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
4213             * </p>
4214             *
4215             * @param templateId the template ID
4216             * @param start the lower bound of the range of journal articles
4217             * @param end the upper bound of the range of journal articles (not inclusive)
4218             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4219             * @return the ordered range of matching journal articles
4220             * @throws SystemException if a system exception occurred
4221             */
4222            @Override
4223            public List<JournalArticle> findByTemplateId(String templateId, int start,
4224                    int end, OrderByComparator orderByComparator) throws SystemException {
4225                    boolean pagination = true;
4226                    FinderPath finderPath = null;
4227                    Object[] finderArgs = null;
4228    
4229                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4230                                    (orderByComparator == null)) {
4231                            pagination = false;
4232                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID;
4233                            finderArgs = new Object[] { templateId };
4234                    }
4235                    else {
4236                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TEMPLATEID;
4237                            finderArgs = new Object[] { templateId, start, end, orderByComparator };
4238                    }
4239    
4240                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
4241                                    finderArgs, this);
4242    
4243                    if ((list != null) && !list.isEmpty()) {
4244                            for (JournalArticle journalArticle : list) {
4245                                    if (!Validator.equals(templateId, journalArticle.getTemplateId())) {
4246                                            list = null;
4247    
4248                                            break;
4249                                    }
4250                            }
4251                    }
4252    
4253                    if (list == null) {
4254                            StringBundler query = null;
4255    
4256                            if (orderByComparator != null) {
4257                                    query = new StringBundler(3 +
4258                                                    (orderByComparator.getOrderByFields().length * 3));
4259                            }
4260                            else {
4261                                    query = new StringBundler(3);
4262                            }
4263    
4264                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
4265    
4266                            boolean bindTemplateId = false;
4267    
4268                            if (templateId == null) {
4269                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
4270                            }
4271                            else if (templateId.equals(StringPool.BLANK)) {
4272                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
4273                            }
4274                            else {
4275                                    bindTemplateId = true;
4276    
4277                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
4278                            }
4279    
4280                            if (orderByComparator != null) {
4281                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4282                                            orderByComparator);
4283                            }
4284                            else
4285                             if (pagination) {
4286                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
4287                            }
4288    
4289                            String sql = query.toString();
4290    
4291                            Session session = null;
4292    
4293                            try {
4294                                    session = openSession();
4295    
4296                                    Query q = session.createQuery(sql);
4297    
4298                                    QueryPos qPos = QueryPos.getInstance(q);
4299    
4300                                    if (bindTemplateId) {
4301                                            qPos.add(templateId);
4302                                    }
4303    
4304                                    if (!pagination) {
4305                                            list = (List<JournalArticle>)QueryUtil.list(q,
4306                                                            getDialect(), start, end, false);
4307    
4308                                            Collections.sort(list);
4309    
4310                                            list = new UnmodifiableList<JournalArticle>(list);
4311                                    }
4312                                    else {
4313                                            list = (List<JournalArticle>)QueryUtil.list(q,
4314                                                            getDialect(), start, end);
4315                                    }
4316    
4317                                    cacheResult(list);
4318    
4319                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4320                            }
4321                            catch (Exception e) {
4322                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4323    
4324                                    throw processException(e);
4325                            }
4326                            finally {
4327                                    closeSession(session);
4328                            }
4329                    }
4330    
4331                    return list;
4332            }
4333    
4334            /**
4335             * Returns the first journal article in the ordered set where templateId = &#63;.
4336             *
4337             * @param templateId the template ID
4338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4339             * @return the first matching journal article
4340             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
4341             * @throws SystemException if a system exception occurred
4342             */
4343            @Override
4344            public JournalArticle findByTemplateId_First(String templateId,
4345                    OrderByComparator orderByComparator)
4346                    throws NoSuchArticleException, SystemException {
4347                    JournalArticle journalArticle = fetchByTemplateId_First(templateId,
4348                                    orderByComparator);
4349    
4350                    if (journalArticle != null) {
4351                            return journalArticle;
4352                    }
4353    
4354                    StringBundler msg = new StringBundler(4);
4355    
4356                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4357    
4358                    msg.append("templateId=");
4359                    msg.append(templateId);
4360    
4361                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4362    
4363                    throw new NoSuchArticleException(msg.toString());
4364            }
4365    
4366            /**
4367             * Returns the first journal article in the ordered set where templateId = &#63;.
4368             *
4369             * @param templateId the template ID
4370             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4371             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
4372             * @throws SystemException if a system exception occurred
4373             */
4374            @Override
4375            public JournalArticle fetchByTemplateId_First(String templateId,
4376                    OrderByComparator orderByComparator) throws SystemException {
4377                    List<JournalArticle> list = findByTemplateId(templateId, 0, 1,
4378                                    orderByComparator);
4379    
4380                    if (!list.isEmpty()) {
4381                            return list.get(0);
4382                    }
4383    
4384                    return null;
4385            }
4386    
4387            /**
4388             * Returns the last journal article in the ordered set where templateId = &#63;.
4389             *
4390             * @param templateId the template ID
4391             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4392             * @return the last matching journal article
4393             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
4394             * @throws SystemException if a system exception occurred
4395             */
4396            @Override
4397            public JournalArticle findByTemplateId_Last(String templateId,
4398                    OrderByComparator orderByComparator)
4399                    throws NoSuchArticleException, SystemException {
4400                    JournalArticle journalArticle = fetchByTemplateId_Last(templateId,
4401                                    orderByComparator);
4402    
4403                    if (journalArticle != null) {
4404                            return journalArticle;
4405                    }
4406    
4407                    StringBundler msg = new StringBundler(4);
4408    
4409                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4410    
4411                    msg.append("templateId=");
4412                    msg.append(templateId);
4413    
4414                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4415    
4416                    throw new NoSuchArticleException(msg.toString());
4417            }
4418    
4419            /**
4420             * Returns the last journal article in the ordered set where templateId = &#63;.
4421             *
4422             * @param templateId the template ID
4423             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4424             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
4425             * @throws SystemException if a system exception occurred
4426             */
4427            @Override
4428            public JournalArticle fetchByTemplateId_Last(String templateId,
4429                    OrderByComparator orderByComparator) throws SystemException {
4430                    int count = countByTemplateId(templateId);
4431    
4432                    if (count == 0) {
4433                            return null;
4434                    }
4435    
4436                    List<JournalArticle> list = findByTemplateId(templateId, count - 1,
4437                                    count, orderByComparator);
4438    
4439                    if (!list.isEmpty()) {
4440                            return list.get(0);
4441                    }
4442    
4443                    return null;
4444            }
4445    
4446            /**
4447             * Returns the journal articles before and after the current journal article in the ordered set where templateId = &#63;.
4448             *
4449             * @param id the primary key of the current journal article
4450             * @param templateId the template ID
4451             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4452             * @return the previous, current, and next journal article
4453             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
4454             * @throws SystemException if a system exception occurred
4455             */
4456            @Override
4457            public JournalArticle[] findByTemplateId_PrevAndNext(long id,
4458                    String templateId, OrderByComparator orderByComparator)
4459                    throws NoSuchArticleException, SystemException {
4460                    JournalArticle journalArticle = findByPrimaryKey(id);
4461    
4462                    Session session = null;
4463    
4464                    try {
4465                            session = openSession();
4466    
4467                            JournalArticle[] array = new JournalArticleImpl[3];
4468    
4469                            array[0] = getByTemplateId_PrevAndNext(session, journalArticle,
4470                                            templateId, orderByComparator, true);
4471    
4472                            array[1] = journalArticle;
4473    
4474                            array[2] = getByTemplateId_PrevAndNext(session, journalArticle,
4475                                            templateId, orderByComparator, false);
4476    
4477                            return array;
4478                    }
4479                    catch (Exception e) {
4480                            throw processException(e);
4481                    }
4482                    finally {
4483                            closeSession(session);
4484                    }
4485            }
4486    
4487            protected JournalArticle getByTemplateId_PrevAndNext(Session session,
4488                    JournalArticle journalArticle, String templateId,
4489                    OrderByComparator orderByComparator, boolean previous) {
4490                    StringBundler query = null;
4491    
4492                    if (orderByComparator != null) {
4493                            query = new StringBundler(6 +
4494                                            (orderByComparator.getOrderByFields().length * 6));
4495                    }
4496                    else {
4497                            query = new StringBundler(3);
4498                    }
4499    
4500                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
4501    
4502                    boolean bindTemplateId = false;
4503    
4504                    if (templateId == null) {
4505                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
4506                    }
4507                    else if (templateId.equals(StringPool.BLANK)) {
4508                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
4509                    }
4510                    else {
4511                            bindTemplateId = true;
4512    
4513                            query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
4514                    }
4515    
4516                    if (orderByComparator != null) {
4517                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4518    
4519                            if (orderByConditionFields.length > 0) {
4520                                    query.append(WHERE_AND);
4521                            }
4522    
4523                            for (int i = 0; i < orderByConditionFields.length; i++) {
4524                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4525                                    query.append(orderByConditionFields[i]);
4526    
4527                                    if ((i + 1) < orderByConditionFields.length) {
4528                                            if (orderByComparator.isAscending() ^ previous) {
4529                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4530                                            }
4531                                            else {
4532                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4533                                            }
4534                                    }
4535                                    else {
4536                                            if (orderByComparator.isAscending() ^ previous) {
4537                                                    query.append(WHERE_GREATER_THAN);
4538                                            }
4539                                            else {
4540                                                    query.append(WHERE_LESSER_THAN);
4541                                            }
4542                                    }
4543                            }
4544    
4545                            query.append(ORDER_BY_CLAUSE);
4546    
4547                            String[] orderByFields = orderByComparator.getOrderByFields();
4548    
4549                            for (int i = 0; i < orderByFields.length; i++) {
4550                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4551                                    query.append(orderByFields[i]);
4552    
4553                                    if ((i + 1) < orderByFields.length) {
4554                                            if (orderByComparator.isAscending() ^ previous) {
4555                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4556                                            }
4557                                            else {
4558                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4559                                            }
4560                                    }
4561                                    else {
4562                                            if (orderByComparator.isAscending() ^ previous) {
4563                                                    query.append(ORDER_BY_ASC);
4564                                            }
4565                                            else {
4566                                                    query.append(ORDER_BY_DESC);
4567                                            }
4568                                    }
4569                            }
4570                    }
4571                    else {
4572                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
4573                    }
4574    
4575                    String sql = query.toString();
4576    
4577                    Query q = session.createQuery(sql);
4578    
4579                    q.setFirstResult(0);
4580                    q.setMaxResults(2);
4581    
4582                    QueryPos qPos = QueryPos.getInstance(q);
4583    
4584                    if (bindTemplateId) {
4585                            qPos.add(templateId);
4586                    }
4587    
4588                    if (orderByComparator != null) {
4589                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
4590    
4591                            for (Object value : values) {
4592                                    qPos.add(value);
4593                            }
4594                    }
4595    
4596                    List<JournalArticle> list = q.list();
4597    
4598                    if (list.size() == 2) {
4599                            return list.get(1);
4600                    }
4601                    else {
4602                            return null;
4603                    }
4604            }
4605    
4606            /**
4607             * Removes all the journal articles where templateId = &#63; from the database.
4608             *
4609             * @param templateId the template ID
4610             * @throws SystemException if a system exception occurred
4611             */
4612            @Override
4613            public void removeByTemplateId(String templateId) throws SystemException {
4614                    for (JournalArticle journalArticle : findByTemplateId(templateId,
4615                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4616                            remove(journalArticle);
4617                    }
4618            }
4619    
4620            /**
4621             * Returns the number of journal articles where templateId = &#63;.
4622             *
4623             * @param templateId the template ID
4624             * @return the number of matching journal articles
4625             * @throws SystemException if a system exception occurred
4626             */
4627            @Override
4628            public int countByTemplateId(String templateId) throws SystemException {
4629                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TEMPLATEID;
4630    
4631                    Object[] finderArgs = new Object[] { templateId };
4632    
4633                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4634                                    this);
4635    
4636                    if (count == null) {
4637                            StringBundler query = new StringBundler(2);
4638    
4639                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
4640    
4641                            boolean bindTemplateId = false;
4642    
4643                            if (templateId == null) {
4644                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1);
4645                            }
4646                            else if (templateId.equals(StringPool.BLANK)) {
4647                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3);
4648                            }
4649                            else {
4650                                    bindTemplateId = true;
4651    
4652                                    query.append(_FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2);
4653                            }
4654    
4655                            String sql = query.toString();
4656    
4657                            Session session = null;
4658    
4659                            try {
4660                                    session = openSession();
4661    
4662                                    Query q = session.createQuery(sql);
4663    
4664                                    QueryPos qPos = QueryPos.getInstance(q);
4665    
4666                                    if (bindTemplateId) {
4667                                            qPos.add(templateId);
4668                                    }
4669    
4670                                    count = (Long)q.uniqueResult();
4671    
4672                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4673                            }
4674                            catch (Exception e) {
4675                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4676    
4677                                    throw processException(e);
4678                            }
4679                            finally {
4680                                    closeSession(session);
4681                            }
4682                    }
4683    
4684                    return count.intValue();
4685            }
4686    
4687            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_1 = "journalArticle.templateId IS NULL";
4688            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_2 = "journalArticle.templateId = ?";
4689            private static final String _FINDER_COLUMN_TEMPLATEID_TEMPLATEID_3 = "(journalArticle.templateId IS NULL OR journalArticle.templateId = '')";
4690            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTUUID =
4691                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4692                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
4693                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4694                            "findByLayoutUuid",
4695                            new String[] {
4696                                    String.class.getName(),
4697                                    
4698                            Integer.class.getName(), Integer.class.getName(),
4699                                    OrderByComparator.class.getName()
4700                            });
4701            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID =
4702                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4703                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
4704                            JournalArticleImpl.class,
4705                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByLayoutUuid",
4706                            new String[] { String.class.getName() },
4707                            JournalArticleModelImpl.LAYOUTUUID_COLUMN_BITMASK |
4708                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
4709                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
4710            public static final FinderPath FINDER_PATH_COUNT_BY_LAYOUTUUID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
4711                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4712                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLayoutUuid",
4713                            new String[] { String.class.getName() });
4714    
4715            /**
4716             * Returns all the journal articles where layoutUuid = &#63;.
4717             *
4718             * @param layoutUuid the layout uuid
4719             * @return the matching journal articles
4720             * @throws SystemException if a system exception occurred
4721             */
4722            @Override
4723            public List<JournalArticle> findByLayoutUuid(String layoutUuid)
4724                    throws SystemException {
4725                    return findByLayoutUuid(layoutUuid, QueryUtil.ALL_POS,
4726                            QueryUtil.ALL_POS, null);
4727            }
4728    
4729            /**
4730             * Returns a range of all the journal articles where layoutUuid = &#63;.
4731             *
4732             * <p>
4733             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
4734             * </p>
4735             *
4736             * @param layoutUuid the layout uuid
4737             * @param start the lower bound of the range of journal articles
4738             * @param end the upper bound of the range of journal articles (not inclusive)
4739             * @return the range of matching journal articles
4740             * @throws SystemException if a system exception occurred
4741             */
4742            @Override
4743            public List<JournalArticle> findByLayoutUuid(String layoutUuid, int start,
4744                    int end) throws SystemException {
4745                    return findByLayoutUuid(layoutUuid, start, end, null);
4746            }
4747    
4748            /**
4749             * Returns an ordered range of all the journal articles where layoutUuid = &#63;.
4750             *
4751             * <p>
4752             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
4753             * </p>
4754             *
4755             * @param layoutUuid the layout uuid
4756             * @param start the lower bound of the range of journal articles
4757             * @param end the upper bound of the range of journal articles (not inclusive)
4758             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4759             * @return the ordered range of matching journal articles
4760             * @throws SystemException if a system exception occurred
4761             */
4762            @Override
4763            public List<JournalArticle> findByLayoutUuid(String layoutUuid, int start,
4764                    int end, OrderByComparator orderByComparator) throws SystemException {
4765                    boolean pagination = true;
4766                    FinderPath finderPath = null;
4767                    Object[] finderArgs = null;
4768    
4769                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4770                                    (orderByComparator == null)) {
4771                            pagination = false;
4772                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID;
4773                            finderArgs = new Object[] { layoutUuid };
4774                    }
4775                    else {
4776                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LAYOUTUUID;
4777                            finderArgs = new Object[] { layoutUuid, start, end, orderByComparator };
4778                    }
4779    
4780                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
4781                                    finderArgs, this);
4782    
4783                    if ((list != null) && !list.isEmpty()) {
4784                            for (JournalArticle journalArticle : list) {
4785                                    if (!Validator.equals(layoutUuid, journalArticle.getLayoutUuid())) {
4786                                            list = null;
4787    
4788                                            break;
4789                                    }
4790                            }
4791                    }
4792    
4793                    if (list == null) {
4794                            StringBundler query = null;
4795    
4796                            if (orderByComparator != null) {
4797                                    query = new StringBundler(3 +
4798                                                    (orderByComparator.getOrderByFields().length * 3));
4799                            }
4800                            else {
4801                                    query = new StringBundler(3);
4802                            }
4803    
4804                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
4805    
4806                            boolean bindLayoutUuid = false;
4807    
4808                            if (layoutUuid == null) {
4809                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
4810                            }
4811                            else if (layoutUuid.equals(StringPool.BLANK)) {
4812                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
4813                            }
4814                            else {
4815                                    bindLayoutUuid = true;
4816    
4817                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
4818                            }
4819    
4820                            if (orderByComparator != null) {
4821                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4822                                            orderByComparator);
4823                            }
4824                            else
4825                             if (pagination) {
4826                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
4827                            }
4828    
4829                            String sql = query.toString();
4830    
4831                            Session session = null;
4832    
4833                            try {
4834                                    session = openSession();
4835    
4836                                    Query q = session.createQuery(sql);
4837    
4838                                    QueryPos qPos = QueryPos.getInstance(q);
4839    
4840                                    if (bindLayoutUuid) {
4841                                            qPos.add(layoutUuid);
4842                                    }
4843    
4844                                    if (!pagination) {
4845                                            list = (List<JournalArticle>)QueryUtil.list(q,
4846                                                            getDialect(), start, end, false);
4847    
4848                                            Collections.sort(list);
4849    
4850                                            list = new UnmodifiableList<JournalArticle>(list);
4851                                    }
4852                                    else {
4853                                            list = (List<JournalArticle>)QueryUtil.list(q,
4854                                                            getDialect(), start, end);
4855                                    }
4856    
4857                                    cacheResult(list);
4858    
4859                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4860                            }
4861                            catch (Exception e) {
4862                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4863    
4864                                    throw processException(e);
4865                            }
4866                            finally {
4867                                    closeSession(session);
4868                            }
4869                    }
4870    
4871                    return list;
4872            }
4873    
4874            /**
4875             * Returns the first journal article in the ordered set where layoutUuid = &#63;.
4876             *
4877             * @param layoutUuid the layout uuid
4878             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4879             * @return the first matching journal article
4880             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
4881             * @throws SystemException if a system exception occurred
4882             */
4883            @Override
4884            public JournalArticle findByLayoutUuid_First(String layoutUuid,
4885                    OrderByComparator orderByComparator)
4886                    throws NoSuchArticleException, SystemException {
4887                    JournalArticle journalArticle = fetchByLayoutUuid_First(layoutUuid,
4888                                    orderByComparator);
4889    
4890                    if (journalArticle != null) {
4891                            return journalArticle;
4892                    }
4893    
4894                    StringBundler msg = new StringBundler(4);
4895    
4896                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4897    
4898                    msg.append("layoutUuid=");
4899                    msg.append(layoutUuid);
4900    
4901                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4902    
4903                    throw new NoSuchArticleException(msg.toString());
4904            }
4905    
4906            /**
4907             * Returns the first journal article in the ordered set where layoutUuid = &#63;.
4908             *
4909             * @param layoutUuid the layout uuid
4910             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4911             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
4912             * @throws SystemException if a system exception occurred
4913             */
4914            @Override
4915            public JournalArticle fetchByLayoutUuid_First(String layoutUuid,
4916                    OrderByComparator orderByComparator) throws SystemException {
4917                    List<JournalArticle> list = findByLayoutUuid(layoutUuid, 0, 1,
4918                                    orderByComparator);
4919    
4920                    if (!list.isEmpty()) {
4921                            return list.get(0);
4922                    }
4923    
4924                    return null;
4925            }
4926    
4927            /**
4928             * Returns the last journal article in the ordered set where layoutUuid = &#63;.
4929             *
4930             * @param layoutUuid the layout uuid
4931             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4932             * @return the last matching journal article
4933             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
4934             * @throws SystemException if a system exception occurred
4935             */
4936            @Override
4937            public JournalArticle findByLayoutUuid_Last(String layoutUuid,
4938                    OrderByComparator orderByComparator)
4939                    throws NoSuchArticleException, SystemException {
4940                    JournalArticle journalArticle = fetchByLayoutUuid_Last(layoutUuid,
4941                                    orderByComparator);
4942    
4943                    if (journalArticle != null) {
4944                            return journalArticle;
4945                    }
4946    
4947                    StringBundler msg = new StringBundler(4);
4948    
4949                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4950    
4951                    msg.append("layoutUuid=");
4952                    msg.append(layoutUuid);
4953    
4954                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4955    
4956                    throw new NoSuchArticleException(msg.toString());
4957            }
4958    
4959            /**
4960             * Returns the last journal article in the ordered set where layoutUuid = &#63;.
4961             *
4962             * @param layoutUuid the layout uuid
4963             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4964             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
4965             * @throws SystemException if a system exception occurred
4966             */
4967            @Override
4968            public JournalArticle fetchByLayoutUuid_Last(String layoutUuid,
4969                    OrderByComparator orderByComparator) throws SystemException {
4970                    int count = countByLayoutUuid(layoutUuid);
4971    
4972                    if (count == 0) {
4973                            return null;
4974                    }
4975    
4976                    List<JournalArticle> list = findByLayoutUuid(layoutUuid, count - 1,
4977                                    count, orderByComparator);
4978    
4979                    if (!list.isEmpty()) {
4980                            return list.get(0);
4981                    }
4982    
4983                    return null;
4984            }
4985    
4986            /**
4987             * Returns the journal articles before and after the current journal article in the ordered set where layoutUuid = &#63;.
4988             *
4989             * @param id the primary key of the current journal article
4990             * @param layoutUuid the layout uuid
4991             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4992             * @return the previous, current, and next journal article
4993             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
4994             * @throws SystemException if a system exception occurred
4995             */
4996            @Override
4997            public JournalArticle[] findByLayoutUuid_PrevAndNext(long id,
4998                    String layoutUuid, OrderByComparator orderByComparator)
4999                    throws NoSuchArticleException, SystemException {
5000                    JournalArticle journalArticle = findByPrimaryKey(id);
5001    
5002                    Session session = null;
5003    
5004                    try {
5005                            session = openSession();
5006    
5007                            JournalArticle[] array = new JournalArticleImpl[3];
5008    
5009                            array[0] = getByLayoutUuid_PrevAndNext(session, journalArticle,
5010                                            layoutUuid, orderByComparator, true);
5011    
5012                            array[1] = journalArticle;
5013    
5014                            array[2] = getByLayoutUuid_PrevAndNext(session, journalArticle,
5015                                            layoutUuid, orderByComparator, false);
5016    
5017                            return array;
5018                    }
5019                    catch (Exception e) {
5020                            throw processException(e);
5021                    }
5022                    finally {
5023                            closeSession(session);
5024                    }
5025            }
5026    
5027            protected JournalArticle getByLayoutUuid_PrevAndNext(Session session,
5028                    JournalArticle journalArticle, String layoutUuid,
5029                    OrderByComparator orderByComparator, boolean previous) {
5030                    StringBundler query = null;
5031    
5032                    if (orderByComparator != null) {
5033                            query = new StringBundler(6 +
5034                                            (orderByComparator.getOrderByFields().length * 6));
5035                    }
5036                    else {
5037                            query = new StringBundler(3);
5038                    }
5039    
5040                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
5041    
5042                    boolean bindLayoutUuid = false;
5043    
5044                    if (layoutUuid == null) {
5045                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
5046                    }
5047                    else if (layoutUuid.equals(StringPool.BLANK)) {
5048                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
5049                    }
5050                    else {
5051                            bindLayoutUuid = true;
5052    
5053                            query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
5054                    }
5055    
5056                    if (orderByComparator != null) {
5057                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5058    
5059                            if (orderByConditionFields.length > 0) {
5060                                    query.append(WHERE_AND);
5061                            }
5062    
5063                            for (int i = 0; i < orderByConditionFields.length; i++) {
5064                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5065                                    query.append(orderByConditionFields[i]);
5066    
5067                                    if ((i + 1) < orderByConditionFields.length) {
5068                                            if (orderByComparator.isAscending() ^ previous) {
5069                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5070                                            }
5071                                            else {
5072                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5073                                            }
5074                                    }
5075                                    else {
5076                                            if (orderByComparator.isAscending() ^ previous) {
5077                                                    query.append(WHERE_GREATER_THAN);
5078                                            }
5079                                            else {
5080                                                    query.append(WHERE_LESSER_THAN);
5081                                            }
5082                                    }
5083                            }
5084    
5085                            query.append(ORDER_BY_CLAUSE);
5086    
5087                            String[] orderByFields = orderByComparator.getOrderByFields();
5088    
5089                            for (int i = 0; i < orderByFields.length; i++) {
5090                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5091                                    query.append(orderByFields[i]);
5092    
5093                                    if ((i + 1) < orderByFields.length) {
5094                                            if (orderByComparator.isAscending() ^ previous) {
5095                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5096                                            }
5097                                            else {
5098                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5099                                            }
5100                                    }
5101                                    else {
5102                                            if (orderByComparator.isAscending() ^ previous) {
5103                                                    query.append(ORDER_BY_ASC);
5104                                            }
5105                                            else {
5106                                                    query.append(ORDER_BY_DESC);
5107                                            }
5108                                    }
5109                            }
5110                    }
5111                    else {
5112                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
5113                    }
5114    
5115                    String sql = query.toString();
5116    
5117                    Query q = session.createQuery(sql);
5118    
5119                    q.setFirstResult(0);
5120                    q.setMaxResults(2);
5121    
5122                    QueryPos qPos = QueryPos.getInstance(q);
5123    
5124                    if (bindLayoutUuid) {
5125                            qPos.add(layoutUuid);
5126                    }
5127    
5128                    if (orderByComparator != null) {
5129                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
5130    
5131                            for (Object value : values) {
5132                                    qPos.add(value);
5133                            }
5134                    }
5135    
5136                    List<JournalArticle> list = q.list();
5137    
5138                    if (list.size() == 2) {
5139                            return list.get(1);
5140                    }
5141                    else {
5142                            return null;
5143                    }
5144            }
5145    
5146            /**
5147             * Removes all the journal articles where layoutUuid = &#63; from the database.
5148             *
5149             * @param layoutUuid the layout uuid
5150             * @throws SystemException if a system exception occurred
5151             */
5152            @Override
5153            public void removeByLayoutUuid(String layoutUuid) throws SystemException {
5154                    for (JournalArticle journalArticle : findByLayoutUuid(layoutUuid,
5155                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5156                            remove(journalArticle);
5157                    }
5158            }
5159    
5160            /**
5161             * Returns the number of journal articles where layoutUuid = &#63;.
5162             *
5163             * @param layoutUuid the layout uuid
5164             * @return the number of matching journal articles
5165             * @throws SystemException if a system exception occurred
5166             */
5167            @Override
5168            public int countByLayoutUuid(String layoutUuid) throws SystemException {
5169                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LAYOUTUUID;
5170    
5171                    Object[] finderArgs = new Object[] { layoutUuid };
5172    
5173                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5174                                    this);
5175    
5176                    if (count == null) {
5177                            StringBundler query = new StringBundler(2);
5178    
5179                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
5180    
5181                            boolean bindLayoutUuid = false;
5182    
5183                            if (layoutUuid == null) {
5184                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1);
5185                            }
5186                            else if (layoutUuid.equals(StringPool.BLANK)) {
5187                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3);
5188                            }
5189                            else {
5190                                    bindLayoutUuid = true;
5191    
5192                                    query.append(_FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2);
5193                            }
5194    
5195                            String sql = query.toString();
5196    
5197                            Session session = null;
5198    
5199                            try {
5200                                    session = openSession();
5201    
5202                                    Query q = session.createQuery(sql);
5203    
5204                                    QueryPos qPos = QueryPos.getInstance(q);
5205    
5206                                    if (bindLayoutUuid) {
5207                                            qPos.add(layoutUuid);
5208                                    }
5209    
5210                                    count = (Long)q.uniqueResult();
5211    
5212                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5213                            }
5214                            catch (Exception e) {
5215                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5216    
5217                                    throw processException(e);
5218                            }
5219                            finally {
5220                                    closeSession(session);
5221                            }
5222                    }
5223    
5224                    return count.intValue();
5225            }
5226    
5227            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_1 = "journalArticle.layoutUuid IS NULL";
5228            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_2 = "journalArticle.layoutUuid = ?";
5229            private static final String _FINDER_COLUMN_LAYOUTUUID_LAYOUTUUID_3 = "(journalArticle.layoutUuid IS NULL OR journalArticle.layoutUuid = '')";
5230            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SMALLIMAGEID =
5231                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5232                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
5233                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5234                            "findBySmallImageId",
5235                            new String[] {
5236                                    Long.class.getName(),
5237                                    
5238                            Integer.class.getName(), Integer.class.getName(),
5239                                    OrderByComparator.class.getName()
5240                            });
5241            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SMALLIMAGEID =
5242                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5243                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
5244                            JournalArticleImpl.class,
5245                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySmallImageId",
5246                            new String[] { Long.class.getName() },
5247                            JournalArticleModelImpl.SMALLIMAGEID_COLUMN_BITMASK |
5248                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
5249                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
5250            public static final FinderPath FINDER_PATH_COUNT_BY_SMALLIMAGEID = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5251                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5252                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySmallImageId",
5253                            new String[] { Long.class.getName() });
5254    
5255            /**
5256             * Returns all the journal articles where smallImageId = &#63;.
5257             *
5258             * @param smallImageId the small image ID
5259             * @return the matching journal articles
5260             * @throws SystemException if a system exception occurred
5261             */
5262            @Override
5263            public List<JournalArticle> findBySmallImageId(long smallImageId)
5264                    throws SystemException {
5265                    return findBySmallImageId(smallImageId, QueryUtil.ALL_POS,
5266                            QueryUtil.ALL_POS, null);
5267            }
5268    
5269            /**
5270             * Returns a range of all the journal articles where smallImageId = &#63;.
5271             *
5272             * <p>
5273             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
5274             * </p>
5275             *
5276             * @param smallImageId the small image ID
5277             * @param start the lower bound of the range of journal articles
5278             * @param end the upper bound of the range of journal articles (not inclusive)
5279             * @return the range of matching journal articles
5280             * @throws SystemException if a system exception occurred
5281             */
5282            @Override
5283            public List<JournalArticle> findBySmallImageId(long smallImageId,
5284                    int start, int end) throws SystemException {
5285                    return findBySmallImageId(smallImageId, start, end, null);
5286            }
5287    
5288            /**
5289             * Returns an ordered range of all the journal articles where smallImageId = &#63;.
5290             *
5291             * <p>
5292             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
5293             * </p>
5294             *
5295             * @param smallImageId the small image ID
5296             * @param start the lower bound of the range of journal articles
5297             * @param end the upper bound of the range of journal articles (not inclusive)
5298             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5299             * @return the ordered range of matching journal articles
5300             * @throws SystemException if a system exception occurred
5301             */
5302            @Override
5303            public List<JournalArticle> findBySmallImageId(long smallImageId,
5304                    int start, int end, OrderByComparator orderByComparator)
5305                    throws SystemException {
5306                    boolean pagination = true;
5307                    FinderPath finderPath = null;
5308                    Object[] finderArgs = null;
5309    
5310                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5311                                    (orderByComparator == null)) {
5312                            pagination = false;
5313                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SMALLIMAGEID;
5314                            finderArgs = new Object[] { smallImageId };
5315                    }
5316                    else {
5317                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SMALLIMAGEID;
5318                            finderArgs = new Object[] {
5319                                            smallImageId,
5320                                            
5321                                            start, end, orderByComparator
5322                                    };
5323                    }
5324    
5325                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
5326                                    finderArgs, this);
5327    
5328                    if ((list != null) && !list.isEmpty()) {
5329                            for (JournalArticle journalArticle : list) {
5330                                    if ((smallImageId != journalArticle.getSmallImageId())) {
5331                                            list = null;
5332    
5333                                            break;
5334                                    }
5335                            }
5336                    }
5337    
5338                    if (list == null) {
5339                            StringBundler query = null;
5340    
5341                            if (orderByComparator != null) {
5342                                    query = new StringBundler(3 +
5343                                                    (orderByComparator.getOrderByFields().length * 3));
5344                            }
5345                            else {
5346                                    query = new StringBundler(3);
5347                            }
5348    
5349                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
5350    
5351                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
5352    
5353                            if (orderByComparator != null) {
5354                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5355                                            orderByComparator);
5356                            }
5357                            else
5358                             if (pagination) {
5359                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
5360                            }
5361    
5362                            String sql = query.toString();
5363    
5364                            Session session = null;
5365    
5366                            try {
5367                                    session = openSession();
5368    
5369                                    Query q = session.createQuery(sql);
5370    
5371                                    QueryPos qPos = QueryPos.getInstance(q);
5372    
5373                                    qPos.add(smallImageId);
5374    
5375                                    if (!pagination) {
5376                                            list = (List<JournalArticle>)QueryUtil.list(q,
5377                                                            getDialect(), start, end, false);
5378    
5379                                            Collections.sort(list);
5380    
5381                                            list = new UnmodifiableList<JournalArticle>(list);
5382                                    }
5383                                    else {
5384                                            list = (List<JournalArticle>)QueryUtil.list(q,
5385                                                            getDialect(), start, end);
5386                                    }
5387    
5388                                    cacheResult(list);
5389    
5390                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5391                            }
5392                            catch (Exception e) {
5393                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5394    
5395                                    throw processException(e);
5396                            }
5397                            finally {
5398                                    closeSession(session);
5399                            }
5400                    }
5401    
5402                    return list;
5403            }
5404    
5405            /**
5406             * Returns the first journal article in the ordered set where smallImageId = &#63;.
5407             *
5408             * @param smallImageId the small image ID
5409             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5410             * @return the first matching journal article
5411             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
5412             * @throws SystemException if a system exception occurred
5413             */
5414            @Override
5415            public JournalArticle findBySmallImageId_First(long smallImageId,
5416                    OrderByComparator orderByComparator)
5417                    throws NoSuchArticleException, SystemException {
5418                    JournalArticle journalArticle = fetchBySmallImageId_First(smallImageId,
5419                                    orderByComparator);
5420    
5421                    if (journalArticle != null) {
5422                            return journalArticle;
5423                    }
5424    
5425                    StringBundler msg = new StringBundler(4);
5426    
5427                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5428    
5429                    msg.append("smallImageId=");
5430                    msg.append(smallImageId);
5431    
5432                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5433    
5434                    throw new NoSuchArticleException(msg.toString());
5435            }
5436    
5437            /**
5438             * Returns the first journal article in the ordered set where smallImageId = &#63;.
5439             *
5440             * @param smallImageId the small image ID
5441             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5442             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
5443             * @throws SystemException if a system exception occurred
5444             */
5445            @Override
5446            public JournalArticle fetchBySmallImageId_First(long smallImageId,
5447                    OrderByComparator orderByComparator) throws SystemException {
5448                    List<JournalArticle> list = findBySmallImageId(smallImageId, 0, 1,
5449                                    orderByComparator);
5450    
5451                    if (!list.isEmpty()) {
5452                            return list.get(0);
5453                    }
5454    
5455                    return null;
5456            }
5457    
5458            /**
5459             * Returns the last journal article in the ordered set where smallImageId = &#63;.
5460             *
5461             * @param smallImageId the small image ID
5462             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5463             * @return the last matching journal article
5464             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
5465             * @throws SystemException if a system exception occurred
5466             */
5467            @Override
5468            public JournalArticle findBySmallImageId_Last(long smallImageId,
5469                    OrderByComparator orderByComparator)
5470                    throws NoSuchArticleException, SystemException {
5471                    JournalArticle journalArticle = fetchBySmallImageId_Last(smallImageId,
5472                                    orderByComparator);
5473    
5474                    if (journalArticle != null) {
5475                            return journalArticle;
5476                    }
5477    
5478                    StringBundler msg = new StringBundler(4);
5479    
5480                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5481    
5482                    msg.append("smallImageId=");
5483                    msg.append(smallImageId);
5484    
5485                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5486    
5487                    throw new NoSuchArticleException(msg.toString());
5488            }
5489    
5490            /**
5491             * Returns the last journal article in the ordered set where smallImageId = &#63;.
5492             *
5493             * @param smallImageId the small image ID
5494             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5495             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
5496             * @throws SystemException if a system exception occurred
5497             */
5498            @Override
5499            public JournalArticle fetchBySmallImageId_Last(long smallImageId,
5500                    OrderByComparator orderByComparator) throws SystemException {
5501                    int count = countBySmallImageId(smallImageId);
5502    
5503                    if (count == 0) {
5504                            return null;
5505                    }
5506    
5507                    List<JournalArticle> list = findBySmallImageId(smallImageId, count - 1,
5508                                    count, orderByComparator);
5509    
5510                    if (!list.isEmpty()) {
5511                            return list.get(0);
5512                    }
5513    
5514                    return null;
5515            }
5516    
5517            /**
5518             * Returns the journal articles before and after the current journal article in the ordered set where smallImageId = &#63;.
5519             *
5520             * @param id the primary key of the current journal article
5521             * @param smallImageId the small image ID
5522             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5523             * @return the previous, current, and next journal article
5524             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
5525             * @throws SystemException if a system exception occurred
5526             */
5527            @Override
5528            public JournalArticle[] findBySmallImageId_PrevAndNext(long id,
5529                    long smallImageId, OrderByComparator orderByComparator)
5530                    throws NoSuchArticleException, SystemException {
5531                    JournalArticle journalArticle = findByPrimaryKey(id);
5532    
5533                    Session session = null;
5534    
5535                    try {
5536                            session = openSession();
5537    
5538                            JournalArticle[] array = new JournalArticleImpl[3];
5539    
5540                            array[0] = getBySmallImageId_PrevAndNext(session, journalArticle,
5541                                            smallImageId, orderByComparator, true);
5542    
5543                            array[1] = journalArticle;
5544    
5545                            array[2] = getBySmallImageId_PrevAndNext(session, journalArticle,
5546                                            smallImageId, orderByComparator, false);
5547    
5548                            return array;
5549                    }
5550                    catch (Exception e) {
5551                            throw processException(e);
5552                    }
5553                    finally {
5554                            closeSession(session);
5555                    }
5556            }
5557    
5558            protected JournalArticle getBySmallImageId_PrevAndNext(Session session,
5559                    JournalArticle journalArticle, long smallImageId,
5560                    OrderByComparator orderByComparator, boolean previous) {
5561                    StringBundler query = null;
5562    
5563                    if (orderByComparator != null) {
5564                            query = new StringBundler(6 +
5565                                            (orderByComparator.getOrderByFields().length * 6));
5566                    }
5567                    else {
5568                            query = new StringBundler(3);
5569                    }
5570    
5571                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
5572    
5573                    query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
5574    
5575                    if (orderByComparator != null) {
5576                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5577    
5578                            if (orderByConditionFields.length > 0) {
5579                                    query.append(WHERE_AND);
5580                            }
5581    
5582                            for (int i = 0; i < orderByConditionFields.length; i++) {
5583                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5584                                    query.append(orderByConditionFields[i]);
5585    
5586                                    if ((i + 1) < orderByConditionFields.length) {
5587                                            if (orderByComparator.isAscending() ^ previous) {
5588                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5589                                            }
5590                                            else {
5591                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5592                                            }
5593                                    }
5594                                    else {
5595                                            if (orderByComparator.isAscending() ^ previous) {
5596                                                    query.append(WHERE_GREATER_THAN);
5597                                            }
5598                                            else {
5599                                                    query.append(WHERE_LESSER_THAN);
5600                                            }
5601                                    }
5602                            }
5603    
5604                            query.append(ORDER_BY_CLAUSE);
5605    
5606                            String[] orderByFields = orderByComparator.getOrderByFields();
5607    
5608                            for (int i = 0; i < orderByFields.length; i++) {
5609                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5610                                    query.append(orderByFields[i]);
5611    
5612                                    if ((i + 1) < orderByFields.length) {
5613                                            if (orderByComparator.isAscending() ^ previous) {
5614                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5615                                            }
5616                                            else {
5617                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5618                                            }
5619                                    }
5620                                    else {
5621                                            if (orderByComparator.isAscending() ^ previous) {
5622                                                    query.append(ORDER_BY_ASC);
5623                                            }
5624                                            else {
5625                                                    query.append(ORDER_BY_DESC);
5626                                            }
5627                                    }
5628                            }
5629                    }
5630                    else {
5631                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
5632                    }
5633    
5634                    String sql = query.toString();
5635    
5636                    Query q = session.createQuery(sql);
5637    
5638                    q.setFirstResult(0);
5639                    q.setMaxResults(2);
5640    
5641                    QueryPos qPos = QueryPos.getInstance(q);
5642    
5643                    qPos.add(smallImageId);
5644    
5645                    if (orderByComparator != null) {
5646                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
5647    
5648                            for (Object value : values) {
5649                                    qPos.add(value);
5650                            }
5651                    }
5652    
5653                    List<JournalArticle> list = q.list();
5654    
5655                    if (list.size() == 2) {
5656                            return list.get(1);
5657                    }
5658                    else {
5659                            return null;
5660                    }
5661            }
5662    
5663            /**
5664             * Removes all the journal articles where smallImageId = &#63; from the database.
5665             *
5666             * @param smallImageId the small image ID
5667             * @throws SystemException if a system exception occurred
5668             */
5669            @Override
5670            public void removeBySmallImageId(long smallImageId)
5671                    throws SystemException {
5672                    for (JournalArticle journalArticle : findBySmallImageId(smallImageId,
5673                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5674                            remove(journalArticle);
5675                    }
5676            }
5677    
5678            /**
5679             * Returns the number of journal articles where smallImageId = &#63;.
5680             *
5681             * @param smallImageId the small image ID
5682             * @return the number of matching journal articles
5683             * @throws SystemException if a system exception occurred
5684             */
5685            @Override
5686            public int countBySmallImageId(long smallImageId) throws SystemException {
5687                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SMALLIMAGEID;
5688    
5689                    Object[] finderArgs = new Object[] { smallImageId };
5690    
5691                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5692                                    this);
5693    
5694                    if (count == null) {
5695                            StringBundler query = new StringBundler(2);
5696    
5697                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
5698    
5699                            query.append(_FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2);
5700    
5701                            String sql = query.toString();
5702    
5703                            Session session = null;
5704    
5705                            try {
5706                                    session = openSession();
5707    
5708                                    Query q = session.createQuery(sql);
5709    
5710                                    QueryPos qPos = QueryPos.getInstance(q);
5711    
5712                                    qPos.add(smallImageId);
5713    
5714                                    count = (Long)q.uniqueResult();
5715    
5716                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5717                            }
5718                            catch (Exception e) {
5719                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5720    
5721                                    throw processException(e);
5722                            }
5723                            finally {
5724                                    closeSession(session);
5725                            }
5726                    }
5727    
5728                    return count.intValue();
5729            }
5730    
5731            private static final String _FINDER_COLUMN_SMALLIMAGEID_SMALLIMAGEID_2 = "journalArticle.smallImageId = ?";
5732            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5733                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
5734                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5735                            "findByR_ST",
5736                            new String[] {
5737                                    Long.class.getName(), Integer.class.getName(),
5738                                    
5739                            Integer.class.getName(), Integer.class.getName(),
5740                                    OrderByComparator.class.getName()
5741                            });
5742            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5743                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
5744                            JournalArticleImpl.class,
5745                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_ST",
5746                            new String[] { Long.class.getName(), Integer.class.getName() },
5747                            JournalArticleModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
5748                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
5749                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
5750                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
5751            public static final FinderPath FINDER_PATH_COUNT_BY_R_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
5752                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5753                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_ST",
5754                            new String[] { Long.class.getName(), Integer.class.getName() });
5755    
5756            /**
5757             * Returns all the journal articles where resourcePrimKey = &#63; and status = &#63;.
5758             *
5759             * @param resourcePrimKey the resource prim key
5760             * @param status the status
5761             * @return the matching journal articles
5762             * @throws SystemException if a system exception occurred
5763             */
5764            @Override
5765            public List<JournalArticle> findByR_ST(long resourcePrimKey, int status)
5766                    throws SystemException {
5767                    return findByR_ST(resourcePrimKey, status, QueryUtil.ALL_POS,
5768                            QueryUtil.ALL_POS, null);
5769            }
5770    
5771            /**
5772             * Returns a range of all the journal articles where resourcePrimKey = &#63; and status = &#63;.
5773             *
5774             * <p>
5775             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
5776             * </p>
5777             *
5778             * @param resourcePrimKey the resource prim key
5779             * @param status the status
5780             * @param start the lower bound of the range of journal articles
5781             * @param end the upper bound of the range of journal articles (not inclusive)
5782             * @return the range of matching journal articles
5783             * @throws SystemException if a system exception occurred
5784             */
5785            @Override
5786            public List<JournalArticle> findByR_ST(long resourcePrimKey, int status,
5787                    int start, int end) throws SystemException {
5788                    return findByR_ST(resourcePrimKey, status, start, end, null);
5789            }
5790    
5791            /**
5792             * Returns an ordered range of all the journal articles where resourcePrimKey = &#63; and status = &#63;.
5793             *
5794             * <p>
5795             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
5796             * </p>
5797             *
5798             * @param resourcePrimKey the resource prim key
5799             * @param status the status
5800             * @param start the lower bound of the range of journal articles
5801             * @param end the upper bound of the range of journal articles (not inclusive)
5802             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5803             * @return the ordered range of matching journal articles
5804             * @throws SystemException if a system exception occurred
5805             */
5806            @Override
5807            public List<JournalArticle> findByR_ST(long resourcePrimKey, int status,
5808                    int start, int end, OrderByComparator orderByComparator)
5809                    throws SystemException {
5810                    boolean pagination = true;
5811                    FinderPath finderPath = null;
5812                    Object[] finderArgs = null;
5813    
5814                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5815                                    (orderByComparator == null)) {
5816                            pagination = false;
5817                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_ST;
5818                            finderArgs = new Object[] { resourcePrimKey, status };
5819                    }
5820                    else {
5821                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_ST;
5822                            finderArgs = new Object[] {
5823                                            resourcePrimKey, status,
5824                                            
5825                                            start, end, orderByComparator
5826                                    };
5827                    }
5828    
5829                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
5830                                    finderArgs, this);
5831    
5832                    if ((list != null) && !list.isEmpty()) {
5833                            for (JournalArticle journalArticle : list) {
5834                                    if ((resourcePrimKey != journalArticle.getResourcePrimKey()) ||
5835                                                    (status != journalArticle.getStatus())) {
5836                                            list = null;
5837    
5838                                            break;
5839                                    }
5840                            }
5841                    }
5842    
5843                    if (list == null) {
5844                            StringBundler query = null;
5845    
5846                            if (orderByComparator != null) {
5847                                    query = new StringBundler(4 +
5848                                                    (orderByComparator.getOrderByFields().length * 3));
5849                            }
5850                            else {
5851                                    query = new StringBundler(4);
5852                            }
5853    
5854                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
5855    
5856                            query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2);
5857    
5858                            query.append(_FINDER_COLUMN_R_ST_STATUS_2);
5859    
5860                            if (orderByComparator != null) {
5861                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5862                                            orderByComparator);
5863                            }
5864                            else
5865                             if (pagination) {
5866                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
5867                            }
5868    
5869                            String sql = query.toString();
5870    
5871                            Session session = null;
5872    
5873                            try {
5874                                    session = openSession();
5875    
5876                                    Query q = session.createQuery(sql);
5877    
5878                                    QueryPos qPos = QueryPos.getInstance(q);
5879    
5880                                    qPos.add(resourcePrimKey);
5881    
5882                                    qPos.add(status);
5883    
5884                                    if (!pagination) {
5885                                            list = (List<JournalArticle>)QueryUtil.list(q,
5886                                                            getDialect(), start, end, false);
5887    
5888                                            Collections.sort(list);
5889    
5890                                            list = new UnmodifiableList<JournalArticle>(list);
5891                                    }
5892                                    else {
5893                                            list = (List<JournalArticle>)QueryUtil.list(q,
5894                                                            getDialect(), start, end);
5895                                    }
5896    
5897                                    cacheResult(list);
5898    
5899                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5900                            }
5901                            catch (Exception e) {
5902                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5903    
5904                                    throw processException(e);
5905                            }
5906                            finally {
5907                                    closeSession(session);
5908                            }
5909                    }
5910    
5911                    return list;
5912            }
5913    
5914            /**
5915             * Returns the first journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
5916             *
5917             * @param resourcePrimKey the resource prim key
5918             * @param status the status
5919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5920             * @return the first matching journal article
5921             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
5922             * @throws SystemException if a system exception occurred
5923             */
5924            @Override
5925            public JournalArticle findByR_ST_First(long resourcePrimKey, int status,
5926                    OrderByComparator orderByComparator)
5927                    throws NoSuchArticleException, SystemException {
5928                    JournalArticle journalArticle = fetchByR_ST_First(resourcePrimKey,
5929                                    status, orderByComparator);
5930    
5931                    if (journalArticle != null) {
5932                            return journalArticle;
5933                    }
5934    
5935                    StringBundler msg = new StringBundler(6);
5936    
5937                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5938    
5939                    msg.append("resourcePrimKey=");
5940                    msg.append(resourcePrimKey);
5941    
5942                    msg.append(", status=");
5943                    msg.append(status);
5944    
5945                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5946    
5947                    throw new NoSuchArticleException(msg.toString());
5948            }
5949    
5950            /**
5951             * Returns the first journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
5952             *
5953             * @param resourcePrimKey the resource prim key
5954             * @param status the status
5955             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5956             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
5957             * @throws SystemException if a system exception occurred
5958             */
5959            @Override
5960            public JournalArticle fetchByR_ST_First(long resourcePrimKey, int status,
5961                    OrderByComparator orderByComparator) throws SystemException {
5962                    List<JournalArticle> list = findByR_ST(resourcePrimKey, status, 0, 1,
5963                                    orderByComparator);
5964    
5965                    if (!list.isEmpty()) {
5966                            return list.get(0);
5967                    }
5968    
5969                    return null;
5970            }
5971    
5972            /**
5973             * Returns the last journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
5974             *
5975             * @param resourcePrimKey the resource prim key
5976             * @param status the status
5977             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5978             * @return the last matching journal article
5979             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
5980             * @throws SystemException if a system exception occurred
5981             */
5982            @Override
5983            public JournalArticle findByR_ST_Last(long resourcePrimKey, int status,
5984                    OrderByComparator orderByComparator)
5985                    throws NoSuchArticleException, SystemException {
5986                    JournalArticle journalArticle = fetchByR_ST_Last(resourcePrimKey,
5987                                    status, orderByComparator);
5988    
5989                    if (journalArticle != null) {
5990                            return journalArticle;
5991                    }
5992    
5993                    StringBundler msg = new StringBundler(6);
5994    
5995                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5996    
5997                    msg.append("resourcePrimKey=");
5998                    msg.append(resourcePrimKey);
5999    
6000                    msg.append(", status=");
6001                    msg.append(status);
6002    
6003                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6004    
6005                    throw new NoSuchArticleException(msg.toString());
6006            }
6007    
6008            /**
6009             * Returns the last journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
6010             *
6011             * @param resourcePrimKey the resource prim key
6012             * @param status the status
6013             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6014             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
6015             * @throws SystemException if a system exception occurred
6016             */
6017            @Override
6018            public JournalArticle fetchByR_ST_Last(long resourcePrimKey, int status,
6019                    OrderByComparator orderByComparator) throws SystemException {
6020                    int count = countByR_ST(resourcePrimKey, status);
6021    
6022                    if (count == 0) {
6023                            return null;
6024                    }
6025    
6026                    List<JournalArticle> list = findByR_ST(resourcePrimKey, status,
6027                                    count - 1, count, orderByComparator);
6028    
6029                    if (!list.isEmpty()) {
6030                            return list.get(0);
6031                    }
6032    
6033                    return null;
6034            }
6035    
6036            /**
6037             * Returns the journal articles before and after the current journal article in the ordered set where resourcePrimKey = &#63; and status = &#63;.
6038             *
6039             * @param id the primary key of the current journal article
6040             * @param resourcePrimKey the resource prim key
6041             * @param status the status
6042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6043             * @return the previous, current, and next journal article
6044             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
6045             * @throws SystemException if a system exception occurred
6046             */
6047            @Override
6048            public JournalArticle[] findByR_ST_PrevAndNext(long id,
6049                    long resourcePrimKey, int status, OrderByComparator orderByComparator)
6050                    throws NoSuchArticleException, SystemException {
6051                    JournalArticle journalArticle = findByPrimaryKey(id);
6052    
6053                    Session session = null;
6054    
6055                    try {
6056                            session = openSession();
6057    
6058                            JournalArticle[] array = new JournalArticleImpl[3];
6059    
6060                            array[0] = getByR_ST_PrevAndNext(session, journalArticle,
6061                                            resourcePrimKey, status, orderByComparator, true);
6062    
6063                            array[1] = journalArticle;
6064    
6065                            array[2] = getByR_ST_PrevAndNext(session, journalArticle,
6066                                            resourcePrimKey, status, orderByComparator, false);
6067    
6068                            return array;
6069                    }
6070                    catch (Exception e) {
6071                            throw processException(e);
6072                    }
6073                    finally {
6074                            closeSession(session);
6075                    }
6076            }
6077    
6078            protected JournalArticle getByR_ST_PrevAndNext(Session session,
6079                    JournalArticle journalArticle, long resourcePrimKey, int status,
6080                    OrderByComparator orderByComparator, boolean previous) {
6081                    StringBundler query = null;
6082    
6083                    if (orderByComparator != null) {
6084                            query = new StringBundler(6 +
6085                                            (orderByComparator.getOrderByFields().length * 6));
6086                    }
6087                    else {
6088                            query = new StringBundler(3);
6089                    }
6090    
6091                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
6092    
6093                    query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2);
6094    
6095                    query.append(_FINDER_COLUMN_R_ST_STATUS_2);
6096    
6097                    if (orderByComparator != null) {
6098                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6099    
6100                            if (orderByConditionFields.length > 0) {
6101                                    query.append(WHERE_AND);
6102                            }
6103    
6104                            for (int i = 0; i < orderByConditionFields.length; i++) {
6105                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6106                                    query.append(orderByConditionFields[i]);
6107    
6108                                    if ((i + 1) < orderByConditionFields.length) {
6109                                            if (orderByComparator.isAscending() ^ previous) {
6110                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6111                                            }
6112                                            else {
6113                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6114                                            }
6115                                    }
6116                                    else {
6117                                            if (orderByComparator.isAscending() ^ previous) {
6118                                                    query.append(WHERE_GREATER_THAN);
6119                                            }
6120                                            else {
6121                                                    query.append(WHERE_LESSER_THAN);
6122                                            }
6123                                    }
6124                            }
6125    
6126                            query.append(ORDER_BY_CLAUSE);
6127    
6128                            String[] orderByFields = orderByComparator.getOrderByFields();
6129    
6130                            for (int i = 0; i < orderByFields.length; i++) {
6131                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6132                                    query.append(orderByFields[i]);
6133    
6134                                    if ((i + 1) < orderByFields.length) {
6135                                            if (orderByComparator.isAscending() ^ previous) {
6136                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6137                                            }
6138                                            else {
6139                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6140                                            }
6141                                    }
6142                                    else {
6143                                            if (orderByComparator.isAscending() ^ previous) {
6144                                                    query.append(ORDER_BY_ASC);
6145                                            }
6146                                            else {
6147                                                    query.append(ORDER_BY_DESC);
6148                                            }
6149                                    }
6150                            }
6151                    }
6152                    else {
6153                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6154                    }
6155    
6156                    String sql = query.toString();
6157    
6158                    Query q = session.createQuery(sql);
6159    
6160                    q.setFirstResult(0);
6161                    q.setMaxResults(2);
6162    
6163                    QueryPos qPos = QueryPos.getInstance(q);
6164    
6165                    qPos.add(resourcePrimKey);
6166    
6167                    qPos.add(status);
6168    
6169                    if (orderByComparator != null) {
6170                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
6171    
6172                            for (Object value : values) {
6173                                    qPos.add(value);
6174                            }
6175                    }
6176    
6177                    List<JournalArticle> list = q.list();
6178    
6179                    if (list.size() == 2) {
6180                            return list.get(1);
6181                    }
6182                    else {
6183                            return null;
6184                    }
6185            }
6186    
6187            /**
6188             * Removes all the journal articles where resourcePrimKey = &#63; and status = &#63; from the database.
6189             *
6190             * @param resourcePrimKey the resource prim key
6191             * @param status the status
6192             * @throws SystemException if a system exception occurred
6193             */
6194            @Override
6195            public void removeByR_ST(long resourcePrimKey, int status)
6196                    throws SystemException {
6197                    for (JournalArticle journalArticle : findByR_ST(resourcePrimKey,
6198                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6199                            remove(journalArticle);
6200                    }
6201            }
6202    
6203            /**
6204             * Returns the number of journal articles where resourcePrimKey = &#63; and status = &#63;.
6205             *
6206             * @param resourcePrimKey the resource prim key
6207             * @param status the status
6208             * @return the number of matching journal articles
6209             * @throws SystemException if a system exception occurred
6210             */
6211            @Override
6212            public int countByR_ST(long resourcePrimKey, int status)
6213                    throws SystemException {
6214                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_ST;
6215    
6216                    Object[] finderArgs = new Object[] { resourcePrimKey, status };
6217    
6218                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6219                                    this);
6220    
6221                    if (count == null) {
6222                            StringBundler query = new StringBundler(3);
6223    
6224                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
6225    
6226                            query.append(_FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2);
6227    
6228                            query.append(_FINDER_COLUMN_R_ST_STATUS_2);
6229    
6230                            String sql = query.toString();
6231    
6232                            Session session = null;
6233    
6234                            try {
6235                                    session = openSession();
6236    
6237                                    Query q = session.createQuery(sql);
6238    
6239                                    QueryPos qPos = QueryPos.getInstance(q);
6240    
6241                                    qPos.add(resourcePrimKey);
6242    
6243                                    qPos.add(status);
6244    
6245                                    count = (Long)q.uniqueResult();
6246    
6247                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6248                            }
6249                            catch (Exception e) {
6250                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6251    
6252                                    throw processException(e);
6253                            }
6254                            finally {
6255                                    closeSession(session);
6256                            }
6257                    }
6258    
6259                    return count.intValue();
6260            }
6261    
6262            private static final String _FINDER_COLUMN_R_ST_RESOURCEPRIMKEY_2 = "journalArticle.resourcePrimKey = ? AND ";
6263            private static final String _FINDER_COLUMN_R_ST_STATUS_2 = "journalArticle.status = ?";
6264            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
6265                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
6266                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
6267                            "findByG_U",
6268                            new String[] {
6269                                    Long.class.getName(), Long.class.getName(),
6270                                    
6271                            Integer.class.getName(), Integer.class.getName(),
6272                                    OrderByComparator.class.getName()
6273                            });
6274            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
6275                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
6276                            JournalArticleImpl.class,
6277                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
6278                            new String[] { Long.class.getName(), Long.class.getName() },
6279                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
6280                            JournalArticleModelImpl.USERID_COLUMN_BITMASK |
6281                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
6282                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
6283            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
6284                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
6285                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
6286                            new String[] { Long.class.getName(), Long.class.getName() });
6287    
6288            /**
6289             * Returns all the journal articles where groupId = &#63; and userId = &#63;.
6290             *
6291             * @param groupId the group ID
6292             * @param userId the user ID
6293             * @return the matching journal articles
6294             * @throws SystemException if a system exception occurred
6295             */
6296            @Override
6297            public List<JournalArticle> findByG_U(long groupId, long userId)
6298                    throws SystemException {
6299                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
6300                            null);
6301            }
6302    
6303            /**
6304             * Returns a range of all the journal articles where groupId = &#63; and userId = &#63;.
6305             *
6306             * <p>
6307             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
6308             * </p>
6309             *
6310             * @param groupId the group ID
6311             * @param userId the user ID
6312             * @param start the lower bound of the range of journal articles
6313             * @param end the upper bound of the range of journal articles (not inclusive)
6314             * @return the range of matching journal articles
6315             * @throws SystemException if a system exception occurred
6316             */
6317            @Override
6318            public List<JournalArticle> findByG_U(long groupId, long userId, int start,
6319                    int end) throws SystemException {
6320                    return findByG_U(groupId, userId, start, end, null);
6321            }
6322    
6323            /**
6324             * Returns an ordered range of all the journal articles where groupId = &#63; and userId = &#63;.
6325             *
6326             * <p>
6327             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
6328             * </p>
6329             *
6330             * @param groupId the group ID
6331             * @param userId the user ID
6332             * @param start the lower bound of the range of journal articles
6333             * @param end the upper bound of the range of journal articles (not inclusive)
6334             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6335             * @return the ordered range of matching journal articles
6336             * @throws SystemException if a system exception occurred
6337             */
6338            @Override
6339            public List<JournalArticle> findByG_U(long groupId, long userId, int start,
6340                    int end, OrderByComparator orderByComparator) throws SystemException {
6341                    boolean pagination = true;
6342                    FinderPath finderPath = null;
6343                    Object[] finderArgs = null;
6344    
6345                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6346                                    (orderByComparator == null)) {
6347                            pagination = false;
6348                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
6349                            finderArgs = new Object[] { groupId, userId };
6350                    }
6351                    else {
6352                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
6353                            finderArgs = new Object[] {
6354                                            groupId, userId,
6355                                            
6356                                            start, end, orderByComparator
6357                                    };
6358                    }
6359    
6360                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
6361                                    finderArgs, this);
6362    
6363                    if ((list != null) && !list.isEmpty()) {
6364                            for (JournalArticle journalArticle : list) {
6365                                    if ((groupId != journalArticle.getGroupId()) ||
6366                                                    (userId != journalArticle.getUserId())) {
6367                                            list = null;
6368    
6369                                            break;
6370                                    }
6371                            }
6372                    }
6373    
6374                    if (list == null) {
6375                            StringBundler query = null;
6376    
6377                            if (orderByComparator != null) {
6378                                    query = new StringBundler(4 +
6379                                                    (orderByComparator.getOrderByFields().length * 3));
6380                            }
6381                            else {
6382                                    query = new StringBundler(4);
6383                            }
6384    
6385                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
6386    
6387                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
6388    
6389                            query.append(_FINDER_COLUMN_G_U_USERID_2);
6390    
6391                            if (orderByComparator != null) {
6392                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6393                                            orderByComparator);
6394                            }
6395                            else
6396                             if (pagination) {
6397                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6398                            }
6399    
6400                            String sql = query.toString();
6401    
6402                            Session session = null;
6403    
6404                            try {
6405                                    session = openSession();
6406    
6407                                    Query q = session.createQuery(sql);
6408    
6409                                    QueryPos qPos = QueryPos.getInstance(q);
6410    
6411                                    qPos.add(groupId);
6412    
6413                                    qPos.add(userId);
6414    
6415                                    if (!pagination) {
6416                                            list = (List<JournalArticle>)QueryUtil.list(q,
6417                                                            getDialect(), start, end, false);
6418    
6419                                            Collections.sort(list);
6420    
6421                                            list = new UnmodifiableList<JournalArticle>(list);
6422                                    }
6423                                    else {
6424                                            list = (List<JournalArticle>)QueryUtil.list(q,
6425                                                            getDialect(), start, end);
6426                                    }
6427    
6428                                    cacheResult(list);
6429    
6430                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6431                            }
6432                            catch (Exception e) {
6433                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6434    
6435                                    throw processException(e);
6436                            }
6437                            finally {
6438                                    closeSession(session);
6439                            }
6440                    }
6441    
6442                    return list;
6443            }
6444    
6445            /**
6446             * Returns the first journal article in the ordered set where groupId = &#63; and userId = &#63;.
6447             *
6448             * @param groupId the group ID
6449             * @param userId the user ID
6450             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6451             * @return the first matching journal article
6452             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
6453             * @throws SystemException if a system exception occurred
6454             */
6455            @Override
6456            public JournalArticle findByG_U_First(long groupId, long userId,
6457                    OrderByComparator orderByComparator)
6458                    throws NoSuchArticleException, SystemException {
6459                    JournalArticle journalArticle = fetchByG_U_First(groupId, userId,
6460                                    orderByComparator);
6461    
6462                    if (journalArticle != null) {
6463                            return journalArticle;
6464                    }
6465    
6466                    StringBundler msg = new StringBundler(6);
6467    
6468                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6469    
6470                    msg.append("groupId=");
6471                    msg.append(groupId);
6472    
6473                    msg.append(", userId=");
6474                    msg.append(userId);
6475    
6476                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6477    
6478                    throw new NoSuchArticleException(msg.toString());
6479            }
6480    
6481            /**
6482             * Returns the first journal article in the ordered set where groupId = &#63; and userId = &#63;.
6483             *
6484             * @param groupId the group ID
6485             * @param userId the user ID
6486             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6487             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
6488             * @throws SystemException if a system exception occurred
6489             */
6490            @Override
6491            public JournalArticle fetchByG_U_First(long groupId, long userId,
6492                    OrderByComparator orderByComparator) throws SystemException {
6493                    List<JournalArticle> list = findByG_U(groupId, userId, 0, 1,
6494                                    orderByComparator);
6495    
6496                    if (!list.isEmpty()) {
6497                            return list.get(0);
6498                    }
6499    
6500                    return null;
6501            }
6502    
6503            /**
6504             * Returns the last journal article in the ordered set where groupId = &#63; and userId = &#63;.
6505             *
6506             * @param groupId the group ID
6507             * @param userId the user ID
6508             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6509             * @return the last matching journal article
6510             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
6511             * @throws SystemException if a system exception occurred
6512             */
6513            @Override
6514            public JournalArticle findByG_U_Last(long groupId, long userId,
6515                    OrderByComparator orderByComparator)
6516                    throws NoSuchArticleException, SystemException {
6517                    JournalArticle journalArticle = fetchByG_U_Last(groupId, userId,
6518                                    orderByComparator);
6519    
6520                    if (journalArticle != null) {
6521                            return journalArticle;
6522                    }
6523    
6524                    StringBundler msg = new StringBundler(6);
6525    
6526                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6527    
6528                    msg.append("groupId=");
6529                    msg.append(groupId);
6530    
6531                    msg.append(", userId=");
6532                    msg.append(userId);
6533    
6534                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6535    
6536                    throw new NoSuchArticleException(msg.toString());
6537            }
6538    
6539            /**
6540             * Returns the last journal article in the ordered set where groupId = &#63; and userId = &#63;.
6541             *
6542             * @param groupId the group ID
6543             * @param userId the user ID
6544             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6545             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
6546             * @throws SystemException if a system exception occurred
6547             */
6548            @Override
6549            public JournalArticle fetchByG_U_Last(long groupId, long userId,
6550                    OrderByComparator orderByComparator) throws SystemException {
6551                    int count = countByG_U(groupId, userId);
6552    
6553                    if (count == 0) {
6554                            return null;
6555                    }
6556    
6557                    List<JournalArticle> list = findByG_U(groupId, userId, count - 1,
6558                                    count, orderByComparator);
6559    
6560                    if (!list.isEmpty()) {
6561                            return list.get(0);
6562                    }
6563    
6564                    return null;
6565            }
6566    
6567            /**
6568             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and userId = &#63;.
6569             *
6570             * @param id the primary key of the current journal article
6571             * @param groupId the group ID
6572             * @param userId the user ID
6573             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6574             * @return the previous, current, and next journal article
6575             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
6576             * @throws SystemException if a system exception occurred
6577             */
6578            @Override
6579            public JournalArticle[] findByG_U_PrevAndNext(long id, long groupId,
6580                    long userId, OrderByComparator orderByComparator)
6581                    throws NoSuchArticleException, SystemException {
6582                    JournalArticle journalArticle = findByPrimaryKey(id);
6583    
6584                    Session session = null;
6585    
6586                    try {
6587                            session = openSession();
6588    
6589                            JournalArticle[] array = new JournalArticleImpl[3];
6590    
6591                            array[0] = getByG_U_PrevAndNext(session, journalArticle, groupId,
6592                                            userId, orderByComparator, true);
6593    
6594                            array[1] = journalArticle;
6595    
6596                            array[2] = getByG_U_PrevAndNext(session, journalArticle, groupId,
6597                                            userId, orderByComparator, false);
6598    
6599                            return array;
6600                    }
6601                    catch (Exception e) {
6602                            throw processException(e);
6603                    }
6604                    finally {
6605                            closeSession(session);
6606                    }
6607            }
6608    
6609            protected JournalArticle getByG_U_PrevAndNext(Session session,
6610                    JournalArticle journalArticle, long groupId, long userId,
6611                    OrderByComparator orderByComparator, boolean previous) {
6612                    StringBundler query = null;
6613    
6614                    if (orderByComparator != null) {
6615                            query = new StringBundler(6 +
6616                                            (orderByComparator.getOrderByFields().length * 6));
6617                    }
6618                    else {
6619                            query = new StringBundler(3);
6620                    }
6621    
6622                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
6623    
6624                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
6625    
6626                    query.append(_FINDER_COLUMN_G_U_USERID_2);
6627    
6628                    if (orderByComparator != null) {
6629                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6630    
6631                            if (orderByConditionFields.length > 0) {
6632                                    query.append(WHERE_AND);
6633                            }
6634    
6635                            for (int i = 0; i < orderByConditionFields.length; i++) {
6636                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6637                                    query.append(orderByConditionFields[i]);
6638    
6639                                    if ((i + 1) < orderByConditionFields.length) {
6640                                            if (orderByComparator.isAscending() ^ previous) {
6641                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6642                                            }
6643                                            else {
6644                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6645                                            }
6646                                    }
6647                                    else {
6648                                            if (orderByComparator.isAscending() ^ previous) {
6649                                                    query.append(WHERE_GREATER_THAN);
6650                                            }
6651                                            else {
6652                                                    query.append(WHERE_LESSER_THAN);
6653                                            }
6654                                    }
6655                            }
6656    
6657                            query.append(ORDER_BY_CLAUSE);
6658    
6659                            String[] orderByFields = orderByComparator.getOrderByFields();
6660    
6661                            for (int i = 0; i < orderByFields.length; i++) {
6662                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6663                                    query.append(orderByFields[i]);
6664    
6665                                    if ((i + 1) < orderByFields.length) {
6666                                            if (orderByComparator.isAscending() ^ previous) {
6667                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6668                                            }
6669                                            else {
6670                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6671                                            }
6672                                    }
6673                                    else {
6674                                            if (orderByComparator.isAscending() ^ previous) {
6675                                                    query.append(ORDER_BY_ASC);
6676                                            }
6677                                            else {
6678                                                    query.append(ORDER_BY_DESC);
6679                                            }
6680                                    }
6681                            }
6682                    }
6683                    else {
6684                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6685                    }
6686    
6687                    String sql = query.toString();
6688    
6689                    Query q = session.createQuery(sql);
6690    
6691                    q.setFirstResult(0);
6692                    q.setMaxResults(2);
6693    
6694                    QueryPos qPos = QueryPos.getInstance(q);
6695    
6696                    qPos.add(groupId);
6697    
6698                    qPos.add(userId);
6699    
6700                    if (orderByComparator != null) {
6701                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
6702    
6703                            for (Object value : values) {
6704                                    qPos.add(value);
6705                            }
6706                    }
6707    
6708                    List<JournalArticle> list = q.list();
6709    
6710                    if (list.size() == 2) {
6711                            return list.get(1);
6712                    }
6713                    else {
6714                            return null;
6715                    }
6716            }
6717    
6718            /**
6719             * Returns all the journal articles that the user has permission to view where groupId = &#63; and userId = &#63;.
6720             *
6721             * @param groupId the group ID
6722             * @param userId the user ID
6723             * @return the matching journal articles that the user has permission to view
6724             * @throws SystemException if a system exception occurred
6725             */
6726            @Override
6727            public List<JournalArticle> filterFindByG_U(long groupId, long userId)
6728                    throws SystemException {
6729                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
6730                            QueryUtil.ALL_POS, null);
6731            }
6732    
6733            /**
6734             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and userId = &#63;.
6735             *
6736             * <p>
6737             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
6738             * </p>
6739             *
6740             * @param groupId the group ID
6741             * @param userId the user ID
6742             * @param start the lower bound of the range of journal articles
6743             * @param end the upper bound of the range of journal articles (not inclusive)
6744             * @return the range of matching journal articles that the user has permission to view
6745             * @throws SystemException if a system exception occurred
6746             */
6747            @Override
6748            public List<JournalArticle> filterFindByG_U(long groupId, long userId,
6749                    int start, int end) throws SystemException {
6750                    return filterFindByG_U(groupId, userId, start, end, null);
6751            }
6752    
6753            /**
6754             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and userId = &#63;.
6755             *
6756             * <p>
6757             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
6758             * </p>
6759             *
6760             * @param groupId the group ID
6761             * @param userId the user ID
6762             * @param start the lower bound of the range of journal articles
6763             * @param end the upper bound of the range of journal articles (not inclusive)
6764             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6765             * @return the ordered range of matching journal articles that the user has permission to view
6766             * @throws SystemException if a system exception occurred
6767             */
6768            @Override
6769            public List<JournalArticle> filterFindByG_U(long groupId, long userId,
6770                    int start, int end, OrderByComparator orderByComparator)
6771                    throws SystemException {
6772                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6773                            return findByG_U(groupId, userId, start, end, orderByComparator);
6774                    }
6775    
6776                    StringBundler query = null;
6777    
6778                    if (orderByComparator != null) {
6779                            query = new StringBundler(4 +
6780                                            (orderByComparator.getOrderByFields().length * 3));
6781                    }
6782                    else {
6783                            query = new StringBundler(4);
6784                    }
6785    
6786                    if (getDB().isSupportsInlineDistinct()) {
6787                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
6788                    }
6789                    else {
6790                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
6791                    }
6792    
6793                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
6794    
6795                    query.append(_FINDER_COLUMN_G_U_USERID_2);
6796    
6797                    if (!getDB().isSupportsInlineDistinct()) {
6798                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
6799                    }
6800    
6801                    if (orderByComparator != null) {
6802                            if (getDB().isSupportsInlineDistinct()) {
6803                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6804                                            orderByComparator, true);
6805                            }
6806                            else {
6807                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6808                                            orderByComparator, true);
6809                            }
6810                    }
6811                    else {
6812                            if (getDB().isSupportsInlineDistinct()) {
6813                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6814                            }
6815                            else {
6816                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
6817                            }
6818                    }
6819    
6820                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6821                                    JournalArticle.class.getName(),
6822                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6823    
6824                    Session session = null;
6825    
6826                    try {
6827                            session = openSession();
6828    
6829                            SQLQuery q = session.createSQLQuery(sql);
6830    
6831                            if (getDB().isSupportsInlineDistinct()) {
6832                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
6833                            }
6834                            else {
6835                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
6836                            }
6837    
6838                            QueryPos qPos = QueryPos.getInstance(q);
6839    
6840                            qPos.add(groupId);
6841    
6842                            qPos.add(userId);
6843    
6844                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
6845                                    end);
6846                    }
6847                    catch (Exception e) {
6848                            throw processException(e);
6849                    }
6850                    finally {
6851                            closeSession(session);
6852                    }
6853            }
6854    
6855            /**
6856             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and userId = &#63;.
6857             *
6858             * @param id the primary key of the current journal article
6859             * @param groupId the group ID
6860             * @param userId the user ID
6861             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6862             * @return the previous, current, and next journal article
6863             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
6864             * @throws SystemException if a system exception occurred
6865             */
6866            @Override
6867            public JournalArticle[] filterFindByG_U_PrevAndNext(long id, long groupId,
6868                    long userId, OrderByComparator orderByComparator)
6869                    throws NoSuchArticleException, SystemException {
6870                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6871                            return findByG_U_PrevAndNext(id, groupId, userId, orderByComparator);
6872                    }
6873    
6874                    JournalArticle journalArticle = findByPrimaryKey(id);
6875    
6876                    Session session = null;
6877    
6878                    try {
6879                            session = openSession();
6880    
6881                            JournalArticle[] array = new JournalArticleImpl[3];
6882    
6883                            array[0] = filterGetByG_U_PrevAndNext(session, journalArticle,
6884                                            groupId, userId, orderByComparator, true);
6885    
6886                            array[1] = journalArticle;
6887    
6888                            array[2] = filterGetByG_U_PrevAndNext(session, journalArticle,
6889                                            groupId, userId, orderByComparator, false);
6890    
6891                            return array;
6892                    }
6893                    catch (Exception e) {
6894                            throw processException(e);
6895                    }
6896                    finally {
6897                            closeSession(session);
6898                    }
6899            }
6900    
6901            protected JournalArticle filterGetByG_U_PrevAndNext(Session session,
6902                    JournalArticle journalArticle, long groupId, long userId,
6903                    OrderByComparator orderByComparator, boolean previous) {
6904                    StringBundler query = null;
6905    
6906                    if (orderByComparator != null) {
6907                            query = new StringBundler(6 +
6908                                            (orderByComparator.getOrderByFields().length * 6));
6909                    }
6910                    else {
6911                            query = new StringBundler(3);
6912                    }
6913    
6914                    if (getDB().isSupportsInlineDistinct()) {
6915                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
6916                    }
6917                    else {
6918                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
6919                    }
6920    
6921                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
6922    
6923                    query.append(_FINDER_COLUMN_G_U_USERID_2);
6924    
6925                    if (!getDB().isSupportsInlineDistinct()) {
6926                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
6927                    }
6928    
6929                    if (orderByComparator != null) {
6930                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6931    
6932                            if (orderByConditionFields.length > 0) {
6933                                    query.append(WHERE_AND);
6934                            }
6935    
6936                            for (int i = 0; i < orderByConditionFields.length; i++) {
6937                                    if (getDB().isSupportsInlineDistinct()) {
6938                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6939                                    }
6940                                    else {
6941                                            query.append(_ORDER_BY_ENTITY_TABLE);
6942                                    }
6943    
6944                                    query.append(orderByConditionFields[i]);
6945    
6946                                    if ((i + 1) < orderByConditionFields.length) {
6947                                            if (orderByComparator.isAscending() ^ previous) {
6948                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6949                                            }
6950                                            else {
6951                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6952                                            }
6953                                    }
6954                                    else {
6955                                            if (orderByComparator.isAscending() ^ previous) {
6956                                                    query.append(WHERE_GREATER_THAN);
6957                                            }
6958                                            else {
6959                                                    query.append(WHERE_LESSER_THAN);
6960                                            }
6961                                    }
6962                            }
6963    
6964                            query.append(ORDER_BY_CLAUSE);
6965    
6966                            String[] orderByFields = orderByComparator.getOrderByFields();
6967    
6968                            for (int i = 0; i < orderByFields.length; i++) {
6969                                    if (getDB().isSupportsInlineDistinct()) {
6970                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6971                                    }
6972                                    else {
6973                                            query.append(_ORDER_BY_ENTITY_TABLE);
6974                                    }
6975    
6976                                    query.append(orderByFields[i]);
6977    
6978                                    if ((i + 1) < orderByFields.length) {
6979                                            if (orderByComparator.isAscending() ^ previous) {
6980                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6981                                            }
6982                                            else {
6983                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6984                                            }
6985                                    }
6986                                    else {
6987                                            if (orderByComparator.isAscending() ^ previous) {
6988                                                    query.append(ORDER_BY_ASC);
6989                                            }
6990                                            else {
6991                                                    query.append(ORDER_BY_DESC);
6992                                            }
6993                                    }
6994                            }
6995                    }
6996                    else {
6997                            if (getDB().isSupportsInlineDistinct()) {
6998                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
6999                            }
7000                            else {
7001                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
7002                            }
7003                    }
7004    
7005                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7006                                    JournalArticle.class.getName(),
7007                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7008    
7009                    SQLQuery q = session.createSQLQuery(sql);
7010    
7011                    q.setFirstResult(0);
7012                    q.setMaxResults(2);
7013    
7014                    if (getDB().isSupportsInlineDistinct()) {
7015                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
7016                    }
7017                    else {
7018                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
7019                    }
7020    
7021                    QueryPos qPos = QueryPos.getInstance(q);
7022    
7023                    qPos.add(groupId);
7024    
7025                    qPos.add(userId);
7026    
7027                    if (orderByComparator != null) {
7028                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
7029    
7030                            for (Object value : values) {
7031                                    qPos.add(value);
7032                            }
7033                    }
7034    
7035                    List<JournalArticle> list = q.list();
7036    
7037                    if (list.size() == 2) {
7038                            return list.get(1);
7039                    }
7040                    else {
7041                            return null;
7042                    }
7043            }
7044    
7045            /**
7046             * Removes all the journal articles where groupId = &#63; and userId = &#63; from the database.
7047             *
7048             * @param groupId the group ID
7049             * @param userId the user ID
7050             * @throws SystemException if a system exception occurred
7051             */
7052            @Override
7053            public void removeByG_U(long groupId, long userId)
7054                    throws SystemException {
7055                    for (JournalArticle journalArticle : findByG_U(groupId, userId,
7056                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7057                            remove(journalArticle);
7058                    }
7059            }
7060    
7061            /**
7062             * Returns the number of journal articles where groupId = &#63; and userId = &#63;.
7063             *
7064             * @param groupId the group ID
7065             * @param userId the user ID
7066             * @return the number of matching journal articles
7067             * @throws SystemException if a system exception occurred
7068             */
7069            @Override
7070            public int countByG_U(long groupId, long userId) throws SystemException {
7071                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
7072    
7073                    Object[] finderArgs = new Object[] { groupId, userId };
7074    
7075                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7076                                    this);
7077    
7078                    if (count == null) {
7079                            StringBundler query = new StringBundler(3);
7080    
7081                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
7082    
7083                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
7084    
7085                            query.append(_FINDER_COLUMN_G_U_USERID_2);
7086    
7087                            String sql = query.toString();
7088    
7089                            Session session = null;
7090    
7091                            try {
7092                                    session = openSession();
7093    
7094                                    Query q = session.createQuery(sql);
7095    
7096                                    QueryPos qPos = QueryPos.getInstance(q);
7097    
7098                                    qPos.add(groupId);
7099    
7100                                    qPos.add(userId);
7101    
7102                                    count = (Long)q.uniqueResult();
7103    
7104                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7105                            }
7106                            catch (Exception e) {
7107                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7108    
7109                                    throw processException(e);
7110                            }
7111                            finally {
7112                                    closeSession(session);
7113                            }
7114                    }
7115    
7116                    return count.intValue();
7117            }
7118    
7119            /**
7120             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and userId = &#63;.
7121             *
7122             * @param groupId the group ID
7123             * @param userId the user ID
7124             * @return the number of matching journal articles that the user has permission to view
7125             * @throws SystemException if a system exception occurred
7126             */
7127            @Override
7128            public int filterCountByG_U(long groupId, long userId)
7129                    throws SystemException {
7130                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7131                            return countByG_U(groupId, userId);
7132                    }
7133    
7134                    StringBundler query = new StringBundler(3);
7135    
7136                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
7137    
7138                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
7139    
7140                    query.append(_FINDER_COLUMN_G_U_USERID_2);
7141    
7142                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7143                                    JournalArticle.class.getName(),
7144                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7145    
7146                    Session session = null;
7147    
7148                    try {
7149                            session = openSession();
7150    
7151                            SQLQuery q = session.createSQLQuery(sql);
7152    
7153                            q.addScalar(COUNT_COLUMN_NAME,
7154                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7155    
7156                            QueryPos qPos = QueryPos.getInstance(q);
7157    
7158                            qPos.add(groupId);
7159    
7160                            qPos.add(userId);
7161    
7162                            Long count = (Long)q.uniqueResult();
7163    
7164                            return count.intValue();
7165                    }
7166                    catch (Exception e) {
7167                            throw processException(e);
7168                    }
7169                    finally {
7170                            closeSession(session);
7171                    }
7172            }
7173    
7174            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "journalArticle.groupId = ? AND ";
7175            private static final String _FINDER_COLUMN_G_U_USERID_2 = "journalArticle.userId = ?";
7176            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
7177                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
7178                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
7179                            "findByG_F",
7180                            new String[] {
7181                                    Long.class.getName(), Long.class.getName(),
7182                                    
7183                            Integer.class.getName(), Integer.class.getName(),
7184                                    OrderByComparator.class.getName()
7185                            });
7186            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
7187                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
7188                            JournalArticleImpl.class,
7189                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_F",
7190                            new String[] { Long.class.getName(), Long.class.getName() },
7191                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
7192                            JournalArticleModelImpl.FOLDERID_COLUMN_BITMASK |
7193                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
7194                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
7195            public static final FinderPath FINDER_PATH_COUNT_BY_G_F = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
7196                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
7197                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F",
7198                            new String[] { Long.class.getName(), Long.class.getName() });
7199            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
7200                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
7201                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_F",
7202                            new String[] { Long.class.getName(), Long.class.getName() });
7203    
7204            /**
7205             * Returns all the journal articles where groupId = &#63; and folderId = &#63;.
7206             *
7207             * @param groupId the group ID
7208             * @param folderId the folder ID
7209             * @return the matching journal articles
7210             * @throws SystemException if a system exception occurred
7211             */
7212            @Override
7213            public List<JournalArticle> findByG_F(long groupId, long folderId)
7214                    throws SystemException {
7215                    return findByG_F(groupId, folderId, QueryUtil.ALL_POS,
7216                            QueryUtil.ALL_POS, null);
7217            }
7218    
7219            /**
7220             * Returns a range of all the journal articles where groupId = &#63; and folderId = &#63;.
7221             *
7222             * <p>
7223             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
7224             * </p>
7225             *
7226             * @param groupId the group ID
7227             * @param folderId the folder ID
7228             * @param start the lower bound of the range of journal articles
7229             * @param end the upper bound of the range of journal articles (not inclusive)
7230             * @return the range of matching journal articles
7231             * @throws SystemException if a system exception occurred
7232             */
7233            @Override
7234            public List<JournalArticle> findByG_F(long groupId, long folderId,
7235                    int start, int end) throws SystemException {
7236                    return findByG_F(groupId, folderId, start, end, null);
7237            }
7238    
7239            /**
7240             * Returns an ordered range of all the journal articles where groupId = &#63; and folderId = &#63;.
7241             *
7242             * <p>
7243             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
7244             * </p>
7245             *
7246             * @param groupId the group ID
7247             * @param folderId the folder ID
7248             * @param start the lower bound of the range of journal articles
7249             * @param end the upper bound of the range of journal articles (not inclusive)
7250             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7251             * @return the ordered range of matching journal articles
7252             * @throws SystemException if a system exception occurred
7253             */
7254            @Override
7255            public List<JournalArticle> findByG_F(long groupId, long folderId,
7256                    int start, int end, OrderByComparator orderByComparator)
7257                    throws SystemException {
7258                    boolean pagination = true;
7259                    FinderPath finderPath = null;
7260                    Object[] finderArgs = null;
7261    
7262                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7263                                    (orderByComparator == null)) {
7264                            pagination = false;
7265                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F;
7266                            finderArgs = new Object[] { groupId, folderId };
7267                    }
7268                    else {
7269                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F;
7270                            finderArgs = new Object[] {
7271                                            groupId, folderId,
7272                                            
7273                                            start, end, orderByComparator
7274                                    };
7275                    }
7276    
7277                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
7278                                    finderArgs, this);
7279    
7280                    if ((list != null) && !list.isEmpty()) {
7281                            for (JournalArticle journalArticle : list) {
7282                                    if ((groupId != journalArticle.getGroupId()) ||
7283                                                    (folderId != journalArticle.getFolderId())) {
7284                                            list = null;
7285    
7286                                            break;
7287                                    }
7288                            }
7289                    }
7290    
7291                    if (list == null) {
7292                            StringBundler query = null;
7293    
7294                            if (orderByComparator != null) {
7295                                    query = new StringBundler(4 +
7296                                                    (orderByComparator.getOrderByFields().length * 3));
7297                            }
7298                            else {
7299                                    query = new StringBundler(4);
7300                            }
7301    
7302                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
7303    
7304                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
7305    
7306                            query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
7307    
7308                            if (orderByComparator != null) {
7309                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7310                                            orderByComparator);
7311                            }
7312                            else
7313                             if (pagination) {
7314                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
7315                            }
7316    
7317                            String sql = query.toString();
7318    
7319                            Session session = null;
7320    
7321                            try {
7322                                    session = openSession();
7323    
7324                                    Query q = session.createQuery(sql);
7325    
7326                                    QueryPos qPos = QueryPos.getInstance(q);
7327    
7328                                    qPos.add(groupId);
7329    
7330                                    qPos.add(folderId);
7331    
7332                                    if (!pagination) {
7333                                            list = (List<JournalArticle>)QueryUtil.list(q,
7334                                                            getDialect(), start, end, false);
7335    
7336                                            Collections.sort(list);
7337    
7338                                            list = new UnmodifiableList<JournalArticle>(list);
7339                                    }
7340                                    else {
7341                                            list = (List<JournalArticle>)QueryUtil.list(q,
7342                                                            getDialect(), start, end);
7343                                    }
7344    
7345                                    cacheResult(list);
7346    
7347                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7348                            }
7349                            catch (Exception e) {
7350                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7351    
7352                                    throw processException(e);
7353                            }
7354                            finally {
7355                                    closeSession(session);
7356                            }
7357                    }
7358    
7359                    return list;
7360            }
7361    
7362            /**
7363             * Returns the first journal article in the ordered set where groupId = &#63; and folderId = &#63;.
7364             *
7365             * @param groupId the group ID
7366             * @param folderId the folder ID
7367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7368             * @return the first matching journal article
7369             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
7370             * @throws SystemException if a system exception occurred
7371             */
7372            @Override
7373            public JournalArticle findByG_F_First(long groupId, long folderId,
7374                    OrderByComparator orderByComparator)
7375                    throws NoSuchArticleException, SystemException {
7376                    JournalArticle journalArticle = fetchByG_F_First(groupId, folderId,
7377                                    orderByComparator);
7378    
7379                    if (journalArticle != null) {
7380                            return journalArticle;
7381                    }
7382    
7383                    StringBundler msg = new StringBundler(6);
7384    
7385                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7386    
7387                    msg.append("groupId=");
7388                    msg.append(groupId);
7389    
7390                    msg.append(", folderId=");
7391                    msg.append(folderId);
7392    
7393                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7394    
7395                    throw new NoSuchArticleException(msg.toString());
7396            }
7397    
7398            /**
7399             * Returns the first journal article in the ordered set where groupId = &#63; and folderId = &#63;.
7400             *
7401             * @param groupId the group ID
7402             * @param folderId the folder ID
7403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7404             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
7405             * @throws SystemException if a system exception occurred
7406             */
7407            @Override
7408            public JournalArticle fetchByG_F_First(long groupId, long folderId,
7409                    OrderByComparator orderByComparator) throws SystemException {
7410                    List<JournalArticle> list = findByG_F(groupId, folderId, 0, 1,
7411                                    orderByComparator);
7412    
7413                    if (!list.isEmpty()) {
7414                            return list.get(0);
7415                    }
7416    
7417                    return null;
7418            }
7419    
7420            /**
7421             * Returns the last journal article in the ordered set where groupId = &#63; and folderId = &#63;.
7422             *
7423             * @param groupId the group ID
7424             * @param folderId the folder ID
7425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7426             * @return the last matching journal article
7427             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
7428             * @throws SystemException if a system exception occurred
7429             */
7430            @Override
7431            public JournalArticle findByG_F_Last(long groupId, long folderId,
7432                    OrderByComparator orderByComparator)
7433                    throws NoSuchArticleException, SystemException {
7434                    JournalArticle journalArticle = fetchByG_F_Last(groupId, folderId,
7435                                    orderByComparator);
7436    
7437                    if (journalArticle != null) {
7438                            return journalArticle;
7439                    }
7440    
7441                    StringBundler msg = new StringBundler(6);
7442    
7443                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7444    
7445                    msg.append("groupId=");
7446                    msg.append(groupId);
7447    
7448                    msg.append(", folderId=");
7449                    msg.append(folderId);
7450    
7451                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7452    
7453                    throw new NoSuchArticleException(msg.toString());
7454            }
7455    
7456            /**
7457             * Returns the last journal article in the ordered set where groupId = &#63; and folderId = &#63;.
7458             *
7459             * @param groupId the group ID
7460             * @param folderId the folder ID
7461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7462             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
7463             * @throws SystemException if a system exception occurred
7464             */
7465            @Override
7466            public JournalArticle fetchByG_F_Last(long groupId, long folderId,
7467                    OrderByComparator orderByComparator) throws SystemException {
7468                    int count = countByG_F(groupId, folderId);
7469    
7470                    if (count == 0) {
7471                            return null;
7472                    }
7473    
7474                    List<JournalArticle> list = findByG_F(groupId, folderId, count - 1,
7475                                    count, orderByComparator);
7476    
7477                    if (!list.isEmpty()) {
7478                            return list.get(0);
7479                    }
7480    
7481                    return null;
7482            }
7483    
7484            /**
7485             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and folderId = &#63;.
7486             *
7487             * @param id the primary key of the current journal article
7488             * @param groupId the group ID
7489             * @param folderId the folder ID
7490             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7491             * @return the previous, current, and next journal article
7492             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
7493             * @throws SystemException if a system exception occurred
7494             */
7495            @Override
7496            public JournalArticle[] findByG_F_PrevAndNext(long id, long groupId,
7497                    long folderId, OrderByComparator orderByComparator)
7498                    throws NoSuchArticleException, SystemException {
7499                    JournalArticle journalArticle = findByPrimaryKey(id);
7500    
7501                    Session session = null;
7502    
7503                    try {
7504                            session = openSession();
7505    
7506                            JournalArticle[] array = new JournalArticleImpl[3];
7507    
7508                            array[0] = getByG_F_PrevAndNext(session, journalArticle, groupId,
7509                                            folderId, orderByComparator, true);
7510    
7511                            array[1] = journalArticle;
7512    
7513                            array[2] = getByG_F_PrevAndNext(session, journalArticle, groupId,
7514                                            folderId, orderByComparator, false);
7515    
7516                            return array;
7517                    }
7518                    catch (Exception e) {
7519                            throw processException(e);
7520                    }
7521                    finally {
7522                            closeSession(session);
7523                    }
7524            }
7525    
7526            protected JournalArticle getByG_F_PrevAndNext(Session session,
7527                    JournalArticle journalArticle, long groupId, long folderId,
7528                    OrderByComparator orderByComparator, boolean previous) {
7529                    StringBundler query = null;
7530    
7531                    if (orderByComparator != null) {
7532                            query = new StringBundler(6 +
7533                                            (orderByComparator.getOrderByFields().length * 6));
7534                    }
7535                    else {
7536                            query = new StringBundler(3);
7537                    }
7538    
7539                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
7540    
7541                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
7542    
7543                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
7544    
7545                    if (orderByComparator != null) {
7546                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7547    
7548                            if (orderByConditionFields.length > 0) {
7549                                    query.append(WHERE_AND);
7550                            }
7551    
7552                            for (int i = 0; i < orderByConditionFields.length; i++) {
7553                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7554                                    query.append(orderByConditionFields[i]);
7555    
7556                                    if ((i + 1) < orderByConditionFields.length) {
7557                                            if (orderByComparator.isAscending() ^ previous) {
7558                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7559                                            }
7560                                            else {
7561                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7562                                            }
7563                                    }
7564                                    else {
7565                                            if (orderByComparator.isAscending() ^ previous) {
7566                                                    query.append(WHERE_GREATER_THAN);
7567                                            }
7568                                            else {
7569                                                    query.append(WHERE_LESSER_THAN);
7570                                            }
7571                                    }
7572                            }
7573    
7574                            query.append(ORDER_BY_CLAUSE);
7575    
7576                            String[] orderByFields = orderByComparator.getOrderByFields();
7577    
7578                            for (int i = 0; i < orderByFields.length; i++) {
7579                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7580                                    query.append(orderByFields[i]);
7581    
7582                                    if ((i + 1) < orderByFields.length) {
7583                                            if (orderByComparator.isAscending() ^ previous) {
7584                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7585                                            }
7586                                            else {
7587                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7588                                            }
7589                                    }
7590                                    else {
7591                                            if (orderByComparator.isAscending() ^ previous) {
7592                                                    query.append(ORDER_BY_ASC);
7593                                            }
7594                                            else {
7595                                                    query.append(ORDER_BY_DESC);
7596                                            }
7597                                    }
7598                            }
7599                    }
7600                    else {
7601                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
7602                    }
7603    
7604                    String sql = query.toString();
7605    
7606                    Query q = session.createQuery(sql);
7607    
7608                    q.setFirstResult(0);
7609                    q.setMaxResults(2);
7610    
7611                    QueryPos qPos = QueryPos.getInstance(q);
7612    
7613                    qPos.add(groupId);
7614    
7615                    qPos.add(folderId);
7616    
7617                    if (orderByComparator != null) {
7618                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
7619    
7620                            for (Object value : values) {
7621                                    qPos.add(value);
7622                            }
7623                    }
7624    
7625                    List<JournalArticle> list = q.list();
7626    
7627                    if (list.size() == 2) {
7628                            return list.get(1);
7629                    }
7630                    else {
7631                            return null;
7632                    }
7633            }
7634    
7635            /**
7636             * Returns all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63;.
7637             *
7638             * @param groupId the group ID
7639             * @param folderId the folder ID
7640             * @return the matching journal articles that the user has permission to view
7641             * @throws SystemException if a system exception occurred
7642             */
7643            @Override
7644            public List<JournalArticle> filterFindByG_F(long groupId, long folderId)
7645                    throws SystemException {
7646                    return filterFindByG_F(groupId, folderId, QueryUtil.ALL_POS,
7647                            QueryUtil.ALL_POS, null);
7648            }
7649    
7650            /**
7651             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63;.
7652             *
7653             * <p>
7654             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
7655             * </p>
7656             *
7657             * @param groupId the group ID
7658             * @param folderId the folder ID
7659             * @param start the lower bound of the range of journal articles
7660             * @param end the upper bound of the range of journal articles (not inclusive)
7661             * @return the range of matching journal articles that the user has permission to view
7662             * @throws SystemException if a system exception occurred
7663             */
7664            @Override
7665            public List<JournalArticle> filterFindByG_F(long groupId, long folderId,
7666                    int start, int end) throws SystemException {
7667                    return filterFindByG_F(groupId, folderId, start, end, null);
7668            }
7669    
7670            /**
7671             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and folderId = &#63;.
7672             *
7673             * <p>
7674             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
7675             * </p>
7676             *
7677             * @param groupId the group ID
7678             * @param folderId the folder ID
7679             * @param start the lower bound of the range of journal articles
7680             * @param end the upper bound of the range of journal articles (not inclusive)
7681             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7682             * @return the ordered range of matching journal articles that the user has permission to view
7683             * @throws SystemException if a system exception occurred
7684             */
7685            @Override
7686            public List<JournalArticle> filterFindByG_F(long groupId, long folderId,
7687                    int start, int end, OrderByComparator orderByComparator)
7688                    throws SystemException {
7689                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7690                            return findByG_F(groupId, folderId, start, end, orderByComparator);
7691                    }
7692    
7693                    StringBundler query = null;
7694    
7695                    if (orderByComparator != null) {
7696                            query = new StringBundler(4 +
7697                                            (orderByComparator.getOrderByFields().length * 3));
7698                    }
7699                    else {
7700                            query = new StringBundler(4);
7701                    }
7702    
7703                    if (getDB().isSupportsInlineDistinct()) {
7704                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
7705                    }
7706                    else {
7707                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
7708                    }
7709    
7710                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
7711    
7712                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
7713    
7714                    if (!getDB().isSupportsInlineDistinct()) {
7715                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
7716                    }
7717    
7718                    if (orderByComparator != null) {
7719                            if (getDB().isSupportsInlineDistinct()) {
7720                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7721                                            orderByComparator, true);
7722                            }
7723                            else {
7724                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7725                                            orderByComparator, true);
7726                            }
7727                    }
7728                    else {
7729                            if (getDB().isSupportsInlineDistinct()) {
7730                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
7731                            }
7732                            else {
7733                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
7734                            }
7735                    }
7736    
7737                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7738                                    JournalArticle.class.getName(),
7739                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7740    
7741                    Session session = null;
7742    
7743                    try {
7744                            session = openSession();
7745    
7746                            SQLQuery q = session.createSQLQuery(sql);
7747    
7748                            if (getDB().isSupportsInlineDistinct()) {
7749                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
7750                            }
7751                            else {
7752                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
7753                            }
7754    
7755                            QueryPos qPos = QueryPos.getInstance(q);
7756    
7757                            qPos.add(groupId);
7758    
7759                            qPos.add(folderId);
7760    
7761                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
7762                                    end);
7763                    }
7764                    catch (Exception e) {
7765                            throw processException(e);
7766                    }
7767                    finally {
7768                            closeSession(session);
7769                    }
7770            }
7771    
7772            /**
7773             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and folderId = &#63;.
7774             *
7775             * @param id the primary key of the current journal article
7776             * @param groupId the group ID
7777             * @param folderId the folder ID
7778             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7779             * @return the previous, current, and next journal article
7780             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
7781             * @throws SystemException if a system exception occurred
7782             */
7783            @Override
7784            public JournalArticle[] filterFindByG_F_PrevAndNext(long id, long groupId,
7785                    long folderId, OrderByComparator orderByComparator)
7786                    throws NoSuchArticleException, SystemException {
7787                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7788                            return findByG_F_PrevAndNext(id, groupId, folderId,
7789                                    orderByComparator);
7790                    }
7791    
7792                    JournalArticle journalArticle = findByPrimaryKey(id);
7793    
7794                    Session session = null;
7795    
7796                    try {
7797                            session = openSession();
7798    
7799                            JournalArticle[] array = new JournalArticleImpl[3];
7800    
7801                            array[0] = filterGetByG_F_PrevAndNext(session, journalArticle,
7802                                            groupId, folderId, orderByComparator, true);
7803    
7804                            array[1] = journalArticle;
7805    
7806                            array[2] = filterGetByG_F_PrevAndNext(session, journalArticle,
7807                                            groupId, folderId, orderByComparator, false);
7808    
7809                            return array;
7810                    }
7811                    catch (Exception e) {
7812                            throw processException(e);
7813                    }
7814                    finally {
7815                            closeSession(session);
7816                    }
7817            }
7818    
7819            protected JournalArticle filterGetByG_F_PrevAndNext(Session session,
7820                    JournalArticle journalArticle, long groupId, long folderId,
7821                    OrderByComparator orderByComparator, boolean previous) {
7822                    StringBundler query = null;
7823    
7824                    if (orderByComparator != null) {
7825                            query = new StringBundler(6 +
7826                                            (orderByComparator.getOrderByFields().length * 6));
7827                    }
7828                    else {
7829                            query = new StringBundler(3);
7830                    }
7831    
7832                    if (getDB().isSupportsInlineDistinct()) {
7833                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
7834                    }
7835                    else {
7836                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
7837                    }
7838    
7839                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
7840    
7841                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
7842    
7843                    if (!getDB().isSupportsInlineDistinct()) {
7844                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
7845                    }
7846    
7847                    if (orderByComparator != null) {
7848                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7849    
7850                            if (orderByConditionFields.length > 0) {
7851                                    query.append(WHERE_AND);
7852                            }
7853    
7854                            for (int i = 0; i < orderByConditionFields.length; i++) {
7855                                    if (getDB().isSupportsInlineDistinct()) {
7856                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7857                                    }
7858                                    else {
7859                                            query.append(_ORDER_BY_ENTITY_TABLE);
7860                                    }
7861    
7862                                    query.append(orderByConditionFields[i]);
7863    
7864                                    if ((i + 1) < orderByConditionFields.length) {
7865                                            if (orderByComparator.isAscending() ^ previous) {
7866                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7867                                            }
7868                                            else {
7869                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7870                                            }
7871                                    }
7872                                    else {
7873                                            if (orderByComparator.isAscending() ^ previous) {
7874                                                    query.append(WHERE_GREATER_THAN);
7875                                            }
7876                                            else {
7877                                                    query.append(WHERE_LESSER_THAN);
7878                                            }
7879                                    }
7880                            }
7881    
7882                            query.append(ORDER_BY_CLAUSE);
7883    
7884                            String[] orderByFields = orderByComparator.getOrderByFields();
7885    
7886                            for (int i = 0; i < orderByFields.length; i++) {
7887                                    if (getDB().isSupportsInlineDistinct()) {
7888                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7889                                    }
7890                                    else {
7891                                            query.append(_ORDER_BY_ENTITY_TABLE);
7892                                    }
7893    
7894                                    query.append(orderByFields[i]);
7895    
7896                                    if ((i + 1) < orderByFields.length) {
7897                                            if (orderByComparator.isAscending() ^ previous) {
7898                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7899                                            }
7900                                            else {
7901                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7902                                            }
7903                                    }
7904                                    else {
7905                                            if (orderByComparator.isAscending() ^ previous) {
7906                                                    query.append(ORDER_BY_ASC);
7907                                            }
7908                                            else {
7909                                                    query.append(ORDER_BY_DESC);
7910                                            }
7911                                    }
7912                            }
7913                    }
7914                    else {
7915                            if (getDB().isSupportsInlineDistinct()) {
7916                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
7917                            }
7918                            else {
7919                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
7920                            }
7921                    }
7922    
7923                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7924                                    JournalArticle.class.getName(),
7925                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7926    
7927                    SQLQuery q = session.createSQLQuery(sql);
7928    
7929                    q.setFirstResult(0);
7930                    q.setMaxResults(2);
7931    
7932                    if (getDB().isSupportsInlineDistinct()) {
7933                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
7934                    }
7935                    else {
7936                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
7937                    }
7938    
7939                    QueryPos qPos = QueryPos.getInstance(q);
7940    
7941                    qPos.add(groupId);
7942    
7943                    qPos.add(folderId);
7944    
7945                    if (orderByComparator != null) {
7946                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
7947    
7948                            for (Object value : values) {
7949                                    qPos.add(value);
7950                            }
7951                    }
7952    
7953                    List<JournalArticle> list = q.list();
7954    
7955                    if (list.size() == 2) {
7956                            return list.get(1);
7957                    }
7958                    else {
7959                            return null;
7960                    }
7961            }
7962    
7963            /**
7964             * Returns all the journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
7965             *
7966             * @param groupId the group ID
7967             * @param folderIds the folder IDs
7968             * @return the matching journal articles that the user has permission to view
7969             * @throws SystemException if a system exception occurred
7970             */
7971            @Override
7972            public List<JournalArticle> filterFindByG_F(long groupId, long[] folderIds)
7973                    throws SystemException {
7974                    return filterFindByG_F(groupId, folderIds, QueryUtil.ALL_POS,
7975                            QueryUtil.ALL_POS, null);
7976            }
7977    
7978            /**
7979             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
7980             *
7981             * <p>
7982             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
7983             * </p>
7984             *
7985             * @param groupId the group ID
7986             * @param folderIds the folder IDs
7987             * @param start the lower bound of the range of journal articles
7988             * @param end the upper bound of the range of journal articles (not inclusive)
7989             * @return the range of matching journal articles that the user has permission to view
7990             * @throws SystemException if a system exception occurred
7991             */
7992            @Override
7993            public List<JournalArticle> filterFindByG_F(long groupId, long[] folderIds,
7994                    int start, int end) throws SystemException {
7995                    return filterFindByG_F(groupId, folderIds, start, end, null);
7996            }
7997    
7998            /**
7999             * Returns an ordered range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
8000             *
8001             * <p>
8002             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
8003             * </p>
8004             *
8005             * @param groupId the group ID
8006             * @param folderIds the folder IDs
8007             * @param start the lower bound of the range of journal articles
8008             * @param end the upper bound of the range of journal articles (not inclusive)
8009             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8010             * @return the ordered range of matching journal articles that the user has permission to view
8011             * @throws SystemException if a system exception occurred
8012             */
8013            @Override
8014            public List<JournalArticle> filterFindByG_F(long groupId, long[] folderIds,
8015                    int start, int end, OrderByComparator orderByComparator)
8016                    throws SystemException {
8017                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8018                            return findByG_F(groupId, folderIds, start, end, orderByComparator);
8019                    }
8020    
8021                    StringBundler query = new StringBundler();
8022    
8023                    if (getDB().isSupportsInlineDistinct()) {
8024                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
8025                    }
8026                    else {
8027                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
8028                    }
8029    
8030                    boolean conjunctionable = false;
8031    
8032                    if (conjunctionable) {
8033                            query.append(WHERE_AND);
8034                    }
8035    
8036                    query.append(_FINDER_COLUMN_G_F_GROUPID_5);
8037    
8038                    conjunctionable = true;
8039    
8040                    if ((folderIds == null) || (folderIds.length > 0)) {
8041                            if (conjunctionable) {
8042                                    query.append(WHERE_AND);
8043                            }
8044    
8045                            query.append(StringPool.OPEN_PARENTHESIS);
8046    
8047                            for (int i = 0; i < folderIds.length; i++) {
8048                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
8049    
8050                                    if ((i + 1) < folderIds.length) {
8051                                            query.append(WHERE_OR);
8052                                    }
8053                            }
8054    
8055                            query.append(StringPool.CLOSE_PARENTHESIS);
8056    
8057                            conjunctionable = true;
8058                    }
8059    
8060                    if (!getDB().isSupportsInlineDistinct()) {
8061                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
8062                    }
8063    
8064                    if (orderByComparator != null) {
8065                            if (getDB().isSupportsInlineDistinct()) {
8066                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8067                                            orderByComparator, true);
8068                            }
8069                            else {
8070                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8071                                            orderByComparator, true);
8072                            }
8073                    }
8074                    else {
8075                            if (getDB().isSupportsInlineDistinct()) {
8076                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
8077                            }
8078                            else {
8079                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
8080                            }
8081                    }
8082    
8083                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8084                                    JournalArticle.class.getName(),
8085                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8086    
8087                    Session session = null;
8088    
8089                    try {
8090                            session = openSession();
8091    
8092                            SQLQuery q = session.createSQLQuery(sql);
8093    
8094                            if (getDB().isSupportsInlineDistinct()) {
8095                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
8096                            }
8097                            else {
8098                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
8099                            }
8100    
8101                            QueryPos qPos = QueryPos.getInstance(q);
8102    
8103                            qPos.add(groupId);
8104    
8105                            if (folderIds != null) {
8106                                    qPos.add(folderIds);
8107                            }
8108    
8109                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
8110                                    end);
8111                    }
8112                    catch (Exception e) {
8113                            throw processException(e);
8114                    }
8115                    finally {
8116                            closeSession(session);
8117                    }
8118            }
8119    
8120            /**
8121             * Returns all the journal articles where groupId = &#63; and folderId = any &#63;.
8122             *
8123             * <p>
8124             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
8125             * </p>
8126             *
8127             * @param groupId the group ID
8128             * @param folderIds the folder IDs
8129             * @return the matching journal articles
8130             * @throws SystemException if a system exception occurred
8131             */
8132            @Override
8133            public List<JournalArticle> findByG_F(long groupId, long[] folderIds)
8134                    throws SystemException {
8135                    return findByG_F(groupId, folderIds, QueryUtil.ALL_POS,
8136                            QueryUtil.ALL_POS, null);
8137            }
8138    
8139            /**
8140             * Returns a range of all the journal articles where groupId = &#63; and folderId = any &#63;.
8141             *
8142             * <p>
8143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
8144             * </p>
8145             *
8146             * @param groupId the group ID
8147             * @param folderIds the folder IDs
8148             * @param start the lower bound of the range of journal articles
8149             * @param end the upper bound of the range of journal articles (not inclusive)
8150             * @return the range of matching journal articles
8151             * @throws SystemException if a system exception occurred
8152             */
8153            @Override
8154            public List<JournalArticle> findByG_F(long groupId, long[] folderIds,
8155                    int start, int end) throws SystemException {
8156                    return findByG_F(groupId, folderIds, start, end, null);
8157            }
8158    
8159            /**
8160             * Returns an ordered range of all the journal articles where groupId = &#63; and folderId = any &#63;.
8161             *
8162             * <p>
8163             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
8164             * </p>
8165             *
8166             * @param groupId the group ID
8167             * @param folderIds the folder IDs
8168             * @param start the lower bound of the range of journal articles
8169             * @param end the upper bound of the range of journal articles (not inclusive)
8170             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8171             * @return the ordered range of matching journal articles
8172             * @throws SystemException if a system exception occurred
8173             */
8174            @Override
8175            public List<JournalArticle> findByG_F(long groupId, long[] folderIds,
8176                    int start, int end, OrderByComparator orderByComparator)
8177                    throws SystemException {
8178                    if ((folderIds != null) && (folderIds.length == 1)) {
8179                            return findByG_F(groupId, folderIds[0], start, end,
8180                                    orderByComparator);
8181                    }
8182    
8183                    boolean pagination = true;
8184                    Object[] finderArgs = null;
8185    
8186                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8187                                    (orderByComparator == null)) {
8188                            pagination = false;
8189                            finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };
8190                    }
8191                    else {
8192                            finderArgs = new Object[] {
8193                                            groupId, StringUtil.merge(folderIds),
8194                                            
8195                                            start, end, orderByComparator
8196                                    };
8197                    }
8198    
8199                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F,
8200                                    finderArgs, this);
8201    
8202                    if ((list != null) && !list.isEmpty()) {
8203                            for (JournalArticle journalArticle : list) {
8204                                    if ((groupId != journalArticle.getGroupId()) ||
8205                                                    !ArrayUtil.contains(folderIds,
8206                                                            journalArticle.getFolderId())) {
8207                                            list = null;
8208    
8209                                            break;
8210                                    }
8211                            }
8212                    }
8213    
8214                    if (list == null) {
8215                            StringBundler query = new StringBundler();
8216    
8217                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
8218    
8219                            boolean conjunctionable = false;
8220    
8221                            if (conjunctionable) {
8222                                    query.append(WHERE_AND);
8223                            }
8224    
8225                            query.append(_FINDER_COLUMN_G_F_GROUPID_5);
8226    
8227                            conjunctionable = true;
8228    
8229                            if ((folderIds == null) || (folderIds.length > 0)) {
8230                                    if (conjunctionable) {
8231                                            query.append(WHERE_AND);
8232                                    }
8233    
8234                                    query.append(StringPool.OPEN_PARENTHESIS);
8235    
8236                                    for (int i = 0; i < folderIds.length; i++) {
8237                                            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
8238    
8239                                            if ((i + 1) < folderIds.length) {
8240                                                    query.append(WHERE_OR);
8241                                            }
8242                                    }
8243    
8244                                    query.append(StringPool.CLOSE_PARENTHESIS);
8245    
8246                                    conjunctionable = true;
8247                            }
8248    
8249                            if (orderByComparator != null) {
8250                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8251                                            orderByComparator);
8252                            }
8253                            else
8254                             if (pagination) {
8255                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
8256                            }
8257    
8258                            String sql = query.toString();
8259    
8260                            Session session = null;
8261    
8262                            try {
8263                                    session = openSession();
8264    
8265                                    Query q = session.createQuery(sql);
8266    
8267                                    QueryPos qPos = QueryPos.getInstance(q);
8268    
8269                                    qPos.add(groupId);
8270    
8271                                    if (folderIds != null) {
8272                                            qPos.add(folderIds);
8273                                    }
8274    
8275                                    if (!pagination) {
8276                                            list = (List<JournalArticle>)QueryUtil.list(q,
8277                                                            getDialect(), start, end, false);
8278    
8279                                            Collections.sort(list);
8280    
8281                                            list = new UnmodifiableList<JournalArticle>(list);
8282                                    }
8283                                    else {
8284                                            list = (List<JournalArticle>)QueryUtil.list(q,
8285                                                            getDialect(), start, end);
8286                                    }
8287    
8288                                    cacheResult(list);
8289    
8290                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F,
8291                                            finderArgs, list);
8292                            }
8293                            catch (Exception e) {
8294                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F,
8295                                            finderArgs);
8296    
8297                                    throw processException(e);
8298                            }
8299                            finally {
8300                                    closeSession(session);
8301                            }
8302                    }
8303    
8304                    return list;
8305            }
8306    
8307            /**
8308             * Removes all the journal articles where groupId = &#63; and folderId = &#63; from the database.
8309             *
8310             * @param groupId the group ID
8311             * @param folderId the folder ID
8312             * @throws SystemException if a system exception occurred
8313             */
8314            @Override
8315            public void removeByG_F(long groupId, long folderId)
8316                    throws SystemException {
8317                    for (JournalArticle journalArticle : findByG_F(groupId, folderId,
8318                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8319                            remove(journalArticle);
8320                    }
8321            }
8322    
8323            /**
8324             * Returns the number of journal articles where groupId = &#63; and folderId = &#63;.
8325             *
8326             * @param groupId the group ID
8327             * @param folderId the folder ID
8328             * @return the number of matching journal articles
8329             * @throws SystemException if a system exception occurred
8330             */
8331            @Override
8332            public int countByG_F(long groupId, long folderId)
8333                    throws SystemException {
8334                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F;
8335    
8336                    Object[] finderArgs = new Object[] { groupId, folderId };
8337    
8338                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8339                                    this);
8340    
8341                    if (count == null) {
8342                            StringBundler query = new StringBundler(3);
8343    
8344                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
8345    
8346                            query.append(_FINDER_COLUMN_G_F_GROUPID_2);
8347    
8348                            query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
8349    
8350                            String sql = query.toString();
8351    
8352                            Session session = null;
8353    
8354                            try {
8355                                    session = openSession();
8356    
8357                                    Query q = session.createQuery(sql);
8358    
8359                                    QueryPos qPos = QueryPos.getInstance(q);
8360    
8361                                    qPos.add(groupId);
8362    
8363                                    qPos.add(folderId);
8364    
8365                                    count = (Long)q.uniqueResult();
8366    
8367                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8368                            }
8369                            catch (Exception e) {
8370                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8371    
8372                                    throw processException(e);
8373                            }
8374                            finally {
8375                                    closeSession(session);
8376                            }
8377                    }
8378    
8379                    return count.intValue();
8380            }
8381    
8382            /**
8383             * Returns the number of journal articles where groupId = &#63; and folderId = any &#63;.
8384             *
8385             * @param groupId the group ID
8386             * @param folderIds the folder IDs
8387             * @return the number of matching journal articles
8388             * @throws SystemException if a system exception occurred
8389             */
8390            @Override
8391            public int countByG_F(long groupId, long[] folderIds)
8392                    throws SystemException {
8393                    Object[] finderArgs = new Object[] { groupId, StringUtil.merge(folderIds) };
8394    
8395                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F,
8396                                    finderArgs, this);
8397    
8398                    if (count == null) {
8399                            StringBundler query = new StringBundler();
8400    
8401                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
8402    
8403                            boolean conjunctionable = false;
8404    
8405                            if (conjunctionable) {
8406                                    query.append(WHERE_AND);
8407                            }
8408    
8409                            query.append(_FINDER_COLUMN_G_F_GROUPID_5);
8410    
8411                            conjunctionable = true;
8412    
8413                            if ((folderIds == null) || (folderIds.length > 0)) {
8414                                    if (conjunctionable) {
8415                                            query.append(WHERE_AND);
8416                                    }
8417    
8418                                    query.append(StringPool.OPEN_PARENTHESIS);
8419    
8420                                    for (int i = 0; i < folderIds.length; i++) {
8421                                            query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
8422    
8423                                            if ((i + 1) < folderIds.length) {
8424                                                    query.append(WHERE_OR);
8425                                            }
8426                                    }
8427    
8428                                    query.append(StringPool.CLOSE_PARENTHESIS);
8429    
8430                                    conjunctionable = true;
8431                            }
8432    
8433                            String sql = query.toString();
8434    
8435                            Session session = null;
8436    
8437                            try {
8438                                    session = openSession();
8439    
8440                                    Query q = session.createQuery(sql);
8441    
8442                                    QueryPos qPos = QueryPos.getInstance(q);
8443    
8444                                    qPos.add(groupId);
8445    
8446                                    if (folderIds != null) {
8447                                            qPos.add(folderIds);
8448                                    }
8449    
8450                                    count = (Long)q.uniqueResult();
8451    
8452                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F,
8453                                            finderArgs, count);
8454                            }
8455                            catch (Exception e) {
8456                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F,
8457                                            finderArgs);
8458    
8459                                    throw processException(e);
8460                            }
8461                            finally {
8462                                    closeSession(session);
8463                            }
8464                    }
8465    
8466                    return count.intValue();
8467            }
8468    
8469            /**
8470             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and folderId = &#63;.
8471             *
8472             * @param groupId the group ID
8473             * @param folderId the folder ID
8474             * @return the number of matching journal articles that the user has permission to view
8475             * @throws SystemException if a system exception occurred
8476             */
8477            @Override
8478            public int filterCountByG_F(long groupId, long folderId)
8479                    throws SystemException {
8480                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8481                            return countByG_F(groupId, folderId);
8482                    }
8483    
8484                    StringBundler query = new StringBundler(3);
8485    
8486                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
8487    
8488                    query.append(_FINDER_COLUMN_G_F_GROUPID_2);
8489    
8490                    query.append(_FINDER_COLUMN_G_F_FOLDERID_2);
8491    
8492                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8493                                    JournalArticle.class.getName(),
8494                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8495    
8496                    Session session = null;
8497    
8498                    try {
8499                            session = openSession();
8500    
8501                            SQLQuery q = session.createSQLQuery(sql);
8502    
8503                            q.addScalar(COUNT_COLUMN_NAME,
8504                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8505    
8506                            QueryPos qPos = QueryPos.getInstance(q);
8507    
8508                            qPos.add(groupId);
8509    
8510                            qPos.add(folderId);
8511    
8512                            Long count = (Long)q.uniqueResult();
8513    
8514                            return count.intValue();
8515                    }
8516                    catch (Exception e) {
8517                            throw processException(e);
8518                    }
8519                    finally {
8520                            closeSession(session);
8521                    }
8522            }
8523    
8524            /**
8525             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and folderId = any &#63;.
8526             *
8527             * @param groupId the group ID
8528             * @param folderIds the folder IDs
8529             * @return the number of matching journal articles that the user has permission to view
8530             * @throws SystemException if a system exception occurred
8531             */
8532            @Override
8533            public int filterCountByG_F(long groupId, long[] folderIds)
8534                    throws SystemException {
8535                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8536                            return countByG_F(groupId, folderIds);
8537                    }
8538    
8539                    StringBundler query = new StringBundler();
8540    
8541                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
8542    
8543                    boolean conjunctionable = false;
8544    
8545                    if (conjunctionable) {
8546                            query.append(WHERE_AND);
8547                    }
8548    
8549                    query.append(_FINDER_COLUMN_G_F_GROUPID_5);
8550    
8551                    conjunctionable = true;
8552    
8553                    if ((folderIds == null) || (folderIds.length > 0)) {
8554                            if (conjunctionable) {
8555                                    query.append(WHERE_AND);
8556                            }
8557    
8558                            query.append(StringPool.OPEN_PARENTHESIS);
8559    
8560                            for (int i = 0; i < folderIds.length; i++) {
8561                                    query.append(_FINDER_COLUMN_G_F_FOLDERID_5);
8562    
8563                                    if ((i + 1) < folderIds.length) {
8564                                            query.append(WHERE_OR);
8565                                    }
8566                            }
8567    
8568                            query.append(StringPool.CLOSE_PARENTHESIS);
8569    
8570                            conjunctionable = true;
8571                    }
8572    
8573                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8574                                    JournalArticle.class.getName(),
8575                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8576    
8577                    Session session = null;
8578    
8579                    try {
8580                            session = openSession();
8581    
8582                            SQLQuery q = session.createSQLQuery(sql);
8583    
8584                            q.addScalar(COUNT_COLUMN_NAME,
8585                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8586    
8587                            QueryPos qPos = QueryPos.getInstance(q);
8588    
8589                            qPos.add(groupId);
8590    
8591                            if (folderIds != null) {
8592                                    qPos.add(folderIds);
8593                            }
8594    
8595                            Long count = (Long)q.uniqueResult();
8596    
8597                            return count.intValue();
8598                    }
8599                    catch (Exception e) {
8600                            throw processException(e);
8601                    }
8602                    finally {
8603                            closeSession(session);
8604                    }
8605            }
8606    
8607            private static final String _FINDER_COLUMN_G_F_GROUPID_2 = "journalArticle.groupId = ? AND ";
8608            private static final String _FINDER_COLUMN_G_F_GROUPID_5 = "(" +
8609                    removeConjunction(_FINDER_COLUMN_G_F_GROUPID_2) + ")";
8610            private static final String _FINDER_COLUMN_G_F_FOLDERID_2 = "journalArticle.folderId = ?";
8611            private static final String _FINDER_COLUMN_G_F_FOLDERID_5 = "(" +
8612                    removeConjunction(_FINDER_COLUMN_G_F_FOLDERID_2) + ")";
8613            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
8614                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
8615                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
8616                            "findByG_A",
8617                            new String[] {
8618                                    Long.class.getName(), String.class.getName(),
8619                                    
8620                            Integer.class.getName(), Integer.class.getName(),
8621                                    OrderByComparator.class.getName()
8622                            });
8623            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
8624                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
8625                            JournalArticleImpl.class,
8626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_A",
8627                            new String[] { Long.class.getName(), String.class.getName() },
8628                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
8629                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
8630                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
8631            public static final FinderPath FINDER_PATH_COUNT_BY_G_A = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
8632                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
8633                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A",
8634                            new String[] { Long.class.getName(), String.class.getName() });
8635    
8636            /**
8637             * Returns all the journal articles where groupId = &#63; and articleId = &#63;.
8638             *
8639             * @param groupId the group ID
8640             * @param articleId the article ID
8641             * @return the matching journal articles
8642             * @throws SystemException if a system exception occurred
8643             */
8644            @Override
8645            public List<JournalArticle> findByG_A(long groupId, String articleId)
8646                    throws SystemException {
8647                    return findByG_A(groupId, articleId, QueryUtil.ALL_POS,
8648                            QueryUtil.ALL_POS, null);
8649            }
8650    
8651            /**
8652             * Returns a range of all the journal articles where groupId = &#63; and articleId = &#63;.
8653             *
8654             * <p>
8655             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
8656             * </p>
8657             *
8658             * @param groupId the group ID
8659             * @param articleId the article ID
8660             * @param start the lower bound of the range of journal articles
8661             * @param end the upper bound of the range of journal articles (not inclusive)
8662             * @return the range of matching journal articles
8663             * @throws SystemException if a system exception occurred
8664             */
8665            @Override
8666            public List<JournalArticle> findByG_A(long groupId, String articleId,
8667                    int start, int end) throws SystemException {
8668                    return findByG_A(groupId, articleId, start, end, null);
8669            }
8670    
8671            /**
8672             * Returns an ordered range of all the journal articles where groupId = &#63; and articleId = &#63;.
8673             *
8674             * <p>
8675             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
8676             * </p>
8677             *
8678             * @param groupId the group ID
8679             * @param articleId the article ID
8680             * @param start the lower bound of the range of journal articles
8681             * @param end the upper bound of the range of journal articles (not inclusive)
8682             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8683             * @return the ordered range of matching journal articles
8684             * @throws SystemException if a system exception occurred
8685             */
8686            @Override
8687            public List<JournalArticle> findByG_A(long groupId, String articleId,
8688                    int start, int end, OrderByComparator orderByComparator)
8689                    throws SystemException {
8690                    boolean pagination = true;
8691                    FinderPath finderPath = null;
8692                    Object[] finderArgs = null;
8693    
8694                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8695                                    (orderByComparator == null)) {
8696                            pagination = false;
8697                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A;
8698                            finderArgs = new Object[] { groupId, articleId };
8699                    }
8700                    else {
8701                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A;
8702                            finderArgs = new Object[] {
8703                                            groupId, articleId,
8704                                            
8705                                            start, end, orderByComparator
8706                                    };
8707                    }
8708    
8709                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
8710                                    finderArgs, this);
8711    
8712                    if ((list != null) && !list.isEmpty()) {
8713                            for (JournalArticle journalArticle : list) {
8714                                    if ((groupId != journalArticle.getGroupId()) ||
8715                                                    !Validator.equals(articleId,
8716                                                            journalArticle.getArticleId())) {
8717                                            list = null;
8718    
8719                                            break;
8720                                    }
8721                            }
8722                    }
8723    
8724                    if (list == null) {
8725                            StringBundler query = null;
8726    
8727                            if (orderByComparator != null) {
8728                                    query = new StringBundler(4 +
8729                                                    (orderByComparator.getOrderByFields().length * 3));
8730                            }
8731                            else {
8732                                    query = new StringBundler(4);
8733                            }
8734    
8735                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
8736    
8737                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
8738    
8739                            boolean bindArticleId = false;
8740    
8741                            if (articleId == null) {
8742                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
8743                            }
8744                            else if (articleId.equals(StringPool.BLANK)) {
8745                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
8746                            }
8747                            else {
8748                                    bindArticleId = true;
8749    
8750                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
8751                            }
8752    
8753                            if (orderByComparator != null) {
8754                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8755                                            orderByComparator);
8756                            }
8757                            else
8758                             if (pagination) {
8759                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
8760                            }
8761    
8762                            String sql = query.toString();
8763    
8764                            Session session = null;
8765    
8766                            try {
8767                                    session = openSession();
8768    
8769                                    Query q = session.createQuery(sql);
8770    
8771                                    QueryPos qPos = QueryPos.getInstance(q);
8772    
8773                                    qPos.add(groupId);
8774    
8775                                    if (bindArticleId) {
8776                                            qPos.add(articleId);
8777                                    }
8778    
8779                                    if (!pagination) {
8780                                            list = (List<JournalArticle>)QueryUtil.list(q,
8781                                                            getDialect(), start, end, false);
8782    
8783                                            Collections.sort(list);
8784    
8785                                            list = new UnmodifiableList<JournalArticle>(list);
8786                                    }
8787                                    else {
8788                                            list = (List<JournalArticle>)QueryUtil.list(q,
8789                                                            getDialect(), start, end);
8790                                    }
8791    
8792                                    cacheResult(list);
8793    
8794                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8795                            }
8796                            catch (Exception e) {
8797                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8798    
8799                                    throw processException(e);
8800                            }
8801                            finally {
8802                                    closeSession(session);
8803                            }
8804                    }
8805    
8806                    return list;
8807            }
8808    
8809            /**
8810             * Returns the first journal article in the ordered set where groupId = &#63; and articleId = &#63;.
8811             *
8812             * @param groupId the group ID
8813             * @param articleId the article ID
8814             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8815             * @return the first matching journal article
8816             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
8817             * @throws SystemException if a system exception occurred
8818             */
8819            @Override
8820            public JournalArticle findByG_A_First(long groupId, String articleId,
8821                    OrderByComparator orderByComparator)
8822                    throws NoSuchArticleException, SystemException {
8823                    JournalArticle journalArticle = fetchByG_A_First(groupId, articleId,
8824                                    orderByComparator);
8825    
8826                    if (journalArticle != null) {
8827                            return journalArticle;
8828                    }
8829    
8830                    StringBundler msg = new StringBundler(6);
8831    
8832                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8833    
8834                    msg.append("groupId=");
8835                    msg.append(groupId);
8836    
8837                    msg.append(", articleId=");
8838                    msg.append(articleId);
8839    
8840                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8841    
8842                    throw new NoSuchArticleException(msg.toString());
8843            }
8844    
8845            /**
8846             * Returns the first journal article in the ordered set where groupId = &#63; and articleId = &#63;.
8847             *
8848             * @param groupId the group ID
8849             * @param articleId the article ID
8850             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8851             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
8852             * @throws SystemException if a system exception occurred
8853             */
8854            @Override
8855            public JournalArticle fetchByG_A_First(long groupId, String articleId,
8856                    OrderByComparator orderByComparator) throws SystemException {
8857                    List<JournalArticle> list = findByG_A(groupId, articleId, 0, 1,
8858                                    orderByComparator);
8859    
8860                    if (!list.isEmpty()) {
8861                            return list.get(0);
8862                    }
8863    
8864                    return null;
8865            }
8866    
8867            /**
8868             * Returns the last journal article in the ordered set where groupId = &#63; and articleId = &#63;.
8869             *
8870             * @param groupId the group ID
8871             * @param articleId the article ID
8872             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8873             * @return the last matching journal article
8874             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
8875             * @throws SystemException if a system exception occurred
8876             */
8877            @Override
8878            public JournalArticle findByG_A_Last(long groupId, String articleId,
8879                    OrderByComparator orderByComparator)
8880                    throws NoSuchArticleException, SystemException {
8881                    JournalArticle journalArticle = fetchByG_A_Last(groupId, articleId,
8882                                    orderByComparator);
8883    
8884                    if (journalArticle != null) {
8885                            return journalArticle;
8886                    }
8887    
8888                    StringBundler msg = new StringBundler(6);
8889    
8890                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8891    
8892                    msg.append("groupId=");
8893                    msg.append(groupId);
8894    
8895                    msg.append(", articleId=");
8896                    msg.append(articleId);
8897    
8898                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8899    
8900                    throw new NoSuchArticleException(msg.toString());
8901            }
8902    
8903            /**
8904             * Returns the last journal article in the ordered set where groupId = &#63; and articleId = &#63;.
8905             *
8906             * @param groupId the group ID
8907             * @param articleId the article ID
8908             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8909             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
8910             * @throws SystemException if a system exception occurred
8911             */
8912            @Override
8913            public JournalArticle fetchByG_A_Last(long groupId, String articleId,
8914                    OrderByComparator orderByComparator) throws SystemException {
8915                    int count = countByG_A(groupId, articleId);
8916    
8917                    if (count == 0) {
8918                            return null;
8919                    }
8920    
8921                    List<JournalArticle> list = findByG_A(groupId, articleId, count - 1,
8922                                    count, orderByComparator);
8923    
8924                    if (!list.isEmpty()) {
8925                            return list.get(0);
8926                    }
8927    
8928                    return null;
8929            }
8930    
8931            /**
8932             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and articleId = &#63;.
8933             *
8934             * @param id the primary key of the current journal article
8935             * @param groupId the group ID
8936             * @param articleId the article ID
8937             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8938             * @return the previous, current, and next journal article
8939             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
8940             * @throws SystemException if a system exception occurred
8941             */
8942            @Override
8943            public JournalArticle[] findByG_A_PrevAndNext(long id, long groupId,
8944                    String articleId, OrderByComparator orderByComparator)
8945                    throws NoSuchArticleException, SystemException {
8946                    JournalArticle journalArticle = findByPrimaryKey(id);
8947    
8948                    Session session = null;
8949    
8950                    try {
8951                            session = openSession();
8952    
8953                            JournalArticle[] array = new JournalArticleImpl[3];
8954    
8955                            array[0] = getByG_A_PrevAndNext(session, journalArticle, groupId,
8956                                            articleId, orderByComparator, true);
8957    
8958                            array[1] = journalArticle;
8959    
8960                            array[2] = getByG_A_PrevAndNext(session, journalArticle, groupId,
8961                                            articleId, orderByComparator, false);
8962    
8963                            return array;
8964                    }
8965                    catch (Exception e) {
8966                            throw processException(e);
8967                    }
8968                    finally {
8969                            closeSession(session);
8970                    }
8971            }
8972    
8973            protected JournalArticle getByG_A_PrevAndNext(Session session,
8974                    JournalArticle journalArticle, long groupId, String articleId,
8975                    OrderByComparator orderByComparator, boolean previous) {
8976                    StringBundler query = null;
8977    
8978                    if (orderByComparator != null) {
8979                            query = new StringBundler(6 +
8980                                            (orderByComparator.getOrderByFields().length * 6));
8981                    }
8982                    else {
8983                            query = new StringBundler(3);
8984                    }
8985    
8986                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
8987    
8988                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
8989    
8990                    boolean bindArticleId = false;
8991    
8992                    if (articleId == null) {
8993                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
8994                    }
8995                    else if (articleId.equals(StringPool.BLANK)) {
8996                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
8997                    }
8998                    else {
8999                            bindArticleId = true;
9000    
9001                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
9002                    }
9003    
9004                    if (orderByComparator != null) {
9005                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9006    
9007                            if (orderByConditionFields.length > 0) {
9008                                    query.append(WHERE_AND);
9009                            }
9010    
9011                            for (int i = 0; i < orderByConditionFields.length; i++) {
9012                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9013                                    query.append(orderByConditionFields[i]);
9014    
9015                                    if ((i + 1) < orderByConditionFields.length) {
9016                                            if (orderByComparator.isAscending() ^ previous) {
9017                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9018                                            }
9019                                            else {
9020                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9021                                            }
9022                                    }
9023                                    else {
9024                                            if (orderByComparator.isAscending() ^ previous) {
9025                                                    query.append(WHERE_GREATER_THAN);
9026                                            }
9027                                            else {
9028                                                    query.append(WHERE_LESSER_THAN);
9029                                            }
9030                                    }
9031                            }
9032    
9033                            query.append(ORDER_BY_CLAUSE);
9034    
9035                            String[] orderByFields = orderByComparator.getOrderByFields();
9036    
9037                            for (int i = 0; i < orderByFields.length; i++) {
9038                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9039                                    query.append(orderByFields[i]);
9040    
9041                                    if ((i + 1) < orderByFields.length) {
9042                                            if (orderByComparator.isAscending() ^ previous) {
9043                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9044                                            }
9045                                            else {
9046                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9047                                            }
9048                                    }
9049                                    else {
9050                                            if (orderByComparator.isAscending() ^ previous) {
9051                                                    query.append(ORDER_BY_ASC);
9052                                            }
9053                                            else {
9054                                                    query.append(ORDER_BY_DESC);
9055                                            }
9056                                    }
9057                            }
9058                    }
9059                    else {
9060                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
9061                    }
9062    
9063                    String sql = query.toString();
9064    
9065                    Query q = session.createQuery(sql);
9066    
9067                    q.setFirstResult(0);
9068                    q.setMaxResults(2);
9069    
9070                    QueryPos qPos = QueryPos.getInstance(q);
9071    
9072                    qPos.add(groupId);
9073    
9074                    if (bindArticleId) {
9075                            qPos.add(articleId);
9076                    }
9077    
9078                    if (orderByComparator != null) {
9079                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
9080    
9081                            for (Object value : values) {
9082                                    qPos.add(value);
9083                            }
9084                    }
9085    
9086                    List<JournalArticle> list = q.list();
9087    
9088                    if (list.size() == 2) {
9089                            return list.get(1);
9090                    }
9091                    else {
9092                            return null;
9093                    }
9094            }
9095    
9096            /**
9097             * Returns all the journal articles that the user has permission to view where groupId = &#63; and articleId = &#63;.
9098             *
9099             * @param groupId the group ID
9100             * @param articleId the article ID
9101             * @return the matching journal articles that the user has permission to view
9102             * @throws SystemException if a system exception occurred
9103             */
9104            @Override
9105            public List<JournalArticle> filterFindByG_A(long groupId, String articleId)
9106                    throws SystemException {
9107                    return filterFindByG_A(groupId, articleId, QueryUtil.ALL_POS,
9108                            QueryUtil.ALL_POS, null);
9109            }
9110    
9111            /**
9112             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and articleId = &#63;.
9113             *
9114             * <p>
9115             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
9116             * </p>
9117             *
9118             * @param groupId the group ID
9119             * @param articleId the article ID
9120             * @param start the lower bound of the range of journal articles
9121             * @param end the upper bound of the range of journal articles (not inclusive)
9122             * @return the range of matching journal articles that the user has permission to view
9123             * @throws SystemException if a system exception occurred
9124             */
9125            @Override
9126            public List<JournalArticle> filterFindByG_A(long groupId, String articleId,
9127                    int start, int end) throws SystemException {
9128                    return filterFindByG_A(groupId, articleId, start, end, null);
9129            }
9130    
9131            /**
9132             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and articleId = &#63;.
9133             *
9134             * <p>
9135             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
9136             * </p>
9137             *
9138             * @param groupId the group ID
9139             * @param articleId the article ID
9140             * @param start the lower bound of the range of journal articles
9141             * @param end the upper bound of the range of journal articles (not inclusive)
9142             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9143             * @return the ordered range of matching journal articles that the user has permission to view
9144             * @throws SystemException if a system exception occurred
9145             */
9146            @Override
9147            public List<JournalArticle> filterFindByG_A(long groupId, String articleId,
9148                    int start, int end, OrderByComparator orderByComparator)
9149                    throws SystemException {
9150                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9151                            return findByG_A(groupId, articleId, start, end, orderByComparator);
9152                    }
9153    
9154                    StringBundler query = null;
9155    
9156                    if (orderByComparator != null) {
9157                            query = new StringBundler(4 +
9158                                            (orderByComparator.getOrderByFields().length * 3));
9159                    }
9160                    else {
9161                            query = new StringBundler(4);
9162                    }
9163    
9164                    if (getDB().isSupportsInlineDistinct()) {
9165                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
9166                    }
9167                    else {
9168                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
9169                    }
9170    
9171                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
9172    
9173                    boolean bindArticleId = false;
9174    
9175                    if (articleId == null) {
9176                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
9177                    }
9178                    else if (articleId.equals(StringPool.BLANK)) {
9179                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
9180                    }
9181                    else {
9182                            bindArticleId = true;
9183    
9184                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
9185                    }
9186    
9187                    if (!getDB().isSupportsInlineDistinct()) {
9188                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
9189                    }
9190    
9191                    if (orderByComparator != null) {
9192                            if (getDB().isSupportsInlineDistinct()) {
9193                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9194                                            orderByComparator, true);
9195                            }
9196                            else {
9197                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9198                                            orderByComparator, true);
9199                            }
9200                    }
9201                    else {
9202                            if (getDB().isSupportsInlineDistinct()) {
9203                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
9204                            }
9205                            else {
9206                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
9207                            }
9208                    }
9209    
9210                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9211                                    JournalArticle.class.getName(),
9212                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9213    
9214                    Session session = null;
9215    
9216                    try {
9217                            session = openSession();
9218    
9219                            SQLQuery q = session.createSQLQuery(sql);
9220    
9221                            if (getDB().isSupportsInlineDistinct()) {
9222                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
9223                            }
9224                            else {
9225                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
9226                            }
9227    
9228                            QueryPos qPos = QueryPos.getInstance(q);
9229    
9230                            qPos.add(groupId);
9231    
9232                            if (bindArticleId) {
9233                                    qPos.add(articleId);
9234                            }
9235    
9236                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
9237                                    end);
9238                    }
9239                    catch (Exception e) {
9240                            throw processException(e);
9241                    }
9242                    finally {
9243                            closeSession(session);
9244                    }
9245            }
9246    
9247            /**
9248             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and articleId = &#63;.
9249             *
9250             * @param id the primary key of the current journal article
9251             * @param groupId the group ID
9252             * @param articleId the article ID
9253             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9254             * @return the previous, current, and next journal article
9255             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
9256             * @throws SystemException if a system exception occurred
9257             */
9258            @Override
9259            public JournalArticle[] filterFindByG_A_PrevAndNext(long id, long groupId,
9260                    String articleId, OrderByComparator orderByComparator)
9261                    throws NoSuchArticleException, SystemException {
9262                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9263                            return findByG_A_PrevAndNext(id, groupId, articleId,
9264                                    orderByComparator);
9265                    }
9266    
9267                    JournalArticle journalArticle = findByPrimaryKey(id);
9268    
9269                    Session session = null;
9270    
9271                    try {
9272                            session = openSession();
9273    
9274                            JournalArticle[] array = new JournalArticleImpl[3];
9275    
9276                            array[0] = filterGetByG_A_PrevAndNext(session, journalArticle,
9277                                            groupId, articleId, orderByComparator, true);
9278    
9279                            array[1] = journalArticle;
9280    
9281                            array[2] = filterGetByG_A_PrevAndNext(session, journalArticle,
9282                                            groupId, articleId, orderByComparator, false);
9283    
9284                            return array;
9285                    }
9286                    catch (Exception e) {
9287                            throw processException(e);
9288                    }
9289                    finally {
9290                            closeSession(session);
9291                    }
9292            }
9293    
9294            protected JournalArticle filterGetByG_A_PrevAndNext(Session session,
9295                    JournalArticle journalArticle, long groupId, String articleId,
9296                    OrderByComparator orderByComparator, boolean previous) {
9297                    StringBundler query = null;
9298    
9299                    if (orderByComparator != null) {
9300                            query = new StringBundler(6 +
9301                                            (orderByComparator.getOrderByFields().length * 6));
9302                    }
9303                    else {
9304                            query = new StringBundler(3);
9305                    }
9306    
9307                    if (getDB().isSupportsInlineDistinct()) {
9308                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
9309                    }
9310                    else {
9311                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
9312                    }
9313    
9314                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
9315    
9316                    boolean bindArticleId = false;
9317    
9318                    if (articleId == null) {
9319                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
9320                    }
9321                    else if (articleId.equals(StringPool.BLANK)) {
9322                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
9323                    }
9324                    else {
9325                            bindArticleId = true;
9326    
9327                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
9328                    }
9329    
9330                    if (!getDB().isSupportsInlineDistinct()) {
9331                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
9332                    }
9333    
9334                    if (orderByComparator != null) {
9335                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9336    
9337                            if (orderByConditionFields.length > 0) {
9338                                    query.append(WHERE_AND);
9339                            }
9340    
9341                            for (int i = 0; i < orderByConditionFields.length; i++) {
9342                                    if (getDB().isSupportsInlineDistinct()) {
9343                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9344                                    }
9345                                    else {
9346                                            query.append(_ORDER_BY_ENTITY_TABLE);
9347                                    }
9348    
9349                                    query.append(orderByConditionFields[i]);
9350    
9351                                    if ((i + 1) < orderByConditionFields.length) {
9352                                            if (orderByComparator.isAscending() ^ previous) {
9353                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9354                                            }
9355                                            else {
9356                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9357                                            }
9358                                    }
9359                                    else {
9360                                            if (orderByComparator.isAscending() ^ previous) {
9361                                                    query.append(WHERE_GREATER_THAN);
9362                                            }
9363                                            else {
9364                                                    query.append(WHERE_LESSER_THAN);
9365                                            }
9366                                    }
9367                            }
9368    
9369                            query.append(ORDER_BY_CLAUSE);
9370    
9371                            String[] orderByFields = orderByComparator.getOrderByFields();
9372    
9373                            for (int i = 0; i < orderByFields.length; i++) {
9374                                    if (getDB().isSupportsInlineDistinct()) {
9375                                            query.append(_ORDER_BY_ENTITY_ALIAS);
9376                                    }
9377                                    else {
9378                                            query.append(_ORDER_BY_ENTITY_TABLE);
9379                                    }
9380    
9381                                    query.append(orderByFields[i]);
9382    
9383                                    if ((i + 1) < orderByFields.length) {
9384                                            if (orderByComparator.isAscending() ^ previous) {
9385                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9386                                            }
9387                                            else {
9388                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9389                                            }
9390                                    }
9391                                    else {
9392                                            if (orderByComparator.isAscending() ^ previous) {
9393                                                    query.append(ORDER_BY_ASC);
9394                                            }
9395                                            else {
9396                                                    query.append(ORDER_BY_DESC);
9397                                            }
9398                                    }
9399                            }
9400                    }
9401                    else {
9402                            if (getDB().isSupportsInlineDistinct()) {
9403                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
9404                            }
9405                            else {
9406                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
9407                            }
9408                    }
9409    
9410                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9411                                    JournalArticle.class.getName(),
9412                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9413    
9414                    SQLQuery q = session.createSQLQuery(sql);
9415    
9416                    q.setFirstResult(0);
9417                    q.setMaxResults(2);
9418    
9419                    if (getDB().isSupportsInlineDistinct()) {
9420                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
9421                    }
9422                    else {
9423                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
9424                    }
9425    
9426                    QueryPos qPos = QueryPos.getInstance(q);
9427    
9428                    qPos.add(groupId);
9429    
9430                    if (bindArticleId) {
9431                            qPos.add(articleId);
9432                    }
9433    
9434                    if (orderByComparator != null) {
9435                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
9436    
9437                            for (Object value : values) {
9438                                    qPos.add(value);
9439                            }
9440                    }
9441    
9442                    List<JournalArticle> list = q.list();
9443    
9444                    if (list.size() == 2) {
9445                            return list.get(1);
9446                    }
9447                    else {
9448                            return null;
9449                    }
9450            }
9451    
9452            /**
9453             * Removes all the journal articles where groupId = &#63; and articleId = &#63; from the database.
9454             *
9455             * @param groupId the group ID
9456             * @param articleId the article ID
9457             * @throws SystemException if a system exception occurred
9458             */
9459            @Override
9460            public void removeByG_A(long groupId, String articleId)
9461                    throws SystemException {
9462                    for (JournalArticle journalArticle : findByG_A(groupId, articleId,
9463                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9464                            remove(journalArticle);
9465                    }
9466            }
9467    
9468            /**
9469             * Returns the number of journal articles where groupId = &#63; and articleId = &#63;.
9470             *
9471             * @param groupId the group ID
9472             * @param articleId the article ID
9473             * @return the number of matching journal articles
9474             * @throws SystemException if a system exception occurred
9475             */
9476            @Override
9477            public int countByG_A(long groupId, String articleId)
9478                    throws SystemException {
9479                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_A;
9480    
9481                    Object[] finderArgs = new Object[] { groupId, articleId };
9482    
9483                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9484                                    this);
9485    
9486                    if (count == null) {
9487                            StringBundler query = new StringBundler(3);
9488    
9489                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
9490    
9491                            query.append(_FINDER_COLUMN_G_A_GROUPID_2);
9492    
9493                            boolean bindArticleId = false;
9494    
9495                            if (articleId == null) {
9496                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
9497                            }
9498                            else if (articleId.equals(StringPool.BLANK)) {
9499                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
9500                            }
9501                            else {
9502                                    bindArticleId = true;
9503    
9504                                    query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
9505                            }
9506    
9507                            String sql = query.toString();
9508    
9509                            Session session = null;
9510    
9511                            try {
9512                                    session = openSession();
9513    
9514                                    Query q = session.createQuery(sql);
9515    
9516                                    QueryPos qPos = QueryPos.getInstance(q);
9517    
9518                                    qPos.add(groupId);
9519    
9520                                    if (bindArticleId) {
9521                                            qPos.add(articleId);
9522                                    }
9523    
9524                                    count = (Long)q.uniqueResult();
9525    
9526                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9527                            }
9528                            catch (Exception e) {
9529                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9530    
9531                                    throw processException(e);
9532                            }
9533                            finally {
9534                                    closeSession(session);
9535                            }
9536                    }
9537    
9538                    return count.intValue();
9539            }
9540    
9541            /**
9542             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and articleId = &#63;.
9543             *
9544             * @param groupId the group ID
9545             * @param articleId the article ID
9546             * @return the number of matching journal articles that the user has permission to view
9547             * @throws SystemException if a system exception occurred
9548             */
9549            @Override
9550            public int filterCountByG_A(long groupId, String articleId)
9551                    throws SystemException {
9552                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9553                            return countByG_A(groupId, articleId);
9554                    }
9555    
9556                    StringBundler query = new StringBundler(3);
9557    
9558                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
9559    
9560                    query.append(_FINDER_COLUMN_G_A_GROUPID_2);
9561    
9562                    boolean bindArticleId = false;
9563    
9564                    if (articleId == null) {
9565                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_1);
9566                    }
9567                    else if (articleId.equals(StringPool.BLANK)) {
9568                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_3);
9569                    }
9570                    else {
9571                            bindArticleId = true;
9572    
9573                            query.append(_FINDER_COLUMN_G_A_ARTICLEID_2);
9574                    }
9575    
9576                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9577                                    JournalArticle.class.getName(),
9578                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9579    
9580                    Session session = null;
9581    
9582                    try {
9583                            session = openSession();
9584    
9585                            SQLQuery q = session.createSQLQuery(sql);
9586    
9587                            q.addScalar(COUNT_COLUMN_NAME,
9588                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9589    
9590                            QueryPos qPos = QueryPos.getInstance(q);
9591    
9592                            qPos.add(groupId);
9593    
9594                            if (bindArticleId) {
9595                                    qPos.add(articleId);
9596                            }
9597    
9598                            Long count = (Long)q.uniqueResult();
9599    
9600                            return count.intValue();
9601                    }
9602                    catch (Exception e) {
9603                            throw processException(e);
9604                    }
9605                    finally {
9606                            closeSession(session);
9607                    }
9608            }
9609    
9610            private static final String _FINDER_COLUMN_G_A_GROUPID_2 = "journalArticle.groupId = ? AND ";
9611            private static final String _FINDER_COLUMN_G_A_ARTICLEID_1 = "journalArticle.articleId IS NULL";
9612            private static final String _FINDER_COLUMN_G_A_ARTICLEID_2 = "journalArticle.articleId = ?";
9613            private static final String _FINDER_COLUMN_G_A_ARTICLEID_3 = "(journalArticle.articleId IS NULL OR journalArticle.articleId = '')";
9614            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_UT = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
9615                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
9616                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
9617                            "findByG_UT",
9618                            new String[] {
9619                                    Long.class.getName(), String.class.getName(),
9620                                    
9621                            Integer.class.getName(), Integer.class.getName(),
9622                                    OrderByComparator.class.getName()
9623                            });
9624            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
9625                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
9626                            JournalArticleImpl.class,
9627                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_UT",
9628                            new String[] { Long.class.getName(), String.class.getName() },
9629                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
9630                            JournalArticleModelImpl.URLTITLE_COLUMN_BITMASK |
9631                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
9632                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
9633            public static final FinderPath FINDER_PATH_COUNT_BY_G_UT = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
9634                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
9635                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_UT",
9636                            new String[] { Long.class.getName(), String.class.getName() });
9637    
9638            /**
9639             * Returns all the journal articles where groupId = &#63; and urlTitle = &#63;.
9640             *
9641             * @param groupId the group ID
9642             * @param urlTitle the url title
9643             * @return the matching journal articles
9644             * @throws SystemException if a system exception occurred
9645             */
9646            @Override
9647            public List<JournalArticle> findByG_UT(long groupId, String urlTitle)
9648                    throws SystemException {
9649                    return findByG_UT(groupId, urlTitle, QueryUtil.ALL_POS,
9650                            QueryUtil.ALL_POS, null);
9651            }
9652    
9653            /**
9654             * Returns a range of all the journal articles where groupId = &#63; and urlTitle = &#63;.
9655             *
9656             * <p>
9657             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
9658             * </p>
9659             *
9660             * @param groupId the group ID
9661             * @param urlTitle the url title
9662             * @param start the lower bound of the range of journal articles
9663             * @param end the upper bound of the range of journal articles (not inclusive)
9664             * @return the range of matching journal articles
9665             * @throws SystemException if a system exception occurred
9666             */
9667            @Override
9668            public List<JournalArticle> findByG_UT(long groupId, String urlTitle,
9669                    int start, int end) throws SystemException {
9670                    return findByG_UT(groupId, urlTitle, start, end, null);
9671            }
9672    
9673            /**
9674             * Returns an ordered range of all the journal articles where groupId = &#63; and urlTitle = &#63;.
9675             *
9676             * <p>
9677             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
9678             * </p>
9679             *
9680             * @param groupId the group ID
9681             * @param urlTitle the url title
9682             * @param start the lower bound of the range of journal articles
9683             * @param end the upper bound of the range of journal articles (not inclusive)
9684             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9685             * @return the ordered range of matching journal articles
9686             * @throws SystemException if a system exception occurred
9687             */
9688            @Override
9689            public List<JournalArticle> findByG_UT(long groupId, String urlTitle,
9690                    int start, int end, OrderByComparator orderByComparator)
9691                    throws SystemException {
9692                    boolean pagination = true;
9693                    FinderPath finderPath = null;
9694                    Object[] finderArgs = null;
9695    
9696                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9697                                    (orderByComparator == null)) {
9698                            pagination = false;
9699                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT;
9700                            finderArgs = new Object[] { groupId, urlTitle };
9701                    }
9702                    else {
9703                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_UT;
9704                            finderArgs = new Object[] {
9705                                            groupId, urlTitle,
9706                                            
9707                                            start, end, orderByComparator
9708                                    };
9709                    }
9710    
9711                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
9712                                    finderArgs, this);
9713    
9714                    if ((list != null) && !list.isEmpty()) {
9715                            for (JournalArticle journalArticle : list) {
9716                                    if ((groupId != journalArticle.getGroupId()) ||
9717                                                    !Validator.equals(urlTitle, journalArticle.getUrlTitle())) {
9718                                            list = null;
9719    
9720                                            break;
9721                                    }
9722                            }
9723                    }
9724    
9725                    if (list == null) {
9726                            StringBundler query = null;
9727    
9728                            if (orderByComparator != null) {
9729                                    query = new StringBundler(4 +
9730                                                    (orderByComparator.getOrderByFields().length * 3));
9731                            }
9732                            else {
9733                                    query = new StringBundler(4);
9734                            }
9735    
9736                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
9737    
9738                            query.append(_FINDER_COLUMN_G_UT_GROUPID_2);
9739    
9740                            boolean bindUrlTitle = false;
9741    
9742                            if (urlTitle == null) {
9743                                    query.append(_FINDER_COLUMN_G_UT_URLTITLE_1);
9744                            }
9745                            else if (urlTitle.equals(StringPool.BLANK)) {
9746                                    query.append(_FINDER_COLUMN_G_UT_URLTITLE_3);
9747                            }
9748                            else {
9749                                    bindUrlTitle = true;
9750    
9751                                    query.append(_FINDER_COLUMN_G_UT_URLTITLE_2);
9752                            }
9753    
9754                            if (orderByComparator != null) {
9755                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9756                                            orderByComparator);
9757                            }
9758                            else
9759                             if (pagination) {
9760                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
9761                            }
9762    
9763                            String sql = query.toString();
9764    
9765                            Session session = null;
9766    
9767                            try {
9768                                    session = openSession();
9769    
9770                                    Query q = session.createQuery(sql);
9771    
9772                                    QueryPos qPos = QueryPos.getInstance(q);
9773    
9774                                    qPos.add(groupId);
9775    
9776                                    if (bindUrlTitle) {
9777                                            qPos.add(urlTitle);
9778                                    }
9779    
9780                                    if (!pagination) {
9781                                            list = (List<JournalArticle>)QueryUtil.list(q,
9782                                                            getDialect(), start, end, false);
9783    
9784                                            Collections.sort(list);
9785    
9786                                            list = new UnmodifiableList<JournalArticle>(list);
9787                                    }
9788                                    else {
9789                                            list = (List<JournalArticle>)QueryUtil.list(q,
9790                                                            getDialect(), start, end);
9791                                    }
9792    
9793                                    cacheResult(list);
9794    
9795                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9796                            }
9797                            catch (Exception e) {
9798                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9799    
9800                                    throw processException(e);
9801                            }
9802                            finally {
9803                                    closeSession(session);
9804                            }
9805                    }
9806    
9807                    return list;
9808            }
9809    
9810            /**
9811             * Returns the first journal article in the ordered set where groupId = &#63; and urlTitle = &#63;.
9812             *
9813             * @param groupId the group ID
9814             * @param urlTitle the url title
9815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9816             * @return the first matching journal article
9817             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
9818             * @throws SystemException if a system exception occurred
9819             */
9820            @Override
9821            public JournalArticle findByG_UT_First(long groupId, String urlTitle,
9822                    OrderByComparator orderByComparator)
9823                    throws NoSuchArticleException, SystemException {
9824                    JournalArticle journalArticle = fetchByG_UT_First(groupId, urlTitle,
9825                                    orderByComparator);
9826    
9827                    if (journalArticle != null) {
9828                            return journalArticle;
9829                    }
9830    
9831                    StringBundler msg = new StringBundler(6);
9832    
9833                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9834    
9835                    msg.append("groupId=");
9836                    msg.append(groupId);
9837    
9838                    msg.append(", urlTitle=");
9839                    msg.append(urlTitle);
9840    
9841                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9842    
9843                    throw new NoSuchArticleException(msg.toString());
9844            }
9845    
9846            /**
9847             * Returns the first journal article in the ordered set where groupId = &#63; and urlTitle = &#63;.
9848             *
9849             * @param groupId the group ID
9850             * @param urlTitle the url title
9851             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9852             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
9853             * @throws SystemException if a system exception occurred
9854             */
9855            @Override
9856            public JournalArticle fetchByG_UT_First(long groupId, String urlTitle,
9857                    OrderByComparator orderByComparator) throws SystemException {
9858                    List<JournalArticle> list = findByG_UT(groupId, urlTitle, 0, 1,
9859                                    orderByComparator);
9860    
9861                    if (!list.isEmpty()) {
9862                            return list.get(0);
9863                    }
9864    
9865                    return null;
9866            }
9867    
9868            /**
9869             * Returns the last journal article in the ordered set where groupId = &#63; and urlTitle = &#63;.
9870             *
9871             * @param groupId the group ID
9872             * @param urlTitle the url title
9873             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9874             * @return the last matching journal article
9875             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
9876             * @throws SystemException if a system exception occurred
9877             */
9878            @Override
9879            public JournalArticle findByG_UT_Last(long groupId, String urlTitle,
9880                    OrderByComparator orderByComparator)
9881                    throws NoSuchArticleException, SystemException {
9882                    JournalArticle journalArticle = fetchByG_UT_Last(groupId, urlTitle,
9883                                    orderByComparator);
9884    
9885                    if (journalArticle != null) {
9886                            return journalArticle;
9887                    }
9888    
9889                    StringBundler msg = new StringBundler(6);
9890    
9891                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9892    
9893                    msg.append("groupId=");
9894                    msg.append(groupId);
9895    
9896                    msg.append(", urlTitle=");
9897                    msg.append(urlTitle);
9898    
9899                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9900    
9901                    throw new NoSuchArticleException(msg.toString());
9902            }
9903    
9904            /**
9905             * Returns the last journal article in the ordered set where groupId = &#63; and urlTitle = &#63;.
9906             *
9907             * @param groupId the group ID
9908             * @param urlTitle the url title
9909             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9910             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
9911             * @throws SystemException if a system exception occurred
9912             */
9913            @Override
9914            public JournalArticle fetchByG_UT_Last(long groupId, String urlTitle,
9915                    OrderByComparator orderByComparator) throws SystemException {
9916                    int count = countByG_UT(groupId, urlTitle);
9917    
9918                    if (count == 0) {
9919                            return null;
9920                    }
9921    
9922                    List<JournalArticle> list = findByG_UT(groupId, urlTitle, count - 1,
9923                                    count, orderByComparator);
9924    
9925                    if (!list.isEmpty()) {
9926                            return list.get(0);
9927                    }
9928    
9929                    return null;
9930            }
9931    
9932            /**
9933             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and urlTitle = &#63;.
9934             *
9935             * @param id the primary key of the current journal article
9936             * @param groupId the group ID
9937             * @param urlTitle the url title
9938             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9939             * @return the previous, current, and next journal article
9940             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
9941             * @throws SystemException if a system exception occurred
9942             */
9943            @Override
9944            public JournalArticle[] findByG_UT_PrevAndNext(long id, long groupId,
9945                    String urlTitle, OrderByComparator orderByComparator)
9946                    throws NoSuchArticleException, SystemException {
9947                    JournalArticle journalArticle = findByPrimaryKey(id);
9948    
9949                    Session session = null;
9950    
9951                    try {
9952                            session = openSession();
9953    
9954                            JournalArticle[] array = new JournalArticleImpl[3];
9955    
9956                            array[0] = getByG_UT_PrevAndNext(session, journalArticle, groupId,
9957                                            urlTitle, orderByComparator, true);
9958    
9959                            array[1] = journalArticle;
9960    
9961                            array[2] = getByG_UT_PrevAndNext(session, journalArticle, groupId,
9962                                            urlTitle, orderByComparator, false);
9963    
9964                            return array;
9965                    }
9966                    catch (Exception e) {
9967                            throw processException(e);
9968                    }
9969                    finally {
9970                            closeSession(session);
9971                    }
9972            }
9973    
9974            protected JournalArticle getByG_UT_PrevAndNext(Session session,
9975                    JournalArticle journalArticle, long groupId, String urlTitle,
9976                    OrderByComparator orderByComparator, boolean previous) {
9977                    StringBundler query = null;
9978    
9979                    if (orderByComparator != null) {
9980                            query = new StringBundler(6 +
9981                                            (orderByComparator.getOrderByFields().length * 6));
9982                    }
9983                    else {
9984                            query = new StringBundler(3);
9985                    }
9986    
9987                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
9988    
9989                    query.append(_FINDER_COLUMN_G_UT_GROUPID_2);
9990    
9991                    boolean bindUrlTitle = false;
9992    
9993                    if (urlTitle == null) {
9994                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_1);
9995                    }
9996                    else if (urlTitle.equals(StringPool.BLANK)) {
9997                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_3);
9998                    }
9999                    else {
10000                            bindUrlTitle = true;
10001    
10002                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_2);
10003                    }
10004    
10005                    if (orderByComparator != null) {
10006                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10007    
10008                            if (orderByConditionFields.length > 0) {
10009                                    query.append(WHERE_AND);
10010                            }
10011    
10012                            for (int i = 0; i < orderByConditionFields.length; i++) {
10013                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10014                                    query.append(orderByConditionFields[i]);
10015    
10016                                    if ((i + 1) < orderByConditionFields.length) {
10017                                            if (orderByComparator.isAscending() ^ previous) {
10018                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10019                                            }
10020                                            else {
10021                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10022                                            }
10023                                    }
10024                                    else {
10025                                            if (orderByComparator.isAscending() ^ previous) {
10026                                                    query.append(WHERE_GREATER_THAN);
10027                                            }
10028                                            else {
10029                                                    query.append(WHERE_LESSER_THAN);
10030                                            }
10031                                    }
10032                            }
10033    
10034                            query.append(ORDER_BY_CLAUSE);
10035    
10036                            String[] orderByFields = orderByComparator.getOrderByFields();
10037    
10038                            for (int i = 0; i < orderByFields.length; i++) {
10039                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10040                                    query.append(orderByFields[i]);
10041    
10042                                    if ((i + 1) < orderByFields.length) {
10043                                            if (orderByComparator.isAscending() ^ previous) {
10044                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10045                                            }
10046                                            else {
10047                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10048                                            }
10049                                    }
10050                                    else {
10051                                            if (orderByComparator.isAscending() ^ previous) {
10052                                                    query.append(ORDER_BY_ASC);
10053                                            }
10054                                            else {
10055                                                    query.append(ORDER_BY_DESC);
10056                                            }
10057                                    }
10058                            }
10059                    }
10060                    else {
10061                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
10062                    }
10063    
10064                    String sql = query.toString();
10065    
10066                    Query q = session.createQuery(sql);
10067    
10068                    q.setFirstResult(0);
10069                    q.setMaxResults(2);
10070    
10071                    QueryPos qPos = QueryPos.getInstance(q);
10072    
10073                    qPos.add(groupId);
10074    
10075                    if (bindUrlTitle) {
10076                            qPos.add(urlTitle);
10077                    }
10078    
10079                    if (orderByComparator != null) {
10080                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
10081    
10082                            for (Object value : values) {
10083                                    qPos.add(value);
10084                            }
10085                    }
10086    
10087                    List<JournalArticle> list = q.list();
10088    
10089                    if (list.size() == 2) {
10090                            return list.get(1);
10091                    }
10092                    else {
10093                            return null;
10094                    }
10095            }
10096    
10097            /**
10098             * Returns all the journal articles that the user has permission to view where groupId = &#63; and urlTitle = &#63;.
10099             *
10100             * @param groupId the group ID
10101             * @param urlTitle the url title
10102             * @return the matching journal articles that the user has permission to view
10103             * @throws SystemException if a system exception occurred
10104             */
10105            @Override
10106            public List<JournalArticle> filterFindByG_UT(long groupId, String urlTitle)
10107                    throws SystemException {
10108                    return filterFindByG_UT(groupId, urlTitle, QueryUtil.ALL_POS,
10109                            QueryUtil.ALL_POS, null);
10110            }
10111    
10112            /**
10113             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and urlTitle = &#63;.
10114             *
10115             * <p>
10116             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
10117             * </p>
10118             *
10119             * @param groupId the group ID
10120             * @param urlTitle the url title
10121             * @param start the lower bound of the range of journal articles
10122             * @param end the upper bound of the range of journal articles (not inclusive)
10123             * @return the range of matching journal articles that the user has permission to view
10124             * @throws SystemException if a system exception occurred
10125             */
10126            @Override
10127            public List<JournalArticle> filterFindByG_UT(long groupId, String urlTitle,
10128                    int start, int end) throws SystemException {
10129                    return filterFindByG_UT(groupId, urlTitle, start, end, null);
10130            }
10131    
10132            /**
10133             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and urlTitle = &#63;.
10134             *
10135             * <p>
10136             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
10137             * </p>
10138             *
10139             * @param groupId the group ID
10140             * @param urlTitle the url title
10141             * @param start the lower bound of the range of journal articles
10142             * @param end the upper bound of the range of journal articles (not inclusive)
10143             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10144             * @return the ordered range of matching journal articles that the user has permission to view
10145             * @throws SystemException if a system exception occurred
10146             */
10147            @Override
10148            public List<JournalArticle> filterFindByG_UT(long groupId, String urlTitle,
10149                    int start, int end, OrderByComparator orderByComparator)
10150                    throws SystemException {
10151                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10152                            return findByG_UT(groupId, urlTitle, start, end, orderByComparator);
10153                    }
10154    
10155                    StringBundler query = null;
10156    
10157                    if (orderByComparator != null) {
10158                            query = new StringBundler(4 +
10159                                            (orderByComparator.getOrderByFields().length * 3));
10160                    }
10161                    else {
10162                            query = new StringBundler(4);
10163                    }
10164    
10165                    if (getDB().isSupportsInlineDistinct()) {
10166                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
10167                    }
10168                    else {
10169                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
10170                    }
10171    
10172                    query.append(_FINDER_COLUMN_G_UT_GROUPID_2);
10173    
10174                    boolean bindUrlTitle = false;
10175    
10176                    if (urlTitle == null) {
10177                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_1);
10178                    }
10179                    else if (urlTitle.equals(StringPool.BLANK)) {
10180                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_3);
10181                    }
10182                    else {
10183                            bindUrlTitle = true;
10184    
10185                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_2);
10186                    }
10187    
10188                    if (!getDB().isSupportsInlineDistinct()) {
10189                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
10190                    }
10191    
10192                    if (orderByComparator != null) {
10193                            if (getDB().isSupportsInlineDistinct()) {
10194                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10195                                            orderByComparator, true);
10196                            }
10197                            else {
10198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10199                                            orderByComparator, true);
10200                            }
10201                    }
10202                    else {
10203                            if (getDB().isSupportsInlineDistinct()) {
10204                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
10205                            }
10206                            else {
10207                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
10208                            }
10209                    }
10210    
10211                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10212                                    JournalArticle.class.getName(),
10213                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10214    
10215                    Session session = null;
10216    
10217                    try {
10218                            session = openSession();
10219    
10220                            SQLQuery q = session.createSQLQuery(sql);
10221    
10222                            if (getDB().isSupportsInlineDistinct()) {
10223                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
10224                            }
10225                            else {
10226                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
10227                            }
10228    
10229                            QueryPos qPos = QueryPos.getInstance(q);
10230    
10231                            qPos.add(groupId);
10232    
10233                            if (bindUrlTitle) {
10234                                    qPos.add(urlTitle);
10235                            }
10236    
10237                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
10238                                    end);
10239                    }
10240                    catch (Exception e) {
10241                            throw processException(e);
10242                    }
10243                    finally {
10244                            closeSession(session);
10245                    }
10246            }
10247    
10248            /**
10249             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and urlTitle = &#63;.
10250             *
10251             * @param id the primary key of the current journal article
10252             * @param groupId the group ID
10253             * @param urlTitle the url title
10254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10255             * @return the previous, current, and next journal article
10256             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
10257             * @throws SystemException if a system exception occurred
10258             */
10259            @Override
10260            public JournalArticle[] filterFindByG_UT_PrevAndNext(long id, long groupId,
10261                    String urlTitle, OrderByComparator orderByComparator)
10262                    throws NoSuchArticleException, SystemException {
10263                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10264                            return findByG_UT_PrevAndNext(id, groupId, urlTitle,
10265                                    orderByComparator);
10266                    }
10267    
10268                    JournalArticle journalArticle = findByPrimaryKey(id);
10269    
10270                    Session session = null;
10271    
10272                    try {
10273                            session = openSession();
10274    
10275                            JournalArticle[] array = new JournalArticleImpl[3];
10276    
10277                            array[0] = filterGetByG_UT_PrevAndNext(session, journalArticle,
10278                                            groupId, urlTitle, orderByComparator, true);
10279    
10280                            array[1] = journalArticle;
10281    
10282                            array[2] = filterGetByG_UT_PrevAndNext(session, journalArticle,
10283                                            groupId, urlTitle, orderByComparator, false);
10284    
10285                            return array;
10286                    }
10287                    catch (Exception e) {
10288                            throw processException(e);
10289                    }
10290                    finally {
10291                            closeSession(session);
10292                    }
10293            }
10294    
10295            protected JournalArticle filterGetByG_UT_PrevAndNext(Session session,
10296                    JournalArticle journalArticle, long groupId, String urlTitle,
10297                    OrderByComparator orderByComparator, boolean previous) {
10298                    StringBundler query = null;
10299    
10300                    if (orderByComparator != null) {
10301                            query = new StringBundler(6 +
10302                                            (orderByComparator.getOrderByFields().length * 6));
10303                    }
10304                    else {
10305                            query = new StringBundler(3);
10306                    }
10307    
10308                    if (getDB().isSupportsInlineDistinct()) {
10309                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
10310                    }
10311                    else {
10312                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
10313                    }
10314    
10315                    query.append(_FINDER_COLUMN_G_UT_GROUPID_2);
10316    
10317                    boolean bindUrlTitle = false;
10318    
10319                    if (urlTitle == null) {
10320                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_1);
10321                    }
10322                    else if (urlTitle.equals(StringPool.BLANK)) {
10323                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_3);
10324                    }
10325                    else {
10326                            bindUrlTitle = true;
10327    
10328                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_2);
10329                    }
10330    
10331                    if (!getDB().isSupportsInlineDistinct()) {
10332                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
10333                    }
10334    
10335                    if (orderByComparator != null) {
10336                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10337    
10338                            if (orderByConditionFields.length > 0) {
10339                                    query.append(WHERE_AND);
10340                            }
10341    
10342                            for (int i = 0; i < orderByConditionFields.length; i++) {
10343                                    if (getDB().isSupportsInlineDistinct()) {
10344                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10345                                    }
10346                                    else {
10347                                            query.append(_ORDER_BY_ENTITY_TABLE);
10348                                    }
10349    
10350                                    query.append(orderByConditionFields[i]);
10351    
10352                                    if ((i + 1) < orderByConditionFields.length) {
10353                                            if (orderByComparator.isAscending() ^ previous) {
10354                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10355                                            }
10356                                            else {
10357                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10358                                            }
10359                                    }
10360                                    else {
10361                                            if (orderByComparator.isAscending() ^ previous) {
10362                                                    query.append(WHERE_GREATER_THAN);
10363                                            }
10364                                            else {
10365                                                    query.append(WHERE_LESSER_THAN);
10366                                            }
10367                                    }
10368                            }
10369    
10370                            query.append(ORDER_BY_CLAUSE);
10371    
10372                            String[] orderByFields = orderByComparator.getOrderByFields();
10373    
10374                            for (int i = 0; i < orderByFields.length; i++) {
10375                                    if (getDB().isSupportsInlineDistinct()) {
10376                                            query.append(_ORDER_BY_ENTITY_ALIAS);
10377                                    }
10378                                    else {
10379                                            query.append(_ORDER_BY_ENTITY_TABLE);
10380                                    }
10381    
10382                                    query.append(orderByFields[i]);
10383    
10384                                    if ((i + 1) < orderByFields.length) {
10385                                            if (orderByComparator.isAscending() ^ previous) {
10386                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10387                                            }
10388                                            else {
10389                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10390                                            }
10391                                    }
10392                                    else {
10393                                            if (orderByComparator.isAscending() ^ previous) {
10394                                                    query.append(ORDER_BY_ASC);
10395                                            }
10396                                            else {
10397                                                    query.append(ORDER_BY_DESC);
10398                                            }
10399                                    }
10400                            }
10401                    }
10402                    else {
10403                            if (getDB().isSupportsInlineDistinct()) {
10404                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
10405                            }
10406                            else {
10407                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
10408                            }
10409                    }
10410    
10411                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10412                                    JournalArticle.class.getName(),
10413                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10414    
10415                    SQLQuery q = session.createSQLQuery(sql);
10416    
10417                    q.setFirstResult(0);
10418                    q.setMaxResults(2);
10419    
10420                    if (getDB().isSupportsInlineDistinct()) {
10421                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
10422                    }
10423                    else {
10424                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
10425                    }
10426    
10427                    QueryPos qPos = QueryPos.getInstance(q);
10428    
10429                    qPos.add(groupId);
10430    
10431                    if (bindUrlTitle) {
10432                            qPos.add(urlTitle);
10433                    }
10434    
10435                    if (orderByComparator != null) {
10436                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
10437    
10438                            for (Object value : values) {
10439                                    qPos.add(value);
10440                            }
10441                    }
10442    
10443                    List<JournalArticle> list = q.list();
10444    
10445                    if (list.size() == 2) {
10446                            return list.get(1);
10447                    }
10448                    else {
10449                            return null;
10450                    }
10451            }
10452    
10453            /**
10454             * Removes all the journal articles where groupId = &#63; and urlTitle = &#63; from the database.
10455             *
10456             * @param groupId the group ID
10457             * @param urlTitle the url title
10458             * @throws SystemException if a system exception occurred
10459             */
10460            @Override
10461            public void removeByG_UT(long groupId, String urlTitle)
10462                    throws SystemException {
10463                    for (JournalArticle journalArticle : findByG_UT(groupId, urlTitle,
10464                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10465                            remove(journalArticle);
10466                    }
10467            }
10468    
10469            /**
10470             * Returns the number of journal articles where groupId = &#63; and urlTitle = &#63;.
10471             *
10472             * @param groupId the group ID
10473             * @param urlTitle the url title
10474             * @return the number of matching journal articles
10475             * @throws SystemException if a system exception occurred
10476             */
10477            @Override
10478            public int countByG_UT(long groupId, String urlTitle)
10479                    throws SystemException {
10480                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_UT;
10481    
10482                    Object[] finderArgs = new Object[] { groupId, urlTitle };
10483    
10484                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10485                                    this);
10486    
10487                    if (count == null) {
10488                            StringBundler query = new StringBundler(3);
10489    
10490                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
10491    
10492                            query.append(_FINDER_COLUMN_G_UT_GROUPID_2);
10493    
10494                            boolean bindUrlTitle = false;
10495    
10496                            if (urlTitle == null) {
10497                                    query.append(_FINDER_COLUMN_G_UT_URLTITLE_1);
10498                            }
10499                            else if (urlTitle.equals(StringPool.BLANK)) {
10500                                    query.append(_FINDER_COLUMN_G_UT_URLTITLE_3);
10501                            }
10502                            else {
10503                                    bindUrlTitle = true;
10504    
10505                                    query.append(_FINDER_COLUMN_G_UT_URLTITLE_2);
10506                            }
10507    
10508                            String sql = query.toString();
10509    
10510                            Session session = null;
10511    
10512                            try {
10513                                    session = openSession();
10514    
10515                                    Query q = session.createQuery(sql);
10516    
10517                                    QueryPos qPos = QueryPos.getInstance(q);
10518    
10519                                    qPos.add(groupId);
10520    
10521                                    if (bindUrlTitle) {
10522                                            qPos.add(urlTitle);
10523                                    }
10524    
10525                                    count = (Long)q.uniqueResult();
10526    
10527                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10528                            }
10529                            catch (Exception e) {
10530                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10531    
10532                                    throw processException(e);
10533                            }
10534                            finally {
10535                                    closeSession(session);
10536                            }
10537                    }
10538    
10539                    return count.intValue();
10540            }
10541    
10542            /**
10543             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and urlTitle = &#63;.
10544             *
10545             * @param groupId the group ID
10546             * @param urlTitle the url title
10547             * @return the number of matching journal articles that the user has permission to view
10548             * @throws SystemException if a system exception occurred
10549             */
10550            @Override
10551            public int filterCountByG_UT(long groupId, String urlTitle)
10552                    throws SystemException {
10553                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10554                            return countByG_UT(groupId, urlTitle);
10555                    }
10556    
10557                    StringBundler query = new StringBundler(3);
10558    
10559                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
10560    
10561                    query.append(_FINDER_COLUMN_G_UT_GROUPID_2);
10562    
10563                    boolean bindUrlTitle = false;
10564    
10565                    if (urlTitle == null) {
10566                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_1);
10567                    }
10568                    else if (urlTitle.equals(StringPool.BLANK)) {
10569                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_3);
10570                    }
10571                    else {
10572                            bindUrlTitle = true;
10573    
10574                            query.append(_FINDER_COLUMN_G_UT_URLTITLE_2);
10575                    }
10576    
10577                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10578                                    JournalArticle.class.getName(),
10579                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10580    
10581                    Session session = null;
10582    
10583                    try {
10584                            session = openSession();
10585    
10586                            SQLQuery q = session.createSQLQuery(sql);
10587    
10588                            q.addScalar(COUNT_COLUMN_NAME,
10589                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
10590    
10591                            QueryPos qPos = QueryPos.getInstance(q);
10592    
10593                            qPos.add(groupId);
10594    
10595                            if (bindUrlTitle) {
10596                                    qPos.add(urlTitle);
10597                            }
10598    
10599                            Long count = (Long)q.uniqueResult();
10600    
10601                            return count.intValue();
10602                    }
10603                    catch (Exception e) {
10604                            throw processException(e);
10605                    }
10606                    finally {
10607                            closeSession(session);
10608                    }
10609            }
10610    
10611            private static final String _FINDER_COLUMN_G_UT_GROUPID_2 = "journalArticle.groupId = ? AND ";
10612            private static final String _FINDER_COLUMN_G_UT_URLTITLE_1 = "journalArticle.urlTitle IS NULL";
10613            private static final String _FINDER_COLUMN_G_UT_URLTITLE_2 = "journalArticle.urlTitle = ?";
10614            private static final String _FINDER_COLUMN_G_UT_URLTITLE_3 = "(journalArticle.urlTitle IS NULL OR journalArticle.urlTitle = '')";
10615            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
10616                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
10617                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
10618                            "findByG_S",
10619                            new String[] {
10620                                    Long.class.getName(), String.class.getName(),
10621                                    
10622                            Integer.class.getName(), Integer.class.getName(),
10623                                    OrderByComparator.class.getName()
10624                            });
10625            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
10626                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
10627                            JournalArticleImpl.class,
10628                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
10629                            new String[] { Long.class.getName(), String.class.getName() },
10630                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
10631                            JournalArticleModelImpl.STRUCTUREID_COLUMN_BITMASK |
10632                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
10633                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
10634            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
10635                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
10636                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
10637                            new String[] { Long.class.getName(), String.class.getName() });
10638    
10639            /**
10640             * Returns all the journal articles where groupId = &#63; and structureId = &#63;.
10641             *
10642             * @param groupId the group ID
10643             * @param structureId the structure ID
10644             * @return the matching journal articles
10645             * @throws SystemException if a system exception occurred
10646             */
10647            @Override
10648            public List<JournalArticle> findByG_S(long groupId, String structureId)
10649                    throws SystemException {
10650                    return findByG_S(groupId, structureId, QueryUtil.ALL_POS,
10651                            QueryUtil.ALL_POS, null);
10652            }
10653    
10654            /**
10655             * Returns a range of all the journal articles where groupId = &#63; and structureId = &#63;.
10656             *
10657             * <p>
10658             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
10659             * </p>
10660             *
10661             * @param groupId the group ID
10662             * @param structureId the structure ID
10663             * @param start the lower bound of the range of journal articles
10664             * @param end the upper bound of the range of journal articles (not inclusive)
10665             * @return the range of matching journal articles
10666             * @throws SystemException if a system exception occurred
10667             */
10668            @Override
10669            public List<JournalArticle> findByG_S(long groupId, String structureId,
10670                    int start, int end) throws SystemException {
10671                    return findByG_S(groupId, structureId, start, end, null);
10672            }
10673    
10674            /**
10675             * Returns an ordered range of all the journal articles where groupId = &#63; and structureId = &#63;.
10676             *
10677             * <p>
10678             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
10679             * </p>
10680             *
10681             * @param groupId the group ID
10682             * @param structureId the structure ID
10683             * @param start the lower bound of the range of journal articles
10684             * @param end the upper bound of the range of journal articles (not inclusive)
10685             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10686             * @return the ordered range of matching journal articles
10687             * @throws SystemException if a system exception occurred
10688             */
10689            @Override
10690            public List<JournalArticle> findByG_S(long groupId, String structureId,
10691                    int start, int end, OrderByComparator orderByComparator)
10692                    throws SystemException {
10693                    boolean pagination = true;
10694                    FinderPath finderPath = null;
10695                    Object[] finderArgs = null;
10696    
10697                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10698                                    (orderByComparator == null)) {
10699                            pagination = false;
10700                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
10701                            finderArgs = new Object[] { groupId, structureId };
10702                    }
10703                    else {
10704                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
10705                            finderArgs = new Object[] {
10706                                            groupId, structureId,
10707                                            
10708                                            start, end, orderByComparator
10709                                    };
10710                    }
10711    
10712                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
10713                                    finderArgs, this);
10714    
10715                    if ((list != null) && !list.isEmpty()) {
10716                            for (JournalArticle journalArticle : list) {
10717                                    if ((groupId != journalArticle.getGroupId()) ||
10718                                                    !Validator.equals(structureId,
10719                                                            journalArticle.getStructureId())) {
10720                                            list = null;
10721    
10722                                            break;
10723                                    }
10724                            }
10725                    }
10726    
10727                    if (list == null) {
10728                            StringBundler query = null;
10729    
10730                            if (orderByComparator != null) {
10731                                    query = new StringBundler(4 +
10732                                                    (orderByComparator.getOrderByFields().length * 3));
10733                            }
10734                            else {
10735                                    query = new StringBundler(4);
10736                            }
10737    
10738                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
10739    
10740                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
10741    
10742                            boolean bindStructureId = false;
10743    
10744                            if (structureId == null) {
10745                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
10746                            }
10747                            else if (structureId.equals(StringPool.BLANK)) {
10748                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
10749                            }
10750                            else {
10751                                    bindStructureId = true;
10752    
10753                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
10754                            }
10755    
10756                            if (orderByComparator != null) {
10757                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10758                                            orderByComparator);
10759                            }
10760                            else
10761                             if (pagination) {
10762                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
10763                            }
10764    
10765                            String sql = query.toString();
10766    
10767                            Session session = null;
10768    
10769                            try {
10770                                    session = openSession();
10771    
10772                                    Query q = session.createQuery(sql);
10773    
10774                                    QueryPos qPos = QueryPos.getInstance(q);
10775    
10776                                    qPos.add(groupId);
10777    
10778                                    if (bindStructureId) {
10779                                            qPos.add(structureId);
10780                                    }
10781    
10782                                    if (!pagination) {
10783                                            list = (List<JournalArticle>)QueryUtil.list(q,
10784                                                            getDialect(), start, end, false);
10785    
10786                                            Collections.sort(list);
10787    
10788                                            list = new UnmodifiableList<JournalArticle>(list);
10789                                    }
10790                                    else {
10791                                            list = (List<JournalArticle>)QueryUtil.list(q,
10792                                                            getDialect(), start, end);
10793                                    }
10794    
10795                                    cacheResult(list);
10796    
10797                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10798                            }
10799                            catch (Exception e) {
10800                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10801    
10802                                    throw processException(e);
10803                            }
10804                            finally {
10805                                    closeSession(session);
10806                            }
10807                    }
10808    
10809                    return list;
10810            }
10811    
10812            /**
10813             * Returns the first journal article in the ordered set where groupId = &#63; and structureId = &#63;.
10814             *
10815             * @param groupId the group ID
10816             * @param structureId the structure ID
10817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10818             * @return the first matching journal article
10819             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
10820             * @throws SystemException if a system exception occurred
10821             */
10822            @Override
10823            public JournalArticle findByG_S_First(long groupId, String structureId,
10824                    OrderByComparator orderByComparator)
10825                    throws NoSuchArticleException, SystemException {
10826                    JournalArticle journalArticle = fetchByG_S_First(groupId, structureId,
10827                                    orderByComparator);
10828    
10829                    if (journalArticle != null) {
10830                            return journalArticle;
10831                    }
10832    
10833                    StringBundler msg = new StringBundler(6);
10834    
10835                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10836    
10837                    msg.append("groupId=");
10838                    msg.append(groupId);
10839    
10840                    msg.append(", structureId=");
10841                    msg.append(structureId);
10842    
10843                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10844    
10845                    throw new NoSuchArticleException(msg.toString());
10846            }
10847    
10848            /**
10849             * Returns the first journal article in the ordered set where groupId = &#63; and structureId = &#63;.
10850             *
10851             * @param groupId the group ID
10852             * @param structureId the structure ID
10853             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10854             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
10855             * @throws SystemException if a system exception occurred
10856             */
10857            @Override
10858            public JournalArticle fetchByG_S_First(long groupId, String structureId,
10859                    OrderByComparator orderByComparator) throws SystemException {
10860                    List<JournalArticle> list = findByG_S(groupId, structureId, 0, 1,
10861                                    orderByComparator);
10862    
10863                    if (!list.isEmpty()) {
10864                            return list.get(0);
10865                    }
10866    
10867                    return null;
10868            }
10869    
10870            /**
10871             * Returns the last journal article in the ordered set where groupId = &#63; and structureId = &#63;.
10872             *
10873             * @param groupId the group ID
10874             * @param structureId the structure ID
10875             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10876             * @return the last matching journal article
10877             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
10878             * @throws SystemException if a system exception occurred
10879             */
10880            @Override
10881            public JournalArticle findByG_S_Last(long groupId, String structureId,
10882                    OrderByComparator orderByComparator)
10883                    throws NoSuchArticleException, SystemException {
10884                    JournalArticle journalArticle = fetchByG_S_Last(groupId, structureId,
10885                                    orderByComparator);
10886    
10887                    if (journalArticle != null) {
10888                            return journalArticle;
10889                    }
10890    
10891                    StringBundler msg = new StringBundler(6);
10892    
10893                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10894    
10895                    msg.append("groupId=");
10896                    msg.append(groupId);
10897    
10898                    msg.append(", structureId=");
10899                    msg.append(structureId);
10900    
10901                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10902    
10903                    throw new NoSuchArticleException(msg.toString());
10904            }
10905    
10906            /**
10907             * Returns the last journal article in the ordered set where groupId = &#63; and structureId = &#63;.
10908             *
10909             * @param groupId the group ID
10910             * @param structureId the structure ID
10911             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10912             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
10913             * @throws SystemException if a system exception occurred
10914             */
10915            @Override
10916            public JournalArticle fetchByG_S_Last(long groupId, String structureId,
10917                    OrderByComparator orderByComparator) throws SystemException {
10918                    int count = countByG_S(groupId, structureId);
10919    
10920                    if (count == 0) {
10921                            return null;
10922                    }
10923    
10924                    List<JournalArticle> list = findByG_S(groupId, structureId, count - 1,
10925                                    count, orderByComparator);
10926    
10927                    if (!list.isEmpty()) {
10928                            return list.get(0);
10929                    }
10930    
10931                    return null;
10932            }
10933    
10934            /**
10935             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and structureId = &#63;.
10936             *
10937             * @param id the primary key of the current journal article
10938             * @param groupId the group ID
10939             * @param structureId the structure ID
10940             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10941             * @return the previous, current, and next journal article
10942             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
10943             * @throws SystemException if a system exception occurred
10944             */
10945            @Override
10946            public JournalArticle[] findByG_S_PrevAndNext(long id, long groupId,
10947                    String structureId, OrderByComparator orderByComparator)
10948                    throws NoSuchArticleException, SystemException {
10949                    JournalArticle journalArticle = findByPrimaryKey(id);
10950    
10951                    Session session = null;
10952    
10953                    try {
10954                            session = openSession();
10955    
10956                            JournalArticle[] array = new JournalArticleImpl[3];
10957    
10958                            array[0] = getByG_S_PrevAndNext(session, journalArticle, groupId,
10959                                            structureId, orderByComparator, true);
10960    
10961                            array[1] = journalArticle;
10962    
10963                            array[2] = getByG_S_PrevAndNext(session, journalArticle, groupId,
10964                                            structureId, orderByComparator, false);
10965    
10966                            return array;
10967                    }
10968                    catch (Exception e) {
10969                            throw processException(e);
10970                    }
10971                    finally {
10972                            closeSession(session);
10973                    }
10974            }
10975    
10976            protected JournalArticle getByG_S_PrevAndNext(Session session,
10977                    JournalArticle journalArticle, long groupId, String structureId,
10978                    OrderByComparator orderByComparator, boolean previous) {
10979                    StringBundler query = null;
10980    
10981                    if (orderByComparator != null) {
10982                            query = new StringBundler(6 +
10983                                            (orderByComparator.getOrderByFields().length * 6));
10984                    }
10985                    else {
10986                            query = new StringBundler(3);
10987                    }
10988    
10989                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
10990    
10991                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
10992    
10993                    boolean bindStructureId = false;
10994    
10995                    if (structureId == null) {
10996                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
10997                    }
10998                    else if (structureId.equals(StringPool.BLANK)) {
10999                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
11000                    }
11001                    else {
11002                            bindStructureId = true;
11003    
11004                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
11005                    }
11006    
11007                    if (orderByComparator != null) {
11008                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11009    
11010                            if (orderByConditionFields.length > 0) {
11011                                    query.append(WHERE_AND);
11012                            }
11013    
11014                            for (int i = 0; i < orderByConditionFields.length; i++) {
11015                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11016                                    query.append(orderByConditionFields[i]);
11017    
11018                                    if ((i + 1) < orderByConditionFields.length) {
11019                                            if (orderByComparator.isAscending() ^ previous) {
11020                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11021                                            }
11022                                            else {
11023                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11024                                            }
11025                                    }
11026                                    else {
11027                                            if (orderByComparator.isAscending() ^ previous) {
11028                                                    query.append(WHERE_GREATER_THAN);
11029                                            }
11030                                            else {
11031                                                    query.append(WHERE_LESSER_THAN);
11032                                            }
11033                                    }
11034                            }
11035    
11036                            query.append(ORDER_BY_CLAUSE);
11037    
11038                            String[] orderByFields = orderByComparator.getOrderByFields();
11039    
11040                            for (int i = 0; i < orderByFields.length; i++) {
11041                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11042                                    query.append(orderByFields[i]);
11043    
11044                                    if ((i + 1) < orderByFields.length) {
11045                                            if (orderByComparator.isAscending() ^ previous) {
11046                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11047                                            }
11048                                            else {
11049                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11050                                            }
11051                                    }
11052                                    else {
11053                                            if (orderByComparator.isAscending() ^ previous) {
11054                                                    query.append(ORDER_BY_ASC);
11055                                            }
11056                                            else {
11057                                                    query.append(ORDER_BY_DESC);
11058                                            }
11059                                    }
11060                            }
11061                    }
11062                    else {
11063                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
11064                    }
11065    
11066                    String sql = query.toString();
11067    
11068                    Query q = session.createQuery(sql);
11069    
11070                    q.setFirstResult(0);
11071                    q.setMaxResults(2);
11072    
11073                    QueryPos qPos = QueryPos.getInstance(q);
11074    
11075                    qPos.add(groupId);
11076    
11077                    if (bindStructureId) {
11078                            qPos.add(structureId);
11079                    }
11080    
11081                    if (orderByComparator != null) {
11082                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
11083    
11084                            for (Object value : values) {
11085                                    qPos.add(value);
11086                            }
11087                    }
11088    
11089                    List<JournalArticle> list = q.list();
11090    
11091                    if (list.size() == 2) {
11092                            return list.get(1);
11093                    }
11094                    else {
11095                            return null;
11096                    }
11097            }
11098    
11099            /**
11100             * Returns all the journal articles that the user has permission to view where groupId = &#63; and structureId = &#63;.
11101             *
11102             * @param groupId the group ID
11103             * @param structureId the structure ID
11104             * @return the matching journal articles that the user has permission to view
11105             * @throws SystemException if a system exception occurred
11106             */
11107            @Override
11108            public List<JournalArticle> filterFindByG_S(long groupId, String structureId)
11109                    throws SystemException {
11110                    return filterFindByG_S(groupId, structureId, QueryUtil.ALL_POS,
11111                            QueryUtil.ALL_POS, null);
11112            }
11113    
11114            /**
11115             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and structureId = &#63;.
11116             *
11117             * <p>
11118             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
11119             * </p>
11120             *
11121             * @param groupId the group ID
11122             * @param structureId the structure ID
11123             * @param start the lower bound of the range of journal articles
11124             * @param end the upper bound of the range of journal articles (not inclusive)
11125             * @return the range of matching journal articles that the user has permission to view
11126             * @throws SystemException if a system exception occurred
11127             */
11128            @Override
11129            public List<JournalArticle> filterFindByG_S(long groupId,
11130                    String structureId, int start, int end) throws SystemException {
11131                    return filterFindByG_S(groupId, structureId, start, end, null);
11132            }
11133    
11134            /**
11135             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and structureId = &#63;.
11136             *
11137             * <p>
11138             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
11139             * </p>
11140             *
11141             * @param groupId the group ID
11142             * @param structureId the structure ID
11143             * @param start the lower bound of the range of journal articles
11144             * @param end the upper bound of the range of journal articles (not inclusive)
11145             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11146             * @return the ordered range of matching journal articles that the user has permission to view
11147             * @throws SystemException if a system exception occurred
11148             */
11149            @Override
11150            public List<JournalArticle> filterFindByG_S(long groupId,
11151                    String structureId, int start, int end,
11152                    OrderByComparator orderByComparator) throws SystemException {
11153                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11154                            return findByG_S(groupId, structureId, start, end, orderByComparator);
11155                    }
11156    
11157                    StringBundler query = null;
11158    
11159                    if (orderByComparator != null) {
11160                            query = new StringBundler(4 +
11161                                            (orderByComparator.getOrderByFields().length * 3));
11162                    }
11163                    else {
11164                            query = new StringBundler(4);
11165                    }
11166    
11167                    if (getDB().isSupportsInlineDistinct()) {
11168                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
11169                    }
11170                    else {
11171                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
11172                    }
11173    
11174                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
11175    
11176                    boolean bindStructureId = false;
11177    
11178                    if (structureId == null) {
11179                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
11180                    }
11181                    else if (structureId.equals(StringPool.BLANK)) {
11182                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
11183                    }
11184                    else {
11185                            bindStructureId = true;
11186    
11187                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
11188                    }
11189    
11190                    if (!getDB().isSupportsInlineDistinct()) {
11191                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
11192                    }
11193    
11194                    if (orderByComparator != null) {
11195                            if (getDB().isSupportsInlineDistinct()) {
11196                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11197                                            orderByComparator, true);
11198                            }
11199                            else {
11200                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11201                                            orderByComparator, true);
11202                            }
11203                    }
11204                    else {
11205                            if (getDB().isSupportsInlineDistinct()) {
11206                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
11207                            }
11208                            else {
11209                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
11210                            }
11211                    }
11212    
11213                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11214                                    JournalArticle.class.getName(),
11215                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11216    
11217                    Session session = null;
11218    
11219                    try {
11220                            session = openSession();
11221    
11222                            SQLQuery q = session.createSQLQuery(sql);
11223    
11224                            if (getDB().isSupportsInlineDistinct()) {
11225                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
11226                            }
11227                            else {
11228                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
11229                            }
11230    
11231                            QueryPos qPos = QueryPos.getInstance(q);
11232    
11233                            qPos.add(groupId);
11234    
11235                            if (bindStructureId) {
11236                                    qPos.add(structureId);
11237                            }
11238    
11239                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
11240                                    end);
11241                    }
11242                    catch (Exception e) {
11243                            throw processException(e);
11244                    }
11245                    finally {
11246                            closeSession(session);
11247                    }
11248            }
11249    
11250            /**
11251             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and structureId = &#63;.
11252             *
11253             * @param id the primary key of the current journal article
11254             * @param groupId the group ID
11255             * @param structureId the structure ID
11256             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11257             * @return the previous, current, and next journal article
11258             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
11259             * @throws SystemException if a system exception occurred
11260             */
11261            @Override
11262            public JournalArticle[] filterFindByG_S_PrevAndNext(long id, long groupId,
11263                    String structureId, OrderByComparator orderByComparator)
11264                    throws NoSuchArticleException, SystemException {
11265                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11266                            return findByG_S_PrevAndNext(id, groupId, structureId,
11267                                    orderByComparator);
11268                    }
11269    
11270                    JournalArticle journalArticle = findByPrimaryKey(id);
11271    
11272                    Session session = null;
11273    
11274                    try {
11275                            session = openSession();
11276    
11277                            JournalArticle[] array = new JournalArticleImpl[3];
11278    
11279                            array[0] = filterGetByG_S_PrevAndNext(session, journalArticle,
11280                                            groupId, structureId, orderByComparator, true);
11281    
11282                            array[1] = journalArticle;
11283    
11284                            array[2] = filterGetByG_S_PrevAndNext(session, journalArticle,
11285                                            groupId, structureId, orderByComparator, false);
11286    
11287                            return array;
11288                    }
11289                    catch (Exception e) {
11290                            throw processException(e);
11291                    }
11292                    finally {
11293                            closeSession(session);
11294                    }
11295            }
11296    
11297            protected JournalArticle filterGetByG_S_PrevAndNext(Session session,
11298                    JournalArticle journalArticle, long groupId, String structureId,
11299                    OrderByComparator orderByComparator, boolean previous) {
11300                    StringBundler query = null;
11301    
11302                    if (orderByComparator != null) {
11303                            query = new StringBundler(6 +
11304                                            (orderByComparator.getOrderByFields().length * 6));
11305                    }
11306                    else {
11307                            query = new StringBundler(3);
11308                    }
11309    
11310                    if (getDB().isSupportsInlineDistinct()) {
11311                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
11312                    }
11313                    else {
11314                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
11315                    }
11316    
11317                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
11318    
11319                    boolean bindStructureId = false;
11320    
11321                    if (structureId == null) {
11322                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
11323                    }
11324                    else if (structureId.equals(StringPool.BLANK)) {
11325                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
11326                    }
11327                    else {
11328                            bindStructureId = true;
11329    
11330                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
11331                    }
11332    
11333                    if (!getDB().isSupportsInlineDistinct()) {
11334                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
11335                    }
11336    
11337                    if (orderByComparator != null) {
11338                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11339    
11340                            if (orderByConditionFields.length > 0) {
11341                                    query.append(WHERE_AND);
11342                            }
11343    
11344                            for (int i = 0; i < orderByConditionFields.length; i++) {
11345                                    if (getDB().isSupportsInlineDistinct()) {
11346                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11347                                    }
11348                                    else {
11349                                            query.append(_ORDER_BY_ENTITY_TABLE);
11350                                    }
11351    
11352                                    query.append(orderByConditionFields[i]);
11353    
11354                                    if ((i + 1) < orderByConditionFields.length) {
11355                                            if (orderByComparator.isAscending() ^ previous) {
11356                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11357                                            }
11358                                            else {
11359                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11360                                            }
11361                                    }
11362                                    else {
11363                                            if (orderByComparator.isAscending() ^ previous) {
11364                                                    query.append(WHERE_GREATER_THAN);
11365                                            }
11366                                            else {
11367                                                    query.append(WHERE_LESSER_THAN);
11368                                            }
11369                                    }
11370                            }
11371    
11372                            query.append(ORDER_BY_CLAUSE);
11373    
11374                            String[] orderByFields = orderByComparator.getOrderByFields();
11375    
11376                            for (int i = 0; i < orderByFields.length; i++) {
11377                                    if (getDB().isSupportsInlineDistinct()) {
11378                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11379                                    }
11380                                    else {
11381                                            query.append(_ORDER_BY_ENTITY_TABLE);
11382                                    }
11383    
11384                                    query.append(orderByFields[i]);
11385    
11386                                    if ((i + 1) < orderByFields.length) {
11387                                            if (orderByComparator.isAscending() ^ previous) {
11388                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11389                                            }
11390                                            else {
11391                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11392                                            }
11393                                    }
11394                                    else {
11395                                            if (orderByComparator.isAscending() ^ previous) {
11396                                                    query.append(ORDER_BY_ASC);
11397                                            }
11398                                            else {
11399                                                    query.append(ORDER_BY_DESC);
11400                                            }
11401                                    }
11402                            }
11403                    }
11404                    else {
11405                            if (getDB().isSupportsInlineDistinct()) {
11406                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
11407                            }
11408                            else {
11409                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
11410                            }
11411                    }
11412    
11413                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11414                                    JournalArticle.class.getName(),
11415                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11416    
11417                    SQLQuery q = session.createSQLQuery(sql);
11418    
11419                    q.setFirstResult(0);
11420                    q.setMaxResults(2);
11421    
11422                    if (getDB().isSupportsInlineDistinct()) {
11423                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
11424                    }
11425                    else {
11426                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
11427                    }
11428    
11429                    QueryPos qPos = QueryPos.getInstance(q);
11430    
11431                    qPos.add(groupId);
11432    
11433                    if (bindStructureId) {
11434                            qPos.add(structureId);
11435                    }
11436    
11437                    if (orderByComparator != null) {
11438                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
11439    
11440                            for (Object value : values) {
11441                                    qPos.add(value);
11442                            }
11443                    }
11444    
11445                    List<JournalArticle> list = q.list();
11446    
11447                    if (list.size() == 2) {
11448                            return list.get(1);
11449                    }
11450                    else {
11451                            return null;
11452                    }
11453            }
11454    
11455            /**
11456             * Removes all the journal articles where groupId = &#63; and structureId = &#63; from the database.
11457             *
11458             * @param groupId the group ID
11459             * @param structureId the structure ID
11460             * @throws SystemException if a system exception occurred
11461             */
11462            @Override
11463            public void removeByG_S(long groupId, String structureId)
11464                    throws SystemException {
11465                    for (JournalArticle journalArticle : findByG_S(groupId, structureId,
11466                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11467                            remove(journalArticle);
11468                    }
11469            }
11470    
11471            /**
11472             * Returns the number of journal articles where groupId = &#63; and structureId = &#63;.
11473             *
11474             * @param groupId the group ID
11475             * @param structureId the structure ID
11476             * @return the number of matching journal articles
11477             * @throws SystemException if a system exception occurred
11478             */
11479            @Override
11480            public int countByG_S(long groupId, String structureId)
11481                    throws SystemException {
11482                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
11483    
11484                    Object[] finderArgs = new Object[] { groupId, structureId };
11485    
11486                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11487                                    this);
11488    
11489                    if (count == null) {
11490                            StringBundler query = new StringBundler(3);
11491    
11492                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
11493    
11494                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
11495    
11496                            boolean bindStructureId = false;
11497    
11498                            if (structureId == null) {
11499                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
11500                            }
11501                            else if (structureId.equals(StringPool.BLANK)) {
11502                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
11503                            }
11504                            else {
11505                                    bindStructureId = true;
11506    
11507                                    query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
11508                            }
11509    
11510                            String sql = query.toString();
11511    
11512                            Session session = null;
11513    
11514                            try {
11515                                    session = openSession();
11516    
11517                                    Query q = session.createQuery(sql);
11518    
11519                                    QueryPos qPos = QueryPos.getInstance(q);
11520    
11521                                    qPos.add(groupId);
11522    
11523                                    if (bindStructureId) {
11524                                            qPos.add(structureId);
11525                                    }
11526    
11527                                    count = (Long)q.uniqueResult();
11528    
11529                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11530                            }
11531                            catch (Exception e) {
11532                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11533    
11534                                    throw processException(e);
11535                            }
11536                            finally {
11537                                    closeSession(session);
11538                            }
11539                    }
11540    
11541                    return count.intValue();
11542            }
11543    
11544            /**
11545             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and structureId = &#63;.
11546             *
11547             * @param groupId the group ID
11548             * @param structureId the structure ID
11549             * @return the number of matching journal articles that the user has permission to view
11550             * @throws SystemException if a system exception occurred
11551             */
11552            @Override
11553            public int filterCountByG_S(long groupId, String structureId)
11554                    throws SystemException {
11555                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11556                            return countByG_S(groupId, structureId);
11557                    }
11558    
11559                    StringBundler query = new StringBundler(3);
11560    
11561                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
11562    
11563                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
11564    
11565                    boolean bindStructureId = false;
11566    
11567                    if (structureId == null) {
11568                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_1);
11569                    }
11570                    else if (structureId.equals(StringPool.BLANK)) {
11571                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_3);
11572                    }
11573                    else {
11574                            bindStructureId = true;
11575    
11576                            query.append(_FINDER_COLUMN_G_S_STRUCTUREID_2);
11577                    }
11578    
11579                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11580                                    JournalArticle.class.getName(),
11581                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11582    
11583                    Session session = null;
11584    
11585                    try {
11586                            session = openSession();
11587    
11588                            SQLQuery q = session.createSQLQuery(sql);
11589    
11590                            q.addScalar(COUNT_COLUMN_NAME,
11591                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11592    
11593                            QueryPos qPos = QueryPos.getInstance(q);
11594    
11595                            qPos.add(groupId);
11596    
11597                            if (bindStructureId) {
11598                                    qPos.add(structureId);
11599                            }
11600    
11601                            Long count = (Long)q.uniqueResult();
11602    
11603                            return count.intValue();
11604                    }
11605                    catch (Exception e) {
11606                            throw processException(e);
11607                    }
11608                    finally {
11609                            closeSession(session);
11610                    }
11611            }
11612    
11613            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "journalArticle.groupId = ? AND ";
11614            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_1 = "journalArticle.structureId IS NULL";
11615            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_2 = "journalArticle.structureId = ?";
11616            private static final String _FINDER_COLUMN_G_S_STRUCTUREID_3 = "(journalArticle.structureId IS NULL OR journalArticle.structureId = '')";
11617            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
11618                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
11619                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
11620                            "findByG_T",
11621                            new String[] {
11622                                    Long.class.getName(), String.class.getName(),
11623                                    
11624                            Integer.class.getName(), Integer.class.getName(),
11625                                    OrderByComparator.class.getName()
11626                            });
11627            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
11628                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
11629                            JournalArticleImpl.class,
11630                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_T",
11631                            new String[] { Long.class.getName(), String.class.getName() },
11632                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
11633                            JournalArticleModelImpl.TEMPLATEID_COLUMN_BITMASK |
11634                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
11635                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
11636            public static final FinderPath FINDER_PATH_COUNT_BY_G_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
11637                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
11638                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_T",
11639                            new String[] { Long.class.getName(), String.class.getName() });
11640    
11641            /**
11642             * Returns all the journal articles where groupId = &#63; and templateId = &#63;.
11643             *
11644             * @param groupId the group ID
11645             * @param templateId the template ID
11646             * @return the matching journal articles
11647             * @throws SystemException if a system exception occurred
11648             */
11649            @Override
11650            public List<JournalArticle> findByG_T(long groupId, String templateId)
11651                    throws SystemException {
11652                    return findByG_T(groupId, templateId, QueryUtil.ALL_POS,
11653                            QueryUtil.ALL_POS, null);
11654            }
11655    
11656            /**
11657             * Returns a range of all the journal articles where groupId = &#63; and templateId = &#63;.
11658             *
11659             * <p>
11660             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
11661             * </p>
11662             *
11663             * @param groupId the group ID
11664             * @param templateId the template ID
11665             * @param start the lower bound of the range of journal articles
11666             * @param end the upper bound of the range of journal articles (not inclusive)
11667             * @return the range of matching journal articles
11668             * @throws SystemException if a system exception occurred
11669             */
11670            @Override
11671            public List<JournalArticle> findByG_T(long groupId, String templateId,
11672                    int start, int end) throws SystemException {
11673                    return findByG_T(groupId, templateId, start, end, null);
11674            }
11675    
11676            /**
11677             * Returns an ordered range of all the journal articles where groupId = &#63; and templateId = &#63;.
11678             *
11679             * <p>
11680             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
11681             * </p>
11682             *
11683             * @param groupId the group ID
11684             * @param templateId the template ID
11685             * @param start the lower bound of the range of journal articles
11686             * @param end the upper bound of the range of journal articles (not inclusive)
11687             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11688             * @return the ordered range of matching journal articles
11689             * @throws SystemException if a system exception occurred
11690             */
11691            @Override
11692            public List<JournalArticle> findByG_T(long groupId, String templateId,
11693                    int start, int end, OrderByComparator orderByComparator)
11694                    throws SystemException {
11695                    boolean pagination = true;
11696                    FinderPath finderPath = null;
11697                    Object[] finderArgs = null;
11698    
11699                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11700                                    (orderByComparator == null)) {
11701                            pagination = false;
11702                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T;
11703                            finderArgs = new Object[] { groupId, templateId };
11704                    }
11705                    else {
11706                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_T;
11707                            finderArgs = new Object[] {
11708                                            groupId, templateId,
11709                                            
11710                                            start, end, orderByComparator
11711                                    };
11712                    }
11713    
11714                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
11715                                    finderArgs, this);
11716    
11717                    if ((list != null) && !list.isEmpty()) {
11718                            for (JournalArticle journalArticle : list) {
11719                                    if ((groupId != journalArticle.getGroupId()) ||
11720                                                    !Validator.equals(templateId,
11721                                                            journalArticle.getTemplateId())) {
11722                                            list = null;
11723    
11724                                            break;
11725                                    }
11726                            }
11727                    }
11728    
11729                    if (list == null) {
11730                            StringBundler query = null;
11731    
11732                            if (orderByComparator != null) {
11733                                    query = new StringBundler(4 +
11734                                                    (orderByComparator.getOrderByFields().length * 3));
11735                            }
11736                            else {
11737                                    query = new StringBundler(4);
11738                            }
11739    
11740                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
11741    
11742                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
11743    
11744                            boolean bindTemplateId = false;
11745    
11746                            if (templateId == null) {
11747                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
11748                            }
11749                            else if (templateId.equals(StringPool.BLANK)) {
11750                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
11751                            }
11752                            else {
11753                                    bindTemplateId = true;
11754    
11755                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
11756                            }
11757    
11758                            if (orderByComparator != null) {
11759                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11760                                            orderByComparator);
11761                            }
11762                            else
11763                             if (pagination) {
11764                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
11765                            }
11766    
11767                            String sql = query.toString();
11768    
11769                            Session session = null;
11770    
11771                            try {
11772                                    session = openSession();
11773    
11774                                    Query q = session.createQuery(sql);
11775    
11776                                    QueryPos qPos = QueryPos.getInstance(q);
11777    
11778                                    qPos.add(groupId);
11779    
11780                                    if (bindTemplateId) {
11781                                            qPos.add(templateId);
11782                                    }
11783    
11784                                    if (!pagination) {
11785                                            list = (List<JournalArticle>)QueryUtil.list(q,
11786                                                            getDialect(), start, end, false);
11787    
11788                                            Collections.sort(list);
11789    
11790                                            list = new UnmodifiableList<JournalArticle>(list);
11791                                    }
11792                                    else {
11793                                            list = (List<JournalArticle>)QueryUtil.list(q,
11794                                                            getDialect(), start, end);
11795                                    }
11796    
11797                                    cacheResult(list);
11798    
11799                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11800                            }
11801                            catch (Exception e) {
11802                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11803    
11804                                    throw processException(e);
11805                            }
11806                            finally {
11807                                    closeSession(session);
11808                            }
11809                    }
11810    
11811                    return list;
11812            }
11813    
11814            /**
11815             * Returns the first journal article in the ordered set where groupId = &#63; and templateId = &#63;.
11816             *
11817             * @param groupId the group ID
11818             * @param templateId the template ID
11819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11820             * @return the first matching journal article
11821             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
11822             * @throws SystemException if a system exception occurred
11823             */
11824            @Override
11825            public JournalArticle findByG_T_First(long groupId, String templateId,
11826                    OrderByComparator orderByComparator)
11827                    throws NoSuchArticleException, SystemException {
11828                    JournalArticle journalArticle = fetchByG_T_First(groupId, templateId,
11829                                    orderByComparator);
11830    
11831                    if (journalArticle != null) {
11832                            return journalArticle;
11833                    }
11834    
11835                    StringBundler msg = new StringBundler(6);
11836    
11837                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11838    
11839                    msg.append("groupId=");
11840                    msg.append(groupId);
11841    
11842                    msg.append(", templateId=");
11843                    msg.append(templateId);
11844    
11845                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11846    
11847                    throw new NoSuchArticleException(msg.toString());
11848            }
11849    
11850            /**
11851             * Returns the first journal article in the ordered set where groupId = &#63; and templateId = &#63;.
11852             *
11853             * @param groupId the group ID
11854             * @param templateId the template ID
11855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11856             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
11857             * @throws SystemException if a system exception occurred
11858             */
11859            @Override
11860            public JournalArticle fetchByG_T_First(long groupId, String templateId,
11861                    OrderByComparator orderByComparator) throws SystemException {
11862                    List<JournalArticle> list = findByG_T(groupId, templateId, 0, 1,
11863                                    orderByComparator);
11864    
11865                    if (!list.isEmpty()) {
11866                            return list.get(0);
11867                    }
11868    
11869                    return null;
11870            }
11871    
11872            /**
11873             * Returns the last journal article in the ordered set where groupId = &#63; and templateId = &#63;.
11874             *
11875             * @param groupId the group ID
11876             * @param templateId the template ID
11877             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11878             * @return the last matching journal article
11879             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
11880             * @throws SystemException if a system exception occurred
11881             */
11882            @Override
11883            public JournalArticle findByG_T_Last(long groupId, String templateId,
11884                    OrderByComparator orderByComparator)
11885                    throws NoSuchArticleException, SystemException {
11886                    JournalArticle journalArticle = fetchByG_T_Last(groupId, templateId,
11887                                    orderByComparator);
11888    
11889                    if (journalArticle != null) {
11890                            return journalArticle;
11891                    }
11892    
11893                    StringBundler msg = new StringBundler(6);
11894    
11895                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11896    
11897                    msg.append("groupId=");
11898                    msg.append(groupId);
11899    
11900                    msg.append(", templateId=");
11901                    msg.append(templateId);
11902    
11903                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11904    
11905                    throw new NoSuchArticleException(msg.toString());
11906            }
11907    
11908            /**
11909             * Returns the last journal article in the ordered set where groupId = &#63; and templateId = &#63;.
11910             *
11911             * @param groupId the group ID
11912             * @param templateId the template ID
11913             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11914             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
11915             * @throws SystemException if a system exception occurred
11916             */
11917            @Override
11918            public JournalArticle fetchByG_T_Last(long groupId, String templateId,
11919                    OrderByComparator orderByComparator) throws SystemException {
11920                    int count = countByG_T(groupId, templateId);
11921    
11922                    if (count == 0) {
11923                            return null;
11924                    }
11925    
11926                    List<JournalArticle> list = findByG_T(groupId, templateId, count - 1,
11927                                    count, orderByComparator);
11928    
11929                    if (!list.isEmpty()) {
11930                            return list.get(0);
11931                    }
11932    
11933                    return null;
11934            }
11935    
11936            /**
11937             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and templateId = &#63;.
11938             *
11939             * @param id the primary key of the current journal article
11940             * @param groupId the group ID
11941             * @param templateId the template ID
11942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11943             * @return the previous, current, and next journal article
11944             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
11945             * @throws SystemException if a system exception occurred
11946             */
11947            @Override
11948            public JournalArticle[] findByG_T_PrevAndNext(long id, long groupId,
11949                    String templateId, OrderByComparator orderByComparator)
11950                    throws NoSuchArticleException, SystemException {
11951                    JournalArticle journalArticle = findByPrimaryKey(id);
11952    
11953                    Session session = null;
11954    
11955                    try {
11956                            session = openSession();
11957    
11958                            JournalArticle[] array = new JournalArticleImpl[3];
11959    
11960                            array[0] = getByG_T_PrevAndNext(session, journalArticle, groupId,
11961                                            templateId, orderByComparator, true);
11962    
11963                            array[1] = journalArticle;
11964    
11965                            array[2] = getByG_T_PrevAndNext(session, journalArticle, groupId,
11966                                            templateId, orderByComparator, false);
11967    
11968                            return array;
11969                    }
11970                    catch (Exception e) {
11971                            throw processException(e);
11972                    }
11973                    finally {
11974                            closeSession(session);
11975                    }
11976            }
11977    
11978            protected JournalArticle getByG_T_PrevAndNext(Session session,
11979                    JournalArticle journalArticle, long groupId, String templateId,
11980                    OrderByComparator orderByComparator, boolean previous) {
11981                    StringBundler query = null;
11982    
11983                    if (orderByComparator != null) {
11984                            query = new StringBundler(6 +
11985                                            (orderByComparator.getOrderByFields().length * 6));
11986                    }
11987                    else {
11988                            query = new StringBundler(3);
11989                    }
11990    
11991                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
11992    
11993                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
11994    
11995                    boolean bindTemplateId = false;
11996    
11997                    if (templateId == null) {
11998                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
11999                    }
12000                    else if (templateId.equals(StringPool.BLANK)) {
12001                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
12002                    }
12003                    else {
12004                            bindTemplateId = true;
12005    
12006                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
12007                    }
12008    
12009                    if (orderByComparator != null) {
12010                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12011    
12012                            if (orderByConditionFields.length > 0) {
12013                                    query.append(WHERE_AND);
12014                            }
12015    
12016                            for (int i = 0; i < orderByConditionFields.length; i++) {
12017                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12018                                    query.append(orderByConditionFields[i]);
12019    
12020                                    if ((i + 1) < orderByConditionFields.length) {
12021                                            if (orderByComparator.isAscending() ^ previous) {
12022                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12023                                            }
12024                                            else {
12025                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12026                                            }
12027                                    }
12028                                    else {
12029                                            if (orderByComparator.isAscending() ^ previous) {
12030                                                    query.append(WHERE_GREATER_THAN);
12031                                            }
12032                                            else {
12033                                                    query.append(WHERE_LESSER_THAN);
12034                                            }
12035                                    }
12036                            }
12037    
12038                            query.append(ORDER_BY_CLAUSE);
12039    
12040                            String[] orderByFields = orderByComparator.getOrderByFields();
12041    
12042                            for (int i = 0; i < orderByFields.length; i++) {
12043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12044                                    query.append(orderByFields[i]);
12045    
12046                                    if ((i + 1) < orderByFields.length) {
12047                                            if (orderByComparator.isAscending() ^ previous) {
12048                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12049                                            }
12050                                            else {
12051                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12052                                            }
12053                                    }
12054                                    else {
12055                                            if (orderByComparator.isAscending() ^ previous) {
12056                                                    query.append(ORDER_BY_ASC);
12057                                            }
12058                                            else {
12059                                                    query.append(ORDER_BY_DESC);
12060                                            }
12061                                    }
12062                            }
12063                    }
12064                    else {
12065                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
12066                    }
12067    
12068                    String sql = query.toString();
12069    
12070                    Query q = session.createQuery(sql);
12071    
12072                    q.setFirstResult(0);
12073                    q.setMaxResults(2);
12074    
12075                    QueryPos qPos = QueryPos.getInstance(q);
12076    
12077                    qPos.add(groupId);
12078    
12079                    if (bindTemplateId) {
12080                            qPos.add(templateId);
12081                    }
12082    
12083                    if (orderByComparator != null) {
12084                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
12085    
12086                            for (Object value : values) {
12087                                    qPos.add(value);
12088                            }
12089                    }
12090    
12091                    List<JournalArticle> list = q.list();
12092    
12093                    if (list.size() == 2) {
12094                            return list.get(1);
12095                    }
12096                    else {
12097                            return null;
12098                    }
12099            }
12100    
12101            /**
12102             * Returns all the journal articles that the user has permission to view where groupId = &#63; and templateId = &#63;.
12103             *
12104             * @param groupId the group ID
12105             * @param templateId the template ID
12106             * @return the matching journal articles that the user has permission to view
12107             * @throws SystemException if a system exception occurred
12108             */
12109            @Override
12110            public List<JournalArticle> filterFindByG_T(long groupId, String templateId)
12111                    throws SystemException {
12112                    return filterFindByG_T(groupId, templateId, QueryUtil.ALL_POS,
12113                            QueryUtil.ALL_POS, null);
12114            }
12115    
12116            /**
12117             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and templateId = &#63;.
12118             *
12119             * <p>
12120             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
12121             * </p>
12122             *
12123             * @param groupId the group ID
12124             * @param templateId the template ID
12125             * @param start the lower bound of the range of journal articles
12126             * @param end the upper bound of the range of journal articles (not inclusive)
12127             * @return the range of matching journal articles that the user has permission to view
12128             * @throws SystemException if a system exception occurred
12129             */
12130            @Override
12131            public List<JournalArticle> filterFindByG_T(long groupId,
12132                    String templateId, int start, int end) throws SystemException {
12133                    return filterFindByG_T(groupId, templateId, start, end, null);
12134            }
12135    
12136            /**
12137             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and templateId = &#63;.
12138             *
12139             * <p>
12140             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
12141             * </p>
12142             *
12143             * @param groupId the group ID
12144             * @param templateId the template ID
12145             * @param start the lower bound of the range of journal articles
12146             * @param end the upper bound of the range of journal articles (not inclusive)
12147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12148             * @return the ordered range of matching journal articles that the user has permission to view
12149             * @throws SystemException if a system exception occurred
12150             */
12151            @Override
12152            public List<JournalArticle> filterFindByG_T(long groupId,
12153                    String templateId, int start, int end,
12154                    OrderByComparator orderByComparator) throws SystemException {
12155                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12156                            return findByG_T(groupId, templateId, start, end, orderByComparator);
12157                    }
12158    
12159                    StringBundler query = null;
12160    
12161                    if (orderByComparator != null) {
12162                            query = new StringBundler(4 +
12163                                            (orderByComparator.getOrderByFields().length * 3));
12164                    }
12165                    else {
12166                            query = new StringBundler(4);
12167                    }
12168    
12169                    if (getDB().isSupportsInlineDistinct()) {
12170                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
12171                    }
12172                    else {
12173                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
12174                    }
12175    
12176                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
12177    
12178                    boolean bindTemplateId = false;
12179    
12180                    if (templateId == null) {
12181                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
12182                    }
12183                    else if (templateId.equals(StringPool.BLANK)) {
12184                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
12185                    }
12186                    else {
12187                            bindTemplateId = true;
12188    
12189                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
12190                    }
12191    
12192                    if (!getDB().isSupportsInlineDistinct()) {
12193                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
12194                    }
12195    
12196                    if (orderByComparator != null) {
12197                            if (getDB().isSupportsInlineDistinct()) {
12198                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12199                                            orderByComparator, true);
12200                            }
12201                            else {
12202                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12203                                            orderByComparator, true);
12204                            }
12205                    }
12206                    else {
12207                            if (getDB().isSupportsInlineDistinct()) {
12208                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
12209                            }
12210                            else {
12211                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
12212                            }
12213                    }
12214    
12215                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12216                                    JournalArticle.class.getName(),
12217                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12218    
12219                    Session session = null;
12220    
12221                    try {
12222                            session = openSession();
12223    
12224                            SQLQuery q = session.createSQLQuery(sql);
12225    
12226                            if (getDB().isSupportsInlineDistinct()) {
12227                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
12228                            }
12229                            else {
12230                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
12231                            }
12232    
12233                            QueryPos qPos = QueryPos.getInstance(q);
12234    
12235                            qPos.add(groupId);
12236    
12237                            if (bindTemplateId) {
12238                                    qPos.add(templateId);
12239                            }
12240    
12241                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
12242                                    end);
12243                    }
12244                    catch (Exception e) {
12245                            throw processException(e);
12246                    }
12247                    finally {
12248                            closeSession(session);
12249                    }
12250            }
12251    
12252            /**
12253             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and templateId = &#63;.
12254             *
12255             * @param id the primary key of the current journal article
12256             * @param groupId the group ID
12257             * @param templateId the template ID
12258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12259             * @return the previous, current, and next journal article
12260             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
12261             * @throws SystemException if a system exception occurred
12262             */
12263            @Override
12264            public JournalArticle[] filterFindByG_T_PrevAndNext(long id, long groupId,
12265                    String templateId, OrderByComparator orderByComparator)
12266                    throws NoSuchArticleException, SystemException {
12267                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12268                            return findByG_T_PrevAndNext(id, groupId, templateId,
12269                                    orderByComparator);
12270                    }
12271    
12272                    JournalArticle journalArticle = findByPrimaryKey(id);
12273    
12274                    Session session = null;
12275    
12276                    try {
12277                            session = openSession();
12278    
12279                            JournalArticle[] array = new JournalArticleImpl[3];
12280    
12281                            array[0] = filterGetByG_T_PrevAndNext(session, journalArticle,
12282                                            groupId, templateId, orderByComparator, true);
12283    
12284                            array[1] = journalArticle;
12285    
12286                            array[2] = filterGetByG_T_PrevAndNext(session, journalArticle,
12287                                            groupId, templateId, orderByComparator, false);
12288    
12289                            return array;
12290                    }
12291                    catch (Exception e) {
12292                            throw processException(e);
12293                    }
12294                    finally {
12295                            closeSession(session);
12296                    }
12297            }
12298    
12299            protected JournalArticle filterGetByG_T_PrevAndNext(Session session,
12300                    JournalArticle journalArticle, long groupId, String templateId,
12301                    OrderByComparator orderByComparator, boolean previous) {
12302                    StringBundler query = null;
12303    
12304                    if (orderByComparator != null) {
12305                            query = new StringBundler(6 +
12306                                            (orderByComparator.getOrderByFields().length * 6));
12307                    }
12308                    else {
12309                            query = new StringBundler(3);
12310                    }
12311    
12312                    if (getDB().isSupportsInlineDistinct()) {
12313                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
12314                    }
12315                    else {
12316                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
12317                    }
12318    
12319                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
12320    
12321                    boolean bindTemplateId = false;
12322    
12323                    if (templateId == null) {
12324                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
12325                    }
12326                    else if (templateId.equals(StringPool.BLANK)) {
12327                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
12328                    }
12329                    else {
12330                            bindTemplateId = true;
12331    
12332                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
12333                    }
12334    
12335                    if (!getDB().isSupportsInlineDistinct()) {
12336                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
12337                    }
12338    
12339                    if (orderByComparator != null) {
12340                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12341    
12342                            if (orderByConditionFields.length > 0) {
12343                                    query.append(WHERE_AND);
12344                            }
12345    
12346                            for (int i = 0; i < orderByConditionFields.length; i++) {
12347                                    if (getDB().isSupportsInlineDistinct()) {
12348                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12349                                    }
12350                                    else {
12351                                            query.append(_ORDER_BY_ENTITY_TABLE);
12352                                    }
12353    
12354                                    query.append(orderByConditionFields[i]);
12355    
12356                                    if ((i + 1) < orderByConditionFields.length) {
12357                                            if (orderByComparator.isAscending() ^ previous) {
12358                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12359                                            }
12360                                            else {
12361                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12362                                            }
12363                                    }
12364                                    else {
12365                                            if (orderByComparator.isAscending() ^ previous) {
12366                                                    query.append(WHERE_GREATER_THAN);
12367                                            }
12368                                            else {
12369                                                    query.append(WHERE_LESSER_THAN);
12370                                            }
12371                                    }
12372                            }
12373    
12374                            query.append(ORDER_BY_CLAUSE);
12375    
12376                            String[] orderByFields = orderByComparator.getOrderByFields();
12377    
12378                            for (int i = 0; i < orderByFields.length; i++) {
12379                                    if (getDB().isSupportsInlineDistinct()) {
12380                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12381                                    }
12382                                    else {
12383                                            query.append(_ORDER_BY_ENTITY_TABLE);
12384                                    }
12385    
12386                                    query.append(orderByFields[i]);
12387    
12388                                    if ((i + 1) < orderByFields.length) {
12389                                            if (orderByComparator.isAscending() ^ previous) {
12390                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12391                                            }
12392                                            else {
12393                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12394                                            }
12395                                    }
12396                                    else {
12397                                            if (orderByComparator.isAscending() ^ previous) {
12398                                                    query.append(ORDER_BY_ASC);
12399                                            }
12400                                            else {
12401                                                    query.append(ORDER_BY_DESC);
12402                                            }
12403                                    }
12404                            }
12405                    }
12406                    else {
12407                            if (getDB().isSupportsInlineDistinct()) {
12408                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
12409                            }
12410                            else {
12411                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
12412                            }
12413                    }
12414    
12415                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12416                                    JournalArticle.class.getName(),
12417                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12418    
12419                    SQLQuery q = session.createSQLQuery(sql);
12420    
12421                    q.setFirstResult(0);
12422                    q.setMaxResults(2);
12423    
12424                    if (getDB().isSupportsInlineDistinct()) {
12425                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
12426                    }
12427                    else {
12428                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
12429                    }
12430    
12431                    QueryPos qPos = QueryPos.getInstance(q);
12432    
12433                    qPos.add(groupId);
12434    
12435                    if (bindTemplateId) {
12436                            qPos.add(templateId);
12437                    }
12438    
12439                    if (orderByComparator != null) {
12440                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
12441    
12442                            for (Object value : values) {
12443                                    qPos.add(value);
12444                            }
12445                    }
12446    
12447                    List<JournalArticle> list = q.list();
12448    
12449                    if (list.size() == 2) {
12450                            return list.get(1);
12451                    }
12452                    else {
12453                            return null;
12454                    }
12455            }
12456    
12457            /**
12458             * Removes all the journal articles where groupId = &#63; and templateId = &#63; from the database.
12459             *
12460             * @param groupId the group ID
12461             * @param templateId the template ID
12462             * @throws SystemException if a system exception occurred
12463             */
12464            @Override
12465            public void removeByG_T(long groupId, String templateId)
12466                    throws SystemException {
12467                    for (JournalArticle journalArticle : findByG_T(groupId, templateId,
12468                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12469                            remove(journalArticle);
12470                    }
12471            }
12472    
12473            /**
12474             * Returns the number of journal articles where groupId = &#63; and templateId = &#63;.
12475             *
12476             * @param groupId the group ID
12477             * @param templateId the template ID
12478             * @return the number of matching journal articles
12479             * @throws SystemException if a system exception occurred
12480             */
12481            @Override
12482            public int countByG_T(long groupId, String templateId)
12483                    throws SystemException {
12484                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_T;
12485    
12486                    Object[] finderArgs = new Object[] { groupId, templateId };
12487    
12488                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12489                                    this);
12490    
12491                    if (count == null) {
12492                            StringBundler query = new StringBundler(3);
12493    
12494                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
12495    
12496                            query.append(_FINDER_COLUMN_G_T_GROUPID_2);
12497    
12498                            boolean bindTemplateId = false;
12499    
12500                            if (templateId == null) {
12501                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
12502                            }
12503                            else if (templateId.equals(StringPool.BLANK)) {
12504                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
12505                            }
12506                            else {
12507                                    bindTemplateId = true;
12508    
12509                                    query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
12510                            }
12511    
12512                            String sql = query.toString();
12513    
12514                            Session session = null;
12515    
12516                            try {
12517                                    session = openSession();
12518    
12519                                    Query q = session.createQuery(sql);
12520    
12521                                    QueryPos qPos = QueryPos.getInstance(q);
12522    
12523                                    qPos.add(groupId);
12524    
12525                                    if (bindTemplateId) {
12526                                            qPos.add(templateId);
12527                                    }
12528    
12529                                    count = (Long)q.uniqueResult();
12530    
12531                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12532                            }
12533                            catch (Exception e) {
12534                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12535    
12536                                    throw processException(e);
12537                            }
12538                            finally {
12539                                    closeSession(session);
12540                            }
12541                    }
12542    
12543                    return count.intValue();
12544            }
12545    
12546            /**
12547             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and templateId = &#63;.
12548             *
12549             * @param groupId the group ID
12550             * @param templateId the template ID
12551             * @return the number of matching journal articles that the user has permission to view
12552             * @throws SystemException if a system exception occurred
12553             */
12554            @Override
12555            public int filterCountByG_T(long groupId, String templateId)
12556                    throws SystemException {
12557                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12558                            return countByG_T(groupId, templateId);
12559                    }
12560    
12561                    StringBundler query = new StringBundler(3);
12562    
12563                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
12564    
12565                    query.append(_FINDER_COLUMN_G_T_GROUPID_2);
12566    
12567                    boolean bindTemplateId = false;
12568    
12569                    if (templateId == null) {
12570                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_1);
12571                    }
12572                    else if (templateId.equals(StringPool.BLANK)) {
12573                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_3);
12574                    }
12575                    else {
12576                            bindTemplateId = true;
12577    
12578                            query.append(_FINDER_COLUMN_G_T_TEMPLATEID_2);
12579                    }
12580    
12581                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12582                                    JournalArticle.class.getName(),
12583                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12584    
12585                    Session session = null;
12586    
12587                    try {
12588                            session = openSession();
12589    
12590                            SQLQuery q = session.createSQLQuery(sql);
12591    
12592                            q.addScalar(COUNT_COLUMN_NAME,
12593                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12594    
12595                            QueryPos qPos = QueryPos.getInstance(q);
12596    
12597                            qPos.add(groupId);
12598    
12599                            if (bindTemplateId) {
12600                                    qPos.add(templateId);
12601                            }
12602    
12603                            Long count = (Long)q.uniqueResult();
12604    
12605                            return count.intValue();
12606                    }
12607                    catch (Exception e) {
12608                            throw processException(e);
12609                    }
12610                    finally {
12611                            closeSession(session);
12612                    }
12613            }
12614    
12615            private static final String _FINDER_COLUMN_G_T_GROUPID_2 = "journalArticle.groupId = ? AND ";
12616            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_1 = "journalArticle.templateId IS NULL";
12617            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_2 = "journalArticle.templateId = ?";
12618            private static final String _FINDER_COLUMN_G_T_TEMPLATEID_3 = "(journalArticle.templateId IS NULL OR journalArticle.templateId = '')";
12619            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_L = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
12620                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
12621                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
12622                            "findByG_L",
12623                            new String[] {
12624                                    Long.class.getName(), String.class.getName(),
12625                                    
12626                            Integer.class.getName(), Integer.class.getName(),
12627                                    OrderByComparator.class.getName()
12628                            });
12629            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_L = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
12630                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
12631                            JournalArticleImpl.class,
12632                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_L",
12633                            new String[] { Long.class.getName(), String.class.getName() },
12634                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
12635                            JournalArticleModelImpl.LAYOUTUUID_COLUMN_BITMASK |
12636                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
12637                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
12638            public static final FinderPath FINDER_PATH_COUNT_BY_G_L = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
12639                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
12640                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_L",
12641                            new String[] { Long.class.getName(), String.class.getName() });
12642    
12643            /**
12644             * Returns all the journal articles where groupId = &#63; and layoutUuid = &#63;.
12645             *
12646             * @param groupId the group ID
12647             * @param layoutUuid the layout uuid
12648             * @return the matching journal articles
12649             * @throws SystemException if a system exception occurred
12650             */
12651            @Override
12652            public List<JournalArticle> findByG_L(long groupId, String layoutUuid)
12653                    throws SystemException {
12654                    return findByG_L(groupId, layoutUuid, QueryUtil.ALL_POS,
12655                            QueryUtil.ALL_POS, null);
12656            }
12657    
12658            /**
12659             * Returns a range of all the journal articles where groupId = &#63; and layoutUuid = &#63;.
12660             *
12661             * <p>
12662             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
12663             * </p>
12664             *
12665             * @param groupId the group ID
12666             * @param layoutUuid the layout uuid
12667             * @param start the lower bound of the range of journal articles
12668             * @param end the upper bound of the range of journal articles (not inclusive)
12669             * @return the range of matching journal articles
12670             * @throws SystemException if a system exception occurred
12671             */
12672            @Override
12673            public List<JournalArticle> findByG_L(long groupId, String layoutUuid,
12674                    int start, int end) throws SystemException {
12675                    return findByG_L(groupId, layoutUuid, start, end, null);
12676            }
12677    
12678            /**
12679             * Returns an ordered range of all the journal articles where groupId = &#63; and layoutUuid = &#63;.
12680             *
12681             * <p>
12682             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
12683             * </p>
12684             *
12685             * @param groupId the group ID
12686             * @param layoutUuid the layout uuid
12687             * @param start the lower bound of the range of journal articles
12688             * @param end the upper bound of the range of journal articles (not inclusive)
12689             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12690             * @return the ordered range of matching journal articles
12691             * @throws SystemException if a system exception occurred
12692             */
12693            @Override
12694            public List<JournalArticle> findByG_L(long groupId, String layoutUuid,
12695                    int start, int end, OrderByComparator orderByComparator)
12696                    throws SystemException {
12697                    boolean pagination = true;
12698                    FinderPath finderPath = null;
12699                    Object[] finderArgs = null;
12700    
12701                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12702                                    (orderByComparator == null)) {
12703                            pagination = false;
12704                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_L;
12705                            finderArgs = new Object[] { groupId, layoutUuid };
12706                    }
12707                    else {
12708                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_L;
12709                            finderArgs = new Object[] {
12710                                            groupId, layoutUuid,
12711                                            
12712                                            start, end, orderByComparator
12713                                    };
12714                    }
12715    
12716                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
12717                                    finderArgs, this);
12718    
12719                    if ((list != null) && !list.isEmpty()) {
12720                            for (JournalArticle journalArticle : list) {
12721                                    if ((groupId != journalArticle.getGroupId()) ||
12722                                                    !Validator.equals(layoutUuid,
12723                                                            journalArticle.getLayoutUuid())) {
12724                                            list = null;
12725    
12726                                            break;
12727                                    }
12728                            }
12729                    }
12730    
12731                    if (list == null) {
12732                            StringBundler query = null;
12733    
12734                            if (orderByComparator != null) {
12735                                    query = new StringBundler(4 +
12736                                                    (orderByComparator.getOrderByFields().length * 3));
12737                            }
12738                            else {
12739                                    query = new StringBundler(4);
12740                            }
12741    
12742                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
12743    
12744                            query.append(_FINDER_COLUMN_G_L_GROUPID_2);
12745    
12746                            boolean bindLayoutUuid = false;
12747    
12748                            if (layoutUuid == null) {
12749                                    query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_1);
12750                            }
12751                            else if (layoutUuid.equals(StringPool.BLANK)) {
12752                                    query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_3);
12753                            }
12754                            else {
12755                                    bindLayoutUuid = true;
12756    
12757                                    query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_2);
12758                            }
12759    
12760                            if (orderByComparator != null) {
12761                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12762                                            orderByComparator);
12763                            }
12764                            else
12765                             if (pagination) {
12766                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
12767                            }
12768    
12769                            String sql = query.toString();
12770    
12771                            Session session = null;
12772    
12773                            try {
12774                                    session = openSession();
12775    
12776                                    Query q = session.createQuery(sql);
12777    
12778                                    QueryPos qPos = QueryPos.getInstance(q);
12779    
12780                                    qPos.add(groupId);
12781    
12782                                    if (bindLayoutUuid) {
12783                                            qPos.add(layoutUuid);
12784                                    }
12785    
12786                                    if (!pagination) {
12787                                            list = (List<JournalArticle>)QueryUtil.list(q,
12788                                                            getDialect(), start, end, false);
12789    
12790                                            Collections.sort(list);
12791    
12792                                            list = new UnmodifiableList<JournalArticle>(list);
12793                                    }
12794                                    else {
12795                                            list = (List<JournalArticle>)QueryUtil.list(q,
12796                                                            getDialect(), start, end);
12797                                    }
12798    
12799                                    cacheResult(list);
12800    
12801                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12802                            }
12803                            catch (Exception e) {
12804                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12805    
12806                                    throw processException(e);
12807                            }
12808                            finally {
12809                                    closeSession(session);
12810                            }
12811                    }
12812    
12813                    return list;
12814            }
12815    
12816            /**
12817             * Returns the first journal article in the ordered set where groupId = &#63; and layoutUuid = &#63;.
12818             *
12819             * @param groupId the group ID
12820             * @param layoutUuid the layout uuid
12821             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12822             * @return the first matching journal article
12823             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
12824             * @throws SystemException if a system exception occurred
12825             */
12826            @Override
12827            public JournalArticle findByG_L_First(long groupId, String layoutUuid,
12828                    OrderByComparator orderByComparator)
12829                    throws NoSuchArticleException, SystemException {
12830                    JournalArticle journalArticle = fetchByG_L_First(groupId, layoutUuid,
12831                                    orderByComparator);
12832    
12833                    if (journalArticle != null) {
12834                            return journalArticle;
12835                    }
12836    
12837                    StringBundler msg = new StringBundler(6);
12838    
12839                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12840    
12841                    msg.append("groupId=");
12842                    msg.append(groupId);
12843    
12844                    msg.append(", layoutUuid=");
12845                    msg.append(layoutUuid);
12846    
12847                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12848    
12849                    throw new NoSuchArticleException(msg.toString());
12850            }
12851    
12852            /**
12853             * Returns the first journal article in the ordered set where groupId = &#63; and layoutUuid = &#63;.
12854             *
12855             * @param groupId the group ID
12856             * @param layoutUuid the layout uuid
12857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12858             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
12859             * @throws SystemException if a system exception occurred
12860             */
12861            @Override
12862            public JournalArticle fetchByG_L_First(long groupId, String layoutUuid,
12863                    OrderByComparator orderByComparator) throws SystemException {
12864                    List<JournalArticle> list = findByG_L(groupId, layoutUuid, 0, 1,
12865                                    orderByComparator);
12866    
12867                    if (!list.isEmpty()) {
12868                            return list.get(0);
12869                    }
12870    
12871                    return null;
12872            }
12873    
12874            /**
12875             * Returns the last journal article in the ordered set where groupId = &#63; and layoutUuid = &#63;.
12876             *
12877             * @param groupId the group ID
12878             * @param layoutUuid the layout uuid
12879             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12880             * @return the last matching journal article
12881             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
12882             * @throws SystemException if a system exception occurred
12883             */
12884            @Override
12885            public JournalArticle findByG_L_Last(long groupId, String layoutUuid,
12886                    OrderByComparator orderByComparator)
12887                    throws NoSuchArticleException, SystemException {
12888                    JournalArticle journalArticle = fetchByG_L_Last(groupId, layoutUuid,
12889                                    orderByComparator);
12890    
12891                    if (journalArticle != null) {
12892                            return journalArticle;
12893                    }
12894    
12895                    StringBundler msg = new StringBundler(6);
12896    
12897                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12898    
12899                    msg.append("groupId=");
12900                    msg.append(groupId);
12901    
12902                    msg.append(", layoutUuid=");
12903                    msg.append(layoutUuid);
12904    
12905                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12906    
12907                    throw new NoSuchArticleException(msg.toString());
12908            }
12909    
12910            /**
12911             * Returns the last journal article in the ordered set where groupId = &#63; and layoutUuid = &#63;.
12912             *
12913             * @param groupId the group ID
12914             * @param layoutUuid the layout uuid
12915             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12916             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
12917             * @throws SystemException if a system exception occurred
12918             */
12919            @Override
12920            public JournalArticle fetchByG_L_Last(long groupId, String layoutUuid,
12921                    OrderByComparator orderByComparator) throws SystemException {
12922                    int count = countByG_L(groupId, layoutUuid);
12923    
12924                    if (count == 0) {
12925                            return null;
12926                    }
12927    
12928                    List<JournalArticle> list = findByG_L(groupId, layoutUuid, count - 1,
12929                                    count, orderByComparator);
12930    
12931                    if (!list.isEmpty()) {
12932                            return list.get(0);
12933                    }
12934    
12935                    return null;
12936            }
12937    
12938            /**
12939             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and layoutUuid = &#63;.
12940             *
12941             * @param id the primary key of the current journal article
12942             * @param groupId the group ID
12943             * @param layoutUuid the layout uuid
12944             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12945             * @return the previous, current, and next journal article
12946             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
12947             * @throws SystemException if a system exception occurred
12948             */
12949            @Override
12950            public JournalArticle[] findByG_L_PrevAndNext(long id, long groupId,
12951                    String layoutUuid, OrderByComparator orderByComparator)
12952                    throws NoSuchArticleException, SystemException {
12953                    JournalArticle journalArticle = findByPrimaryKey(id);
12954    
12955                    Session session = null;
12956    
12957                    try {
12958                            session = openSession();
12959    
12960                            JournalArticle[] array = new JournalArticleImpl[3];
12961    
12962                            array[0] = getByG_L_PrevAndNext(session, journalArticle, groupId,
12963                                            layoutUuid, orderByComparator, true);
12964    
12965                            array[1] = journalArticle;
12966    
12967                            array[2] = getByG_L_PrevAndNext(session, journalArticle, groupId,
12968                                            layoutUuid, orderByComparator, false);
12969    
12970                            return array;
12971                    }
12972                    catch (Exception e) {
12973                            throw processException(e);
12974                    }
12975                    finally {
12976                            closeSession(session);
12977                    }
12978            }
12979    
12980            protected JournalArticle getByG_L_PrevAndNext(Session session,
12981                    JournalArticle journalArticle, long groupId, String layoutUuid,
12982                    OrderByComparator orderByComparator, boolean previous) {
12983                    StringBundler query = null;
12984    
12985                    if (orderByComparator != null) {
12986                            query = new StringBundler(6 +
12987                                            (orderByComparator.getOrderByFields().length * 6));
12988                    }
12989                    else {
12990                            query = new StringBundler(3);
12991                    }
12992    
12993                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
12994    
12995                    query.append(_FINDER_COLUMN_G_L_GROUPID_2);
12996    
12997                    boolean bindLayoutUuid = false;
12998    
12999                    if (layoutUuid == null) {
13000                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_1);
13001                    }
13002                    else if (layoutUuid.equals(StringPool.BLANK)) {
13003                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_3);
13004                    }
13005                    else {
13006                            bindLayoutUuid = true;
13007    
13008                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_2);
13009                    }
13010    
13011                    if (orderByComparator != null) {
13012                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13013    
13014                            if (orderByConditionFields.length > 0) {
13015                                    query.append(WHERE_AND);
13016                            }
13017    
13018                            for (int i = 0; i < orderByConditionFields.length; i++) {
13019                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13020                                    query.append(orderByConditionFields[i]);
13021    
13022                                    if ((i + 1) < orderByConditionFields.length) {
13023                                            if (orderByComparator.isAscending() ^ previous) {
13024                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13025                                            }
13026                                            else {
13027                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13028                                            }
13029                                    }
13030                                    else {
13031                                            if (orderByComparator.isAscending() ^ previous) {
13032                                                    query.append(WHERE_GREATER_THAN);
13033                                            }
13034                                            else {
13035                                                    query.append(WHERE_LESSER_THAN);
13036                                            }
13037                                    }
13038                            }
13039    
13040                            query.append(ORDER_BY_CLAUSE);
13041    
13042                            String[] orderByFields = orderByComparator.getOrderByFields();
13043    
13044                            for (int i = 0; i < orderByFields.length; i++) {
13045                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13046                                    query.append(orderByFields[i]);
13047    
13048                                    if ((i + 1) < orderByFields.length) {
13049                                            if (orderByComparator.isAscending() ^ previous) {
13050                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13051                                            }
13052                                            else {
13053                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13054                                            }
13055                                    }
13056                                    else {
13057                                            if (orderByComparator.isAscending() ^ previous) {
13058                                                    query.append(ORDER_BY_ASC);
13059                                            }
13060                                            else {
13061                                                    query.append(ORDER_BY_DESC);
13062                                            }
13063                                    }
13064                            }
13065                    }
13066                    else {
13067                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
13068                    }
13069    
13070                    String sql = query.toString();
13071    
13072                    Query q = session.createQuery(sql);
13073    
13074                    q.setFirstResult(0);
13075                    q.setMaxResults(2);
13076    
13077                    QueryPos qPos = QueryPos.getInstance(q);
13078    
13079                    qPos.add(groupId);
13080    
13081                    if (bindLayoutUuid) {
13082                            qPos.add(layoutUuid);
13083                    }
13084    
13085                    if (orderByComparator != null) {
13086                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
13087    
13088                            for (Object value : values) {
13089                                    qPos.add(value);
13090                            }
13091                    }
13092    
13093                    List<JournalArticle> list = q.list();
13094    
13095                    if (list.size() == 2) {
13096                            return list.get(1);
13097                    }
13098                    else {
13099                            return null;
13100                    }
13101            }
13102    
13103            /**
13104             * Returns all the journal articles that the user has permission to view where groupId = &#63; and layoutUuid = &#63;.
13105             *
13106             * @param groupId the group ID
13107             * @param layoutUuid the layout uuid
13108             * @return the matching journal articles that the user has permission to view
13109             * @throws SystemException if a system exception occurred
13110             */
13111            @Override
13112            public List<JournalArticle> filterFindByG_L(long groupId, String layoutUuid)
13113                    throws SystemException {
13114                    return filterFindByG_L(groupId, layoutUuid, QueryUtil.ALL_POS,
13115                            QueryUtil.ALL_POS, null);
13116            }
13117    
13118            /**
13119             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and layoutUuid = &#63;.
13120             *
13121             * <p>
13122             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
13123             * </p>
13124             *
13125             * @param groupId the group ID
13126             * @param layoutUuid the layout uuid
13127             * @param start the lower bound of the range of journal articles
13128             * @param end the upper bound of the range of journal articles (not inclusive)
13129             * @return the range of matching journal articles that the user has permission to view
13130             * @throws SystemException if a system exception occurred
13131             */
13132            @Override
13133            public List<JournalArticle> filterFindByG_L(long groupId,
13134                    String layoutUuid, int start, int end) throws SystemException {
13135                    return filterFindByG_L(groupId, layoutUuid, start, end, null);
13136            }
13137    
13138            /**
13139             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and layoutUuid = &#63;.
13140             *
13141             * <p>
13142             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
13143             * </p>
13144             *
13145             * @param groupId the group ID
13146             * @param layoutUuid the layout uuid
13147             * @param start the lower bound of the range of journal articles
13148             * @param end the upper bound of the range of journal articles (not inclusive)
13149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13150             * @return the ordered range of matching journal articles that the user has permission to view
13151             * @throws SystemException if a system exception occurred
13152             */
13153            @Override
13154            public List<JournalArticle> filterFindByG_L(long groupId,
13155                    String layoutUuid, int start, int end,
13156                    OrderByComparator orderByComparator) throws SystemException {
13157                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13158                            return findByG_L(groupId, layoutUuid, start, end, orderByComparator);
13159                    }
13160    
13161                    StringBundler query = null;
13162    
13163                    if (orderByComparator != null) {
13164                            query = new StringBundler(4 +
13165                                            (orderByComparator.getOrderByFields().length * 3));
13166                    }
13167                    else {
13168                            query = new StringBundler(4);
13169                    }
13170    
13171                    if (getDB().isSupportsInlineDistinct()) {
13172                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
13173                    }
13174                    else {
13175                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
13176                    }
13177    
13178                    query.append(_FINDER_COLUMN_G_L_GROUPID_2);
13179    
13180                    boolean bindLayoutUuid = false;
13181    
13182                    if (layoutUuid == null) {
13183                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_1);
13184                    }
13185                    else if (layoutUuid.equals(StringPool.BLANK)) {
13186                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_3);
13187                    }
13188                    else {
13189                            bindLayoutUuid = true;
13190    
13191                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_2);
13192                    }
13193    
13194                    if (!getDB().isSupportsInlineDistinct()) {
13195                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
13196                    }
13197    
13198                    if (orderByComparator != null) {
13199                            if (getDB().isSupportsInlineDistinct()) {
13200                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13201                                            orderByComparator, true);
13202                            }
13203                            else {
13204                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13205                                            orderByComparator, true);
13206                            }
13207                    }
13208                    else {
13209                            if (getDB().isSupportsInlineDistinct()) {
13210                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
13211                            }
13212                            else {
13213                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
13214                            }
13215                    }
13216    
13217                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13218                                    JournalArticle.class.getName(),
13219                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13220    
13221                    Session session = null;
13222    
13223                    try {
13224                            session = openSession();
13225    
13226                            SQLQuery q = session.createSQLQuery(sql);
13227    
13228                            if (getDB().isSupportsInlineDistinct()) {
13229                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
13230                            }
13231                            else {
13232                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
13233                            }
13234    
13235                            QueryPos qPos = QueryPos.getInstance(q);
13236    
13237                            qPos.add(groupId);
13238    
13239                            if (bindLayoutUuid) {
13240                                    qPos.add(layoutUuid);
13241                            }
13242    
13243                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
13244                                    end);
13245                    }
13246                    catch (Exception e) {
13247                            throw processException(e);
13248                    }
13249                    finally {
13250                            closeSession(session);
13251                    }
13252            }
13253    
13254            /**
13255             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and layoutUuid = &#63;.
13256             *
13257             * @param id the primary key of the current journal article
13258             * @param groupId the group ID
13259             * @param layoutUuid the layout uuid
13260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13261             * @return the previous, current, and next journal article
13262             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
13263             * @throws SystemException if a system exception occurred
13264             */
13265            @Override
13266            public JournalArticle[] filterFindByG_L_PrevAndNext(long id, long groupId,
13267                    String layoutUuid, OrderByComparator orderByComparator)
13268                    throws NoSuchArticleException, SystemException {
13269                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13270                            return findByG_L_PrevAndNext(id, groupId, layoutUuid,
13271                                    orderByComparator);
13272                    }
13273    
13274                    JournalArticle journalArticle = findByPrimaryKey(id);
13275    
13276                    Session session = null;
13277    
13278                    try {
13279                            session = openSession();
13280    
13281                            JournalArticle[] array = new JournalArticleImpl[3];
13282    
13283                            array[0] = filterGetByG_L_PrevAndNext(session, journalArticle,
13284                                            groupId, layoutUuid, orderByComparator, true);
13285    
13286                            array[1] = journalArticle;
13287    
13288                            array[2] = filterGetByG_L_PrevAndNext(session, journalArticle,
13289                                            groupId, layoutUuid, orderByComparator, false);
13290    
13291                            return array;
13292                    }
13293                    catch (Exception e) {
13294                            throw processException(e);
13295                    }
13296                    finally {
13297                            closeSession(session);
13298                    }
13299            }
13300    
13301            protected JournalArticle filterGetByG_L_PrevAndNext(Session session,
13302                    JournalArticle journalArticle, long groupId, String layoutUuid,
13303                    OrderByComparator orderByComparator, boolean previous) {
13304                    StringBundler query = null;
13305    
13306                    if (orderByComparator != null) {
13307                            query = new StringBundler(6 +
13308                                            (orderByComparator.getOrderByFields().length * 6));
13309                    }
13310                    else {
13311                            query = new StringBundler(3);
13312                    }
13313    
13314                    if (getDB().isSupportsInlineDistinct()) {
13315                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
13316                    }
13317                    else {
13318                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
13319                    }
13320    
13321                    query.append(_FINDER_COLUMN_G_L_GROUPID_2);
13322    
13323                    boolean bindLayoutUuid = false;
13324    
13325                    if (layoutUuid == null) {
13326                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_1);
13327                    }
13328                    else if (layoutUuid.equals(StringPool.BLANK)) {
13329                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_3);
13330                    }
13331                    else {
13332                            bindLayoutUuid = true;
13333    
13334                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_2);
13335                    }
13336    
13337                    if (!getDB().isSupportsInlineDistinct()) {
13338                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
13339                    }
13340    
13341                    if (orderByComparator != null) {
13342                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13343    
13344                            if (orderByConditionFields.length > 0) {
13345                                    query.append(WHERE_AND);
13346                            }
13347    
13348                            for (int i = 0; i < orderByConditionFields.length; i++) {
13349                                    if (getDB().isSupportsInlineDistinct()) {
13350                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13351                                    }
13352                                    else {
13353                                            query.append(_ORDER_BY_ENTITY_TABLE);
13354                                    }
13355    
13356                                    query.append(orderByConditionFields[i]);
13357    
13358                                    if ((i + 1) < orderByConditionFields.length) {
13359                                            if (orderByComparator.isAscending() ^ previous) {
13360                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13361                                            }
13362                                            else {
13363                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13364                                            }
13365                                    }
13366                                    else {
13367                                            if (orderByComparator.isAscending() ^ previous) {
13368                                                    query.append(WHERE_GREATER_THAN);
13369                                            }
13370                                            else {
13371                                                    query.append(WHERE_LESSER_THAN);
13372                                            }
13373                                    }
13374                            }
13375    
13376                            query.append(ORDER_BY_CLAUSE);
13377    
13378                            String[] orderByFields = orderByComparator.getOrderByFields();
13379    
13380                            for (int i = 0; i < orderByFields.length; i++) {
13381                                    if (getDB().isSupportsInlineDistinct()) {
13382                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13383                                    }
13384                                    else {
13385                                            query.append(_ORDER_BY_ENTITY_TABLE);
13386                                    }
13387    
13388                                    query.append(orderByFields[i]);
13389    
13390                                    if ((i + 1) < orderByFields.length) {
13391                                            if (orderByComparator.isAscending() ^ previous) {
13392                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13393                                            }
13394                                            else {
13395                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13396                                            }
13397                                    }
13398                                    else {
13399                                            if (orderByComparator.isAscending() ^ previous) {
13400                                                    query.append(ORDER_BY_ASC);
13401                                            }
13402                                            else {
13403                                                    query.append(ORDER_BY_DESC);
13404                                            }
13405                                    }
13406                            }
13407                    }
13408                    else {
13409                            if (getDB().isSupportsInlineDistinct()) {
13410                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
13411                            }
13412                            else {
13413                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
13414                            }
13415                    }
13416    
13417                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13418                                    JournalArticle.class.getName(),
13419                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13420    
13421                    SQLQuery q = session.createSQLQuery(sql);
13422    
13423                    q.setFirstResult(0);
13424                    q.setMaxResults(2);
13425    
13426                    if (getDB().isSupportsInlineDistinct()) {
13427                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
13428                    }
13429                    else {
13430                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
13431                    }
13432    
13433                    QueryPos qPos = QueryPos.getInstance(q);
13434    
13435                    qPos.add(groupId);
13436    
13437                    if (bindLayoutUuid) {
13438                            qPos.add(layoutUuid);
13439                    }
13440    
13441                    if (orderByComparator != null) {
13442                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
13443    
13444                            for (Object value : values) {
13445                                    qPos.add(value);
13446                            }
13447                    }
13448    
13449                    List<JournalArticle> list = q.list();
13450    
13451                    if (list.size() == 2) {
13452                            return list.get(1);
13453                    }
13454                    else {
13455                            return null;
13456                    }
13457            }
13458    
13459            /**
13460             * Removes all the journal articles where groupId = &#63; and layoutUuid = &#63; from the database.
13461             *
13462             * @param groupId the group ID
13463             * @param layoutUuid the layout uuid
13464             * @throws SystemException if a system exception occurred
13465             */
13466            @Override
13467            public void removeByG_L(long groupId, String layoutUuid)
13468                    throws SystemException {
13469                    for (JournalArticle journalArticle : findByG_L(groupId, layoutUuid,
13470                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13471                            remove(journalArticle);
13472                    }
13473            }
13474    
13475            /**
13476             * Returns the number of journal articles where groupId = &#63; and layoutUuid = &#63;.
13477             *
13478             * @param groupId the group ID
13479             * @param layoutUuid the layout uuid
13480             * @return the number of matching journal articles
13481             * @throws SystemException if a system exception occurred
13482             */
13483            @Override
13484            public int countByG_L(long groupId, String layoutUuid)
13485                    throws SystemException {
13486                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_L;
13487    
13488                    Object[] finderArgs = new Object[] { groupId, layoutUuid };
13489    
13490                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13491                                    this);
13492    
13493                    if (count == null) {
13494                            StringBundler query = new StringBundler(3);
13495    
13496                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
13497    
13498                            query.append(_FINDER_COLUMN_G_L_GROUPID_2);
13499    
13500                            boolean bindLayoutUuid = false;
13501    
13502                            if (layoutUuid == null) {
13503                                    query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_1);
13504                            }
13505                            else if (layoutUuid.equals(StringPool.BLANK)) {
13506                                    query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_3);
13507                            }
13508                            else {
13509                                    bindLayoutUuid = true;
13510    
13511                                    query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_2);
13512                            }
13513    
13514                            String sql = query.toString();
13515    
13516                            Session session = null;
13517    
13518                            try {
13519                                    session = openSession();
13520    
13521                                    Query q = session.createQuery(sql);
13522    
13523                                    QueryPos qPos = QueryPos.getInstance(q);
13524    
13525                                    qPos.add(groupId);
13526    
13527                                    if (bindLayoutUuid) {
13528                                            qPos.add(layoutUuid);
13529                                    }
13530    
13531                                    count = (Long)q.uniqueResult();
13532    
13533                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13534                            }
13535                            catch (Exception e) {
13536                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13537    
13538                                    throw processException(e);
13539                            }
13540                            finally {
13541                                    closeSession(session);
13542                            }
13543                    }
13544    
13545                    return count.intValue();
13546            }
13547    
13548            /**
13549             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and layoutUuid = &#63;.
13550             *
13551             * @param groupId the group ID
13552             * @param layoutUuid the layout uuid
13553             * @return the number of matching journal articles that the user has permission to view
13554             * @throws SystemException if a system exception occurred
13555             */
13556            @Override
13557            public int filterCountByG_L(long groupId, String layoutUuid)
13558                    throws SystemException {
13559                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13560                            return countByG_L(groupId, layoutUuid);
13561                    }
13562    
13563                    StringBundler query = new StringBundler(3);
13564    
13565                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
13566    
13567                    query.append(_FINDER_COLUMN_G_L_GROUPID_2);
13568    
13569                    boolean bindLayoutUuid = false;
13570    
13571                    if (layoutUuid == null) {
13572                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_1);
13573                    }
13574                    else if (layoutUuid.equals(StringPool.BLANK)) {
13575                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_3);
13576                    }
13577                    else {
13578                            bindLayoutUuid = true;
13579    
13580                            query.append(_FINDER_COLUMN_G_L_LAYOUTUUID_2);
13581                    }
13582    
13583                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13584                                    JournalArticle.class.getName(),
13585                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13586    
13587                    Session session = null;
13588    
13589                    try {
13590                            session = openSession();
13591    
13592                            SQLQuery q = session.createSQLQuery(sql);
13593    
13594                            q.addScalar(COUNT_COLUMN_NAME,
13595                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13596    
13597                            QueryPos qPos = QueryPos.getInstance(q);
13598    
13599                            qPos.add(groupId);
13600    
13601                            if (bindLayoutUuid) {
13602                                    qPos.add(layoutUuid);
13603                            }
13604    
13605                            Long count = (Long)q.uniqueResult();
13606    
13607                            return count.intValue();
13608                    }
13609                    catch (Exception e) {
13610                            throw processException(e);
13611                    }
13612                    finally {
13613                            closeSession(session);
13614                    }
13615            }
13616    
13617            private static final String _FINDER_COLUMN_G_L_GROUPID_2 = "journalArticle.groupId = ? AND ";
13618            private static final String _FINDER_COLUMN_G_L_LAYOUTUUID_1 = "journalArticle.layoutUuid IS NULL";
13619            private static final String _FINDER_COLUMN_G_L_LAYOUTUUID_2 = "journalArticle.layoutUuid = ?";
13620            private static final String _FINDER_COLUMN_G_L_LAYOUTUUID_3 = "(journalArticle.layoutUuid IS NULL OR journalArticle.layoutUuid = '')";
13621            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
13622                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
13623                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
13624                            "findByG_ST",
13625                            new String[] {
13626                                    Long.class.getName(), Integer.class.getName(),
13627                                    
13628                            Integer.class.getName(), Integer.class.getName(),
13629                                    OrderByComparator.class.getName()
13630                            });
13631            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
13632                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
13633                            JournalArticleImpl.class,
13634                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_ST",
13635                            new String[] { Long.class.getName(), Integer.class.getName() },
13636                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
13637                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
13638                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
13639                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
13640            public static final FinderPath FINDER_PATH_COUNT_BY_G_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
13641                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
13642                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_ST",
13643                            new String[] { Long.class.getName(), Integer.class.getName() });
13644    
13645            /**
13646             * Returns all the journal articles where groupId = &#63; and status = &#63;.
13647             *
13648             * @param groupId the group ID
13649             * @param status the status
13650             * @return the matching journal articles
13651             * @throws SystemException if a system exception occurred
13652             */
13653            @Override
13654            public List<JournalArticle> findByG_ST(long groupId, int status)
13655                    throws SystemException {
13656                    return findByG_ST(groupId, status, QueryUtil.ALL_POS,
13657                            QueryUtil.ALL_POS, null);
13658            }
13659    
13660            /**
13661             * Returns a range of all the journal articles where groupId = &#63; and status = &#63;.
13662             *
13663             * <p>
13664             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
13665             * </p>
13666             *
13667             * @param groupId the group ID
13668             * @param status the status
13669             * @param start the lower bound of the range of journal articles
13670             * @param end the upper bound of the range of journal articles (not inclusive)
13671             * @return the range of matching journal articles
13672             * @throws SystemException if a system exception occurred
13673             */
13674            @Override
13675            public List<JournalArticle> findByG_ST(long groupId, int status, int start,
13676                    int end) throws SystemException {
13677                    return findByG_ST(groupId, status, start, end, null);
13678            }
13679    
13680            /**
13681             * Returns an ordered range of all the journal articles where groupId = &#63; and status = &#63;.
13682             *
13683             * <p>
13684             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
13685             * </p>
13686             *
13687             * @param groupId the group ID
13688             * @param status the status
13689             * @param start the lower bound of the range of journal articles
13690             * @param end the upper bound of the range of journal articles (not inclusive)
13691             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13692             * @return the ordered range of matching journal articles
13693             * @throws SystemException if a system exception occurred
13694             */
13695            @Override
13696            public List<JournalArticle> findByG_ST(long groupId, int status, int start,
13697                    int end, OrderByComparator orderByComparator) throws SystemException {
13698                    boolean pagination = true;
13699                    FinderPath finderPath = null;
13700                    Object[] finderArgs = null;
13701    
13702                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13703                                    (orderByComparator == null)) {
13704                            pagination = false;
13705                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_ST;
13706                            finderArgs = new Object[] { groupId, status };
13707                    }
13708                    else {
13709                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_ST;
13710                            finderArgs = new Object[] {
13711                                            groupId, status,
13712                                            
13713                                            start, end, orderByComparator
13714                                    };
13715                    }
13716    
13717                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
13718                                    finderArgs, this);
13719    
13720                    if ((list != null) && !list.isEmpty()) {
13721                            for (JournalArticle journalArticle : list) {
13722                                    if ((groupId != journalArticle.getGroupId()) ||
13723                                                    (status != journalArticle.getStatus())) {
13724                                            list = null;
13725    
13726                                            break;
13727                                    }
13728                            }
13729                    }
13730    
13731                    if (list == null) {
13732                            StringBundler query = null;
13733    
13734                            if (orderByComparator != null) {
13735                                    query = new StringBundler(4 +
13736                                                    (orderByComparator.getOrderByFields().length * 3));
13737                            }
13738                            else {
13739                                    query = new StringBundler(4);
13740                            }
13741    
13742                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
13743    
13744                            query.append(_FINDER_COLUMN_G_ST_GROUPID_2);
13745    
13746                            query.append(_FINDER_COLUMN_G_ST_STATUS_2);
13747    
13748                            if (orderByComparator != null) {
13749                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13750                                            orderByComparator);
13751                            }
13752                            else
13753                             if (pagination) {
13754                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
13755                            }
13756    
13757                            String sql = query.toString();
13758    
13759                            Session session = null;
13760    
13761                            try {
13762                                    session = openSession();
13763    
13764                                    Query q = session.createQuery(sql);
13765    
13766                                    QueryPos qPos = QueryPos.getInstance(q);
13767    
13768                                    qPos.add(groupId);
13769    
13770                                    qPos.add(status);
13771    
13772                                    if (!pagination) {
13773                                            list = (List<JournalArticle>)QueryUtil.list(q,
13774                                                            getDialect(), start, end, false);
13775    
13776                                            Collections.sort(list);
13777    
13778                                            list = new UnmodifiableList<JournalArticle>(list);
13779                                    }
13780                                    else {
13781                                            list = (List<JournalArticle>)QueryUtil.list(q,
13782                                                            getDialect(), start, end);
13783                                    }
13784    
13785                                    cacheResult(list);
13786    
13787                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13788                            }
13789                            catch (Exception e) {
13790                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13791    
13792                                    throw processException(e);
13793                            }
13794                            finally {
13795                                    closeSession(session);
13796                            }
13797                    }
13798    
13799                    return list;
13800            }
13801    
13802            /**
13803             * Returns the first journal article in the ordered set where groupId = &#63; and status = &#63;.
13804             *
13805             * @param groupId the group ID
13806             * @param status the status
13807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13808             * @return the first matching journal article
13809             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
13810             * @throws SystemException if a system exception occurred
13811             */
13812            @Override
13813            public JournalArticle findByG_ST_First(long groupId, int status,
13814                    OrderByComparator orderByComparator)
13815                    throws NoSuchArticleException, SystemException {
13816                    JournalArticle journalArticle = fetchByG_ST_First(groupId, status,
13817                                    orderByComparator);
13818    
13819                    if (journalArticle != null) {
13820                            return journalArticle;
13821                    }
13822    
13823                    StringBundler msg = new StringBundler(6);
13824    
13825                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13826    
13827                    msg.append("groupId=");
13828                    msg.append(groupId);
13829    
13830                    msg.append(", status=");
13831                    msg.append(status);
13832    
13833                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13834    
13835                    throw new NoSuchArticleException(msg.toString());
13836            }
13837    
13838            /**
13839             * Returns the first journal article in the ordered set where groupId = &#63; and status = &#63;.
13840             *
13841             * @param groupId the group ID
13842             * @param status the status
13843             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13844             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
13845             * @throws SystemException if a system exception occurred
13846             */
13847            @Override
13848            public JournalArticle fetchByG_ST_First(long groupId, int status,
13849                    OrderByComparator orderByComparator) throws SystemException {
13850                    List<JournalArticle> list = findByG_ST(groupId, status, 0, 1,
13851                                    orderByComparator);
13852    
13853                    if (!list.isEmpty()) {
13854                            return list.get(0);
13855                    }
13856    
13857                    return null;
13858            }
13859    
13860            /**
13861             * Returns the last journal article in the ordered set where groupId = &#63; and status = &#63;.
13862             *
13863             * @param groupId the group ID
13864             * @param status the status
13865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13866             * @return the last matching journal article
13867             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
13868             * @throws SystemException if a system exception occurred
13869             */
13870            @Override
13871            public JournalArticle findByG_ST_Last(long groupId, int status,
13872                    OrderByComparator orderByComparator)
13873                    throws NoSuchArticleException, SystemException {
13874                    JournalArticle journalArticle = fetchByG_ST_Last(groupId, status,
13875                                    orderByComparator);
13876    
13877                    if (journalArticle != null) {
13878                            return journalArticle;
13879                    }
13880    
13881                    StringBundler msg = new StringBundler(6);
13882    
13883                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13884    
13885                    msg.append("groupId=");
13886                    msg.append(groupId);
13887    
13888                    msg.append(", status=");
13889                    msg.append(status);
13890    
13891                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13892    
13893                    throw new NoSuchArticleException(msg.toString());
13894            }
13895    
13896            /**
13897             * Returns the last journal article in the ordered set where groupId = &#63; and status = &#63;.
13898             *
13899             * @param groupId the group ID
13900             * @param status the status
13901             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13902             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
13903             * @throws SystemException if a system exception occurred
13904             */
13905            @Override
13906            public JournalArticle fetchByG_ST_Last(long groupId, int status,
13907                    OrderByComparator orderByComparator) throws SystemException {
13908                    int count = countByG_ST(groupId, status);
13909    
13910                    if (count == 0) {
13911                            return null;
13912                    }
13913    
13914                    List<JournalArticle> list = findByG_ST(groupId, status, count - 1,
13915                                    count, orderByComparator);
13916    
13917                    if (!list.isEmpty()) {
13918                            return list.get(0);
13919                    }
13920    
13921                    return null;
13922            }
13923    
13924            /**
13925             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and status = &#63;.
13926             *
13927             * @param id the primary key of the current journal article
13928             * @param groupId the group ID
13929             * @param status the status
13930             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13931             * @return the previous, current, and next journal article
13932             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
13933             * @throws SystemException if a system exception occurred
13934             */
13935            @Override
13936            public JournalArticle[] findByG_ST_PrevAndNext(long id, long groupId,
13937                    int status, OrderByComparator orderByComparator)
13938                    throws NoSuchArticleException, SystemException {
13939                    JournalArticle journalArticle = findByPrimaryKey(id);
13940    
13941                    Session session = null;
13942    
13943                    try {
13944                            session = openSession();
13945    
13946                            JournalArticle[] array = new JournalArticleImpl[3];
13947    
13948                            array[0] = getByG_ST_PrevAndNext(session, journalArticle, groupId,
13949                                            status, orderByComparator, true);
13950    
13951                            array[1] = journalArticle;
13952    
13953                            array[2] = getByG_ST_PrevAndNext(session, journalArticle, groupId,
13954                                            status, orderByComparator, false);
13955    
13956                            return array;
13957                    }
13958                    catch (Exception e) {
13959                            throw processException(e);
13960                    }
13961                    finally {
13962                            closeSession(session);
13963                    }
13964            }
13965    
13966            protected JournalArticle getByG_ST_PrevAndNext(Session session,
13967                    JournalArticle journalArticle, long groupId, int status,
13968                    OrderByComparator orderByComparator, boolean previous) {
13969                    StringBundler query = null;
13970    
13971                    if (orderByComparator != null) {
13972                            query = new StringBundler(6 +
13973                                            (orderByComparator.getOrderByFields().length * 6));
13974                    }
13975                    else {
13976                            query = new StringBundler(3);
13977                    }
13978    
13979                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
13980    
13981                    query.append(_FINDER_COLUMN_G_ST_GROUPID_2);
13982    
13983                    query.append(_FINDER_COLUMN_G_ST_STATUS_2);
13984    
13985                    if (orderByComparator != null) {
13986                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13987    
13988                            if (orderByConditionFields.length > 0) {
13989                                    query.append(WHERE_AND);
13990                            }
13991    
13992                            for (int i = 0; i < orderByConditionFields.length; i++) {
13993                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13994                                    query.append(orderByConditionFields[i]);
13995    
13996                                    if ((i + 1) < orderByConditionFields.length) {
13997                                            if (orderByComparator.isAscending() ^ previous) {
13998                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13999                                            }
14000                                            else {
14001                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14002                                            }
14003                                    }
14004                                    else {
14005                                            if (orderByComparator.isAscending() ^ previous) {
14006                                                    query.append(WHERE_GREATER_THAN);
14007                                            }
14008                                            else {
14009                                                    query.append(WHERE_LESSER_THAN);
14010                                            }
14011                                    }
14012                            }
14013    
14014                            query.append(ORDER_BY_CLAUSE);
14015    
14016                            String[] orderByFields = orderByComparator.getOrderByFields();
14017    
14018                            for (int i = 0; i < orderByFields.length; i++) {
14019                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14020                                    query.append(orderByFields[i]);
14021    
14022                                    if ((i + 1) < orderByFields.length) {
14023                                            if (orderByComparator.isAscending() ^ previous) {
14024                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14025                                            }
14026                                            else {
14027                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14028                                            }
14029                                    }
14030                                    else {
14031                                            if (orderByComparator.isAscending() ^ previous) {
14032                                                    query.append(ORDER_BY_ASC);
14033                                            }
14034                                            else {
14035                                                    query.append(ORDER_BY_DESC);
14036                                            }
14037                                    }
14038                            }
14039                    }
14040                    else {
14041                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
14042                    }
14043    
14044                    String sql = query.toString();
14045    
14046                    Query q = session.createQuery(sql);
14047    
14048                    q.setFirstResult(0);
14049                    q.setMaxResults(2);
14050    
14051                    QueryPos qPos = QueryPos.getInstance(q);
14052    
14053                    qPos.add(groupId);
14054    
14055                    qPos.add(status);
14056    
14057                    if (orderByComparator != null) {
14058                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
14059    
14060                            for (Object value : values) {
14061                                    qPos.add(value);
14062                            }
14063                    }
14064    
14065                    List<JournalArticle> list = q.list();
14066    
14067                    if (list.size() == 2) {
14068                            return list.get(1);
14069                    }
14070                    else {
14071                            return null;
14072                    }
14073            }
14074    
14075            /**
14076             * Returns all the journal articles that the user has permission to view where groupId = &#63; and status = &#63;.
14077             *
14078             * @param groupId the group ID
14079             * @param status the status
14080             * @return the matching journal articles that the user has permission to view
14081             * @throws SystemException if a system exception occurred
14082             */
14083            @Override
14084            public List<JournalArticle> filterFindByG_ST(long groupId, int status)
14085                    throws SystemException {
14086                    return filterFindByG_ST(groupId, status, QueryUtil.ALL_POS,
14087                            QueryUtil.ALL_POS, null);
14088            }
14089    
14090            /**
14091             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and status = &#63;.
14092             *
14093             * <p>
14094             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
14095             * </p>
14096             *
14097             * @param groupId the group ID
14098             * @param status the status
14099             * @param start the lower bound of the range of journal articles
14100             * @param end the upper bound of the range of journal articles (not inclusive)
14101             * @return the range of matching journal articles that the user has permission to view
14102             * @throws SystemException if a system exception occurred
14103             */
14104            @Override
14105            public List<JournalArticle> filterFindByG_ST(long groupId, int status,
14106                    int start, int end) throws SystemException {
14107                    return filterFindByG_ST(groupId, status, start, end, null);
14108            }
14109    
14110            /**
14111             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and status = &#63;.
14112             *
14113             * <p>
14114             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
14115             * </p>
14116             *
14117             * @param groupId the group ID
14118             * @param status the status
14119             * @param start the lower bound of the range of journal articles
14120             * @param end the upper bound of the range of journal articles (not inclusive)
14121             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14122             * @return the ordered range of matching journal articles that the user has permission to view
14123             * @throws SystemException if a system exception occurred
14124             */
14125            @Override
14126            public List<JournalArticle> filterFindByG_ST(long groupId, int status,
14127                    int start, int end, OrderByComparator orderByComparator)
14128                    throws SystemException {
14129                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14130                            return findByG_ST(groupId, status, start, end, orderByComparator);
14131                    }
14132    
14133                    StringBundler query = null;
14134    
14135                    if (orderByComparator != null) {
14136                            query = new StringBundler(4 +
14137                                            (orderByComparator.getOrderByFields().length * 3));
14138                    }
14139                    else {
14140                            query = new StringBundler(4);
14141                    }
14142    
14143                    if (getDB().isSupportsInlineDistinct()) {
14144                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
14145                    }
14146                    else {
14147                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
14148                    }
14149    
14150                    query.append(_FINDER_COLUMN_G_ST_GROUPID_2);
14151    
14152                    query.append(_FINDER_COLUMN_G_ST_STATUS_2);
14153    
14154                    if (!getDB().isSupportsInlineDistinct()) {
14155                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
14156                    }
14157    
14158                    if (orderByComparator != null) {
14159                            if (getDB().isSupportsInlineDistinct()) {
14160                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14161                                            orderByComparator, true);
14162                            }
14163                            else {
14164                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
14165                                            orderByComparator, true);
14166                            }
14167                    }
14168                    else {
14169                            if (getDB().isSupportsInlineDistinct()) {
14170                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
14171                            }
14172                            else {
14173                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
14174                            }
14175                    }
14176    
14177                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14178                                    JournalArticle.class.getName(),
14179                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14180    
14181                    Session session = null;
14182    
14183                    try {
14184                            session = openSession();
14185    
14186                            SQLQuery q = session.createSQLQuery(sql);
14187    
14188                            if (getDB().isSupportsInlineDistinct()) {
14189                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
14190                            }
14191                            else {
14192                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
14193                            }
14194    
14195                            QueryPos qPos = QueryPos.getInstance(q);
14196    
14197                            qPos.add(groupId);
14198    
14199                            qPos.add(status);
14200    
14201                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
14202                                    end);
14203                    }
14204                    catch (Exception e) {
14205                            throw processException(e);
14206                    }
14207                    finally {
14208                            closeSession(session);
14209                    }
14210            }
14211    
14212            /**
14213             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and status = &#63;.
14214             *
14215             * @param id the primary key of the current journal article
14216             * @param groupId the group ID
14217             * @param status the status
14218             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14219             * @return the previous, current, and next journal article
14220             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
14221             * @throws SystemException if a system exception occurred
14222             */
14223            @Override
14224            public JournalArticle[] filterFindByG_ST_PrevAndNext(long id, long groupId,
14225                    int status, OrderByComparator orderByComparator)
14226                    throws NoSuchArticleException, SystemException {
14227                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14228                            return findByG_ST_PrevAndNext(id, groupId, status, orderByComparator);
14229                    }
14230    
14231                    JournalArticle journalArticle = findByPrimaryKey(id);
14232    
14233                    Session session = null;
14234    
14235                    try {
14236                            session = openSession();
14237    
14238                            JournalArticle[] array = new JournalArticleImpl[3];
14239    
14240                            array[0] = filterGetByG_ST_PrevAndNext(session, journalArticle,
14241                                            groupId, status, orderByComparator, true);
14242    
14243                            array[1] = journalArticle;
14244    
14245                            array[2] = filterGetByG_ST_PrevAndNext(session, journalArticle,
14246                                            groupId, status, orderByComparator, false);
14247    
14248                            return array;
14249                    }
14250                    catch (Exception e) {
14251                            throw processException(e);
14252                    }
14253                    finally {
14254                            closeSession(session);
14255                    }
14256            }
14257    
14258            protected JournalArticle filterGetByG_ST_PrevAndNext(Session session,
14259                    JournalArticle journalArticle, long groupId, int status,
14260                    OrderByComparator orderByComparator, boolean previous) {
14261                    StringBundler query = null;
14262    
14263                    if (orderByComparator != null) {
14264                            query = new StringBundler(6 +
14265                                            (orderByComparator.getOrderByFields().length * 6));
14266                    }
14267                    else {
14268                            query = new StringBundler(3);
14269                    }
14270    
14271                    if (getDB().isSupportsInlineDistinct()) {
14272                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
14273                    }
14274                    else {
14275                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
14276                    }
14277    
14278                    query.append(_FINDER_COLUMN_G_ST_GROUPID_2);
14279    
14280                    query.append(_FINDER_COLUMN_G_ST_STATUS_2);
14281    
14282                    if (!getDB().isSupportsInlineDistinct()) {
14283                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
14284                    }
14285    
14286                    if (orderByComparator != null) {
14287                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14288    
14289                            if (orderByConditionFields.length > 0) {
14290                                    query.append(WHERE_AND);
14291                            }
14292    
14293                            for (int i = 0; i < orderByConditionFields.length; i++) {
14294                                    if (getDB().isSupportsInlineDistinct()) {
14295                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14296                                    }
14297                                    else {
14298                                            query.append(_ORDER_BY_ENTITY_TABLE);
14299                                    }
14300    
14301                                    query.append(orderByConditionFields[i]);
14302    
14303                                    if ((i + 1) < orderByConditionFields.length) {
14304                                            if (orderByComparator.isAscending() ^ previous) {
14305                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14306                                            }
14307                                            else {
14308                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14309                                            }
14310                                    }
14311                                    else {
14312                                            if (orderByComparator.isAscending() ^ previous) {
14313                                                    query.append(WHERE_GREATER_THAN);
14314                                            }
14315                                            else {
14316                                                    query.append(WHERE_LESSER_THAN);
14317                                            }
14318                                    }
14319                            }
14320    
14321                            query.append(ORDER_BY_CLAUSE);
14322    
14323                            String[] orderByFields = orderByComparator.getOrderByFields();
14324    
14325                            for (int i = 0; i < orderByFields.length; i++) {
14326                                    if (getDB().isSupportsInlineDistinct()) {
14327                                            query.append(_ORDER_BY_ENTITY_ALIAS);
14328                                    }
14329                                    else {
14330                                            query.append(_ORDER_BY_ENTITY_TABLE);
14331                                    }
14332    
14333                                    query.append(orderByFields[i]);
14334    
14335                                    if ((i + 1) < orderByFields.length) {
14336                                            if (orderByComparator.isAscending() ^ previous) {
14337                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14338                                            }
14339                                            else {
14340                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14341                                            }
14342                                    }
14343                                    else {
14344                                            if (orderByComparator.isAscending() ^ previous) {
14345                                                    query.append(ORDER_BY_ASC);
14346                                            }
14347                                            else {
14348                                                    query.append(ORDER_BY_DESC);
14349                                            }
14350                                    }
14351                            }
14352                    }
14353                    else {
14354                            if (getDB().isSupportsInlineDistinct()) {
14355                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
14356                            }
14357                            else {
14358                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
14359                            }
14360                    }
14361    
14362                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14363                                    JournalArticle.class.getName(),
14364                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14365    
14366                    SQLQuery q = session.createSQLQuery(sql);
14367    
14368                    q.setFirstResult(0);
14369                    q.setMaxResults(2);
14370    
14371                    if (getDB().isSupportsInlineDistinct()) {
14372                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
14373                    }
14374                    else {
14375                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
14376                    }
14377    
14378                    QueryPos qPos = QueryPos.getInstance(q);
14379    
14380                    qPos.add(groupId);
14381    
14382                    qPos.add(status);
14383    
14384                    if (orderByComparator != null) {
14385                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
14386    
14387                            for (Object value : values) {
14388                                    qPos.add(value);
14389                            }
14390                    }
14391    
14392                    List<JournalArticle> list = q.list();
14393    
14394                    if (list.size() == 2) {
14395                            return list.get(1);
14396                    }
14397                    else {
14398                            return null;
14399                    }
14400            }
14401    
14402            /**
14403             * Removes all the journal articles where groupId = &#63; and status = &#63; from the database.
14404             *
14405             * @param groupId the group ID
14406             * @param status the status
14407             * @throws SystemException if a system exception occurred
14408             */
14409            @Override
14410            public void removeByG_ST(long groupId, int status)
14411                    throws SystemException {
14412                    for (JournalArticle journalArticle : findByG_ST(groupId, status,
14413                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14414                            remove(journalArticle);
14415                    }
14416            }
14417    
14418            /**
14419             * Returns the number of journal articles where groupId = &#63; and status = &#63;.
14420             *
14421             * @param groupId the group ID
14422             * @param status the status
14423             * @return the number of matching journal articles
14424             * @throws SystemException if a system exception occurred
14425             */
14426            @Override
14427            public int countByG_ST(long groupId, int status) throws SystemException {
14428                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_ST;
14429    
14430                    Object[] finderArgs = new Object[] { groupId, status };
14431    
14432                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14433                                    this);
14434    
14435                    if (count == null) {
14436                            StringBundler query = new StringBundler(3);
14437    
14438                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
14439    
14440                            query.append(_FINDER_COLUMN_G_ST_GROUPID_2);
14441    
14442                            query.append(_FINDER_COLUMN_G_ST_STATUS_2);
14443    
14444                            String sql = query.toString();
14445    
14446                            Session session = null;
14447    
14448                            try {
14449                                    session = openSession();
14450    
14451                                    Query q = session.createQuery(sql);
14452    
14453                                    QueryPos qPos = QueryPos.getInstance(q);
14454    
14455                                    qPos.add(groupId);
14456    
14457                                    qPos.add(status);
14458    
14459                                    count = (Long)q.uniqueResult();
14460    
14461                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14462                            }
14463                            catch (Exception e) {
14464                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14465    
14466                                    throw processException(e);
14467                            }
14468                            finally {
14469                                    closeSession(session);
14470                            }
14471                    }
14472    
14473                    return count.intValue();
14474            }
14475    
14476            /**
14477             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and status = &#63;.
14478             *
14479             * @param groupId the group ID
14480             * @param status the status
14481             * @return the number of matching journal articles that the user has permission to view
14482             * @throws SystemException if a system exception occurred
14483             */
14484            @Override
14485            public int filterCountByG_ST(long groupId, int status)
14486                    throws SystemException {
14487                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
14488                            return countByG_ST(groupId, status);
14489                    }
14490    
14491                    StringBundler query = new StringBundler(3);
14492    
14493                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
14494    
14495                    query.append(_FINDER_COLUMN_G_ST_GROUPID_2);
14496    
14497                    query.append(_FINDER_COLUMN_G_ST_STATUS_2);
14498    
14499                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
14500                                    JournalArticle.class.getName(),
14501                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
14502    
14503                    Session session = null;
14504    
14505                    try {
14506                            session = openSession();
14507    
14508                            SQLQuery q = session.createSQLQuery(sql);
14509    
14510                            q.addScalar(COUNT_COLUMN_NAME,
14511                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
14512    
14513                            QueryPos qPos = QueryPos.getInstance(q);
14514    
14515                            qPos.add(groupId);
14516    
14517                            qPos.add(status);
14518    
14519                            Long count = (Long)q.uniqueResult();
14520    
14521                            return count.intValue();
14522                    }
14523                    catch (Exception e) {
14524                            throw processException(e);
14525                    }
14526                    finally {
14527                            closeSession(session);
14528                    }
14529            }
14530    
14531            private static final String _FINDER_COLUMN_G_ST_GROUPID_2 = "journalArticle.groupId = ? AND ";
14532            private static final String _FINDER_COLUMN_G_ST_STATUS_2 = "journalArticle.status = ?";
14533            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_V = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
14534                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
14535                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
14536                            "findByC_V",
14537                            new String[] {
14538                                    Long.class.getName(), Double.class.getName(),
14539                                    
14540                            Integer.class.getName(), Integer.class.getName(),
14541                                    OrderByComparator.class.getName()
14542                            });
14543            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
14544                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
14545                            JournalArticleImpl.class,
14546                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_V",
14547                            new String[] { Long.class.getName(), Double.class.getName() },
14548                            JournalArticleModelImpl.COMPANYID_COLUMN_BITMASK |
14549                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK |
14550                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK);
14551            public static final FinderPath FINDER_PATH_COUNT_BY_C_V = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
14552                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
14553                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_V",
14554                            new String[] { Long.class.getName(), Double.class.getName() });
14555    
14556            /**
14557             * Returns all the journal articles where companyId = &#63; and version = &#63;.
14558             *
14559             * @param companyId the company ID
14560             * @param version the version
14561             * @return the matching journal articles
14562             * @throws SystemException if a system exception occurred
14563             */
14564            @Override
14565            public List<JournalArticle> findByC_V(long companyId, double version)
14566                    throws SystemException {
14567                    return findByC_V(companyId, version, QueryUtil.ALL_POS,
14568                            QueryUtil.ALL_POS, null);
14569            }
14570    
14571            /**
14572             * Returns a range of all the journal articles where companyId = &#63; and version = &#63;.
14573             *
14574             * <p>
14575             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
14576             * </p>
14577             *
14578             * @param companyId the company ID
14579             * @param version the version
14580             * @param start the lower bound of the range of journal articles
14581             * @param end the upper bound of the range of journal articles (not inclusive)
14582             * @return the range of matching journal articles
14583             * @throws SystemException if a system exception occurred
14584             */
14585            @Override
14586            public List<JournalArticle> findByC_V(long companyId, double version,
14587                    int start, int end) throws SystemException {
14588                    return findByC_V(companyId, version, start, end, null);
14589            }
14590    
14591            /**
14592             * Returns an ordered range of all the journal articles where companyId = &#63; and version = &#63;.
14593             *
14594             * <p>
14595             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
14596             * </p>
14597             *
14598             * @param companyId the company ID
14599             * @param version the version
14600             * @param start the lower bound of the range of journal articles
14601             * @param end the upper bound of the range of journal articles (not inclusive)
14602             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14603             * @return the ordered range of matching journal articles
14604             * @throws SystemException if a system exception occurred
14605             */
14606            @Override
14607            public List<JournalArticle> findByC_V(long companyId, double version,
14608                    int start, int end, OrderByComparator orderByComparator)
14609                    throws SystemException {
14610                    boolean pagination = true;
14611                    FinderPath finderPath = null;
14612                    Object[] finderArgs = null;
14613    
14614                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14615                                    (orderByComparator == null)) {
14616                            pagination = false;
14617                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V;
14618                            finderArgs = new Object[] { companyId, version };
14619                    }
14620                    else {
14621                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_V;
14622                            finderArgs = new Object[] {
14623                                            companyId, version,
14624                                            
14625                                            start, end, orderByComparator
14626                                    };
14627                    }
14628    
14629                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
14630                                    finderArgs, this);
14631    
14632                    if ((list != null) && !list.isEmpty()) {
14633                            for (JournalArticle journalArticle : list) {
14634                                    if ((companyId != journalArticle.getCompanyId()) ||
14635                                                    (version != journalArticle.getVersion())) {
14636                                            list = null;
14637    
14638                                            break;
14639                                    }
14640                            }
14641                    }
14642    
14643                    if (list == null) {
14644                            StringBundler query = null;
14645    
14646                            if (orderByComparator != null) {
14647                                    query = new StringBundler(4 +
14648                                                    (orderByComparator.getOrderByFields().length * 3));
14649                            }
14650                            else {
14651                                    query = new StringBundler(4);
14652                            }
14653    
14654                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
14655    
14656                            query.append(_FINDER_COLUMN_C_V_COMPANYID_2);
14657    
14658                            query.append(_FINDER_COLUMN_C_V_VERSION_2);
14659    
14660                            if (orderByComparator != null) {
14661                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14662                                            orderByComparator);
14663                            }
14664                            else
14665                             if (pagination) {
14666                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
14667                            }
14668    
14669                            String sql = query.toString();
14670    
14671                            Session session = null;
14672    
14673                            try {
14674                                    session = openSession();
14675    
14676                                    Query q = session.createQuery(sql);
14677    
14678                                    QueryPos qPos = QueryPos.getInstance(q);
14679    
14680                                    qPos.add(companyId);
14681    
14682                                    qPos.add(version);
14683    
14684                                    if (!pagination) {
14685                                            list = (List<JournalArticle>)QueryUtil.list(q,
14686                                                            getDialect(), start, end, false);
14687    
14688                                            Collections.sort(list);
14689    
14690                                            list = new UnmodifiableList<JournalArticle>(list);
14691                                    }
14692                                    else {
14693                                            list = (List<JournalArticle>)QueryUtil.list(q,
14694                                                            getDialect(), start, end);
14695                                    }
14696    
14697                                    cacheResult(list);
14698    
14699                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14700                            }
14701                            catch (Exception e) {
14702                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14703    
14704                                    throw processException(e);
14705                            }
14706                            finally {
14707                                    closeSession(session);
14708                            }
14709                    }
14710    
14711                    return list;
14712            }
14713    
14714            /**
14715             * Returns the first journal article in the ordered set where companyId = &#63; and version = &#63;.
14716             *
14717             * @param companyId the company ID
14718             * @param version the version
14719             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14720             * @return the first matching journal article
14721             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
14722             * @throws SystemException if a system exception occurred
14723             */
14724            @Override
14725            public JournalArticle findByC_V_First(long companyId, double version,
14726                    OrderByComparator orderByComparator)
14727                    throws NoSuchArticleException, SystemException {
14728                    JournalArticle journalArticle = fetchByC_V_First(companyId, version,
14729                                    orderByComparator);
14730    
14731                    if (journalArticle != null) {
14732                            return journalArticle;
14733                    }
14734    
14735                    StringBundler msg = new StringBundler(6);
14736    
14737                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14738    
14739                    msg.append("companyId=");
14740                    msg.append(companyId);
14741    
14742                    msg.append(", version=");
14743                    msg.append(version);
14744    
14745                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14746    
14747                    throw new NoSuchArticleException(msg.toString());
14748            }
14749    
14750            /**
14751             * Returns the first journal article in the ordered set where companyId = &#63; and version = &#63;.
14752             *
14753             * @param companyId the company ID
14754             * @param version the version
14755             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14756             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
14757             * @throws SystemException if a system exception occurred
14758             */
14759            @Override
14760            public JournalArticle fetchByC_V_First(long companyId, double version,
14761                    OrderByComparator orderByComparator) throws SystemException {
14762                    List<JournalArticle> list = findByC_V(companyId, version, 0, 1,
14763                                    orderByComparator);
14764    
14765                    if (!list.isEmpty()) {
14766                            return list.get(0);
14767                    }
14768    
14769                    return null;
14770            }
14771    
14772            /**
14773             * Returns the last journal article in the ordered set where companyId = &#63; and version = &#63;.
14774             *
14775             * @param companyId the company ID
14776             * @param version the version
14777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14778             * @return the last matching journal article
14779             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
14780             * @throws SystemException if a system exception occurred
14781             */
14782            @Override
14783            public JournalArticle findByC_V_Last(long companyId, double version,
14784                    OrderByComparator orderByComparator)
14785                    throws NoSuchArticleException, SystemException {
14786                    JournalArticle journalArticle = fetchByC_V_Last(companyId, version,
14787                                    orderByComparator);
14788    
14789                    if (journalArticle != null) {
14790                            return journalArticle;
14791                    }
14792    
14793                    StringBundler msg = new StringBundler(6);
14794    
14795                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14796    
14797                    msg.append("companyId=");
14798                    msg.append(companyId);
14799    
14800                    msg.append(", version=");
14801                    msg.append(version);
14802    
14803                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14804    
14805                    throw new NoSuchArticleException(msg.toString());
14806            }
14807    
14808            /**
14809             * Returns the last journal article in the ordered set where companyId = &#63; and version = &#63;.
14810             *
14811             * @param companyId the company ID
14812             * @param version the version
14813             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14814             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
14815             * @throws SystemException if a system exception occurred
14816             */
14817            @Override
14818            public JournalArticle fetchByC_V_Last(long companyId, double version,
14819                    OrderByComparator orderByComparator) throws SystemException {
14820                    int count = countByC_V(companyId, version);
14821    
14822                    if (count == 0) {
14823                            return null;
14824                    }
14825    
14826                    List<JournalArticle> list = findByC_V(companyId, version, count - 1,
14827                                    count, orderByComparator);
14828    
14829                    if (!list.isEmpty()) {
14830                            return list.get(0);
14831                    }
14832    
14833                    return null;
14834            }
14835    
14836            /**
14837             * Returns the journal articles before and after the current journal article in the ordered set where companyId = &#63; and version = &#63;.
14838             *
14839             * @param id the primary key of the current journal article
14840             * @param companyId the company ID
14841             * @param version the version
14842             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14843             * @return the previous, current, and next journal article
14844             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
14845             * @throws SystemException if a system exception occurred
14846             */
14847            @Override
14848            public JournalArticle[] findByC_V_PrevAndNext(long id, long companyId,
14849                    double version, OrderByComparator orderByComparator)
14850                    throws NoSuchArticleException, SystemException {
14851                    JournalArticle journalArticle = findByPrimaryKey(id);
14852    
14853                    Session session = null;
14854    
14855                    try {
14856                            session = openSession();
14857    
14858                            JournalArticle[] array = new JournalArticleImpl[3];
14859    
14860                            array[0] = getByC_V_PrevAndNext(session, journalArticle, companyId,
14861                                            version, orderByComparator, true);
14862    
14863                            array[1] = journalArticle;
14864    
14865                            array[2] = getByC_V_PrevAndNext(session, journalArticle, companyId,
14866                                            version, orderByComparator, false);
14867    
14868                            return array;
14869                    }
14870                    catch (Exception e) {
14871                            throw processException(e);
14872                    }
14873                    finally {
14874                            closeSession(session);
14875                    }
14876            }
14877    
14878            protected JournalArticle getByC_V_PrevAndNext(Session session,
14879                    JournalArticle journalArticle, long companyId, double version,
14880                    OrderByComparator orderByComparator, boolean previous) {
14881                    StringBundler query = null;
14882    
14883                    if (orderByComparator != null) {
14884                            query = new StringBundler(6 +
14885                                            (orderByComparator.getOrderByFields().length * 6));
14886                    }
14887                    else {
14888                            query = new StringBundler(3);
14889                    }
14890    
14891                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
14892    
14893                    query.append(_FINDER_COLUMN_C_V_COMPANYID_2);
14894    
14895                    query.append(_FINDER_COLUMN_C_V_VERSION_2);
14896    
14897                    if (orderByComparator != null) {
14898                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14899    
14900                            if (orderByConditionFields.length > 0) {
14901                                    query.append(WHERE_AND);
14902                            }
14903    
14904                            for (int i = 0; i < orderByConditionFields.length; i++) {
14905                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14906                                    query.append(orderByConditionFields[i]);
14907    
14908                                    if ((i + 1) < orderByConditionFields.length) {
14909                                            if (orderByComparator.isAscending() ^ previous) {
14910                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14911                                            }
14912                                            else {
14913                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14914                                            }
14915                                    }
14916                                    else {
14917                                            if (orderByComparator.isAscending() ^ previous) {
14918                                                    query.append(WHERE_GREATER_THAN);
14919                                            }
14920                                            else {
14921                                                    query.append(WHERE_LESSER_THAN);
14922                                            }
14923                                    }
14924                            }
14925    
14926                            query.append(ORDER_BY_CLAUSE);
14927    
14928                            String[] orderByFields = orderByComparator.getOrderByFields();
14929    
14930                            for (int i = 0; i < orderByFields.length; i++) {
14931                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14932                                    query.append(orderByFields[i]);
14933    
14934                                    if ((i + 1) < orderByFields.length) {
14935                                            if (orderByComparator.isAscending() ^ previous) {
14936                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14937                                            }
14938                                            else {
14939                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14940                                            }
14941                                    }
14942                                    else {
14943                                            if (orderByComparator.isAscending() ^ previous) {
14944                                                    query.append(ORDER_BY_ASC);
14945                                            }
14946                                            else {
14947                                                    query.append(ORDER_BY_DESC);
14948                                            }
14949                                    }
14950                            }
14951                    }
14952                    else {
14953                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
14954                    }
14955    
14956                    String sql = query.toString();
14957    
14958                    Query q = session.createQuery(sql);
14959    
14960                    q.setFirstResult(0);
14961                    q.setMaxResults(2);
14962    
14963                    QueryPos qPos = QueryPos.getInstance(q);
14964    
14965                    qPos.add(companyId);
14966    
14967                    qPos.add(version);
14968    
14969                    if (orderByComparator != null) {
14970                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
14971    
14972                            for (Object value : values) {
14973                                    qPos.add(value);
14974                            }
14975                    }
14976    
14977                    List<JournalArticle> list = q.list();
14978    
14979                    if (list.size() == 2) {
14980                            return list.get(1);
14981                    }
14982                    else {
14983                            return null;
14984                    }
14985            }
14986    
14987            /**
14988             * Removes all the journal articles where companyId = &#63; and version = &#63; from the database.
14989             *
14990             * @param companyId the company ID
14991             * @param version the version
14992             * @throws SystemException if a system exception occurred
14993             */
14994            @Override
14995            public void removeByC_V(long companyId, double version)
14996                    throws SystemException {
14997                    for (JournalArticle journalArticle : findByC_V(companyId, version,
14998                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14999                            remove(journalArticle);
15000                    }
15001            }
15002    
15003            /**
15004             * Returns the number of journal articles where companyId = &#63; and version = &#63;.
15005             *
15006             * @param companyId the company ID
15007             * @param version the version
15008             * @return the number of matching journal articles
15009             * @throws SystemException if a system exception occurred
15010             */
15011            @Override
15012            public int countByC_V(long companyId, double version)
15013                    throws SystemException {
15014                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_V;
15015    
15016                    Object[] finderArgs = new Object[] { companyId, version };
15017    
15018                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15019                                    this);
15020    
15021                    if (count == null) {
15022                            StringBundler query = new StringBundler(3);
15023    
15024                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
15025    
15026                            query.append(_FINDER_COLUMN_C_V_COMPANYID_2);
15027    
15028                            query.append(_FINDER_COLUMN_C_V_VERSION_2);
15029    
15030                            String sql = query.toString();
15031    
15032                            Session session = null;
15033    
15034                            try {
15035                                    session = openSession();
15036    
15037                                    Query q = session.createQuery(sql);
15038    
15039                                    QueryPos qPos = QueryPos.getInstance(q);
15040    
15041                                    qPos.add(companyId);
15042    
15043                                    qPos.add(version);
15044    
15045                                    count = (Long)q.uniqueResult();
15046    
15047                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15048                            }
15049                            catch (Exception e) {
15050                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15051    
15052                                    throw processException(e);
15053                            }
15054                            finally {
15055                                    closeSession(session);
15056                            }
15057                    }
15058    
15059                    return count.intValue();
15060            }
15061    
15062            private static final String _FINDER_COLUMN_C_V_COMPANYID_2 = "journalArticle.companyId = ? AND ";
15063            private static final String _FINDER_COLUMN_C_V_VERSION_2 = "journalArticle.version = ?";
15064            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
15065                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
15066                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
15067                            "findByC_ST",
15068                            new String[] {
15069                                    Long.class.getName(), Integer.class.getName(),
15070                                    
15071                            Integer.class.getName(), Integer.class.getName(),
15072                                    OrderByComparator.class.getName()
15073                            });
15074            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
15075                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
15076                            JournalArticleImpl.class,
15077                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_ST",
15078                            new String[] { Long.class.getName(), Integer.class.getName() },
15079                            JournalArticleModelImpl.COMPANYID_COLUMN_BITMASK |
15080                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
15081                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
15082                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
15083            public static final FinderPath FINDER_PATH_COUNT_BY_C_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
15084                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
15085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_ST",
15086                            new String[] { Long.class.getName(), Integer.class.getName() });
15087    
15088            /**
15089             * Returns all the journal articles where companyId = &#63; and status = &#63;.
15090             *
15091             * @param companyId the company ID
15092             * @param status the status
15093             * @return the matching journal articles
15094             * @throws SystemException if a system exception occurred
15095             */
15096            @Override
15097            public List<JournalArticle> findByC_ST(long companyId, int status)
15098                    throws SystemException {
15099                    return findByC_ST(companyId, status, QueryUtil.ALL_POS,
15100                            QueryUtil.ALL_POS, null);
15101            }
15102    
15103            /**
15104             * Returns a range of all the journal articles where companyId = &#63; and status = &#63;.
15105             *
15106             * <p>
15107             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
15108             * </p>
15109             *
15110             * @param companyId the company ID
15111             * @param status the status
15112             * @param start the lower bound of the range of journal articles
15113             * @param end the upper bound of the range of journal articles (not inclusive)
15114             * @return the range of matching journal articles
15115             * @throws SystemException if a system exception occurred
15116             */
15117            @Override
15118            public List<JournalArticle> findByC_ST(long companyId, int status,
15119                    int start, int end) throws SystemException {
15120                    return findByC_ST(companyId, status, start, end, null);
15121            }
15122    
15123            /**
15124             * Returns an ordered range of all the journal articles where companyId = &#63; and status = &#63;.
15125             *
15126             * <p>
15127             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
15128             * </p>
15129             *
15130             * @param companyId the company ID
15131             * @param status the status
15132             * @param start the lower bound of the range of journal articles
15133             * @param end the upper bound of the range of journal articles (not inclusive)
15134             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15135             * @return the ordered range of matching journal articles
15136             * @throws SystemException if a system exception occurred
15137             */
15138            @Override
15139            public List<JournalArticle> findByC_ST(long companyId, int status,
15140                    int start, int end, OrderByComparator orderByComparator)
15141                    throws SystemException {
15142                    boolean pagination = true;
15143                    FinderPath finderPath = null;
15144                    Object[] finderArgs = null;
15145    
15146                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15147                                    (orderByComparator == null)) {
15148                            pagination = false;
15149                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_ST;
15150                            finderArgs = new Object[] { companyId, status };
15151                    }
15152                    else {
15153                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_ST;
15154                            finderArgs = new Object[] {
15155                                            companyId, status,
15156                                            
15157                                            start, end, orderByComparator
15158                                    };
15159                    }
15160    
15161                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
15162                                    finderArgs, this);
15163    
15164                    if ((list != null) && !list.isEmpty()) {
15165                            for (JournalArticle journalArticle : list) {
15166                                    if ((companyId != journalArticle.getCompanyId()) ||
15167                                                    (status != journalArticle.getStatus())) {
15168                                            list = null;
15169    
15170                                            break;
15171                                    }
15172                            }
15173                    }
15174    
15175                    if (list == null) {
15176                            StringBundler query = null;
15177    
15178                            if (orderByComparator != null) {
15179                                    query = new StringBundler(4 +
15180                                                    (orderByComparator.getOrderByFields().length * 3));
15181                            }
15182                            else {
15183                                    query = new StringBundler(4);
15184                            }
15185    
15186                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
15187    
15188                            query.append(_FINDER_COLUMN_C_ST_COMPANYID_2);
15189    
15190                            query.append(_FINDER_COLUMN_C_ST_STATUS_2);
15191    
15192                            if (orderByComparator != null) {
15193                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15194                                            orderByComparator);
15195                            }
15196                            else
15197                             if (pagination) {
15198                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
15199                            }
15200    
15201                            String sql = query.toString();
15202    
15203                            Session session = null;
15204    
15205                            try {
15206                                    session = openSession();
15207    
15208                                    Query q = session.createQuery(sql);
15209    
15210                                    QueryPos qPos = QueryPos.getInstance(q);
15211    
15212                                    qPos.add(companyId);
15213    
15214                                    qPos.add(status);
15215    
15216                                    if (!pagination) {
15217                                            list = (List<JournalArticle>)QueryUtil.list(q,
15218                                                            getDialect(), start, end, false);
15219    
15220                                            Collections.sort(list);
15221    
15222                                            list = new UnmodifiableList<JournalArticle>(list);
15223                                    }
15224                                    else {
15225                                            list = (List<JournalArticle>)QueryUtil.list(q,
15226                                                            getDialect(), start, end);
15227                                    }
15228    
15229                                    cacheResult(list);
15230    
15231                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15232                            }
15233                            catch (Exception e) {
15234                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15235    
15236                                    throw processException(e);
15237                            }
15238                            finally {
15239                                    closeSession(session);
15240                            }
15241                    }
15242    
15243                    return list;
15244            }
15245    
15246            /**
15247             * Returns the first journal article in the ordered set where companyId = &#63; and status = &#63;.
15248             *
15249             * @param companyId the company ID
15250             * @param status the status
15251             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15252             * @return the first matching journal article
15253             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
15254             * @throws SystemException if a system exception occurred
15255             */
15256            @Override
15257            public JournalArticle findByC_ST_First(long companyId, int status,
15258                    OrderByComparator orderByComparator)
15259                    throws NoSuchArticleException, SystemException {
15260                    JournalArticle journalArticle = fetchByC_ST_First(companyId, status,
15261                                    orderByComparator);
15262    
15263                    if (journalArticle != null) {
15264                            return journalArticle;
15265                    }
15266    
15267                    StringBundler msg = new StringBundler(6);
15268    
15269                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15270    
15271                    msg.append("companyId=");
15272                    msg.append(companyId);
15273    
15274                    msg.append(", status=");
15275                    msg.append(status);
15276    
15277                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15278    
15279                    throw new NoSuchArticleException(msg.toString());
15280            }
15281    
15282            /**
15283             * Returns the first journal article in the ordered set where companyId = &#63; and status = &#63;.
15284             *
15285             * @param companyId the company ID
15286             * @param status the status
15287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15288             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
15289             * @throws SystemException if a system exception occurred
15290             */
15291            @Override
15292            public JournalArticle fetchByC_ST_First(long companyId, int status,
15293                    OrderByComparator orderByComparator) throws SystemException {
15294                    List<JournalArticle> list = findByC_ST(companyId, status, 0, 1,
15295                                    orderByComparator);
15296    
15297                    if (!list.isEmpty()) {
15298                            return list.get(0);
15299                    }
15300    
15301                    return null;
15302            }
15303    
15304            /**
15305             * Returns the last journal article in the ordered set where companyId = &#63; and status = &#63;.
15306             *
15307             * @param companyId the company ID
15308             * @param status the status
15309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15310             * @return the last matching journal article
15311             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
15312             * @throws SystemException if a system exception occurred
15313             */
15314            @Override
15315            public JournalArticle findByC_ST_Last(long companyId, int status,
15316                    OrderByComparator orderByComparator)
15317                    throws NoSuchArticleException, SystemException {
15318                    JournalArticle journalArticle = fetchByC_ST_Last(companyId, status,
15319                                    orderByComparator);
15320    
15321                    if (journalArticle != null) {
15322                            return journalArticle;
15323                    }
15324    
15325                    StringBundler msg = new StringBundler(6);
15326    
15327                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15328    
15329                    msg.append("companyId=");
15330                    msg.append(companyId);
15331    
15332                    msg.append(", status=");
15333                    msg.append(status);
15334    
15335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15336    
15337                    throw new NoSuchArticleException(msg.toString());
15338            }
15339    
15340            /**
15341             * Returns the last journal article in the ordered set where companyId = &#63; and status = &#63;.
15342             *
15343             * @param companyId the company ID
15344             * @param status the status
15345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15346             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
15347             * @throws SystemException if a system exception occurred
15348             */
15349            @Override
15350            public JournalArticle fetchByC_ST_Last(long companyId, int status,
15351                    OrderByComparator orderByComparator) throws SystemException {
15352                    int count = countByC_ST(companyId, status);
15353    
15354                    if (count == 0) {
15355                            return null;
15356                    }
15357    
15358                    List<JournalArticle> list = findByC_ST(companyId, status, count - 1,
15359                                    count, orderByComparator);
15360    
15361                    if (!list.isEmpty()) {
15362                            return list.get(0);
15363                    }
15364    
15365                    return null;
15366            }
15367    
15368            /**
15369             * Returns the journal articles before and after the current journal article in the ordered set where companyId = &#63; and status = &#63;.
15370             *
15371             * @param id the primary key of the current journal article
15372             * @param companyId the company ID
15373             * @param status the status
15374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15375             * @return the previous, current, and next journal article
15376             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
15377             * @throws SystemException if a system exception occurred
15378             */
15379            @Override
15380            public JournalArticle[] findByC_ST_PrevAndNext(long id, long companyId,
15381                    int status, OrderByComparator orderByComparator)
15382                    throws NoSuchArticleException, SystemException {
15383                    JournalArticle journalArticle = findByPrimaryKey(id);
15384    
15385                    Session session = null;
15386    
15387                    try {
15388                            session = openSession();
15389    
15390                            JournalArticle[] array = new JournalArticleImpl[3];
15391    
15392                            array[0] = getByC_ST_PrevAndNext(session, journalArticle,
15393                                            companyId, status, orderByComparator, true);
15394    
15395                            array[1] = journalArticle;
15396    
15397                            array[2] = getByC_ST_PrevAndNext(session, journalArticle,
15398                                            companyId, status, orderByComparator, false);
15399    
15400                            return array;
15401                    }
15402                    catch (Exception e) {
15403                            throw processException(e);
15404                    }
15405                    finally {
15406                            closeSession(session);
15407                    }
15408            }
15409    
15410            protected JournalArticle getByC_ST_PrevAndNext(Session session,
15411                    JournalArticle journalArticle, long companyId, int status,
15412                    OrderByComparator orderByComparator, boolean previous) {
15413                    StringBundler query = null;
15414    
15415                    if (orderByComparator != null) {
15416                            query = new StringBundler(6 +
15417                                            (orderByComparator.getOrderByFields().length * 6));
15418                    }
15419                    else {
15420                            query = new StringBundler(3);
15421                    }
15422    
15423                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
15424    
15425                    query.append(_FINDER_COLUMN_C_ST_COMPANYID_2);
15426    
15427                    query.append(_FINDER_COLUMN_C_ST_STATUS_2);
15428    
15429                    if (orderByComparator != null) {
15430                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15431    
15432                            if (orderByConditionFields.length > 0) {
15433                                    query.append(WHERE_AND);
15434                            }
15435    
15436                            for (int i = 0; i < orderByConditionFields.length; i++) {
15437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15438                                    query.append(orderByConditionFields[i]);
15439    
15440                                    if ((i + 1) < orderByConditionFields.length) {
15441                                            if (orderByComparator.isAscending() ^ previous) {
15442                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15443                                            }
15444                                            else {
15445                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15446                                            }
15447                                    }
15448                                    else {
15449                                            if (orderByComparator.isAscending() ^ previous) {
15450                                                    query.append(WHERE_GREATER_THAN);
15451                                            }
15452                                            else {
15453                                                    query.append(WHERE_LESSER_THAN);
15454                                            }
15455                                    }
15456                            }
15457    
15458                            query.append(ORDER_BY_CLAUSE);
15459    
15460                            String[] orderByFields = orderByComparator.getOrderByFields();
15461    
15462                            for (int i = 0; i < orderByFields.length; i++) {
15463                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15464                                    query.append(orderByFields[i]);
15465    
15466                                    if ((i + 1) < orderByFields.length) {
15467                                            if (orderByComparator.isAscending() ^ previous) {
15468                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15469                                            }
15470                                            else {
15471                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15472                                            }
15473                                    }
15474                                    else {
15475                                            if (orderByComparator.isAscending() ^ previous) {
15476                                                    query.append(ORDER_BY_ASC);
15477                                            }
15478                                            else {
15479                                                    query.append(ORDER_BY_DESC);
15480                                            }
15481                                    }
15482                            }
15483                    }
15484                    else {
15485                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
15486                    }
15487    
15488                    String sql = query.toString();
15489    
15490                    Query q = session.createQuery(sql);
15491    
15492                    q.setFirstResult(0);
15493                    q.setMaxResults(2);
15494    
15495                    QueryPos qPos = QueryPos.getInstance(q);
15496    
15497                    qPos.add(companyId);
15498    
15499                    qPos.add(status);
15500    
15501                    if (orderByComparator != null) {
15502                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
15503    
15504                            for (Object value : values) {
15505                                    qPos.add(value);
15506                            }
15507                    }
15508    
15509                    List<JournalArticle> list = q.list();
15510    
15511                    if (list.size() == 2) {
15512                            return list.get(1);
15513                    }
15514                    else {
15515                            return null;
15516                    }
15517            }
15518    
15519            /**
15520             * Removes all the journal articles where companyId = &#63; and status = &#63; from the database.
15521             *
15522             * @param companyId the company ID
15523             * @param status the status
15524             * @throws SystemException if a system exception occurred
15525             */
15526            @Override
15527            public void removeByC_ST(long companyId, int status)
15528                    throws SystemException {
15529                    for (JournalArticle journalArticle : findByC_ST(companyId, status,
15530                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15531                            remove(journalArticle);
15532                    }
15533            }
15534    
15535            /**
15536             * Returns the number of journal articles where companyId = &#63; and status = &#63;.
15537             *
15538             * @param companyId the company ID
15539             * @param status the status
15540             * @return the number of matching journal articles
15541             * @throws SystemException if a system exception occurred
15542             */
15543            @Override
15544            public int countByC_ST(long companyId, int status)
15545                    throws SystemException {
15546                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_ST;
15547    
15548                    Object[] finderArgs = new Object[] { companyId, status };
15549    
15550                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15551                                    this);
15552    
15553                    if (count == null) {
15554                            StringBundler query = new StringBundler(3);
15555    
15556                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
15557    
15558                            query.append(_FINDER_COLUMN_C_ST_COMPANYID_2);
15559    
15560                            query.append(_FINDER_COLUMN_C_ST_STATUS_2);
15561    
15562                            String sql = query.toString();
15563    
15564                            Session session = null;
15565    
15566                            try {
15567                                    session = openSession();
15568    
15569                                    Query q = session.createQuery(sql);
15570    
15571                                    QueryPos qPos = QueryPos.getInstance(q);
15572    
15573                                    qPos.add(companyId);
15574    
15575                                    qPos.add(status);
15576    
15577                                    count = (Long)q.uniqueResult();
15578    
15579                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15580                            }
15581                            catch (Exception e) {
15582                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15583    
15584                                    throw processException(e);
15585                            }
15586                            finally {
15587                                    closeSession(session);
15588                            }
15589                    }
15590    
15591                    return count.intValue();
15592            }
15593    
15594            private static final String _FINDER_COLUMN_C_ST_COMPANYID_2 = "journalArticle.companyId = ? AND ";
15595            private static final String _FINDER_COLUMN_C_ST_STATUS_2 = "journalArticle.status = ?";
15596            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
15597                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
15598                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
15599                            "findByC_NotST",
15600                            new String[] {
15601                                    Long.class.getName(), Integer.class.getName(),
15602                                    
15603                            Integer.class.getName(), Integer.class.getName(),
15604                                    OrderByComparator.class.getName()
15605                            });
15606            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
15607                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
15608                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotST",
15609                            new String[] { Long.class.getName(), Integer.class.getName() });
15610    
15611            /**
15612             * Returns all the journal articles where companyId = &#63; and status &ne; &#63;.
15613             *
15614             * @param companyId the company ID
15615             * @param status the status
15616             * @return the matching journal articles
15617             * @throws SystemException if a system exception occurred
15618             */
15619            @Override
15620            public List<JournalArticle> findByC_NotST(long companyId, int status)
15621                    throws SystemException {
15622                    return findByC_NotST(companyId, status, QueryUtil.ALL_POS,
15623                            QueryUtil.ALL_POS, null);
15624            }
15625    
15626            /**
15627             * Returns a range of all the journal articles where companyId = &#63; and status &ne; &#63;.
15628             *
15629             * <p>
15630             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
15631             * </p>
15632             *
15633             * @param companyId the company ID
15634             * @param status the status
15635             * @param start the lower bound of the range of journal articles
15636             * @param end the upper bound of the range of journal articles (not inclusive)
15637             * @return the range of matching journal articles
15638             * @throws SystemException if a system exception occurred
15639             */
15640            @Override
15641            public List<JournalArticle> findByC_NotST(long companyId, int status,
15642                    int start, int end) throws SystemException {
15643                    return findByC_NotST(companyId, status, start, end, null);
15644            }
15645    
15646            /**
15647             * Returns an ordered range of all the journal articles where companyId = &#63; and status &ne; &#63;.
15648             *
15649             * <p>
15650             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
15651             * </p>
15652             *
15653             * @param companyId the company ID
15654             * @param status the status
15655             * @param start the lower bound of the range of journal articles
15656             * @param end the upper bound of the range of journal articles (not inclusive)
15657             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15658             * @return the ordered range of matching journal articles
15659             * @throws SystemException if a system exception occurred
15660             */
15661            @Override
15662            public List<JournalArticle> findByC_NotST(long companyId, int status,
15663                    int start, int end, OrderByComparator orderByComparator)
15664                    throws SystemException {
15665                    boolean pagination = true;
15666                    FinderPath finderPath = null;
15667                    Object[] finderArgs = null;
15668    
15669                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTST;
15670                    finderArgs = new Object[] {
15671                                    companyId, status,
15672                                    
15673                                    start, end, orderByComparator
15674                            };
15675    
15676                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
15677                                    finderArgs, this);
15678    
15679                    if ((list != null) && !list.isEmpty()) {
15680                            for (JournalArticle journalArticle : list) {
15681                                    if ((companyId != journalArticle.getCompanyId()) ||
15682                                                    (status != journalArticle.getStatus())) {
15683                                            list = null;
15684    
15685                                            break;
15686                                    }
15687                            }
15688                    }
15689    
15690                    if (list == null) {
15691                            StringBundler query = null;
15692    
15693                            if (orderByComparator != null) {
15694                                    query = new StringBundler(4 +
15695                                                    (orderByComparator.getOrderByFields().length * 3));
15696                            }
15697                            else {
15698                                    query = new StringBundler(4);
15699                            }
15700    
15701                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
15702    
15703                            query.append(_FINDER_COLUMN_C_NOTST_COMPANYID_2);
15704    
15705                            query.append(_FINDER_COLUMN_C_NOTST_STATUS_2);
15706    
15707                            if (orderByComparator != null) {
15708                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15709                                            orderByComparator);
15710                            }
15711                            else
15712                             if (pagination) {
15713                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
15714                            }
15715    
15716                            String sql = query.toString();
15717    
15718                            Session session = null;
15719    
15720                            try {
15721                                    session = openSession();
15722    
15723                                    Query q = session.createQuery(sql);
15724    
15725                                    QueryPos qPos = QueryPos.getInstance(q);
15726    
15727                                    qPos.add(companyId);
15728    
15729                                    qPos.add(status);
15730    
15731                                    if (!pagination) {
15732                                            list = (List<JournalArticle>)QueryUtil.list(q,
15733                                                            getDialect(), start, end, false);
15734    
15735                                            Collections.sort(list);
15736    
15737                                            list = new UnmodifiableList<JournalArticle>(list);
15738                                    }
15739                                    else {
15740                                            list = (List<JournalArticle>)QueryUtil.list(q,
15741                                                            getDialect(), start, end);
15742                                    }
15743    
15744                                    cacheResult(list);
15745    
15746                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15747                            }
15748                            catch (Exception e) {
15749                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15750    
15751                                    throw processException(e);
15752                            }
15753                            finally {
15754                                    closeSession(session);
15755                            }
15756                    }
15757    
15758                    return list;
15759            }
15760    
15761            /**
15762             * Returns the first journal article in the ordered set where companyId = &#63; and status &ne; &#63;.
15763             *
15764             * @param companyId the company ID
15765             * @param status the status
15766             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15767             * @return the first matching journal article
15768             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
15769             * @throws SystemException if a system exception occurred
15770             */
15771            @Override
15772            public JournalArticle findByC_NotST_First(long companyId, int status,
15773                    OrderByComparator orderByComparator)
15774                    throws NoSuchArticleException, SystemException {
15775                    JournalArticle journalArticle = fetchByC_NotST_First(companyId, status,
15776                                    orderByComparator);
15777    
15778                    if (journalArticle != null) {
15779                            return journalArticle;
15780                    }
15781    
15782                    StringBundler msg = new StringBundler(6);
15783    
15784                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15785    
15786                    msg.append("companyId=");
15787                    msg.append(companyId);
15788    
15789                    msg.append(", status=");
15790                    msg.append(status);
15791    
15792                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15793    
15794                    throw new NoSuchArticleException(msg.toString());
15795            }
15796    
15797            /**
15798             * Returns the first journal article in the ordered set where companyId = &#63; and status &ne; &#63;.
15799             *
15800             * @param companyId the company ID
15801             * @param status the status
15802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15803             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
15804             * @throws SystemException if a system exception occurred
15805             */
15806            @Override
15807            public JournalArticle fetchByC_NotST_First(long companyId, int status,
15808                    OrderByComparator orderByComparator) throws SystemException {
15809                    List<JournalArticle> list = findByC_NotST(companyId, status, 0, 1,
15810                                    orderByComparator);
15811    
15812                    if (!list.isEmpty()) {
15813                            return list.get(0);
15814                    }
15815    
15816                    return null;
15817            }
15818    
15819            /**
15820             * Returns the last journal article in the ordered set where companyId = &#63; and status &ne; &#63;.
15821             *
15822             * @param companyId the company ID
15823             * @param status the status
15824             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15825             * @return the last matching journal article
15826             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
15827             * @throws SystemException if a system exception occurred
15828             */
15829            @Override
15830            public JournalArticle findByC_NotST_Last(long companyId, int status,
15831                    OrderByComparator orderByComparator)
15832                    throws NoSuchArticleException, SystemException {
15833                    JournalArticle journalArticle = fetchByC_NotST_Last(companyId, status,
15834                                    orderByComparator);
15835    
15836                    if (journalArticle != null) {
15837                            return journalArticle;
15838                    }
15839    
15840                    StringBundler msg = new StringBundler(6);
15841    
15842                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15843    
15844                    msg.append("companyId=");
15845                    msg.append(companyId);
15846    
15847                    msg.append(", status=");
15848                    msg.append(status);
15849    
15850                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15851    
15852                    throw new NoSuchArticleException(msg.toString());
15853            }
15854    
15855            /**
15856             * Returns the last journal article in the ordered set where companyId = &#63; and status &ne; &#63;.
15857             *
15858             * @param companyId the company ID
15859             * @param status the status
15860             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15861             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
15862             * @throws SystemException if a system exception occurred
15863             */
15864            @Override
15865            public JournalArticle fetchByC_NotST_Last(long companyId, int status,
15866                    OrderByComparator orderByComparator) throws SystemException {
15867                    int count = countByC_NotST(companyId, status);
15868    
15869                    if (count == 0) {
15870                            return null;
15871                    }
15872    
15873                    List<JournalArticle> list = findByC_NotST(companyId, status, count - 1,
15874                                    count, orderByComparator);
15875    
15876                    if (!list.isEmpty()) {
15877                            return list.get(0);
15878                    }
15879    
15880                    return null;
15881            }
15882    
15883            /**
15884             * Returns the journal articles before and after the current journal article in the ordered set where companyId = &#63; and status &ne; &#63;.
15885             *
15886             * @param id the primary key of the current journal article
15887             * @param companyId the company ID
15888             * @param status the status
15889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15890             * @return the previous, current, and next journal article
15891             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
15892             * @throws SystemException if a system exception occurred
15893             */
15894            @Override
15895            public JournalArticle[] findByC_NotST_PrevAndNext(long id, long companyId,
15896                    int status, OrderByComparator orderByComparator)
15897                    throws NoSuchArticleException, SystemException {
15898                    JournalArticle journalArticle = findByPrimaryKey(id);
15899    
15900                    Session session = null;
15901    
15902                    try {
15903                            session = openSession();
15904    
15905                            JournalArticle[] array = new JournalArticleImpl[3];
15906    
15907                            array[0] = getByC_NotST_PrevAndNext(session, journalArticle,
15908                                            companyId, status, orderByComparator, true);
15909    
15910                            array[1] = journalArticle;
15911    
15912                            array[2] = getByC_NotST_PrevAndNext(session, journalArticle,
15913                                            companyId, status, orderByComparator, false);
15914    
15915                            return array;
15916                    }
15917                    catch (Exception e) {
15918                            throw processException(e);
15919                    }
15920                    finally {
15921                            closeSession(session);
15922                    }
15923            }
15924    
15925            protected JournalArticle getByC_NotST_PrevAndNext(Session session,
15926                    JournalArticle journalArticle, long companyId, int status,
15927                    OrderByComparator orderByComparator, boolean previous) {
15928                    StringBundler query = null;
15929    
15930                    if (orderByComparator != null) {
15931                            query = new StringBundler(6 +
15932                                            (orderByComparator.getOrderByFields().length * 6));
15933                    }
15934                    else {
15935                            query = new StringBundler(3);
15936                    }
15937    
15938                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
15939    
15940                    query.append(_FINDER_COLUMN_C_NOTST_COMPANYID_2);
15941    
15942                    query.append(_FINDER_COLUMN_C_NOTST_STATUS_2);
15943    
15944                    if (orderByComparator != null) {
15945                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15946    
15947                            if (orderByConditionFields.length > 0) {
15948                                    query.append(WHERE_AND);
15949                            }
15950    
15951                            for (int i = 0; i < orderByConditionFields.length; i++) {
15952                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15953                                    query.append(orderByConditionFields[i]);
15954    
15955                                    if ((i + 1) < orderByConditionFields.length) {
15956                                            if (orderByComparator.isAscending() ^ previous) {
15957                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15958                                            }
15959                                            else {
15960                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15961                                            }
15962                                    }
15963                                    else {
15964                                            if (orderByComparator.isAscending() ^ previous) {
15965                                                    query.append(WHERE_GREATER_THAN);
15966                                            }
15967                                            else {
15968                                                    query.append(WHERE_LESSER_THAN);
15969                                            }
15970                                    }
15971                            }
15972    
15973                            query.append(ORDER_BY_CLAUSE);
15974    
15975                            String[] orderByFields = orderByComparator.getOrderByFields();
15976    
15977                            for (int i = 0; i < orderByFields.length; i++) {
15978                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15979                                    query.append(orderByFields[i]);
15980    
15981                                    if ((i + 1) < orderByFields.length) {
15982                                            if (orderByComparator.isAscending() ^ previous) {
15983                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15984                                            }
15985                                            else {
15986                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15987                                            }
15988                                    }
15989                                    else {
15990                                            if (orderByComparator.isAscending() ^ previous) {
15991                                                    query.append(ORDER_BY_ASC);
15992                                            }
15993                                            else {
15994                                                    query.append(ORDER_BY_DESC);
15995                                            }
15996                                    }
15997                            }
15998                    }
15999                    else {
16000                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
16001                    }
16002    
16003                    String sql = query.toString();
16004    
16005                    Query q = session.createQuery(sql);
16006    
16007                    q.setFirstResult(0);
16008                    q.setMaxResults(2);
16009    
16010                    QueryPos qPos = QueryPos.getInstance(q);
16011    
16012                    qPos.add(companyId);
16013    
16014                    qPos.add(status);
16015    
16016                    if (orderByComparator != null) {
16017                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
16018    
16019                            for (Object value : values) {
16020                                    qPos.add(value);
16021                            }
16022                    }
16023    
16024                    List<JournalArticle> list = q.list();
16025    
16026                    if (list.size() == 2) {
16027                            return list.get(1);
16028                    }
16029                    else {
16030                            return null;
16031                    }
16032            }
16033    
16034            /**
16035             * Removes all the journal articles where companyId = &#63; and status &ne; &#63; from the database.
16036             *
16037             * @param companyId the company ID
16038             * @param status the status
16039             * @throws SystemException if a system exception occurred
16040             */
16041            @Override
16042            public void removeByC_NotST(long companyId, int status)
16043                    throws SystemException {
16044                    for (JournalArticle journalArticle : findByC_NotST(companyId, status,
16045                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16046                            remove(journalArticle);
16047                    }
16048            }
16049    
16050            /**
16051             * Returns the number of journal articles where companyId = &#63; and status &ne; &#63;.
16052             *
16053             * @param companyId the company ID
16054             * @param status the status
16055             * @return the number of matching journal articles
16056             * @throws SystemException if a system exception occurred
16057             */
16058            @Override
16059            public int countByC_NotST(long companyId, int status)
16060                    throws SystemException {
16061                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTST;
16062    
16063                    Object[] finderArgs = new Object[] { companyId, status };
16064    
16065                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16066                                    this);
16067    
16068                    if (count == null) {
16069                            StringBundler query = new StringBundler(3);
16070    
16071                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
16072    
16073                            query.append(_FINDER_COLUMN_C_NOTST_COMPANYID_2);
16074    
16075                            query.append(_FINDER_COLUMN_C_NOTST_STATUS_2);
16076    
16077                            String sql = query.toString();
16078    
16079                            Session session = null;
16080    
16081                            try {
16082                                    session = openSession();
16083    
16084                                    Query q = session.createQuery(sql);
16085    
16086                                    QueryPos qPos = QueryPos.getInstance(q);
16087    
16088                                    qPos.add(companyId);
16089    
16090                                    qPos.add(status);
16091    
16092                                    count = (Long)q.uniqueResult();
16093    
16094                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16095                            }
16096                            catch (Exception e) {
16097                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16098    
16099                                    throw processException(e);
16100                            }
16101                            finally {
16102                                    closeSession(session);
16103                            }
16104                    }
16105    
16106                    return count.intValue();
16107            }
16108    
16109            private static final String _FINDER_COLUMN_C_NOTST_COMPANYID_2 = "journalArticle.companyId = ? AND ";
16110            private static final String _FINDER_COLUMN_C_NOTST_STATUS_2 = "journalArticle.status != ?";
16111            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_LTD_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
16112                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
16113                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
16114                            "findByLtD_S",
16115                            new String[] {
16116                                    Date.class.getName(), Integer.class.getName(),
16117                                    
16118                            Integer.class.getName(), Integer.class.getName(),
16119                                    OrderByComparator.class.getName()
16120                            });
16121            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTD_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
16122                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
16123                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByLtD_S",
16124                            new String[] { Date.class.getName(), Integer.class.getName() });
16125    
16126            /**
16127             * Returns all the journal articles where displayDate &lt; &#63; and status = &#63;.
16128             *
16129             * @param displayDate the display date
16130             * @param status the status
16131             * @return the matching journal articles
16132             * @throws SystemException if a system exception occurred
16133             */
16134            @Override
16135            public List<JournalArticle> findByLtD_S(Date displayDate, int status)
16136                    throws SystemException {
16137                    return findByLtD_S(displayDate, status, QueryUtil.ALL_POS,
16138                            QueryUtil.ALL_POS, null);
16139            }
16140    
16141            /**
16142             * Returns a range of all the journal articles where displayDate &lt; &#63; and status = &#63;.
16143             *
16144             * <p>
16145             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
16146             * </p>
16147             *
16148             * @param displayDate the display date
16149             * @param status the status
16150             * @param start the lower bound of the range of journal articles
16151             * @param end the upper bound of the range of journal articles (not inclusive)
16152             * @return the range of matching journal articles
16153             * @throws SystemException if a system exception occurred
16154             */
16155            @Override
16156            public List<JournalArticle> findByLtD_S(Date displayDate, int status,
16157                    int start, int end) throws SystemException {
16158                    return findByLtD_S(displayDate, status, start, end, null);
16159            }
16160    
16161            /**
16162             * Returns an ordered range of all the journal articles where displayDate &lt; &#63; and status = &#63;.
16163             *
16164             * <p>
16165             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
16166             * </p>
16167             *
16168             * @param displayDate the display date
16169             * @param status the status
16170             * @param start the lower bound of the range of journal articles
16171             * @param end the upper bound of the range of journal articles (not inclusive)
16172             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16173             * @return the ordered range of matching journal articles
16174             * @throws SystemException if a system exception occurred
16175             */
16176            @Override
16177            public List<JournalArticle> findByLtD_S(Date displayDate, int status,
16178                    int start, int end, OrderByComparator orderByComparator)
16179                    throws SystemException {
16180                    boolean pagination = true;
16181                    FinderPath finderPath = null;
16182                    Object[] finderArgs = null;
16183    
16184                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_LTD_S;
16185                    finderArgs = new Object[] {
16186                                    displayDate, status,
16187                                    
16188                                    start, end, orderByComparator
16189                            };
16190    
16191                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
16192                                    finderArgs, this);
16193    
16194                    if ((list != null) && !list.isEmpty()) {
16195                            for (JournalArticle journalArticle : list) {
16196                                    if (!Validator.equals(displayDate,
16197                                                            journalArticle.getDisplayDate()) ||
16198                                                    (status != journalArticle.getStatus())) {
16199                                            list = null;
16200    
16201                                            break;
16202                                    }
16203                            }
16204                    }
16205    
16206                    if (list == null) {
16207                            StringBundler query = null;
16208    
16209                            if (orderByComparator != null) {
16210                                    query = new StringBundler(4 +
16211                                                    (orderByComparator.getOrderByFields().length * 3));
16212                            }
16213                            else {
16214                                    query = new StringBundler(4);
16215                            }
16216    
16217                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
16218    
16219                            boolean bindDisplayDate = false;
16220    
16221                            if (displayDate == null) {
16222                                    query.append(_FINDER_COLUMN_LTD_S_DISPLAYDATE_1);
16223                            }
16224                            else {
16225                                    bindDisplayDate = true;
16226    
16227                                    query.append(_FINDER_COLUMN_LTD_S_DISPLAYDATE_2);
16228                            }
16229    
16230                            query.append(_FINDER_COLUMN_LTD_S_STATUS_2);
16231    
16232                            if (orderByComparator != null) {
16233                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16234                                            orderByComparator);
16235                            }
16236                            else
16237                             if (pagination) {
16238                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
16239                            }
16240    
16241                            String sql = query.toString();
16242    
16243                            Session session = null;
16244    
16245                            try {
16246                                    session = openSession();
16247    
16248                                    Query q = session.createQuery(sql);
16249    
16250                                    QueryPos qPos = QueryPos.getInstance(q);
16251    
16252                                    if (bindDisplayDate) {
16253                                            qPos.add(CalendarUtil.getTimestamp(displayDate));
16254                                    }
16255    
16256                                    qPos.add(status);
16257    
16258                                    if (!pagination) {
16259                                            list = (List<JournalArticle>)QueryUtil.list(q,
16260                                                            getDialect(), start, end, false);
16261    
16262                                            Collections.sort(list);
16263    
16264                                            list = new UnmodifiableList<JournalArticle>(list);
16265                                    }
16266                                    else {
16267                                            list = (List<JournalArticle>)QueryUtil.list(q,
16268                                                            getDialect(), start, end);
16269                                    }
16270    
16271                                    cacheResult(list);
16272    
16273                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16274                            }
16275                            catch (Exception e) {
16276                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16277    
16278                                    throw processException(e);
16279                            }
16280                            finally {
16281                                    closeSession(session);
16282                            }
16283                    }
16284    
16285                    return list;
16286            }
16287    
16288            /**
16289             * Returns the first journal article in the ordered set where displayDate &lt; &#63; and status = &#63;.
16290             *
16291             * @param displayDate the display date
16292             * @param status the status
16293             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16294             * @return the first matching journal article
16295             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
16296             * @throws SystemException if a system exception occurred
16297             */
16298            @Override
16299            public JournalArticle findByLtD_S_First(Date displayDate, int status,
16300                    OrderByComparator orderByComparator)
16301                    throws NoSuchArticleException, SystemException {
16302                    JournalArticle journalArticle = fetchByLtD_S_First(displayDate, status,
16303                                    orderByComparator);
16304    
16305                    if (journalArticle != null) {
16306                            return journalArticle;
16307                    }
16308    
16309                    StringBundler msg = new StringBundler(6);
16310    
16311                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16312    
16313                    msg.append("displayDate=");
16314                    msg.append(displayDate);
16315    
16316                    msg.append(", status=");
16317                    msg.append(status);
16318    
16319                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16320    
16321                    throw new NoSuchArticleException(msg.toString());
16322            }
16323    
16324            /**
16325             * Returns the first journal article in the ordered set where displayDate &lt; &#63; and status = &#63;.
16326             *
16327             * @param displayDate the display date
16328             * @param status the status
16329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16330             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
16331             * @throws SystemException if a system exception occurred
16332             */
16333            @Override
16334            public JournalArticle fetchByLtD_S_First(Date displayDate, int status,
16335                    OrderByComparator orderByComparator) throws SystemException {
16336                    List<JournalArticle> list = findByLtD_S(displayDate, status, 0, 1,
16337                                    orderByComparator);
16338    
16339                    if (!list.isEmpty()) {
16340                            return list.get(0);
16341                    }
16342    
16343                    return null;
16344            }
16345    
16346            /**
16347             * Returns the last journal article in the ordered set where displayDate &lt; &#63; and status = &#63;.
16348             *
16349             * @param displayDate the display date
16350             * @param status the status
16351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16352             * @return the last matching journal article
16353             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
16354             * @throws SystemException if a system exception occurred
16355             */
16356            @Override
16357            public JournalArticle findByLtD_S_Last(Date displayDate, int status,
16358                    OrderByComparator orderByComparator)
16359                    throws NoSuchArticleException, SystemException {
16360                    JournalArticle journalArticle = fetchByLtD_S_Last(displayDate, status,
16361                                    orderByComparator);
16362    
16363                    if (journalArticle != null) {
16364                            return journalArticle;
16365                    }
16366    
16367                    StringBundler msg = new StringBundler(6);
16368    
16369                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16370    
16371                    msg.append("displayDate=");
16372                    msg.append(displayDate);
16373    
16374                    msg.append(", status=");
16375                    msg.append(status);
16376    
16377                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16378    
16379                    throw new NoSuchArticleException(msg.toString());
16380            }
16381    
16382            /**
16383             * Returns the last journal article in the ordered set where displayDate &lt; &#63; and status = &#63;.
16384             *
16385             * @param displayDate the display date
16386             * @param status the status
16387             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16388             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
16389             * @throws SystemException if a system exception occurred
16390             */
16391            @Override
16392            public JournalArticle fetchByLtD_S_Last(Date displayDate, int status,
16393                    OrderByComparator orderByComparator) throws SystemException {
16394                    int count = countByLtD_S(displayDate, status);
16395    
16396                    if (count == 0) {
16397                            return null;
16398                    }
16399    
16400                    List<JournalArticle> list = findByLtD_S(displayDate, status, count - 1,
16401                                    count, orderByComparator);
16402    
16403                    if (!list.isEmpty()) {
16404                            return list.get(0);
16405                    }
16406    
16407                    return null;
16408            }
16409    
16410            /**
16411             * Returns the journal articles before and after the current journal article in the ordered set where displayDate &lt; &#63; and status = &#63;.
16412             *
16413             * @param id the primary key of the current journal article
16414             * @param displayDate the display date
16415             * @param status the status
16416             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16417             * @return the previous, current, and next journal article
16418             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
16419             * @throws SystemException if a system exception occurred
16420             */
16421            @Override
16422            public JournalArticle[] findByLtD_S_PrevAndNext(long id, Date displayDate,
16423                    int status, OrderByComparator orderByComparator)
16424                    throws NoSuchArticleException, SystemException {
16425                    JournalArticle journalArticle = findByPrimaryKey(id);
16426    
16427                    Session session = null;
16428    
16429                    try {
16430                            session = openSession();
16431    
16432                            JournalArticle[] array = new JournalArticleImpl[3];
16433    
16434                            array[0] = getByLtD_S_PrevAndNext(session, journalArticle,
16435                                            displayDate, status, orderByComparator, true);
16436    
16437                            array[1] = journalArticle;
16438    
16439                            array[2] = getByLtD_S_PrevAndNext(session, journalArticle,
16440                                            displayDate, status, orderByComparator, false);
16441    
16442                            return array;
16443                    }
16444                    catch (Exception e) {
16445                            throw processException(e);
16446                    }
16447                    finally {
16448                            closeSession(session);
16449                    }
16450            }
16451    
16452            protected JournalArticle getByLtD_S_PrevAndNext(Session session,
16453                    JournalArticle journalArticle, Date displayDate, int status,
16454                    OrderByComparator orderByComparator, boolean previous) {
16455                    StringBundler query = null;
16456    
16457                    if (orderByComparator != null) {
16458                            query = new StringBundler(6 +
16459                                            (orderByComparator.getOrderByFields().length * 6));
16460                    }
16461                    else {
16462                            query = new StringBundler(3);
16463                    }
16464    
16465                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
16466    
16467                    boolean bindDisplayDate = false;
16468    
16469                    if (displayDate == null) {
16470                            query.append(_FINDER_COLUMN_LTD_S_DISPLAYDATE_1);
16471                    }
16472                    else {
16473                            bindDisplayDate = true;
16474    
16475                            query.append(_FINDER_COLUMN_LTD_S_DISPLAYDATE_2);
16476                    }
16477    
16478                    query.append(_FINDER_COLUMN_LTD_S_STATUS_2);
16479    
16480                    if (orderByComparator != null) {
16481                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16482    
16483                            if (orderByConditionFields.length > 0) {
16484                                    query.append(WHERE_AND);
16485                            }
16486    
16487                            for (int i = 0; i < orderByConditionFields.length; i++) {
16488                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16489                                    query.append(orderByConditionFields[i]);
16490    
16491                                    if ((i + 1) < orderByConditionFields.length) {
16492                                            if (orderByComparator.isAscending() ^ previous) {
16493                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16494                                            }
16495                                            else {
16496                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16497                                            }
16498                                    }
16499                                    else {
16500                                            if (orderByComparator.isAscending() ^ previous) {
16501                                                    query.append(WHERE_GREATER_THAN);
16502                                            }
16503                                            else {
16504                                                    query.append(WHERE_LESSER_THAN);
16505                                            }
16506                                    }
16507                            }
16508    
16509                            query.append(ORDER_BY_CLAUSE);
16510    
16511                            String[] orderByFields = orderByComparator.getOrderByFields();
16512    
16513                            for (int i = 0; i < orderByFields.length; i++) {
16514                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16515                                    query.append(orderByFields[i]);
16516    
16517                                    if ((i + 1) < orderByFields.length) {
16518                                            if (orderByComparator.isAscending() ^ previous) {
16519                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16520                                            }
16521                                            else {
16522                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16523                                            }
16524                                    }
16525                                    else {
16526                                            if (orderByComparator.isAscending() ^ previous) {
16527                                                    query.append(ORDER_BY_ASC);
16528                                            }
16529                                            else {
16530                                                    query.append(ORDER_BY_DESC);
16531                                            }
16532                                    }
16533                            }
16534                    }
16535                    else {
16536                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
16537                    }
16538    
16539                    String sql = query.toString();
16540    
16541                    Query q = session.createQuery(sql);
16542    
16543                    q.setFirstResult(0);
16544                    q.setMaxResults(2);
16545    
16546                    QueryPos qPos = QueryPos.getInstance(q);
16547    
16548                    if (bindDisplayDate) {
16549                            qPos.add(CalendarUtil.getTimestamp(displayDate));
16550                    }
16551    
16552                    qPos.add(status);
16553    
16554                    if (orderByComparator != null) {
16555                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
16556    
16557                            for (Object value : values) {
16558                                    qPos.add(value);
16559                            }
16560                    }
16561    
16562                    List<JournalArticle> list = q.list();
16563    
16564                    if (list.size() == 2) {
16565                            return list.get(1);
16566                    }
16567                    else {
16568                            return null;
16569                    }
16570            }
16571    
16572            /**
16573             * Removes all the journal articles where displayDate &lt; &#63; and status = &#63; from the database.
16574             *
16575             * @param displayDate the display date
16576             * @param status the status
16577             * @throws SystemException if a system exception occurred
16578             */
16579            @Override
16580            public void removeByLtD_S(Date displayDate, int status)
16581                    throws SystemException {
16582                    for (JournalArticle journalArticle : findByLtD_S(displayDate, status,
16583                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16584                            remove(journalArticle);
16585                    }
16586            }
16587    
16588            /**
16589             * Returns the number of journal articles where displayDate &lt; &#63; and status = &#63;.
16590             *
16591             * @param displayDate the display date
16592             * @param status the status
16593             * @return the number of matching journal articles
16594             * @throws SystemException if a system exception occurred
16595             */
16596            @Override
16597            public int countByLtD_S(Date displayDate, int status)
16598                    throws SystemException {
16599                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_LTD_S;
16600    
16601                    Object[] finderArgs = new Object[] { displayDate, status };
16602    
16603                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16604                                    this);
16605    
16606                    if (count == null) {
16607                            StringBundler query = new StringBundler(3);
16608    
16609                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
16610    
16611                            boolean bindDisplayDate = false;
16612    
16613                            if (displayDate == null) {
16614                                    query.append(_FINDER_COLUMN_LTD_S_DISPLAYDATE_1);
16615                            }
16616                            else {
16617                                    bindDisplayDate = true;
16618    
16619                                    query.append(_FINDER_COLUMN_LTD_S_DISPLAYDATE_2);
16620                            }
16621    
16622                            query.append(_FINDER_COLUMN_LTD_S_STATUS_2);
16623    
16624                            String sql = query.toString();
16625    
16626                            Session session = null;
16627    
16628                            try {
16629                                    session = openSession();
16630    
16631                                    Query q = session.createQuery(sql);
16632    
16633                                    QueryPos qPos = QueryPos.getInstance(q);
16634    
16635                                    if (bindDisplayDate) {
16636                                            qPos.add(CalendarUtil.getTimestamp(displayDate));
16637                                    }
16638    
16639                                    qPos.add(status);
16640    
16641                                    count = (Long)q.uniqueResult();
16642    
16643                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16644                            }
16645                            catch (Exception e) {
16646                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16647    
16648                                    throw processException(e);
16649                            }
16650                            finally {
16651                                    closeSession(session);
16652                            }
16653                    }
16654    
16655                    return count.intValue();
16656            }
16657    
16658            private static final String _FINDER_COLUMN_LTD_S_DISPLAYDATE_1 = "journalArticle.displayDate < NULL AND ";
16659            private static final String _FINDER_COLUMN_LTD_S_DISPLAYDATE_2 = "journalArticle.displayDate < ? AND ";
16660            private static final String _FINDER_COLUMN_LTD_S_STATUS_2 = "journalArticle.status = ?";
16661            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_I_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
16662                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
16663                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
16664                            "findByR_I_S",
16665                            new String[] {
16666                                    Long.class.getName(), Boolean.class.getName(),
16667                                    Integer.class.getName(),
16668                                    
16669                            Integer.class.getName(), Integer.class.getName(),
16670                                    OrderByComparator.class.getName()
16671                            });
16672            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_I_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
16673                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
16674                            JournalArticleImpl.class,
16675                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByR_I_S",
16676                            new String[] {
16677                                    Long.class.getName(), Boolean.class.getName(),
16678                                    Integer.class.getName()
16679                            },
16680                            JournalArticleModelImpl.RESOURCEPRIMKEY_COLUMN_BITMASK |
16681                            JournalArticleModelImpl.INDEXABLE_COLUMN_BITMASK |
16682                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
16683                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
16684                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
16685            public static final FinderPath FINDER_PATH_COUNT_BY_R_I_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
16686                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
16687                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_I_S",
16688                            new String[] {
16689                                    Long.class.getName(), Boolean.class.getName(),
16690                                    Integer.class.getName()
16691                            });
16692            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_I_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
16693                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
16694                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByR_I_S",
16695                            new String[] {
16696                                    Long.class.getName(), Boolean.class.getName(),
16697                                    Integer.class.getName()
16698                            });
16699    
16700            /**
16701             * Returns all the journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
16702             *
16703             * @param resourcePrimKey the resource prim key
16704             * @param indexable the indexable
16705             * @param status the status
16706             * @return the matching journal articles
16707             * @throws SystemException if a system exception occurred
16708             */
16709            @Override
16710            public List<JournalArticle> findByR_I_S(long resourcePrimKey,
16711                    boolean indexable, int status) throws SystemException {
16712                    return findByR_I_S(resourcePrimKey, indexable, status,
16713                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16714            }
16715    
16716            /**
16717             * Returns a range of all the journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
16718             *
16719             * <p>
16720             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
16721             * </p>
16722             *
16723             * @param resourcePrimKey the resource prim key
16724             * @param indexable the indexable
16725             * @param status the status
16726             * @param start the lower bound of the range of journal articles
16727             * @param end the upper bound of the range of journal articles (not inclusive)
16728             * @return the range of matching journal articles
16729             * @throws SystemException if a system exception occurred
16730             */
16731            @Override
16732            public List<JournalArticle> findByR_I_S(long resourcePrimKey,
16733                    boolean indexable, int status, int start, int end)
16734                    throws SystemException {
16735                    return findByR_I_S(resourcePrimKey, indexable, status, start, end, null);
16736            }
16737    
16738            /**
16739             * Returns an ordered range of all the journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
16740             *
16741             * <p>
16742             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
16743             * </p>
16744             *
16745             * @param resourcePrimKey the resource prim key
16746             * @param indexable the indexable
16747             * @param status the status
16748             * @param start the lower bound of the range of journal articles
16749             * @param end the upper bound of the range of journal articles (not inclusive)
16750             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16751             * @return the ordered range of matching journal articles
16752             * @throws SystemException if a system exception occurred
16753             */
16754            @Override
16755            public List<JournalArticle> findByR_I_S(long resourcePrimKey,
16756                    boolean indexable, int status, int start, int end,
16757                    OrderByComparator orderByComparator) throws SystemException {
16758                    boolean pagination = true;
16759                    FinderPath finderPath = null;
16760                    Object[] finderArgs = null;
16761    
16762                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16763                                    (orderByComparator == null)) {
16764                            pagination = false;
16765                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_I_S;
16766                            finderArgs = new Object[] { resourcePrimKey, indexable, status };
16767                    }
16768                    else {
16769                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_I_S;
16770                            finderArgs = new Object[] {
16771                                            resourcePrimKey, indexable, status,
16772                                            
16773                                            start, end, orderByComparator
16774                                    };
16775                    }
16776    
16777                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
16778                                    finderArgs, this);
16779    
16780                    if ((list != null) && !list.isEmpty()) {
16781                            for (JournalArticle journalArticle : list) {
16782                                    if ((resourcePrimKey != journalArticle.getResourcePrimKey()) ||
16783                                                    (indexable != journalArticle.getIndexable()) ||
16784                                                    (status != journalArticle.getStatus())) {
16785                                            list = null;
16786    
16787                                            break;
16788                                    }
16789                            }
16790                    }
16791    
16792                    if (list == null) {
16793                            StringBundler query = null;
16794    
16795                            if (orderByComparator != null) {
16796                                    query = new StringBundler(5 +
16797                                                    (orderByComparator.getOrderByFields().length * 3));
16798                            }
16799                            else {
16800                                    query = new StringBundler(5);
16801                            }
16802    
16803                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
16804    
16805                            query.append(_FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_2);
16806    
16807                            query.append(_FINDER_COLUMN_R_I_S_INDEXABLE_2);
16808    
16809                            query.append(_FINDER_COLUMN_R_I_S_STATUS_2);
16810    
16811                            if (orderByComparator != null) {
16812                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16813                                            orderByComparator);
16814                            }
16815                            else
16816                             if (pagination) {
16817                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
16818                            }
16819    
16820                            String sql = query.toString();
16821    
16822                            Session session = null;
16823    
16824                            try {
16825                                    session = openSession();
16826    
16827                                    Query q = session.createQuery(sql);
16828    
16829                                    QueryPos qPos = QueryPos.getInstance(q);
16830    
16831                                    qPos.add(resourcePrimKey);
16832    
16833                                    qPos.add(indexable);
16834    
16835                                    qPos.add(status);
16836    
16837                                    if (!pagination) {
16838                                            list = (List<JournalArticle>)QueryUtil.list(q,
16839                                                            getDialect(), start, end, false);
16840    
16841                                            Collections.sort(list);
16842    
16843                                            list = new UnmodifiableList<JournalArticle>(list);
16844                                    }
16845                                    else {
16846                                            list = (List<JournalArticle>)QueryUtil.list(q,
16847                                                            getDialect(), start, end);
16848                                    }
16849    
16850                                    cacheResult(list);
16851    
16852                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16853                            }
16854                            catch (Exception e) {
16855                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16856    
16857                                    throw processException(e);
16858                            }
16859                            finally {
16860                                    closeSession(session);
16861                            }
16862                    }
16863    
16864                    return list;
16865            }
16866    
16867            /**
16868             * Returns the first journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
16869             *
16870             * @param resourcePrimKey the resource prim key
16871             * @param indexable the indexable
16872             * @param status the status
16873             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16874             * @return the first matching journal article
16875             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
16876             * @throws SystemException if a system exception occurred
16877             */
16878            @Override
16879            public JournalArticle findByR_I_S_First(long resourcePrimKey,
16880                    boolean indexable, int status, OrderByComparator orderByComparator)
16881                    throws NoSuchArticleException, SystemException {
16882                    JournalArticle journalArticle = fetchByR_I_S_First(resourcePrimKey,
16883                                    indexable, status, orderByComparator);
16884    
16885                    if (journalArticle != null) {
16886                            return journalArticle;
16887                    }
16888    
16889                    StringBundler msg = new StringBundler(8);
16890    
16891                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16892    
16893                    msg.append("resourcePrimKey=");
16894                    msg.append(resourcePrimKey);
16895    
16896                    msg.append(", indexable=");
16897                    msg.append(indexable);
16898    
16899                    msg.append(", status=");
16900                    msg.append(status);
16901    
16902                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16903    
16904                    throw new NoSuchArticleException(msg.toString());
16905            }
16906    
16907            /**
16908             * Returns the first journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
16909             *
16910             * @param resourcePrimKey the resource prim key
16911             * @param indexable the indexable
16912             * @param status the status
16913             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16914             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
16915             * @throws SystemException if a system exception occurred
16916             */
16917            @Override
16918            public JournalArticle fetchByR_I_S_First(long resourcePrimKey,
16919                    boolean indexable, int status, OrderByComparator orderByComparator)
16920                    throws SystemException {
16921                    List<JournalArticle> list = findByR_I_S(resourcePrimKey, indexable,
16922                                    status, 0, 1, orderByComparator);
16923    
16924                    if (!list.isEmpty()) {
16925                            return list.get(0);
16926                    }
16927    
16928                    return null;
16929            }
16930    
16931            /**
16932             * Returns the last journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
16933             *
16934             * @param resourcePrimKey the resource prim key
16935             * @param indexable the indexable
16936             * @param status the status
16937             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16938             * @return the last matching journal article
16939             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
16940             * @throws SystemException if a system exception occurred
16941             */
16942            @Override
16943            public JournalArticle findByR_I_S_Last(long resourcePrimKey,
16944                    boolean indexable, int status, OrderByComparator orderByComparator)
16945                    throws NoSuchArticleException, SystemException {
16946                    JournalArticle journalArticle = fetchByR_I_S_Last(resourcePrimKey,
16947                                    indexable, status, orderByComparator);
16948    
16949                    if (journalArticle != null) {
16950                            return journalArticle;
16951                    }
16952    
16953                    StringBundler msg = new StringBundler(8);
16954    
16955                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16956    
16957                    msg.append("resourcePrimKey=");
16958                    msg.append(resourcePrimKey);
16959    
16960                    msg.append(", indexable=");
16961                    msg.append(indexable);
16962    
16963                    msg.append(", status=");
16964                    msg.append(status);
16965    
16966                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16967    
16968                    throw new NoSuchArticleException(msg.toString());
16969            }
16970    
16971            /**
16972             * Returns the last journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
16973             *
16974             * @param resourcePrimKey the resource prim key
16975             * @param indexable the indexable
16976             * @param status the status
16977             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16978             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
16979             * @throws SystemException if a system exception occurred
16980             */
16981            @Override
16982            public JournalArticle fetchByR_I_S_Last(long resourcePrimKey,
16983                    boolean indexable, int status, OrderByComparator orderByComparator)
16984                    throws SystemException {
16985                    int count = countByR_I_S(resourcePrimKey, indexable, status);
16986    
16987                    if (count == 0) {
16988                            return null;
16989                    }
16990    
16991                    List<JournalArticle> list = findByR_I_S(resourcePrimKey, indexable,
16992                                    status, count - 1, count, orderByComparator);
16993    
16994                    if (!list.isEmpty()) {
16995                            return list.get(0);
16996                    }
16997    
16998                    return null;
16999            }
17000    
17001            /**
17002             * Returns the journal articles before and after the current journal article in the ordered set where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
17003             *
17004             * @param id the primary key of the current journal article
17005             * @param resourcePrimKey the resource prim key
17006             * @param indexable the indexable
17007             * @param status the status
17008             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17009             * @return the previous, current, and next journal article
17010             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
17011             * @throws SystemException if a system exception occurred
17012             */
17013            @Override
17014            public JournalArticle[] findByR_I_S_PrevAndNext(long id,
17015                    long resourcePrimKey, boolean indexable, int status,
17016                    OrderByComparator orderByComparator)
17017                    throws NoSuchArticleException, SystemException {
17018                    JournalArticle journalArticle = findByPrimaryKey(id);
17019    
17020                    Session session = null;
17021    
17022                    try {
17023                            session = openSession();
17024    
17025                            JournalArticle[] array = new JournalArticleImpl[3];
17026    
17027                            array[0] = getByR_I_S_PrevAndNext(session, journalArticle,
17028                                            resourcePrimKey, indexable, status, orderByComparator, true);
17029    
17030                            array[1] = journalArticle;
17031    
17032                            array[2] = getByR_I_S_PrevAndNext(session, journalArticle,
17033                                            resourcePrimKey, indexable, status, orderByComparator, false);
17034    
17035                            return array;
17036                    }
17037                    catch (Exception e) {
17038                            throw processException(e);
17039                    }
17040                    finally {
17041                            closeSession(session);
17042                    }
17043            }
17044    
17045            protected JournalArticle getByR_I_S_PrevAndNext(Session session,
17046                    JournalArticle journalArticle, long resourcePrimKey, boolean indexable,
17047                    int status, OrderByComparator orderByComparator, boolean previous) {
17048                    StringBundler query = null;
17049    
17050                    if (orderByComparator != null) {
17051                            query = new StringBundler(6 +
17052                                            (orderByComparator.getOrderByFields().length * 6));
17053                    }
17054                    else {
17055                            query = new StringBundler(3);
17056                    }
17057    
17058                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
17059    
17060                    query.append(_FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_2);
17061    
17062                    query.append(_FINDER_COLUMN_R_I_S_INDEXABLE_2);
17063    
17064                    query.append(_FINDER_COLUMN_R_I_S_STATUS_2);
17065    
17066                    if (orderByComparator != null) {
17067                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17068    
17069                            if (orderByConditionFields.length > 0) {
17070                                    query.append(WHERE_AND);
17071                            }
17072    
17073                            for (int i = 0; i < orderByConditionFields.length; i++) {
17074                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17075                                    query.append(orderByConditionFields[i]);
17076    
17077                                    if ((i + 1) < orderByConditionFields.length) {
17078                                            if (orderByComparator.isAscending() ^ previous) {
17079                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17080                                            }
17081                                            else {
17082                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17083                                            }
17084                                    }
17085                                    else {
17086                                            if (orderByComparator.isAscending() ^ previous) {
17087                                                    query.append(WHERE_GREATER_THAN);
17088                                            }
17089                                            else {
17090                                                    query.append(WHERE_LESSER_THAN);
17091                                            }
17092                                    }
17093                            }
17094    
17095                            query.append(ORDER_BY_CLAUSE);
17096    
17097                            String[] orderByFields = orderByComparator.getOrderByFields();
17098    
17099                            for (int i = 0; i < orderByFields.length; i++) {
17100                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17101                                    query.append(orderByFields[i]);
17102    
17103                                    if ((i + 1) < orderByFields.length) {
17104                                            if (orderByComparator.isAscending() ^ previous) {
17105                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17106                                            }
17107                                            else {
17108                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17109                                            }
17110                                    }
17111                                    else {
17112                                            if (orderByComparator.isAscending() ^ previous) {
17113                                                    query.append(ORDER_BY_ASC);
17114                                            }
17115                                            else {
17116                                                    query.append(ORDER_BY_DESC);
17117                                            }
17118                                    }
17119                            }
17120                    }
17121                    else {
17122                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
17123                    }
17124    
17125                    String sql = query.toString();
17126    
17127                    Query q = session.createQuery(sql);
17128    
17129                    q.setFirstResult(0);
17130                    q.setMaxResults(2);
17131    
17132                    QueryPos qPos = QueryPos.getInstance(q);
17133    
17134                    qPos.add(resourcePrimKey);
17135    
17136                    qPos.add(indexable);
17137    
17138                    qPos.add(status);
17139    
17140                    if (orderByComparator != null) {
17141                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
17142    
17143                            for (Object value : values) {
17144                                    qPos.add(value);
17145                            }
17146                    }
17147    
17148                    List<JournalArticle> list = q.list();
17149    
17150                    if (list.size() == 2) {
17151                            return list.get(1);
17152                    }
17153                    else {
17154                            return null;
17155                    }
17156            }
17157    
17158            /**
17159             * Returns all the journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = any &#63;.
17160             *
17161             * <p>
17162             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
17163             * </p>
17164             *
17165             * @param resourcePrimKey the resource prim key
17166             * @param indexable the indexable
17167             * @param statuses the statuses
17168             * @return the matching journal articles
17169             * @throws SystemException if a system exception occurred
17170             */
17171            @Override
17172            public List<JournalArticle> findByR_I_S(long resourcePrimKey,
17173                    boolean indexable, int[] statuses) throws SystemException {
17174                    return findByR_I_S(resourcePrimKey, indexable, statuses,
17175                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17176            }
17177    
17178            /**
17179             * Returns a range of all the journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = any &#63;.
17180             *
17181             * <p>
17182             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
17183             * </p>
17184             *
17185             * @param resourcePrimKey the resource prim key
17186             * @param indexable the indexable
17187             * @param statuses the statuses
17188             * @param start the lower bound of the range of journal articles
17189             * @param end the upper bound of the range of journal articles (not inclusive)
17190             * @return the range of matching journal articles
17191             * @throws SystemException if a system exception occurred
17192             */
17193            @Override
17194            public List<JournalArticle> findByR_I_S(long resourcePrimKey,
17195                    boolean indexable, int[] statuses, int start, int end)
17196                    throws SystemException {
17197                    return findByR_I_S(resourcePrimKey, indexable, statuses, start, end,
17198                            null);
17199            }
17200    
17201            /**
17202             * Returns an ordered range of all the journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = any &#63;.
17203             *
17204             * <p>
17205             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
17206             * </p>
17207             *
17208             * @param resourcePrimKey the resource prim key
17209             * @param indexable the indexable
17210             * @param statuses the statuses
17211             * @param start the lower bound of the range of journal articles
17212             * @param end the upper bound of the range of journal articles (not inclusive)
17213             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17214             * @return the ordered range of matching journal articles
17215             * @throws SystemException if a system exception occurred
17216             */
17217            @Override
17218            public List<JournalArticle> findByR_I_S(long resourcePrimKey,
17219                    boolean indexable, int[] statuses, int start, int end,
17220                    OrderByComparator orderByComparator) throws SystemException {
17221                    if ((statuses != null) && (statuses.length == 1)) {
17222                            return findByR_I_S(resourcePrimKey, indexable, statuses[0], start,
17223                                    end, orderByComparator);
17224                    }
17225    
17226                    boolean pagination = true;
17227                    Object[] finderArgs = null;
17228    
17229                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17230                                    (orderByComparator == null)) {
17231                            pagination = false;
17232                            finderArgs = new Object[] {
17233                                            resourcePrimKey, indexable, StringUtil.merge(statuses)
17234                                    };
17235                    }
17236                    else {
17237                            finderArgs = new Object[] {
17238                                            resourcePrimKey, indexable, StringUtil.merge(statuses),
17239                                            
17240                                            start, end, orderByComparator
17241                                    };
17242                    }
17243    
17244                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_I_S,
17245                                    finderArgs, this);
17246    
17247                    if ((list != null) && !list.isEmpty()) {
17248                            for (JournalArticle journalArticle : list) {
17249                                    if ((resourcePrimKey != journalArticle.getResourcePrimKey()) ||
17250                                                    (indexable != journalArticle.getIndexable()) ||
17251                                                    !ArrayUtil.contains(statuses, journalArticle.getStatus())) {
17252                                            list = null;
17253    
17254                                            break;
17255                                    }
17256                            }
17257                    }
17258    
17259                    if (list == null) {
17260                            StringBundler query = new StringBundler();
17261    
17262                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
17263    
17264                            boolean conjunctionable = false;
17265    
17266                            if (conjunctionable) {
17267                                    query.append(WHERE_AND);
17268                            }
17269    
17270                            query.append(_FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_5);
17271    
17272                            conjunctionable = true;
17273    
17274                            if (conjunctionable) {
17275                                    query.append(WHERE_AND);
17276                            }
17277    
17278                            query.append(_FINDER_COLUMN_R_I_S_INDEXABLE_5);
17279    
17280                            conjunctionable = true;
17281    
17282                            if ((statuses == null) || (statuses.length > 0)) {
17283                                    if (conjunctionable) {
17284                                            query.append(WHERE_AND);
17285                                    }
17286    
17287                                    query.append(StringPool.OPEN_PARENTHESIS);
17288    
17289                                    for (int i = 0; i < statuses.length; i++) {
17290                                            query.append(_FINDER_COLUMN_R_I_S_STATUS_5);
17291    
17292                                            if ((i + 1) < statuses.length) {
17293                                                    query.append(WHERE_OR);
17294                                            }
17295                                    }
17296    
17297                                    query.append(StringPool.CLOSE_PARENTHESIS);
17298    
17299                                    conjunctionable = true;
17300                            }
17301    
17302                            if (orderByComparator != null) {
17303                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17304                                            orderByComparator);
17305                            }
17306                            else
17307                             if (pagination) {
17308                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
17309                            }
17310    
17311                            String sql = query.toString();
17312    
17313                            Session session = null;
17314    
17315                            try {
17316                                    session = openSession();
17317    
17318                                    Query q = session.createQuery(sql);
17319    
17320                                    QueryPos qPos = QueryPos.getInstance(q);
17321    
17322                                    qPos.add(resourcePrimKey);
17323    
17324                                    qPos.add(indexable);
17325    
17326                                    if (statuses != null) {
17327                                            qPos.add(statuses);
17328                                    }
17329    
17330                                    if (!pagination) {
17331                                            list = (List<JournalArticle>)QueryUtil.list(q,
17332                                                            getDialect(), start, end, false);
17333    
17334                                            Collections.sort(list);
17335    
17336                                            list = new UnmodifiableList<JournalArticle>(list);
17337                                    }
17338                                    else {
17339                                            list = (List<JournalArticle>)QueryUtil.list(q,
17340                                                            getDialect(), start, end);
17341                                    }
17342    
17343                                    cacheResult(list);
17344    
17345                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_I_S,
17346                                            finderArgs, list);
17347                            }
17348                            catch (Exception e) {
17349                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_R_I_S,
17350                                            finderArgs);
17351    
17352                                    throw processException(e);
17353                            }
17354                            finally {
17355                                    closeSession(session);
17356                            }
17357                    }
17358    
17359                    return list;
17360            }
17361    
17362            /**
17363             * Removes all the journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = &#63; from the database.
17364             *
17365             * @param resourcePrimKey the resource prim key
17366             * @param indexable the indexable
17367             * @param status the status
17368             * @throws SystemException if a system exception occurred
17369             */
17370            @Override
17371            public void removeByR_I_S(long resourcePrimKey, boolean indexable,
17372                    int status) throws SystemException {
17373                    for (JournalArticle journalArticle : findByR_I_S(resourcePrimKey,
17374                                    indexable, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17375                            remove(journalArticle);
17376                    }
17377            }
17378    
17379            /**
17380             * Returns the number of journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = &#63;.
17381             *
17382             * @param resourcePrimKey the resource prim key
17383             * @param indexable the indexable
17384             * @param status the status
17385             * @return the number of matching journal articles
17386             * @throws SystemException if a system exception occurred
17387             */
17388            @Override
17389            public int countByR_I_S(long resourcePrimKey, boolean indexable, int status)
17390                    throws SystemException {
17391                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_I_S;
17392    
17393                    Object[] finderArgs = new Object[] { resourcePrimKey, indexable, status };
17394    
17395                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17396                                    this);
17397    
17398                    if (count == null) {
17399                            StringBundler query = new StringBundler(4);
17400    
17401                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
17402    
17403                            query.append(_FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_2);
17404    
17405                            query.append(_FINDER_COLUMN_R_I_S_INDEXABLE_2);
17406    
17407                            query.append(_FINDER_COLUMN_R_I_S_STATUS_2);
17408    
17409                            String sql = query.toString();
17410    
17411                            Session session = null;
17412    
17413                            try {
17414                                    session = openSession();
17415    
17416                                    Query q = session.createQuery(sql);
17417    
17418                                    QueryPos qPos = QueryPos.getInstance(q);
17419    
17420                                    qPos.add(resourcePrimKey);
17421    
17422                                    qPos.add(indexable);
17423    
17424                                    qPos.add(status);
17425    
17426                                    count = (Long)q.uniqueResult();
17427    
17428                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17429                            }
17430                            catch (Exception e) {
17431                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17432    
17433                                    throw processException(e);
17434                            }
17435                            finally {
17436                                    closeSession(session);
17437                            }
17438                    }
17439    
17440                    return count.intValue();
17441            }
17442    
17443            /**
17444             * Returns the number of journal articles where resourcePrimKey = &#63; and indexable = &#63; and status = any &#63;.
17445             *
17446             * @param resourcePrimKey the resource prim key
17447             * @param indexable the indexable
17448             * @param statuses the statuses
17449             * @return the number of matching journal articles
17450             * @throws SystemException if a system exception occurred
17451             */
17452            @Override
17453            public int countByR_I_S(long resourcePrimKey, boolean indexable,
17454                    int[] statuses) throws SystemException {
17455                    Object[] finderArgs = new Object[] {
17456                                    resourcePrimKey, indexable, StringUtil.merge(statuses)
17457                            };
17458    
17459                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_I_S,
17460                                    finderArgs, this);
17461    
17462                    if (count == null) {
17463                            StringBundler query = new StringBundler();
17464    
17465                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
17466    
17467                            boolean conjunctionable = false;
17468    
17469                            if (conjunctionable) {
17470                                    query.append(WHERE_AND);
17471                            }
17472    
17473                            query.append(_FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_5);
17474    
17475                            conjunctionable = true;
17476    
17477                            if (conjunctionable) {
17478                                    query.append(WHERE_AND);
17479                            }
17480    
17481                            query.append(_FINDER_COLUMN_R_I_S_INDEXABLE_5);
17482    
17483                            conjunctionable = true;
17484    
17485                            if ((statuses == null) || (statuses.length > 0)) {
17486                                    if (conjunctionable) {
17487                                            query.append(WHERE_AND);
17488                                    }
17489    
17490                                    query.append(StringPool.OPEN_PARENTHESIS);
17491    
17492                                    for (int i = 0; i < statuses.length; i++) {
17493                                            query.append(_FINDER_COLUMN_R_I_S_STATUS_5);
17494    
17495                                            if ((i + 1) < statuses.length) {
17496                                                    query.append(WHERE_OR);
17497                                            }
17498                                    }
17499    
17500                                    query.append(StringPool.CLOSE_PARENTHESIS);
17501    
17502                                    conjunctionable = true;
17503                            }
17504    
17505                            String sql = query.toString();
17506    
17507                            Session session = null;
17508    
17509                            try {
17510                                    session = openSession();
17511    
17512                                    Query q = session.createQuery(sql);
17513    
17514                                    QueryPos qPos = QueryPos.getInstance(q);
17515    
17516                                    qPos.add(resourcePrimKey);
17517    
17518                                    qPos.add(indexable);
17519    
17520                                    if (statuses != null) {
17521                                            qPos.add(statuses);
17522                                    }
17523    
17524                                    count = (Long)q.uniqueResult();
17525    
17526                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_I_S,
17527                                            finderArgs, count);
17528                            }
17529                            catch (Exception e) {
17530                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_R_I_S,
17531                                            finderArgs);
17532    
17533                                    throw processException(e);
17534                            }
17535                            finally {
17536                                    closeSession(session);
17537                            }
17538                    }
17539    
17540                    return count.intValue();
17541            }
17542    
17543            private static final String _FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_2 = "journalArticle.resourcePrimKey = ? AND ";
17544            private static final String _FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_5 = "(" +
17545                    removeConjunction(_FINDER_COLUMN_R_I_S_RESOURCEPRIMKEY_2) + ")";
17546            private static final String _FINDER_COLUMN_R_I_S_INDEXABLE_2 = "journalArticle.indexable = ? AND ";
17547            private static final String _FINDER_COLUMN_R_I_S_INDEXABLE_5 = "(" +
17548                    removeConjunction(_FINDER_COLUMN_R_I_S_INDEXABLE_2) + ")";
17549            private static final String _FINDER_COLUMN_R_I_S_STATUS_2 = "journalArticle.status = ?";
17550            private static final String _FINDER_COLUMN_R_I_S_STATUS_5 = "(" +
17551                    removeConjunction(_FINDER_COLUMN_R_I_S_STATUS_2) + ")";
17552            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
17553                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
17554                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
17555                            "findByG_U_C",
17556                            new String[] {
17557                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17558                                    
17559                            Integer.class.getName(), Integer.class.getName(),
17560                                    OrderByComparator.class.getName()
17561                            });
17562            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
17563                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
17564                            JournalArticleImpl.class,
17565                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_C",
17566                            new String[] {
17567                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
17568                            },
17569                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
17570                            JournalArticleModelImpl.USERID_COLUMN_BITMASK |
17571                            JournalArticleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
17572                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
17573                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
17574            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
17575                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
17576                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_C",
17577                            new String[] {
17578                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
17579                            });
17580    
17581            /**
17582             * Returns all the journal articles where groupId = &#63; and userId = &#63; and classNameId = &#63;.
17583             *
17584             * @param groupId the group ID
17585             * @param userId the user ID
17586             * @param classNameId the class name ID
17587             * @return the matching journal articles
17588             * @throws SystemException if a system exception occurred
17589             */
17590            @Override
17591            public List<JournalArticle> findByG_U_C(long groupId, long userId,
17592                    long classNameId) throws SystemException {
17593                    return findByG_U_C(groupId, userId, classNameId, QueryUtil.ALL_POS,
17594                            QueryUtil.ALL_POS, null);
17595            }
17596    
17597            /**
17598             * Returns a range of all the journal articles where groupId = &#63; and userId = &#63; and classNameId = &#63;.
17599             *
17600             * <p>
17601             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
17602             * </p>
17603             *
17604             * @param groupId the group ID
17605             * @param userId the user ID
17606             * @param classNameId the class name ID
17607             * @param start the lower bound of the range of journal articles
17608             * @param end the upper bound of the range of journal articles (not inclusive)
17609             * @return the range of matching journal articles
17610             * @throws SystemException if a system exception occurred
17611             */
17612            @Override
17613            public List<JournalArticle> findByG_U_C(long groupId, long userId,
17614                    long classNameId, int start, int end) throws SystemException {
17615                    return findByG_U_C(groupId, userId, classNameId, start, end, null);
17616            }
17617    
17618            /**
17619             * Returns an ordered range of all the journal articles where groupId = &#63; and userId = &#63; and classNameId = &#63;.
17620             *
17621             * <p>
17622             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
17623             * </p>
17624             *
17625             * @param groupId the group ID
17626             * @param userId the user ID
17627             * @param classNameId the class name ID
17628             * @param start the lower bound of the range of journal articles
17629             * @param end the upper bound of the range of journal articles (not inclusive)
17630             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17631             * @return the ordered range of matching journal articles
17632             * @throws SystemException if a system exception occurred
17633             */
17634            @Override
17635            public List<JournalArticle> findByG_U_C(long groupId, long userId,
17636                    long classNameId, int start, int end,
17637                    OrderByComparator orderByComparator) throws SystemException {
17638                    boolean pagination = true;
17639                    FinderPath finderPath = null;
17640                    Object[] finderArgs = null;
17641    
17642                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17643                                    (orderByComparator == null)) {
17644                            pagination = false;
17645                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C;
17646                            finderArgs = new Object[] { groupId, userId, classNameId };
17647                    }
17648                    else {
17649                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C;
17650                            finderArgs = new Object[] {
17651                                            groupId, userId, classNameId,
17652                                            
17653                                            start, end, orderByComparator
17654                                    };
17655                    }
17656    
17657                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
17658                                    finderArgs, this);
17659    
17660                    if ((list != null) && !list.isEmpty()) {
17661                            for (JournalArticle journalArticle : list) {
17662                                    if ((groupId != journalArticle.getGroupId()) ||
17663                                                    (userId != journalArticle.getUserId()) ||
17664                                                    (classNameId != journalArticle.getClassNameId())) {
17665                                            list = null;
17666    
17667                                            break;
17668                                    }
17669                            }
17670                    }
17671    
17672                    if (list == null) {
17673                            StringBundler query = null;
17674    
17675                            if (orderByComparator != null) {
17676                                    query = new StringBundler(5 +
17677                                                    (orderByComparator.getOrderByFields().length * 3));
17678                            }
17679                            else {
17680                                    query = new StringBundler(5);
17681                            }
17682    
17683                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
17684    
17685                            query.append(_FINDER_COLUMN_G_U_C_GROUPID_2);
17686    
17687                            query.append(_FINDER_COLUMN_G_U_C_USERID_2);
17688    
17689                            query.append(_FINDER_COLUMN_G_U_C_CLASSNAMEID_2);
17690    
17691                            if (orderByComparator != null) {
17692                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17693                                            orderByComparator);
17694                            }
17695                            else
17696                             if (pagination) {
17697                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
17698                            }
17699    
17700                            String sql = query.toString();
17701    
17702                            Session session = null;
17703    
17704                            try {
17705                                    session = openSession();
17706    
17707                                    Query q = session.createQuery(sql);
17708    
17709                                    QueryPos qPos = QueryPos.getInstance(q);
17710    
17711                                    qPos.add(groupId);
17712    
17713                                    qPos.add(userId);
17714    
17715                                    qPos.add(classNameId);
17716    
17717                                    if (!pagination) {
17718                                            list = (List<JournalArticle>)QueryUtil.list(q,
17719                                                            getDialect(), start, end, false);
17720    
17721                                            Collections.sort(list);
17722    
17723                                            list = new UnmodifiableList<JournalArticle>(list);
17724                                    }
17725                                    else {
17726                                            list = (List<JournalArticle>)QueryUtil.list(q,
17727                                                            getDialect(), start, end);
17728                                    }
17729    
17730                                    cacheResult(list);
17731    
17732                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17733                            }
17734                            catch (Exception e) {
17735                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17736    
17737                                    throw processException(e);
17738                            }
17739                            finally {
17740                                    closeSession(session);
17741                            }
17742                    }
17743    
17744                    return list;
17745            }
17746    
17747            /**
17748             * Returns the first journal article in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63;.
17749             *
17750             * @param groupId the group ID
17751             * @param userId the user ID
17752             * @param classNameId the class name ID
17753             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17754             * @return the first matching journal article
17755             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
17756             * @throws SystemException if a system exception occurred
17757             */
17758            @Override
17759            public JournalArticle findByG_U_C_First(long groupId, long userId,
17760                    long classNameId, OrderByComparator orderByComparator)
17761                    throws NoSuchArticleException, SystemException {
17762                    JournalArticle journalArticle = fetchByG_U_C_First(groupId, userId,
17763                                    classNameId, orderByComparator);
17764    
17765                    if (journalArticle != null) {
17766                            return journalArticle;
17767                    }
17768    
17769                    StringBundler msg = new StringBundler(8);
17770    
17771                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17772    
17773                    msg.append("groupId=");
17774                    msg.append(groupId);
17775    
17776                    msg.append(", userId=");
17777                    msg.append(userId);
17778    
17779                    msg.append(", classNameId=");
17780                    msg.append(classNameId);
17781    
17782                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17783    
17784                    throw new NoSuchArticleException(msg.toString());
17785            }
17786    
17787            /**
17788             * Returns the first journal article in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63;.
17789             *
17790             * @param groupId the group ID
17791             * @param userId the user ID
17792             * @param classNameId the class name ID
17793             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17794             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
17795             * @throws SystemException if a system exception occurred
17796             */
17797            @Override
17798            public JournalArticle fetchByG_U_C_First(long groupId, long userId,
17799                    long classNameId, OrderByComparator orderByComparator)
17800                    throws SystemException {
17801                    List<JournalArticle> list = findByG_U_C(groupId, userId, classNameId,
17802                                    0, 1, orderByComparator);
17803    
17804                    if (!list.isEmpty()) {
17805                            return list.get(0);
17806                    }
17807    
17808                    return null;
17809            }
17810    
17811            /**
17812             * Returns the last journal article in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63;.
17813             *
17814             * @param groupId the group ID
17815             * @param userId the user ID
17816             * @param classNameId the class name ID
17817             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17818             * @return the last matching journal article
17819             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
17820             * @throws SystemException if a system exception occurred
17821             */
17822            @Override
17823            public JournalArticle findByG_U_C_Last(long groupId, long userId,
17824                    long classNameId, OrderByComparator orderByComparator)
17825                    throws NoSuchArticleException, SystemException {
17826                    JournalArticle journalArticle = fetchByG_U_C_Last(groupId, userId,
17827                                    classNameId, orderByComparator);
17828    
17829                    if (journalArticle != null) {
17830                            return journalArticle;
17831                    }
17832    
17833                    StringBundler msg = new StringBundler(8);
17834    
17835                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17836    
17837                    msg.append("groupId=");
17838                    msg.append(groupId);
17839    
17840                    msg.append(", userId=");
17841                    msg.append(userId);
17842    
17843                    msg.append(", classNameId=");
17844                    msg.append(classNameId);
17845    
17846                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17847    
17848                    throw new NoSuchArticleException(msg.toString());
17849            }
17850    
17851            /**
17852             * Returns the last journal article in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63;.
17853             *
17854             * @param groupId the group ID
17855             * @param userId the user ID
17856             * @param classNameId the class name ID
17857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17858             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
17859             * @throws SystemException if a system exception occurred
17860             */
17861            @Override
17862            public JournalArticle fetchByG_U_C_Last(long groupId, long userId,
17863                    long classNameId, OrderByComparator orderByComparator)
17864                    throws SystemException {
17865                    int count = countByG_U_C(groupId, userId, classNameId);
17866    
17867                    if (count == 0) {
17868                            return null;
17869                    }
17870    
17871                    List<JournalArticle> list = findByG_U_C(groupId, userId, classNameId,
17872                                    count - 1, count, orderByComparator);
17873    
17874                    if (!list.isEmpty()) {
17875                            return list.get(0);
17876                    }
17877    
17878                    return null;
17879            }
17880    
17881            /**
17882             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and userId = &#63; and classNameId = &#63;.
17883             *
17884             * @param id the primary key of the current journal article
17885             * @param groupId the group ID
17886             * @param userId the user ID
17887             * @param classNameId the class name ID
17888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17889             * @return the previous, current, and next journal article
17890             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
17891             * @throws SystemException if a system exception occurred
17892             */
17893            @Override
17894            public JournalArticle[] findByG_U_C_PrevAndNext(long id, long groupId,
17895                    long userId, long classNameId, OrderByComparator orderByComparator)
17896                    throws NoSuchArticleException, SystemException {
17897                    JournalArticle journalArticle = findByPrimaryKey(id);
17898    
17899                    Session session = null;
17900    
17901                    try {
17902                            session = openSession();
17903    
17904                            JournalArticle[] array = new JournalArticleImpl[3];
17905    
17906                            array[0] = getByG_U_C_PrevAndNext(session, journalArticle, groupId,
17907                                            userId, classNameId, orderByComparator, true);
17908    
17909                            array[1] = journalArticle;
17910    
17911                            array[2] = getByG_U_C_PrevAndNext(session, journalArticle, groupId,
17912                                            userId, classNameId, orderByComparator, false);
17913    
17914                            return array;
17915                    }
17916                    catch (Exception e) {
17917                            throw processException(e);
17918                    }
17919                    finally {
17920                            closeSession(session);
17921                    }
17922            }
17923    
17924            protected JournalArticle getByG_U_C_PrevAndNext(Session session,
17925                    JournalArticle journalArticle, long groupId, long userId,
17926                    long classNameId, OrderByComparator orderByComparator, boolean previous) {
17927                    StringBundler query = null;
17928    
17929                    if (orderByComparator != null) {
17930                            query = new StringBundler(6 +
17931                                            (orderByComparator.getOrderByFields().length * 6));
17932                    }
17933                    else {
17934                            query = new StringBundler(3);
17935                    }
17936    
17937                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
17938    
17939                    query.append(_FINDER_COLUMN_G_U_C_GROUPID_2);
17940    
17941                    query.append(_FINDER_COLUMN_G_U_C_USERID_2);
17942    
17943                    query.append(_FINDER_COLUMN_G_U_C_CLASSNAMEID_2);
17944    
17945                    if (orderByComparator != null) {
17946                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17947    
17948                            if (orderByConditionFields.length > 0) {
17949                                    query.append(WHERE_AND);
17950                            }
17951    
17952                            for (int i = 0; i < orderByConditionFields.length; i++) {
17953                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17954                                    query.append(orderByConditionFields[i]);
17955    
17956                                    if ((i + 1) < orderByConditionFields.length) {
17957                                            if (orderByComparator.isAscending() ^ previous) {
17958                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17959                                            }
17960                                            else {
17961                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17962                                            }
17963                                    }
17964                                    else {
17965                                            if (orderByComparator.isAscending() ^ previous) {
17966                                                    query.append(WHERE_GREATER_THAN);
17967                                            }
17968                                            else {
17969                                                    query.append(WHERE_LESSER_THAN);
17970                                            }
17971                                    }
17972                            }
17973    
17974                            query.append(ORDER_BY_CLAUSE);
17975    
17976                            String[] orderByFields = orderByComparator.getOrderByFields();
17977    
17978                            for (int i = 0; i < orderByFields.length; i++) {
17979                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17980                                    query.append(orderByFields[i]);
17981    
17982                                    if ((i + 1) < orderByFields.length) {
17983                                            if (orderByComparator.isAscending() ^ previous) {
17984                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17985                                            }
17986                                            else {
17987                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17988                                            }
17989                                    }
17990                                    else {
17991                                            if (orderByComparator.isAscending() ^ previous) {
17992                                                    query.append(ORDER_BY_ASC);
17993                                            }
17994                                            else {
17995                                                    query.append(ORDER_BY_DESC);
17996                                            }
17997                                    }
17998                            }
17999                    }
18000                    else {
18001                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
18002                    }
18003    
18004                    String sql = query.toString();
18005    
18006                    Query q = session.createQuery(sql);
18007    
18008                    q.setFirstResult(0);
18009                    q.setMaxResults(2);
18010    
18011                    QueryPos qPos = QueryPos.getInstance(q);
18012    
18013                    qPos.add(groupId);
18014    
18015                    qPos.add(userId);
18016    
18017                    qPos.add(classNameId);
18018    
18019                    if (orderByComparator != null) {
18020                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
18021    
18022                            for (Object value : values) {
18023                                    qPos.add(value);
18024                            }
18025                    }
18026    
18027                    List<JournalArticle> list = q.list();
18028    
18029                    if (list.size() == 2) {
18030                            return list.get(1);
18031                    }
18032                    else {
18033                            return null;
18034                    }
18035            }
18036    
18037            /**
18038             * Returns all the journal articles that the user has permission to view where groupId = &#63; and userId = &#63; and classNameId = &#63;.
18039             *
18040             * @param groupId the group ID
18041             * @param userId the user ID
18042             * @param classNameId the class name ID
18043             * @return the matching journal articles that the user has permission to view
18044             * @throws SystemException if a system exception occurred
18045             */
18046            @Override
18047            public List<JournalArticle> filterFindByG_U_C(long groupId, long userId,
18048                    long classNameId) throws SystemException {
18049                    return filterFindByG_U_C(groupId, userId, classNameId,
18050                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18051            }
18052    
18053            /**
18054             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and userId = &#63; and classNameId = &#63;.
18055             *
18056             * <p>
18057             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
18058             * </p>
18059             *
18060             * @param groupId the group ID
18061             * @param userId the user ID
18062             * @param classNameId the class name ID
18063             * @param start the lower bound of the range of journal articles
18064             * @param end the upper bound of the range of journal articles (not inclusive)
18065             * @return the range of matching journal articles that the user has permission to view
18066             * @throws SystemException if a system exception occurred
18067             */
18068            @Override
18069            public List<JournalArticle> filterFindByG_U_C(long groupId, long userId,
18070                    long classNameId, int start, int end) throws SystemException {
18071                    return filterFindByG_U_C(groupId, userId, classNameId, start, end, null);
18072            }
18073    
18074            /**
18075             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and userId = &#63; and classNameId = &#63;.
18076             *
18077             * <p>
18078             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
18079             * </p>
18080             *
18081             * @param groupId the group ID
18082             * @param userId the user ID
18083             * @param classNameId the class name ID
18084             * @param start the lower bound of the range of journal articles
18085             * @param end the upper bound of the range of journal articles (not inclusive)
18086             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18087             * @return the ordered range of matching journal articles that the user has permission to view
18088             * @throws SystemException if a system exception occurred
18089             */
18090            @Override
18091            public List<JournalArticle> filterFindByG_U_C(long groupId, long userId,
18092                    long classNameId, int start, int end,
18093                    OrderByComparator orderByComparator) throws SystemException {
18094                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18095                            return findByG_U_C(groupId, userId, classNameId, start, end,
18096                                    orderByComparator);
18097                    }
18098    
18099                    StringBundler query = null;
18100    
18101                    if (orderByComparator != null) {
18102                            query = new StringBundler(5 +
18103                                            (orderByComparator.getOrderByFields().length * 3));
18104                    }
18105                    else {
18106                            query = new StringBundler(5);
18107                    }
18108    
18109                    if (getDB().isSupportsInlineDistinct()) {
18110                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
18111                    }
18112                    else {
18113                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
18114                    }
18115    
18116                    query.append(_FINDER_COLUMN_G_U_C_GROUPID_2);
18117    
18118                    query.append(_FINDER_COLUMN_G_U_C_USERID_2);
18119    
18120                    query.append(_FINDER_COLUMN_G_U_C_CLASSNAMEID_2);
18121    
18122                    if (!getDB().isSupportsInlineDistinct()) {
18123                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
18124                    }
18125    
18126                    if (orderByComparator != null) {
18127                            if (getDB().isSupportsInlineDistinct()) {
18128                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18129                                            orderByComparator, true);
18130                            }
18131                            else {
18132                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
18133                                            orderByComparator, true);
18134                            }
18135                    }
18136                    else {
18137                            if (getDB().isSupportsInlineDistinct()) {
18138                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
18139                            }
18140                            else {
18141                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
18142                            }
18143                    }
18144    
18145                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18146                                    JournalArticle.class.getName(),
18147                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18148    
18149                    Session session = null;
18150    
18151                    try {
18152                            session = openSession();
18153    
18154                            SQLQuery q = session.createSQLQuery(sql);
18155    
18156                            if (getDB().isSupportsInlineDistinct()) {
18157                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
18158                            }
18159                            else {
18160                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
18161                            }
18162    
18163                            QueryPos qPos = QueryPos.getInstance(q);
18164    
18165                            qPos.add(groupId);
18166    
18167                            qPos.add(userId);
18168    
18169                            qPos.add(classNameId);
18170    
18171                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
18172                                    end);
18173                    }
18174                    catch (Exception e) {
18175                            throw processException(e);
18176                    }
18177                    finally {
18178                            closeSession(session);
18179                    }
18180            }
18181    
18182            /**
18183             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and userId = &#63; and classNameId = &#63;.
18184             *
18185             * @param id the primary key of the current journal article
18186             * @param groupId the group ID
18187             * @param userId the user ID
18188             * @param classNameId the class name ID
18189             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18190             * @return the previous, current, and next journal article
18191             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
18192             * @throws SystemException if a system exception occurred
18193             */
18194            @Override
18195            public JournalArticle[] filterFindByG_U_C_PrevAndNext(long id,
18196                    long groupId, long userId, long classNameId,
18197                    OrderByComparator orderByComparator)
18198                    throws NoSuchArticleException, SystemException {
18199                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18200                            return findByG_U_C_PrevAndNext(id, groupId, userId, classNameId,
18201                                    orderByComparator);
18202                    }
18203    
18204                    JournalArticle journalArticle = findByPrimaryKey(id);
18205    
18206                    Session session = null;
18207    
18208                    try {
18209                            session = openSession();
18210    
18211                            JournalArticle[] array = new JournalArticleImpl[3];
18212    
18213                            array[0] = filterGetByG_U_C_PrevAndNext(session, journalArticle,
18214                                            groupId, userId, classNameId, orderByComparator, true);
18215    
18216                            array[1] = journalArticle;
18217    
18218                            array[2] = filterGetByG_U_C_PrevAndNext(session, journalArticle,
18219                                            groupId, userId, classNameId, orderByComparator, false);
18220    
18221                            return array;
18222                    }
18223                    catch (Exception e) {
18224                            throw processException(e);
18225                    }
18226                    finally {
18227                            closeSession(session);
18228                    }
18229            }
18230    
18231            protected JournalArticle filterGetByG_U_C_PrevAndNext(Session session,
18232                    JournalArticle journalArticle, long groupId, long userId,
18233                    long classNameId, OrderByComparator orderByComparator, boolean previous) {
18234                    StringBundler query = null;
18235    
18236                    if (orderByComparator != null) {
18237                            query = new StringBundler(6 +
18238                                            (orderByComparator.getOrderByFields().length * 6));
18239                    }
18240                    else {
18241                            query = new StringBundler(3);
18242                    }
18243    
18244                    if (getDB().isSupportsInlineDistinct()) {
18245                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
18246                    }
18247                    else {
18248                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
18249                    }
18250    
18251                    query.append(_FINDER_COLUMN_G_U_C_GROUPID_2);
18252    
18253                    query.append(_FINDER_COLUMN_G_U_C_USERID_2);
18254    
18255                    query.append(_FINDER_COLUMN_G_U_C_CLASSNAMEID_2);
18256    
18257                    if (!getDB().isSupportsInlineDistinct()) {
18258                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
18259                    }
18260    
18261                    if (orderByComparator != null) {
18262                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18263    
18264                            if (orderByConditionFields.length > 0) {
18265                                    query.append(WHERE_AND);
18266                            }
18267    
18268                            for (int i = 0; i < orderByConditionFields.length; i++) {
18269                                    if (getDB().isSupportsInlineDistinct()) {
18270                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18271                                    }
18272                                    else {
18273                                            query.append(_ORDER_BY_ENTITY_TABLE);
18274                                    }
18275    
18276                                    query.append(orderByConditionFields[i]);
18277    
18278                                    if ((i + 1) < orderByConditionFields.length) {
18279                                            if (orderByComparator.isAscending() ^ previous) {
18280                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18281                                            }
18282                                            else {
18283                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18284                                            }
18285                                    }
18286                                    else {
18287                                            if (orderByComparator.isAscending() ^ previous) {
18288                                                    query.append(WHERE_GREATER_THAN);
18289                                            }
18290                                            else {
18291                                                    query.append(WHERE_LESSER_THAN);
18292                                            }
18293                                    }
18294                            }
18295    
18296                            query.append(ORDER_BY_CLAUSE);
18297    
18298                            String[] orderByFields = orderByComparator.getOrderByFields();
18299    
18300                            for (int i = 0; i < orderByFields.length; i++) {
18301                                    if (getDB().isSupportsInlineDistinct()) {
18302                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18303                                    }
18304                                    else {
18305                                            query.append(_ORDER_BY_ENTITY_TABLE);
18306                                    }
18307    
18308                                    query.append(orderByFields[i]);
18309    
18310                                    if ((i + 1) < orderByFields.length) {
18311                                            if (orderByComparator.isAscending() ^ previous) {
18312                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18313                                            }
18314                                            else {
18315                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18316                                            }
18317                                    }
18318                                    else {
18319                                            if (orderByComparator.isAscending() ^ previous) {
18320                                                    query.append(ORDER_BY_ASC);
18321                                            }
18322                                            else {
18323                                                    query.append(ORDER_BY_DESC);
18324                                            }
18325                                    }
18326                            }
18327                    }
18328                    else {
18329                            if (getDB().isSupportsInlineDistinct()) {
18330                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
18331                            }
18332                            else {
18333                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
18334                            }
18335                    }
18336    
18337                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18338                                    JournalArticle.class.getName(),
18339                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18340    
18341                    SQLQuery q = session.createSQLQuery(sql);
18342    
18343                    q.setFirstResult(0);
18344                    q.setMaxResults(2);
18345    
18346                    if (getDB().isSupportsInlineDistinct()) {
18347                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
18348                    }
18349                    else {
18350                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
18351                    }
18352    
18353                    QueryPos qPos = QueryPos.getInstance(q);
18354    
18355                    qPos.add(groupId);
18356    
18357                    qPos.add(userId);
18358    
18359                    qPos.add(classNameId);
18360    
18361                    if (orderByComparator != null) {
18362                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
18363    
18364                            for (Object value : values) {
18365                                    qPos.add(value);
18366                            }
18367                    }
18368    
18369                    List<JournalArticle> list = q.list();
18370    
18371                    if (list.size() == 2) {
18372                            return list.get(1);
18373                    }
18374                    else {
18375                            return null;
18376                    }
18377            }
18378    
18379            /**
18380             * Removes all the journal articles where groupId = &#63; and userId = &#63; and classNameId = &#63; from the database.
18381             *
18382             * @param groupId the group ID
18383             * @param userId the user ID
18384             * @param classNameId the class name ID
18385             * @throws SystemException if a system exception occurred
18386             */
18387            @Override
18388            public void removeByG_U_C(long groupId, long userId, long classNameId)
18389                    throws SystemException {
18390                    for (JournalArticle journalArticle : findByG_U_C(groupId, userId,
18391                                    classNameId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18392                            remove(journalArticle);
18393                    }
18394            }
18395    
18396            /**
18397             * Returns the number of journal articles where groupId = &#63; and userId = &#63; and classNameId = &#63;.
18398             *
18399             * @param groupId the group ID
18400             * @param userId the user ID
18401             * @param classNameId the class name ID
18402             * @return the number of matching journal articles
18403             * @throws SystemException if a system exception occurred
18404             */
18405            @Override
18406            public int countByG_U_C(long groupId, long userId, long classNameId)
18407                    throws SystemException {
18408                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_C;
18409    
18410                    Object[] finderArgs = new Object[] { groupId, userId, classNameId };
18411    
18412                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18413                                    this);
18414    
18415                    if (count == null) {
18416                            StringBundler query = new StringBundler(4);
18417    
18418                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
18419    
18420                            query.append(_FINDER_COLUMN_G_U_C_GROUPID_2);
18421    
18422                            query.append(_FINDER_COLUMN_G_U_C_USERID_2);
18423    
18424                            query.append(_FINDER_COLUMN_G_U_C_CLASSNAMEID_2);
18425    
18426                            String sql = query.toString();
18427    
18428                            Session session = null;
18429    
18430                            try {
18431                                    session = openSession();
18432    
18433                                    Query q = session.createQuery(sql);
18434    
18435                                    QueryPos qPos = QueryPos.getInstance(q);
18436    
18437                                    qPos.add(groupId);
18438    
18439                                    qPos.add(userId);
18440    
18441                                    qPos.add(classNameId);
18442    
18443                                    count = (Long)q.uniqueResult();
18444    
18445                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18446                            }
18447                            catch (Exception e) {
18448                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18449    
18450                                    throw processException(e);
18451                            }
18452                            finally {
18453                                    closeSession(session);
18454                            }
18455                    }
18456    
18457                    return count.intValue();
18458            }
18459    
18460            /**
18461             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and userId = &#63; and classNameId = &#63;.
18462             *
18463             * @param groupId the group ID
18464             * @param userId the user ID
18465             * @param classNameId the class name ID
18466             * @return the number of matching journal articles that the user has permission to view
18467             * @throws SystemException if a system exception occurred
18468             */
18469            @Override
18470            public int filterCountByG_U_C(long groupId, long userId, long classNameId)
18471                    throws SystemException {
18472                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18473                            return countByG_U_C(groupId, userId, classNameId);
18474                    }
18475    
18476                    StringBundler query = new StringBundler(4);
18477    
18478                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
18479    
18480                    query.append(_FINDER_COLUMN_G_U_C_GROUPID_2);
18481    
18482                    query.append(_FINDER_COLUMN_G_U_C_USERID_2);
18483    
18484                    query.append(_FINDER_COLUMN_G_U_C_CLASSNAMEID_2);
18485    
18486                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18487                                    JournalArticle.class.getName(),
18488                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18489    
18490                    Session session = null;
18491    
18492                    try {
18493                            session = openSession();
18494    
18495                            SQLQuery q = session.createSQLQuery(sql);
18496    
18497                            q.addScalar(COUNT_COLUMN_NAME,
18498                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18499    
18500                            QueryPos qPos = QueryPos.getInstance(q);
18501    
18502                            qPos.add(groupId);
18503    
18504                            qPos.add(userId);
18505    
18506                            qPos.add(classNameId);
18507    
18508                            Long count = (Long)q.uniqueResult();
18509    
18510                            return count.intValue();
18511                    }
18512                    catch (Exception e) {
18513                            throw processException(e);
18514                    }
18515                    finally {
18516                            closeSession(session);
18517                    }
18518            }
18519    
18520            private static final String _FINDER_COLUMN_G_U_C_GROUPID_2 = "journalArticle.groupId = ? AND ";
18521            private static final String _FINDER_COLUMN_G_U_C_USERID_2 = "journalArticle.userId = ? AND ";
18522            private static final String _FINDER_COLUMN_G_U_C_CLASSNAMEID_2 = "journalArticle.classNameId = ?";
18523            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
18524                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
18525                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
18526                            "findByG_F_ST",
18527                            new String[] {
18528                                    Long.class.getName(), Long.class.getName(),
18529                                    Integer.class.getName(),
18530                                    
18531                            Integer.class.getName(), Integer.class.getName(),
18532                                    OrderByComparator.class.getName()
18533                            });
18534            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_ST =
18535                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
18536                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
18537                            JournalArticleImpl.class,
18538                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_F_ST",
18539                            new String[] {
18540                                    Long.class.getName(), Long.class.getName(),
18541                                    Integer.class.getName()
18542                            },
18543                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
18544                            JournalArticleModelImpl.FOLDERID_COLUMN_BITMASK |
18545                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
18546                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
18547                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
18548            public static final FinderPath FINDER_PATH_COUNT_BY_G_F_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
18549                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
18550                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_F_ST",
18551                            new String[] {
18552                                    Long.class.getName(), Long.class.getName(),
18553                                    Integer.class.getName()
18554                            });
18555            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
18556                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
18557                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_F_ST",
18558                            new String[] {
18559                                    Long.class.getName(), Long.class.getName(),
18560                                    Integer.class.getName()
18561                            });
18562    
18563            /**
18564             * Returns all the journal articles where groupId = &#63; and folderId = &#63; and status = &#63;.
18565             *
18566             * @param groupId the group ID
18567             * @param folderId the folder ID
18568             * @param status the status
18569             * @return the matching journal articles
18570             * @throws SystemException if a system exception occurred
18571             */
18572            @Override
18573            public List<JournalArticle> findByG_F_ST(long groupId, long folderId,
18574                    int status) throws SystemException {
18575                    return findByG_F_ST(groupId, folderId, status, QueryUtil.ALL_POS,
18576                            QueryUtil.ALL_POS, null);
18577            }
18578    
18579            /**
18580             * Returns a range of all the journal articles where groupId = &#63; and folderId = &#63; and status = &#63;.
18581             *
18582             * <p>
18583             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
18584             * </p>
18585             *
18586             * @param groupId the group ID
18587             * @param folderId the folder ID
18588             * @param status the status
18589             * @param start the lower bound of the range of journal articles
18590             * @param end the upper bound of the range of journal articles (not inclusive)
18591             * @return the range of matching journal articles
18592             * @throws SystemException if a system exception occurred
18593             */
18594            @Override
18595            public List<JournalArticle> findByG_F_ST(long groupId, long folderId,
18596                    int status, int start, int end) throws SystemException {
18597                    return findByG_F_ST(groupId, folderId, status, start, end, null);
18598            }
18599    
18600            /**
18601             * Returns an ordered range of all the journal articles where groupId = &#63; and folderId = &#63; and status = &#63;.
18602             *
18603             * <p>
18604             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
18605             * </p>
18606             *
18607             * @param groupId the group ID
18608             * @param folderId the folder ID
18609             * @param status the status
18610             * @param start the lower bound of the range of journal articles
18611             * @param end the upper bound of the range of journal articles (not inclusive)
18612             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18613             * @return the ordered range of matching journal articles
18614             * @throws SystemException if a system exception occurred
18615             */
18616            @Override
18617            public List<JournalArticle> findByG_F_ST(long groupId, long folderId,
18618                    int status, int start, int end, OrderByComparator orderByComparator)
18619                    throws SystemException {
18620                    boolean pagination = true;
18621                    FinderPath finderPath = null;
18622                    Object[] finderArgs = null;
18623    
18624                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18625                                    (orderByComparator == null)) {
18626                            pagination = false;
18627                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_ST;
18628                            finderArgs = new Object[] { groupId, folderId, status };
18629                    }
18630                    else {
18631                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_ST;
18632                            finderArgs = new Object[] {
18633                                            groupId, folderId, status,
18634                                            
18635                                            start, end, orderByComparator
18636                                    };
18637                    }
18638    
18639                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
18640                                    finderArgs, this);
18641    
18642                    if ((list != null) && !list.isEmpty()) {
18643                            for (JournalArticle journalArticle : list) {
18644                                    if ((groupId != journalArticle.getGroupId()) ||
18645                                                    (folderId != journalArticle.getFolderId()) ||
18646                                                    (status != journalArticle.getStatus())) {
18647                                            list = null;
18648    
18649                                            break;
18650                                    }
18651                            }
18652                    }
18653    
18654                    if (list == null) {
18655                            StringBundler query = null;
18656    
18657                            if (orderByComparator != null) {
18658                                    query = new StringBundler(5 +
18659                                                    (orderByComparator.getOrderByFields().length * 3));
18660                            }
18661                            else {
18662                                    query = new StringBundler(5);
18663                            }
18664    
18665                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
18666    
18667                            query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);
18668    
18669                            query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);
18670    
18671                            query.append(_FINDER_COLUMN_G_F_ST_STATUS_2);
18672    
18673                            if (orderByComparator != null) {
18674                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18675                                            orderByComparator);
18676                            }
18677                            else
18678                             if (pagination) {
18679                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
18680                            }
18681    
18682                            String sql = query.toString();
18683    
18684                            Session session = null;
18685    
18686                            try {
18687                                    session = openSession();
18688    
18689                                    Query q = session.createQuery(sql);
18690    
18691                                    QueryPos qPos = QueryPos.getInstance(q);
18692    
18693                                    qPos.add(groupId);
18694    
18695                                    qPos.add(folderId);
18696    
18697                                    qPos.add(status);
18698    
18699                                    if (!pagination) {
18700                                            list = (List<JournalArticle>)QueryUtil.list(q,
18701                                                            getDialect(), start, end, false);
18702    
18703                                            Collections.sort(list);
18704    
18705                                            list = new UnmodifiableList<JournalArticle>(list);
18706                                    }
18707                                    else {
18708                                            list = (List<JournalArticle>)QueryUtil.list(q,
18709                                                            getDialect(), start, end);
18710                                    }
18711    
18712                                    cacheResult(list);
18713    
18714                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18715                            }
18716                            catch (Exception e) {
18717                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18718    
18719                                    throw processException(e);
18720                            }
18721                            finally {
18722                                    closeSession(session);
18723                            }
18724                    }
18725    
18726                    return list;
18727            }
18728    
18729            /**
18730             * Returns the first journal article in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
18731             *
18732             * @param groupId the group ID
18733             * @param folderId the folder ID
18734             * @param status the status
18735             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18736             * @return the first matching journal article
18737             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
18738             * @throws SystemException if a system exception occurred
18739             */
18740            @Override
18741            public JournalArticle findByG_F_ST_First(long groupId, long folderId,
18742                    int status, OrderByComparator orderByComparator)
18743                    throws NoSuchArticleException, SystemException {
18744                    JournalArticle journalArticle = fetchByG_F_ST_First(groupId, folderId,
18745                                    status, orderByComparator);
18746    
18747                    if (journalArticle != null) {
18748                            return journalArticle;
18749                    }
18750    
18751                    StringBundler msg = new StringBundler(8);
18752    
18753                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18754    
18755                    msg.append("groupId=");
18756                    msg.append(groupId);
18757    
18758                    msg.append(", folderId=");
18759                    msg.append(folderId);
18760    
18761                    msg.append(", status=");
18762                    msg.append(status);
18763    
18764                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18765    
18766                    throw new NoSuchArticleException(msg.toString());
18767            }
18768    
18769            /**
18770             * Returns the first journal article in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
18771             *
18772             * @param groupId the group ID
18773             * @param folderId the folder ID
18774             * @param status the status
18775             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18776             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
18777             * @throws SystemException if a system exception occurred
18778             */
18779            @Override
18780            public JournalArticle fetchByG_F_ST_First(long groupId, long folderId,
18781                    int status, OrderByComparator orderByComparator)
18782                    throws SystemException {
18783                    List<JournalArticle> list = findByG_F_ST(groupId, folderId, status, 0,
18784                                    1, orderByComparator);
18785    
18786                    if (!list.isEmpty()) {
18787                            return list.get(0);
18788                    }
18789    
18790                    return null;
18791            }
18792    
18793            /**
18794             * Returns the last journal article in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
18795             *
18796             * @param groupId the group ID
18797             * @param folderId the folder ID
18798             * @param status the status
18799             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18800             * @return the last matching journal article
18801             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
18802             * @throws SystemException if a system exception occurred
18803             */
18804            @Override
18805            public JournalArticle findByG_F_ST_Last(long groupId, long folderId,
18806                    int status, OrderByComparator orderByComparator)
18807                    throws NoSuchArticleException, SystemException {
18808                    JournalArticle journalArticle = fetchByG_F_ST_Last(groupId, folderId,
18809                                    status, orderByComparator);
18810    
18811                    if (journalArticle != null) {
18812                            return journalArticle;
18813                    }
18814    
18815                    StringBundler msg = new StringBundler(8);
18816    
18817                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18818    
18819                    msg.append("groupId=");
18820                    msg.append(groupId);
18821    
18822                    msg.append(", folderId=");
18823                    msg.append(folderId);
18824    
18825                    msg.append(", status=");
18826                    msg.append(status);
18827    
18828                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18829    
18830                    throw new NoSuchArticleException(msg.toString());
18831            }
18832    
18833            /**
18834             * Returns the last journal article in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
18835             *
18836             * @param groupId the group ID
18837             * @param folderId the folder ID
18838             * @param status the status
18839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18840             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
18841             * @throws SystemException if a system exception occurred
18842             */
18843            @Override
18844            public JournalArticle fetchByG_F_ST_Last(long groupId, long folderId,
18845                    int status, OrderByComparator orderByComparator)
18846                    throws SystemException {
18847                    int count = countByG_F_ST(groupId, folderId, status);
18848    
18849                    if (count == 0) {
18850                            return null;
18851                    }
18852    
18853                    List<JournalArticle> list = findByG_F_ST(groupId, folderId, status,
18854                                    count - 1, count, orderByComparator);
18855    
18856                    if (!list.isEmpty()) {
18857                            return list.get(0);
18858                    }
18859    
18860                    return null;
18861            }
18862    
18863            /**
18864             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and folderId = &#63; and status = &#63;.
18865             *
18866             * @param id the primary key of the current journal article
18867             * @param groupId the group ID
18868             * @param folderId the folder ID
18869             * @param status the status
18870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18871             * @return the previous, current, and next journal article
18872             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
18873             * @throws SystemException if a system exception occurred
18874             */
18875            @Override
18876            public JournalArticle[] findByG_F_ST_PrevAndNext(long id, long groupId,
18877                    long folderId, int status, OrderByComparator orderByComparator)
18878                    throws NoSuchArticleException, SystemException {
18879                    JournalArticle journalArticle = findByPrimaryKey(id);
18880    
18881                    Session session = null;
18882    
18883                    try {
18884                            session = openSession();
18885    
18886                            JournalArticle[] array = new JournalArticleImpl[3];
18887    
18888                            array[0] = getByG_F_ST_PrevAndNext(session, journalArticle,
18889                                            groupId, folderId, status, orderByComparator, true);
18890    
18891                            array[1] = journalArticle;
18892    
18893                            array[2] = getByG_F_ST_PrevAndNext(session, journalArticle,
18894                                            groupId, folderId, status, orderByComparator, false);
18895    
18896                            return array;
18897                    }
18898                    catch (Exception e) {
18899                            throw processException(e);
18900                    }
18901                    finally {
18902                            closeSession(session);
18903                    }
18904            }
18905    
18906            protected JournalArticle getByG_F_ST_PrevAndNext(Session session,
18907                    JournalArticle journalArticle, long groupId, long folderId, int status,
18908                    OrderByComparator orderByComparator, boolean previous) {
18909                    StringBundler query = null;
18910    
18911                    if (orderByComparator != null) {
18912                            query = new StringBundler(6 +
18913                                            (orderByComparator.getOrderByFields().length * 6));
18914                    }
18915                    else {
18916                            query = new StringBundler(3);
18917                    }
18918    
18919                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
18920    
18921                    query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);
18922    
18923                    query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);
18924    
18925                    query.append(_FINDER_COLUMN_G_F_ST_STATUS_2);
18926    
18927                    if (orderByComparator != null) {
18928                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18929    
18930                            if (orderByConditionFields.length > 0) {
18931                                    query.append(WHERE_AND);
18932                            }
18933    
18934                            for (int i = 0; i < orderByConditionFields.length; i++) {
18935                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18936                                    query.append(orderByConditionFields[i]);
18937    
18938                                    if ((i + 1) < orderByConditionFields.length) {
18939                                            if (orderByComparator.isAscending() ^ previous) {
18940                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18941                                            }
18942                                            else {
18943                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18944                                            }
18945                                    }
18946                                    else {
18947                                            if (orderByComparator.isAscending() ^ previous) {
18948                                                    query.append(WHERE_GREATER_THAN);
18949                                            }
18950                                            else {
18951                                                    query.append(WHERE_LESSER_THAN);
18952                                            }
18953                                    }
18954                            }
18955    
18956                            query.append(ORDER_BY_CLAUSE);
18957    
18958                            String[] orderByFields = orderByComparator.getOrderByFields();
18959    
18960                            for (int i = 0; i < orderByFields.length; i++) {
18961                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18962                                    query.append(orderByFields[i]);
18963    
18964                                    if ((i + 1) < orderByFields.length) {
18965                                            if (orderByComparator.isAscending() ^ previous) {
18966                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18967                                            }
18968                                            else {
18969                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18970                                            }
18971                                    }
18972                                    else {
18973                                            if (orderByComparator.isAscending() ^ previous) {
18974                                                    query.append(ORDER_BY_ASC);
18975                                            }
18976                                            else {
18977                                                    query.append(ORDER_BY_DESC);
18978                                            }
18979                                    }
18980                            }
18981                    }
18982                    else {
18983                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
18984                    }
18985    
18986                    String sql = query.toString();
18987    
18988                    Query q = session.createQuery(sql);
18989    
18990                    q.setFirstResult(0);
18991                    q.setMaxResults(2);
18992    
18993                    QueryPos qPos = QueryPos.getInstance(q);
18994    
18995                    qPos.add(groupId);
18996    
18997                    qPos.add(folderId);
18998    
18999                    qPos.add(status);
19000    
19001                    if (orderByComparator != null) {
19002                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
19003    
19004                            for (Object value : values) {
19005                                    qPos.add(value);
19006                            }
19007                    }
19008    
19009                    List<JournalArticle> list = q.list();
19010    
19011                    if (list.size() == 2) {
19012                            return list.get(1);
19013                    }
19014                    else {
19015                            return null;
19016                    }
19017            }
19018    
19019            /**
19020             * Returns all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = &#63;.
19021             *
19022             * @param groupId the group ID
19023             * @param folderId the folder ID
19024             * @param status the status
19025             * @return the matching journal articles that the user has permission to view
19026             * @throws SystemException if a system exception occurred
19027             */
19028            @Override
19029            public List<JournalArticle> filterFindByG_F_ST(long groupId, long folderId,
19030                    int status) throws SystemException {
19031                    return filterFindByG_F_ST(groupId, folderId, status, QueryUtil.ALL_POS,
19032                            QueryUtil.ALL_POS, null);
19033            }
19034    
19035            /**
19036             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = &#63;.
19037             *
19038             * <p>
19039             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
19040             * </p>
19041             *
19042             * @param groupId the group ID
19043             * @param folderId the folder ID
19044             * @param status the status
19045             * @param start the lower bound of the range of journal articles
19046             * @param end the upper bound of the range of journal articles (not inclusive)
19047             * @return the range of matching journal articles that the user has permission to view
19048             * @throws SystemException if a system exception occurred
19049             */
19050            @Override
19051            public List<JournalArticle> filterFindByG_F_ST(long groupId, long folderId,
19052                    int status, int start, int end) throws SystemException {
19053                    return filterFindByG_F_ST(groupId, folderId, status, start, end, null);
19054            }
19055    
19056            /**
19057             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and folderId = &#63; and status = &#63;.
19058             *
19059             * <p>
19060             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
19061             * </p>
19062             *
19063             * @param groupId the group ID
19064             * @param folderId the folder ID
19065             * @param status the status
19066             * @param start the lower bound of the range of journal articles
19067             * @param end the upper bound of the range of journal articles (not inclusive)
19068             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19069             * @return the ordered range of matching journal articles that the user has permission to view
19070             * @throws SystemException if a system exception occurred
19071             */
19072            @Override
19073            public List<JournalArticle> filterFindByG_F_ST(long groupId, long folderId,
19074                    int status, int start, int end, OrderByComparator orderByComparator)
19075                    throws SystemException {
19076                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19077                            return findByG_F_ST(groupId, folderId, status, start, end,
19078                                    orderByComparator);
19079                    }
19080    
19081                    StringBundler query = null;
19082    
19083                    if (orderByComparator != null) {
19084                            query = new StringBundler(5 +
19085                                            (orderByComparator.getOrderByFields().length * 3));
19086                    }
19087                    else {
19088                            query = new StringBundler(5);
19089                    }
19090    
19091                    if (getDB().isSupportsInlineDistinct()) {
19092                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
19093                    }
19094                    else {
19095                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
19096                    }
19097    
19098                    query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);
19099    
19100                    query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);
19101    
19102                    query.append(_FINDER_COLUMN_G_F_ST_STATUS_2);
19103    
19104                    if (!getDB().isSupportsInlineDistinct()) {
19105                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
19106                    }
19107    
19108                    if (orderByComparator != null) {
19109                            if (getDB().isSupportsInlineDistinct()) {
19110                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19111                                            orderByComparator, true);
19112                            }
19113                            else {
19114                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
19115                                            orderByComparator, true);
19116                            }
19117                    }
19118                    else {
19119                            if (getDB().isSupportsInlineDistinct()) {
19120                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
19121                            }
19122                            else {
19123                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
19124                            }
19125                    }
19126    
19127                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
19128                                    JournalArticle.class.getName(),
19129                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
19130    
19131                    Session session = null;
19132    
19133                    try {
19134                            session = openSession();
19135    
19136                            SQLQuery q = session.createSQLQuery(sql);
19137    
19138                            if (getDB().isSupportsInlineDistinct()) {
19139                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
19140                            }
19141                            else {
19142                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
19143                            }
19144    
19145                            QueryPos qPos = QueryPos.getInstance(q);
19146    
19147                            qPos.add(groupId);
19148    
19149                            qPos.add(folderId);
19150    
19151                            qPos.add(status);
19152    
19153                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
19154                                    end);
19155                    }
19156                    catch (Exception e) {
19157                            throw processException(e);
19158                    }
19159                    finally {
19160                            closeSession(session);
19161                    }
19162            }
19163    
19164            /**
19165             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = &#63;.
19166             *
19167             * @param id the primary key of the current journal article
19168             * @param groupId the group ID
19169             * @param folderId the folder ID
19170             * @param status the status
19171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19172             * @return the previous, current, and next journal article
19173             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
19174             * @throws SystemException if a system exception occurred
19175             */
19176            @Override
19177            public JournalArticle[] filterFindByG_F_ST_PrevAndNext(long id,
19178                    long groupId, long folderId, int status,
19179                    OrderByComparator orderByComparator)
19180                    throws NoSuchArticleException, SystemException {
19181                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19182                            return findByG_F_ST_PrevAndNext(id, groupId, folderId, status,
19183                                    orderByComparator);
19184                    }
19185    
19186                    JournalArticle journalArticle = findByPrimaryKey(id);
19187    
19188                    Session session = null;
19189    
19190                    try {
19191                            session = openSession();
19192    
19193                            JournalArticle[] array = new JournalArticleImpl[3];
19194    
19195                            array[0] = filterGetByG_F_ST_PrevAndNext(session, journalArticle,
19196                                            groupId, folderId, status, orderByComparator, true);
19197    
19198                            array[1] = journalArticle;
19199    
19200                            array[2] = filterGetByG_F_ST_PrevAndNext(session, journalArticle,
19201                                            groupId, folderId, status, orderByComparator, false);
19202    
19203                            return array;
19204                    }
19205                    catch (Exception e) {
19206                            throw processException(e);
19207                    }
19208                    finally {
19209                            closeSession(session);
19210                    }
19211            }
19212    
19213            protected JournalArticle filterGetByG_F_ST_PrevAndNext(Session session,
19214                    JournalArticle journalArticle, long groupId, long folderId, int status,
19215                    OrderByComparator orderByComparator, boolean previous) {
19216                    StringBundler query = null;
19217    
19218                    if (orderByComparator != null) {
19219                            query = new StringBundler(6 +
19220                                            (orderByComparator.getOrderByFields().length * 6));
19221                    }
19222                    else {
19223                            query = new StringBundler(3);
19224                    }
19225    
19226                    if (getDB().isSupportsInlineDistinct()) {
19227                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
19228                    }
19229                    else {
19230                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
19231                    }
19232    
19233                    query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);
19234    
19235                    query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);
19236    
19237                    query.append(_FINDER_COLUMN_G_F_ST_STATUS_2);
19238    
19239                    if (!getDB().isSupportsInlineDistinct()) {
19240                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
19241                    }
19242    
19243                    if (orderByComparator != null) {
19244                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
19245    
19246                            if (orderByConditionFields.length > 0) {
19247                                    query.append(WHERE_AND);
19248                            }
19249    
19250                            for (int i = 0; i < orderByConditionFields.length; i++) {
19251                                    if (getDB().isSupportsInlineDistinct()) {
19252                                            query.append(_ORDER_BY_ENTITY_ALIAS);
19253                                    }
19254                                    else {
19255                                            query.append(_ORDER_BY_ENTITY_TABLE);
19256                                    }
19257    
19258                                    query.append(orderByConditionFields[i]);
19259    
19260                                    if ((i + 1) < orderByConditionFields.length) {
19261                                            if (orderByComparator.isAscending() ^ previous) {
19262                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
19263                                            }
19264                                            else {
19265                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
19266                                            }
19267                                    }
19268                                    else {
19269                                            if (orderByComparator.isAscending() ^ previous) {
19270                                                    query.append(WHERE_GREATER_THAN);
19271                                            }
19272                                            else {
19273                                                    query.append(WHERE_LESSER_THAN);
19274                                            }
19275                                    }
19276                            }
19277    
19278                            query.append(ORDER_BY_CLAUSE);
19279    
19280                            String[] orderByFields = orderByComparator.getOrderByFields();
19281    
19282                            for (int i = 0; i < orderByFields.length; i++) {
19283                                    if (getDB().isSupportsInlineDistinct()) {
19284                                            query.append(_ORDER_BY_ENTITY_ALIAS);
19285                                    }
19286                                    else {
19287                                            query.append(_ORDER_BY_ENTITY_TABLE);
19288                                    }
19289    
19290                                    query.append(orderByFields[i]);
19291    
19292                                    if ((i + 1) < orderByFields.length) {
19293                                            if (orderByComparator.isAscending() ^ previous) {
19294                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
19295                                            }
19296                                            else {
19297                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
19298                                            }
19299                                    }
19300                                    else {
19301                                            if (orderByComparator.isAscending() ^ previous) {
19302                                                    query.append(ORDER_BY_ASC);
19303                                            }
19304                                            else {
19305                                                    query.append(ORDER_BY_DESC);
19306                                            }
19307                                    }
19308                            }
19309                    }
19310                    else {
19311                            if (getDB().isSupportsInlineDistinct()) {
19312                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
19313                            }
19314                            else {
19315                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
19316                            }
19317                    }
19318    
19319                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
19320                                    JournalArticle.class.getName(),
19321                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
19322    
19323                    SQLQuery q = session.createSQLQuery(sql);
19324    
19325                    q.setFirstResult(0);
19326                    q.setMaxResults(2);
19327    
19328                    if (getDB().isSupportsInlineDistinct()) {
19329                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
19330                    }
19331                    else {
19332                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
19333                    }
19334    
19335                    QueryPos qPos = QueryPos.getInstance(q);
19336    
19337                    qPos.add(groupId);
19338    
19339                    qPos.add(folderId);
19340    
19341                    qPos.add(status);
19342    
19343                    if (orderByComparator != null) {
19344                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
19345    
19346                            for (Object value : values) {
19347                                    qPos.add(value);
19348                            }
19349                    }
19350    
19351                    List<JournalArticle> list = q.list();
19352    
19353                    if (list.size() == 2) {
19354                            return list.get(1);
19355                    }
19356                    else {
19357                            return null;
19358                    }
19359            }
19360    
19361            /**
19362             * Returns all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = any &#63;.
19363             *
19364             * @param groupId the group ID
19365             * @param folderId the folder ID
19366             * @param statuses the statuses
19367             * @return the matching journal articles that the user has permission to view
19368             * @throws SystemException if a system exception occurred
19369             */
19370            @Override
19371            public List<JournalArticle> filterFindByG_F_ST(long groupId, long folderId,
19372                    int[] statuses) throws SystemException {
19373                    return filterFindByG_F_ST(groupId, folderId, statuses,
19374                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19375            }
19376    
19377            /**
19378             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = any &#63;.
19379             *
19380             * <p>
19381             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
19382             * </p>
19383             *
19384             * @param groupId the group ID
19385             * @param folderId the folder ID
19386             * @param statuses the statuses
19387             * @param start the lower bound of the range of journal articles
19388             * @param end the upper bound of the range of journal articles (not inclusive)
19389             * @return the range of matching journal articles that the user has permission to view
19390             * @throws SystemException if a system exception occurred
19391             */
19392            @Override
19393            public List<JournalArticle> filterFindByG_F_ST(long groupId, long folderId,
19394                    int[] statuses, int start, int end) throws SystemException {
19395                    return filterFindByG_F_ST(groupId, folderId, statuses, start, end, null);
19396            }
19397    
19398            /**
19399             * Returns an ordered range of all the journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = any &#63;.
19400             *
19401             * <p>
19402             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
19403             * </p>
19404             *
19405             * @param groupId the group ID
19406             * @param folderId the folder ID
19407             * @param statuses the statuses
19408             * @param start the lower bound of the range of journal articles
19409             * @param end the upper bound of the range of journal articles (not inclusive)
19410             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19411             * @return the ordered range of matching journal articles that the user has permission to view
19412             * @throws SystemException if a system exception occurred
19413             */
19414            @Override
19415            public List<JournalArticle> filterFindByG_F_ST(long groupId, long folderId,
19416                    int[] statuses, int start, int end, OrderByComparator orderByComparator)
19417                    throws SystemException {
19418                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19419                            return findByG_F_ST(groupId, folderId, statuses, start, end,
19420                                    orderByComparator);
19421                    }
19422    
19423                    StringBundler query = new StringBundler();
19424    
19425                    if (getDB().isSupportsInlineDistinct()) {
19426                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
19427                    }
19428                    else {
19429                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
19430                    }
19431    
19432                    boolean conjunctionable = false;
19433    
19434                    if (conjunctionable) {
19435                            query.append(WHERE_AND);
19436                    }
19437    
19438                    query.append(_FINDER_COLUMN_G_F_ST_GROUPID_5);
19439    
19440                    conjunctionable = true;
19441    
19442                    if (conjunctionable) {
19443                            query.append(WHERE_AND);
19444                    }
19445    
19446                    query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_5);
19447    
19448                    conjunctionable = true;
19449    
19450                    if ((statuses == null) || (statuses.length > 0)) {
19451                            if (conjunctionable) {
19452                                    query.append(WHERE_AND);
19453                            }
19454    
19455                            query.append(StringPool.OPEN_PARENTHESIS);
19456    
19457                            for (int i = 0; i < statuses.length; i++) {
19458                                    query.append(_FINDER_COLUMN_G_F_ST_STATUS_5);
19459    
19460                                    if ((i + 1) < statuses.length) {
19461                                            query.append(WHERE_OR);
19462                                    }
19463                            }
19464    
19465                            query.append(StringPool.CLOSE_PARENTHESIS);
19466    
19467                            conjunctionable = true;
19468                    }
19469    
19470                    if (!getDB().isSupportsInlineDistinct()) {
19471                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
19472                    }
19473    
19474                    if (orderByComparator != null) {
19475                            if (getDB().isSupportsInlineDistinct()) {
19476                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19477                                            orderByComparator, true);
19478                            }
19479                            else {
19480                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
19481                                            orderByComparator, true);
19482                            }
19483                    }
19484                    else {
19485                            if (getDB().isSupportsInlineDistinct()) {
19486                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
19487                            }
19488                            else {
19489                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
19490                            }
19491                    }
19492    
19493                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
19494                                    JournalArticle.class.getName(),
19495                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
19496    
19497                    Session session = null;
19498    
19499                    try {
19500                            session = openSession();
19501    
19502                            SQLQuery q = session.createSQLQuery(sql);
19503    
19504                            if (getDB().isSupportsInlineDistinct()) {
19505                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
19506                            }
19507                            else {
19508                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
19509                            }
19510    
19511                            QueryPos qPos = QueryPos.getInstance(q);
19512    
19513                            qPos.add(groupId);
19514    
19515                            qPos.add(folderId);
19516    
19517                            if (statuses != null) {
19518                                    qPos.add(statuses);
19519                            }
19520    
19521                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
19522                                    end);
19523                    }
19524                    catch (Exception e) {
19525                            throw processException(e);
19526                    }
19527                    finally {
19528                            closeSession(session);
19529                    }
19530            }
19531    
19532            /**
19533             * Returns all the journal articles where groupId = &#63; and folderId = &#63; and status = any &#63;.
19534             *
19535             * <p>
19536             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
19537             * </p>
19538             *
19539             * @param groupId the group ID
19540             * @param folderId the folder ID
19541             * @param statuses the statuses
19542             * @return the matching journal articles
19543             * @throws SystemException if a system exception occurred
19544             */
19545            @Override
19546            public List<JournalArticle> findByG_F_ST(long groupId, long folderId,
19547                    int[] statuses) throws SystemException {
19548                    return findByG_F_ST(groupId, folderId, statuses, QueryUtil.ALL_POS,
19549                            QueryUtil.ALL_POS, null);
19550            }
19551    
19552            /**
19553             * Returns a range of all the journal articles where groupId = &#63; and folderId = &#63; and status = any &#63;.
19554             *
19555             * <p>
19556             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
19557             * </p>
19558             *
19559             * @param groupId the group ID
19560             * @param folderId the folder ID
19561             * @param statuses the statuses
19562             * @param start the lower bound of the range of journal articles
19563             * @param end the upper bound of the range of journal articles (not inclusive)
19564             * @return the range of matching journal articles
19565             * @throws SystemException if a system exception occurred
19566             */
19567            @Override
19568            public List<JournalArticle> findByG_F_ST(long groupId, long folderId,
19569                    int[] statuses, int start, int end) throws SystemException {
19570                    return findByG_F_ST(groupId, folderId, statuses, start, end, null);
19571            }
19572    
19573            /**
19574             * Returns an ordered range of all the journal articles where groupId = &#63; and folderId = &#63; and status = any &#63;.
19575             *
19576             * <p>
19577             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
19578             * </p>
19579             *
19580             * @param groupId the group ID
19581             * @param folderId the folder ID
19582             * @param statuses the statuses
19583             * @param start the lower bound of the range of journal articles
19584             * @param end the upper bound of the range of journal articles (not inclusive)
19585             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19586             * @return the ordered range of matching journal articles
19587             * @throws SystemException if a system exception occurred
19588             */
19589            @Override
19590            public List<JournalArticle> findByG_F_ST(long groupId, long folderId,
19591                    int[] statuses, int start, int end, OrderByComparator orderByComparator)
19592                    throws SystemException {
19593                    if ((statuses != null) && (statuses.length == 1)) {
19594                            return findByG_F_ST(groupId, folderId, statuses[0], start, end,
19595                                    orderByComparator);
19596                    }
19597    
19598                    boolean pagination = true;
19599                    Object[] finderArgs = null;
19600    
19601                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19602                                    (orderByComparator == null)) {
19603                            pagination = false;
19604                            finderArgs = new Object[] {
19605                                            groupId, folderId, StringUtil.merge(statuses)
19606                                    };
19607                    }
19608                    else {
19609                            finderArgs = new Object[] {
19610                                            groupId, folderId, StringUtil.merge(statuses),
19611                                            
19612                                            start, end, orderByComparator
19613                                    };
19614                    }
19615    
19616                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_ST,
19617                                    finderArgs, this);
19618    
19619                    if ((list != null) && !list.isEmpty()) {
19620                            for (JournalArticle journalArticle : list) {
19621                                    if ((groupId != journalArticle.getGroupId()) ||
19622                                                    (folderId != journalArticle.getFolderId()) ||
19623                                                    !ArrayUtil.contains(statuses, journalArticle.getStatus())) {
19624                                            list = null;
19625    
19626                                            break;
19627                                    }
19628                            }
19629                    }
19630    
19631                    if (list == null) {
19632                            StringBundler query = new StringBundler();
19633    
19634                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
19635    
19636                            boolean conjunctionable = false;
19637    
19638                            if (conjunctionable) {
19639                                    query.append(WHERE_AND);
19640                            }
19641    
19642                            query.append(_FINDER_COLUMN_G_F_ST_GROUPID_5);
19643    
19644                            conjunctionable = true;
19645    
19646                            if (conjunctionable) {
19647                                    query.append(WHERE_AND);
19648                            }
19649    
19650                            query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_5);
19651    
19652                            conjunctionable = true;
19653    
19654                            if ((statuses == null) || (statuses.length > 0)) {
19655                                    if (conjunctionable) {
19656                                            query.append(WHERE_AND);
19657                                    }
19658    
19659                                    query.append(StringPool.OPEN_PARENTHESIS);
19660    
19661                                    for (int i = 0; i < statuses.length; i++) {
19662                                            query.append(_FINDER_COLUMN_G_F_ST_STATUS_5);
19663    
19664                                            if ((i + 1) < statuses.length) {
19665                                                    query.append(WHERE_OR);
19666                                            }
19667                                    }
19668    
19669                                    query.append(StringPool.CLOSE_PARENTHESIS);
19670    
19671                                    conjunctionable = true;
19672                            }
19673    
19674                            if (orderByComparator != null) {
19675                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19676                                            orderByComparator);
19677                            }
19678                            else
19679                             if (pagination) {
19680                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
19681                            }
19682    
19683                            String sql = query.toString();
19684    
19685                            Session session = null;
19686    
19687                            try {
19688                                    session = openSession();
19689    
19690                                    Query q = session.createQuery(sql);
19691    
19692                                    QueryPos qPos = QueryPos.getInstance(q);
19693    
19694                                    qPos.add(groupId);
19695    
19696                                    qPos.add(folderId);
19697    
19698                                    if (statuses != null) {
19699                                            qPos.add(statuses);
19700                                    }
19701    
19702                                    if (!pagination) {
19703                                            list = (List<JournalArticle>)QueryUtil.list(q,
19704                                                            getDialect(), start, end, false);
19705    
19706                                            Collections.sort(list);
19707    
19708                                            list = new UnmodifiableList<JournalArticle>(list);
19709                                    }
19710                                    else {
19711                                            list = (List<JournalArticle>)QueryUtil.list(q,
19712                                                            getDialect(), start, end);
19713                                    }
19714    
19715                                    cacheResult(list);
19716    
19717                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_ST,
19718                                            finderArgs, list);
19719                            }
19720                            catch (Exception e) {
19721                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_F_ST,
19722                                            finderArgs);
19723    
19724                                    throw processException(e);
19725                            }
19726                            finally {
19727                                    closeSession(session);
19728                            }
19729                    }
19730    
19731                    return list;
19732            }
19733    
19734            /**
19735             * Removes all the journal articles where groupId = &#63; and folderId = &#63; and status = &#63; from the database.
19736             *
19737             * @param groupId the group ID
19738             * @param folderId the folder ID
19739             * @param status the status
19740             * @throws SystemException if a system exception occurred
19741             */
19742            @Override
19743            public void removeByG_F_ST(long groupId, long folderId, int status)
19744                    throws SystemException {
19745                    for (JournalArticle journalArticle : findByG_F_ST(groupId, folderId,
19746                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
19747                            remove(journalArticle);
19748                    }
19749            }
19750    
19751            /**
19752             * Returns the number of journal articles where groupId = &#63; and folderId = &#63; and status = &#63;.
19753             *
19754             * @param groupId the group ID
19755             * @param folderId the folder ID
19756             * @param status the status
19757             * @return the number of matching journal articles
19758             * @throws SystemException if a system exception occurred
19759             */
19760            @Override
19761            public int countByG_F_ST(long groupId, long folderId, int status)
19762                    throws SystemException {
19763                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_F_ST;
19764    
19765                    Object[] finderArgs = new Object[] { groupId, folderId, status };
19766    
19767                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
19768                                    this);
19769    
19770                    if (count == null) {
19771                            StringBundler query = new StringBundler(4);
19772    
19773                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
19774    
19775                            query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);
19776    
19777                            query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);
19778    
19779                            query.append(_FINDER_COLUMN_G_F_ST_STATUS_2);
19780    
19781                            String sql = query.toString();
19782    
19783                            Session session = null;
19784    
19785                            try {
19786                                    session = openSession();
19787    
19788                                    Query q = session.createQuery(sql);
19789    
19790                                    QueryPos qPos = QueryPos.getInstance(q);
19791    
19792                                    qPos.add(groupId);
19793    
19794                                    qPos.add(folderId);
19795    
19796                                    qPos.add(status);
19797    
19798                                    count = (Long)q.uniqueResult();
19799    
19800                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
19801                            }
19802                            catch (Exception e) {
19803                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19804    
19805                                    throw processException(e);
19806                            }
19807                            finally {
19808                                    closeSession(session);
19809                            }
19810                    }
19811    
19812                    return count.intValue();
19813            }
19814    
19815            /**
19816             * Returns the number of journal articles where groupId = &#63; and folderId = &#63; and status = any &#63;.
19817             *
19818             * @param groupId the group ID
19819             * @param folderId the folder ID
19820             * @param statuses the statuses
19821             * @return the number of matching journal articles
19822             * @throws SystemException if a system exception occurred
19823             */
19824            @Override
19825            public int countByG_F_ST(long groupId, long folderId, int[] statuses)
19826                    throws SystemException {
19827                    Object[] finderArgs = new Object[] {
19828                                    groupId, folderId, StringUtil.merge(statuses)
19829                            };
19830    
19831                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F_ST,
19832                                    finderArgs, this);
19833    
19834                    if (count == null) {
19835                            StringBundler query = new StringBundler();
19836    
19837                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
19838    
19839                            boolean conjunctionable = false;
19840    
19841                            if (conjunctionable) {
19842                                    query.append(WHERE_AND);
19843                            }
19844    
19845                            query.append(_FINDER_COLUMN_G_F_ST_GROUPID_5);
19846    
19847                            conjunctionable = true;
19848    
19849                            if (conjunctionable) {
19850                                    query.append(WHERE_AND);
19851                            }
19852    
19853                            query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_5);
19854    
19855                            conjunctionable = true;
19856    
19857                            if ((statuses == null) || (statuses.length > 0)) {
19858                                    if (conjunctionable) {
19859                                            query.append(WHERE_AND);
19860                                    }
19861    
19862                                    query.append(StringPool.OPEN_PARENTHESIS);
19863    
19864                                    for (int i = 0; i < statuses.length; i++) {
19865                                            query.append(_FINDER_COLUMN_G_F_ST_STATUS_5);
19866    
19867                                            if ((i + 1) < statuses.length) {
19868                                                    query.append(WHERE_OR);
19869                                            }
19870                                    }
19871    
19872                                    query.append(StringPool.CLOSE_PARENTHESIS);
19873    
19874                                    conjunctionable = true;
19875                            }
19876    
19877                            String sql = query.toString();
19878    
19879                            Session session = null;
19880    
19881                            try {
19882                                    session = openSession();
19883    
19884                                    Query q = session.createQuery(sql);
19885    
19886                                    QueryPos qPos = QueryPos.getInstance(q);
19887    
19888                                    qPos.add(groupId);
19889    
19890                                    qPos.add(folderId);
19891    
19892                                    if (statuses != null) {
19893                                            qPos.add(statuses);
19894                                    }
19895    
19896                                    count = (Long)q.uniqueResult();
19897    
19898                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F_ST,
19899                                            finderArgs, count);
19900                            }
19901                            catch (Exception e) {
19902                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_F_ST,
19903                                            finderArgs);
19904    
19905                                    throw processException(e);
19906                            }
19907                            finally {
19908                                    closeSession(session);
19909                            }
19910                    }
19911    
19912                    return count.intValue();
19913            }
19914    
19915            /**
19916             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = &#63;.
19917             *
19918             * @param groupId the group ID
19919             * @param folderId the folder ID
19920             * @param status the status
19921             * @return the number of matching journal articles that the user has permission to view
19922             * @throws SystemException if a system exception occurred
19923             */
19924            @Override
19925            public int filterCountByG_F_ST(long groupId, long folderId, int status)
19926                    throws SystemException {
19927                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19928                            return countByG_F_ST(groupId, folderId, status);
19929                    }
19930    
19931                    StringBundler query = new StringBundler(4);
19932    
19933                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
19934    
19935                    query.append(_FINDER_COLUMN_G_F_ST_GROUPID_2);
19936    
19937                    query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_2);
19938    
19939                    query.append(_FINDER_COLUMN_G_F_ST_STATUS_2);
19940    
19941                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
19942                                    JournalArticle.class.getName(),
19943                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
19944    
19945                    Session session = null;
19946    
19947                    try {
19948                            session = openSession();
19949    
19950                            SQLQuery q = session.createSQLQuery(sql);
19951    
19952                            q.addScalar(COUNT_COLUMN_NAME,
19953                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
19954    
19955                            QueryPos qPos = QueryPos.getInstance(q);
19956    
19957                            qPos.add(groupId);
19958    
19959                            qPos.add(folderId);
19960    
19961                            qPos.add(status);
19962    
19963                            Long count = (Long)q.uniqueResult();
19964    
19965                            return count.intValue();
19966                    }
19967                    catch (Exception e) {
19968                            throw processException(e);
19969                    }
19970                    finally {
19971                            closeSession(session);
19972                    }
19973            }
19974    
19975            /**
19976             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and folderId = &#63; and status = any &#63;.
19977             *
19978             * @param groupId the group ID
19979             * @param folderId the folder ID
19980             * @param statuses the statuses
19981             * @return the number of matching journal articles that the user has permission to view
19982             * @throws SystemException if a system exception occurred
19983             */
19984            @Override
19985            public int filterCountByG_F_ST(long groupId, long folderId, int[] statuses)
19986                    throws SystemException {
19987                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19988                            return countByG_F_ST(groupId, folderId, statuses);
19989                    }
19990    
19991                    StringBundler query = new StringBundler();
19992    
19993                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
19994    
19995                    boolean conjunctionable = false;
19996    
19997                    if (conjunctionable) {
19998                            query.append(WHERE_AND);
19999                    }
20000    
20001                    query.append(_FINDER_COLUMN_G_F_ST_GROUPID_5);
20002    
20003                    conjunctionable = true;
20004    
20005                    if (conjunctionable) {
20006                            query.append(WHERE_AND);
20007                    }
20008    
20009                    query.append(_FINDER_COLUMN_G_F_ST_FOLDERID_5);
20010    
20011                    conjunctionable = true;
20012    
20013                    if ((statuses == null) || (statuses.length > 0)) {
20014                            if (conjunctionable) {
20015                                    query.append(WHERE_AND);
20016                            }
20017    
20018                            query.append(StringPool.OPEN_PARENTHESIS);
20019    
20020                            for (int i = 0; i < statuses.length; i++) {
20021                                    query.append(_FINDER_COLUMN_G_F_ST_STATUS_5);
20022    
20023                                    if ((i + 1) < statuses.length) {
20024                                            query.append(WHERE_OR);
20025                                    }
20026                            }
20027    
20028                            query.append(StringPool.CLOSE_PARENTHESIS);
20029    
20030                            conjunctionable = true;
20031                    }
20032    
20033                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
20034                                    JournalArticle.class.getName(),
20035                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
20036    
20037                    Session session = null;
20038    
20039                    try {
20040                            session = openSession();
20041    
20042                            SQLQuery q = session.createSQLQuery(sql);
20043    
20044                            q.addScalar(COUNT_COLUMN_NAME,
20045                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
20046    
20047                            QueryPos qPos = QueryPos.getInstance(q);
20048    
20049                            qPos.add(groupId);
20050    
20051                            qPos.add(folderId);
20052    
20053                            if (statuses != null) {
20054                                    qPos.add(statuses);
20055                            }
20056    
20057                            Long count = (Long)q.uniqueResult();
20058    
20059                            return count.intValue();
20060                    }
20061                    catch (Exception e) {
20062                            throw processException(e);
20063                    }
20064                    finally {
20065                            closeSession(session);
20066                    }
20067            }
20068    
20069            private static final String _FINDER_COLUMN_G_F_ST_GROUPID_2 = "journalArticle.groupId = ? AND ";
20070            private static final String _FINDER_COLUMN_G_F_ST_GROUPID_5 = "(" +
20071                    removeConjunction(_FINDER_COLUMN_G_F_ST_GROUPID_2) + ")";
20072            private static final String _FINDER_COLUMN_G_F_ST_FOLDERID_2 = "journalArticle.folderId = ? AND ";
20073            private static final String _FINDER_COLUMN_G_F_ST_FOLDERID_5 = "(" +
20074                    removeConjunction(_FINDER_COLUMN_G_F_ST_FOLDERID_2) + ")";
20075            private static final String _FINDER_COLUMN_G_F_ST_STATUS_2 = "journalArticle.status = ?";
20076            private static final String _FINDER_COLUMN_G_F_ST_STATUS_5 = "(" +
20077                    removeConjunction(_FINDER_COLUMN_G_F_ST_STATUS_2) + ")";
20078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
20079                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
20080                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
20081                            "findByG_C_C",
20082                            new String[] {
20083                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
20084                                    
20085                            Integer.class.getName(), Integer.class.getName(),
20086                                    OrderByComparator.class.getName()
20087                            });
20088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
20089                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
20090                            JournalArticleImpl.class,
20091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_C",
20092                            new String[] {
20093                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
20094                            },
20095                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
20096                            JournalArticleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
20097                            JournalArticleModelImpl.CLASSPK_COLUMN_BITMASK |
20098                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
20099                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
20100            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_C = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
20101                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
20102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_C",
20103                            new String[] {
20104                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
20105                            });
20106    
20107            /**
20108             * Returns all the journal articles where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20109             *
20110             * @param groupId the group ID
20111             * @param classNameId the class name ID
20112             * @param classPK the class p k
20113             * @return the matching journal articles
20114             * @throws SystemException if a system exception occurred
20115             */
20116            @Override
20117            public List<JournalArticle> findByG_C_C(long groupId, long classNameId,
20118                    long classPK) throws SystemException {
20119                    return findByG_C_C(groupId, classNameId, classPK, QueryUtil.ALL_POS,
20120                            QueryUtil.ALL_POS, null);
20121            }
20122    
20123            /**
20124             * Returns a range of all the journal articles where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20125             *
20126             * <p>
20127             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
20128             * </p>
20129             *
20130             * @param groupId the group ID
20131             * @param classNameId the class name ID
20132             * @param classPK the class p k
20133             * @param start the lower bound of the range of journal articles
20134             * @param end the upper bound of the range of journal articles (not inclusive)
20135             * @return the range of matching journal articles
20136             * @throws SystemException if a system exception occurred
20137             */
20138            @Override
20139            public List<JournalArticle> findByG_C_C(long groupId, long classNameId,
20140                    long classPK, int start, int end) throws SystemException {
20141                    return findByG_C_C(groupId, classNameId, classPK, start, end, null);
20142            }
20143    
20144            /**
20145             * Returns an ordered range of all the journal articles where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20146             *
20147             * <p>
20148             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
20149             * </p>
20150             *
20151             * @param groupId the group ID
20152             * @param classNameId the class name ID
20153             * @param classPK the class p k
20154             * @param start the lower bound of the range of journal articles
20155             * @param end the upper bound of the range of journal articles (not inclusive)
20156             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20157             * @return the ordered range of matching journal articles
20158             * @throws SystemException if a system exception occurred
20159             */
20160            @Override
20161            public List<JournalArticle> findByG_C_C(long groupId, long classNameId,
20162                    long classPK, int start, int end, OrderByComparator orderByComparator)
20163                    throws SystemException {
20164                    boolean pagination = true;
20165                    FinderPath finderPath = null;
20166                    Object[] finderArgs = null;
20167    
20168                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20169                                    (orderByComparator == null)) {
20170                            pagination = false;
20171                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C;
20172                            finderArgs = new Object[] { groupId, classNameId, classPK };
20173                    }
20174                    else {
20175                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_C;
20176                            finderArgs = new Object[] {
20177                                            groupId, classNameId, classPK,
20178                                            
20179                                            start, end, orderByComparator
20180                                    };
20181                    }
20182    
20183                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
20184                                    finderArgs, this);
20185    
20186                    if ((list != null) && !list.isEmpty()) {
20187                            for (JournalArticle journalArticle : list) {
20188                                    if ((groupId != journalArticle.getGroupId()) ||
20189                                                    (classNameId != journalArticle.getClassNameId()) ||
20190                                                    (classPK != journalArticle.getClassPK())) {
20191                                            list = null;
20192    
20193                                            break;
20194                                    }
20195                            }
20196                    }
20197    
20198                    if (list == null) {
20199                            StringBundler query = null;
20200    
20201                            if (orderByComparator != null) {
20202                                    query = new StringBundler(5 +
20203                                                    (orderByComparator.getOrderByFields().length * 3));
20204                            }
20205                            else {
20206                                    query = new StringBundler(5);
20207                            }
20208    
20209                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
20210    
20211                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
20212    
20213                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
20214    
20215                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
20216    
20217                            if (orderByComparator != null) {
20218                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20219                                            orderByComparator);
20220                            }
20221                            else
20222                             if (pagination) {
20223                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
20224                            }
20225    
20226                            String sql = query.toString();
20227    
20228                            Session session = null;
20229    
20230                            try {
20231                                    session = openSession();
20232    
20233                                    Query q = session.createQuery(sql);
20234    
20235                                    QueryPos qPos = QueryPos.getInstance(q);
20236    
20237                                    qPos.add(groupId);
20238    
20239                                    qPos.add(classNameId);
20240    
20241                                    qPos.add(classPK);
20242    
20243                                    if (!pagination) {
20244                                            list = (List<JournalArticle>)QueryUtil.list(q,
20245                                                            getDialect(), start, end, false);
20246    
20247                                            Collections.sort(list);
20248    
20249                                            list = new UnmodifiableList<JournalArticle>(list);
20250                                    }
20251                                    else {
20252                                            list = (List<JournalArticle>)QueryUtil.list(q,
20253                                                            getDialect(), start, end);
20254                                    }
20255    
20256                                    cacheResult(list);
20257    
20258                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
20259                            }
20260                            catch (Exception e) {
20261                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
20262    
20263                                    throw processException(e);
20264                            }
20265                            finally {
20266                                    closeSession(session);
20267                            }
20268                    }
20269    
20270                    return list;
20271            }
20272    
20273            /**
20274             * Returns the first journal article in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20275             *
20276             * @param groupId the group ID
20277             * @param classNameId the class name ID
20278             * @param classPK the class p k
20279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20280             * @return the first matching journal article
20281             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
20282             * @throws SystemException if a system exception occurred
20283             */
20284            @Override
20285            public JournalArticle findByG_C_C_First(long groupId, long classNameId,
20286                    long classPK, OrderByComparator orderByComparator)
20287                    throws NoSuchArticleException, SystemException {
20288                    JournalArticle journalArticle = fetchByG_C_C_First(groupId,
20289                                    classNameId, classPK, orderByComparator);
20290    
20291                    if (journalArticle != null) {
20292                            return journalArticle;
20293                    }
20294    
20295                    StringBundler msg = new StringBundler(8);
20296    
20297                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
20298    
20299                    msg.append("groupId=");
20300                    msg.append(groupId);
20301    
20302                    msg.append(", classNameId=");
20303                    msg.append(classNameId);
20304    
20305                    msg.append(", classPK=");
20306                    msg.append(classPK);
20307    
20308                    msg.append(StringPool.CLOSE_CURLY_BRACE);
20309    
20310                    throw new NoSuchArticleException(msg.toString());
20311            }
20312    
20313            /**
20314             * Returns the first journal article in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20315             *
20316             * @param groupId the group ID
20317             * @param classNameId the class name ID
20318             * @param classPK the class p k
20319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20320             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
20321             * @throws SystemException if a system exception occurred
20322             */
20323            @Override
20324            public JournalArticle fetchByG_C_C_First(long groupId, long classNameId,
20325                    long classPK, OrderByComparator orderByComparator)
20326                    throws SystemException {
20327                    List<JournalArticle> list = findByG_C_C(groupId, classNameId, classPK,
20328                                    0, 1, orderByComparator);
20329    
20330                    if (!list.isEmpty()) {
20331                            return list.get(0);
20332                    }
20333    
20334                    return null;
20335            }
20336    
20337            /**
20338             * Returns the last journal article in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20339             *
20340             * @param groupId the group ID
20341             * @param classNameId the class name ID
20342             * @param classPK the class p k
20343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20344             * @return the last matching journal article
20345             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
20346             * @throws SystemException if a system exception occurred
20347             */
20348            @Override
20349            public JournalArticle findByG_C_C_Last(long groupId, long classNameId,
20350                    long classPK, OrderByComparator orderByComparator)
20351                    throws NoSuchArticleException, SystemException {
20352                    JournalArticle journalArticle = fetchByG_C_C_Last(groupId, classNameId,
20353                                    classPK, orderByComparator);
20354    
20355                    if (journalArticle != null) {
20356                            return journalArticle;
20357                    }
20358    
20359                    StringBundler msg = new StringBundler(8);
20360    
20361                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
20362    
20363                    msg.append("groupId=");
20364                    msg.append(groupId);
20365    
20366                    msg.append(", classNameId=");
20367                    msg.append(classNameId);
20368    
20369                    msg.append(", classPK=");
20370                    msg.append(classPK);
20371    
20372                    msg.append(StringPool.CLOSE_CURLY_BRACE);
20373    
20374                    throw new NoSuchArticleException(msg.toString());
20375            }
20376    
20377            /**
20378             * Returns the last journal article in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20379             *
20380             * @param groupId the group ID
20381             * @param classNameId the class name ID
20382             * @param classPK the class p k
20383             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20384             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
20385             * @throws SystemException if a system exception occurred
20386             */
20387            @Override
20388            public JournalArticle fetchByG_C_C_Last(long groupId, long classNameId,
20389                    long classPK, OrderByComparator orderByComparator)
20390                    throws SystemException {
20391                    int count = countByG_C_C(groupId, classNameId, classPK);
20392    
20393                    if (count == 0) {
20394                            return null;
20395                    }
20396    
20397                    List<JournalArticle> list = findByG_C_C(groupId, classNameId, classPK,
20398                                    count - 1, count, orderByComparator);
20399    
20400                    if (!list.isEmpty()) {
20401                            return list.get(0);
20402                    }
20403    
20404                    return null;
20405            }
20406    
20407            /**
20408             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20409             *
20410             * @param id the primary key of the current journal article
20411             * @param groupId the group ID
20412             * @param classNameId the class name ID
20413             * @param classPK the class p k
20414             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20415             * @return the previous, current, and next journal article
20416             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
20417             * @throws SystemException if a system exception occurred
20418             */
20419            @Override
20420            public JournalArticle[] findByG_C_C_PrevAndNext(long id, long groupId,
20421                    long classNameId, long classPK, OrderByComparator orderByComparator)
20422                    throws NoSuchArticleException, SystemException {
20423                    JournalArticle journalArticle = findByPrimaryKey(id);
20424    
20425                    Session session = null;
20426    
20427                    try {
20428                            session = openSession();
20429    
20430                            JournalArticle[] array = new JournalArticleImpl[3];
20431    
20432                            array[0] = getByG_C_C_PrevAndNext(session, journalArticle, groupId,
20433                                            classNameId, classPK, orderByComparator, true);
20434    
20435                            array[1] = journalArticle;
20436    
20437                            array[2] = getByG_C_C_PrevAndNext(session, journalArticle, groupId,
20438                                            classNameId, classPK, orderByComparator, false);
20439    
20440                            return array;
20441                    }
20442                    catch (Exception e) {
20443                            throw processException(e);
20444                    }
20445                    finally {
20446                            closeSession(session);
20447                    }
20448            }
20449    
20450            protected JournalArticle getByG_C_C_PrevAndNext(Session session,
20451                    JournalArticle journalArticle, long groupId, long classNameId,
20452                    long classPK, OrderByComparator orderByComparator, boolean previous) {
20453                    StringBundler query = null;
20454    
20455                    if (orderByComparator != null) {
20456                            query = new StringBundler(6 +
20457                                            (orderByComparator.getOrderByFields().length * 6));
20458                    }
20459                    else {
20460                            query = new StringBundler(3);
20461                    }
20462    
20463                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
20464    
20465                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
20466    
20467                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
20468    
20469                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
20470    
20471                    if (orderByComparator != null) {
20472                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
20473    
20474                            if (orderByConditionFields.length > 0) {
20475                                    query.append(WHERE_AND);
20476                            }
20477    
20478                            for (int i = 0; i < orderByConditionFields.length; i++) {
20479                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20480                                    query.append(orderByConditionFields[i]);
20481    
20482                                    if ((i + 1) < orderByConditionFields.length) {
20483                                            if (orderByComparator.isAscending() ^ previous) {
20484                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
20485                                            }
20486                                            else {
20487                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
20488                                            }
20489                                    }
20490                                    else {
20491                                            if (orderByComparator.isAscending() ^ previous) {
20492                                                    query.append(WHERE_GREATER_THAN);
20493                                            }
20494                                            else {
20495                                                    query.append(WHERE_LESSER_THAN);
20496                                            }
20497                                    }
20498                            }
20499    
20500                            query.append(ORDER_BY_CLAUSE);
20501    
20502                            String[] orderByFields = orderByComparator.getOrderByFields();
20503    
20504                            for (int i = 0; i < orderByFields.length; i++) {
20505                                    query.append(_ORDER_BY_ENTITY_ALIAS);
20506                                    query.append(orderByFields[i]);
20507    
20508                                    if ((i + 1) < orderByFields.length) {
20509                                            if (orderByComparator.isAscending() ^ previous) {
20510                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
20511                                            }
20512                                            else {
20513                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
20514                                            }
20515                                    }
20516                                    else {
20517                                            if (orderByComparator.isAscending() ^ previous) {
20518                                                    query.append(ORDER_BY_ASC);
20519                                            }
20520                                            else {
20521                                                    query.append(ORDER_BY_DESC);
20522                                            }
20523                                    }
20524                            }
20525                    }
20526                    else {
20527                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
20528                    }
20529    
20530                    String sql = query.toString();
20531    
20532                    Query q = session.createQuery(sql);
20533    
20534                    q.setFirstResult(0);
20535                    q.setMaxResults(2);
20536    
20537                    QueryPos qPos = QueryPos.getInstance(q);
20538    
20539                    qPos.add(groupId);
20540    
20541                    qPos.add(classNameId);
20542    
20543                    qPos.add(classPK);
20544    
20545                    if (orderByComparator != null) {
20546                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
20547    
20548                            for (Object value : values) {
20549                                    qPos.add(value);
20550                            }
20551                    }
20552    
20553                    List<JournalArticle> list = q.list();
20554    
20555                    if (list.size() == 2) {
20556                            return list.get(1);
20557                    }
20558                    else {
20559                            return null;
20560                    }
20561            }
20562    
20563            /**
20564             * Returns all the journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20565             *
20566             * @param groupId the group ID
20567             * @param classNameId the class name ID
20568             * @param classPK the class p k
20569             * @return the matching journal articles that the user has permission to view
20570             * @throws SystemException if a system exception occurred
20571             */
20572            @Override
20573            public List<JournalArticle> filterFindByG_C_C(long groupId,
20574                    long classNameId, long classPK) throws SystemException {
20575                    return filterFindByG_C_C(groupId, classNameId, classPK,
20576                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
20577            }
20578    
20579            /**
20580             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20581             *
20582             * <p>
20583             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
20584             * </p>
20585             *
20586             * @param groupId the group ID
20587             * @param classNameId the class name ID
20588             * @param classPK the class p k
20589             * @param start the lower bound of the range of journal articles
20590             * @param end the upper bound of the range of journal articles (not inclusive)
20591             * @return the range of matching journal articles that the user has permission to view
20592             * @throws SystemException if a system exception occurred
20593             */
20594            @Override
20595            public List<JournalArticle> filterFindByG_C_C(long groupId,
20596                    long classNameId, long classPK, int start, int end)
20597                    throws SystemException {
20598                    return filterFindByG_C_C(groupId, classNameId, classPK, start, end, null);
20599            }
20600    
20601            /**
20602             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20603             *
20604             * <p>
20605             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
20606             * </p>
20607             *
20608             * @param groupId the group ID
20609             * @param classNameId the class name ID
20610             * @param classPK the class p k
20611             * @param start the lower bound of the range of journal articles
20612             * @param end the upper bound of the range of journal articles (not inclusive)
20613             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20614             * @return the ordered range of matching journal articles that the user has permission to view
20615             * @throws SystemException if a system exception occurred
20616             */
20617            @Override
20618            public List<JournalArticle> filterFindByG_C_C(long groupId,
20619                    long classNameId, long classPK, int start, int end,
20620                    OrderByComparator orderByComparator) throws SystemException {
20621                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
20622                            return findByG_C_C(groupId, classNameId, classPK, start, end,
20623                                    orderByComparator);
20624                    }
20625    
20626                    StringBundler query = null;
20627    
20628                    if (orderByComparator != null) {
20629                            query = new StringBundler(5 +
20630                                            (orderByComparator.getOrderByFields().length * 3));
20631                    }
20632                    else {
20633                            query = new StringBundler(5);
20634                    }
20635    
20636                    if (getDB().isSupportsInlineDistinct()) {
20637                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
20638                    }
20639                    else {
20640                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
20641                    }
20642    
20643                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
20644    
20645                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
20646    
20647                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
20648    
20649                    if (!getDB().isSupportsInlineDistinct()) {
20650                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
20651                    }
20652    
20653                    if (orderByComparator != null) {
20654                            if (getDB().isSupportsInlineDistinct()) {
20655                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20656                                            orderByComparator, true);
20657                            }
20658                            else {
20659                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
20660                                            orderByComparator, true);
20661                            }
20662                    }
20663                    else {
20664                            if (getDB().isSupportsInlineDistinct()) {
20665                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
20666                            }
20667                            else {
20668                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
20669                            }
20670                    }
20671    
20672                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
20673                                    JournalArticle.class.getName(),
20674                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
20675    
20676                    Session session = null;
20677    
20678                    try {
20679                            session = openSession();
20680    
20681                            SQLQuery q = session.createSQLQuery(sql);
20682    
20683                            if (getDB().isSupportsInlineDistinct()) {
20684                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
20685                            }
20686                            else {
20687                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
20688                            }
20689    
20690                            QueryPos qPos = QueryPos.getInstance(q);
20691    
20692                            qPos.add(groupId);
20693    
20694                            qPos.add(classNameId);
20695    
20696                            qPos.add(classPK);
20697    
20698                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
20699                                    end);
20700                    }
20701                    catch (Exception e) {
20702                            throw processException(e);
20703                    }
20704                    finally {
20705                            closeSession(session);
20706                    }
20707            }
20708    
20709            /**
20710             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20711             *
20712             * @param id the primary key of the current journal article
20713             * @param groupId the group ID
20714             * @param classNameId the class name ID
20715             * @param classPK the class p k
20716             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
20717             * @return the previous, current, and next journal article
20718             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
20719             * @throws SystemException if a system exception occurred
20720             */
20721            @Override
20722            public JournalArticle[] filterFindByG_C_C_PrevAndNext(long id,
20723                    long groupId, long classNameId, long classPK,
20724                    OrderByComparator orderByComparator)
20725                    throws NoSuchArticleException, SystemException {
20726                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
20727                            return findByG_C_C_PrevAndNext(id, groupId, classNameId, classPK,
20728                                    orderByComparator);
20729                    }
20730    
20731                    JournalArticle journalArticle = findByPrimaryKey(id);
20732    
20733                    Session session = null;
20734    
20735                    try {
20736                            session = openSession();
20737    
20738                            JournalArticle[] array = new JournalArticleImpl[3];
20739    
20740                            array[0] = filterGetByG_C_C_PrevAndNext(session, journalArticle,
20741                                            groupId, classNameId, classPK, orderByComparator, true);
20742    
20743                            array[1] = journalArticle;
20744    
20745                            array[2] = filterGetByG_C_C_PrevAndNext(session, journalArticle,
20746                                            groupId, classNameId, classPK, orderByComparator, false);
20747    
20748                            return array;
20749                    }
20750                    catch (Exception e) {
20751                            throw processException(e);
20752                    }
20753                    finally {
20754                            closeSession(session);
20755                    }
20756            }
20757    
20758            protected JournalArticle filterGetByG_C_C_PrevAndNext(Session session,
20759                    JournalArticle journalArticle, long groupId, long classNameId,
20760                    long classPK, OrderByComparator orderByComparator, boolean previous) {
20761                    StringBundler query = null;
20762    
20763                    if (orderByComparator != null) {
20764                            query = new StringBundler(6 +
20765                                            (orderByComparator.getOrderByFields().length * 6));
20766                    }
20767                    else {
20768                            query = new StringBundler(3);
20769                    }
20770    
20771                    if (getDB().isSupportsInlineDistinct()) {
20772                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
20773                    }
20774                    else {
20775                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
20776                    }
20777    
20778                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
20779    
20780                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
20781    
20782                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
20783    
20784                    if (!getDB().isSupportsInlineDistinct()) {
20785                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
20786                    }
20787    
20788                    if (orderByComparator != null) {
20789                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
20790    
20791                            if (orderByConditionFields.length > 0) {
20792                                    query.append(WHERE_AND);
20793                            }
20794    
20795                            for (int i = 0; i < orderByConditionFields.length; i++) {
20796                                    if (getDB().isSupportsInlineDistinct()) {
20797                                            query.append(_ORDER_BY_ENTITY_ALIAS);
20798                                    }
20799                                    else {
20800                                            query.append(_ORDER_BY_ENTITY_TABLE);
20801                                    }
20802    
20803                                    query.append(orderByConditionFields[i]);
20804    
20805                                    if ((i + 1) < orderByConditionFields.length) {
20806                                            if (orderByComparator.isAscending() ^ previous) {
20807                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
20808                                            }
20809                                            else {
20810                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
20811                                            }
20812                                    }
20813                                    else {
20814                                            if (orderByComparator.isAscending() ^ previous) {
20815                                                    query.append(WHERE_GREATER_THAN);
20816                                            }
20817                                            else {
20818                                                    query.append(WHERE_LESSER_THAN);
20819                                            }
20820                                    }
20821                            }
20822    
20823                            query.append(ORDER_BY_CLAUSE);
20824    
20825                            String[] orderByFields = orderByComparator.getOrderByFields();
20826    
20827                            for (int i = 0; i < orderByFields.length; i++) {
20828                                    if (getDB().isSupportsInlineDistinct()) {
20829                                            query.append(_ORDER_BY_ENTITY_ALIAS);
20830                                    }
20831                                    else {
20832                                            query.append(_ORDER_BY_ENTITY_TABLE);
20833                                    }
20834    
20835                                    query.append(orderByFields[i]);
20836    
20837                                    if ((i + 1) < orderByFields.length) {
20838                                            if (orderByComparator.isAscending() ^ previous) {
20839                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
20840                                            }
20841                                            else {
20842                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
20843                                            }
20844                                    }
20845                                    else {
20846                                            if (orderByComparator.isAscending() ^ previous) {
20847                                                    query.append(ORDER_BY_ASC);
20848                                            }
20849                                            else {
20850                                                    query.append(ORDER_BY_DESC);
20851                                            }
20852                                    }
20853                            }
20854                    }
20855                    else {
20856                            if (getDB().isSupportsInlineDistinct()) {
20857                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
20858                            }
20859                            else {
20860                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
20861                            }
20862                    }
20863    
20864                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
20865                                    JournalArticle.class.getName(),
20866                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
20867    
20868                    SQLQuery q = session.createSQLQuery(sql);
20869    
20870                    q.setFirstResult(0);
20871                    q.setMaxResults(2);
20872    
20873                    if (getDB().isSupportsInlineDistinct()) {
20874                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
20875                    }
20876                    else {
20877                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
20878                    }
20879    
20880                    QueryPos qPos = QueryPos.getInstance(q);
20881    
20882                    qPos.add(groupId);
20883    
20884                    qPos.add(classNameId);
20885    
20886                    qPos.add(classPK);
20887    
20888                    if (orderByComparator != null) {
20889                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
20890    
20891                            for (Object value : values) {
20892                                    qPos.add(value);
20893                            }
20894                    }
20895    
20896                    List<JournalArticle> list = q.list();
20897    
20898                    if (list.size() == 2) {
20899                            return list.get(1);
20900                    }
20901                    else {
20902                            return null;
20903                    }
20904            }
20905    
20906            /**
20907             * Removes all the journal articles where groupId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
20908             *
20909             * @param groupId the group ID
20910             * @param classNameId the class name ID
20911             * @param classPK the class p k
20912             * @throws SystemException if a system exception occurred
20913             */
20914            @Override
20915            public void removeByG_C_C(long groupId, long classNameId, long classPK)
20916                    throws SystemException {
20917                    for (JournalArticle journalArticle : findByG_C_C(groupId, classNameId,
20918                                    classPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
20919                            remove(journalArticle);
20920                    }
20921            }
20922    
20923            /**
20924             * Returns the number of journal articles where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20925             *
20926             * @param groupId the group ID
20927             * @param classNameId the class name ID
20928             * @param classPK the class p k
20929             * @return the number of matching journal articles
20930             * @throws SystemException if a system exception occurred
20931             */
20932            @Override
20933            public int countByG_C_C(long groupId, long classNameId, long classPK)
20934                    throws SystemException {
20935                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_C;
20936    
20937                    Object[] finderArgs = new Object[] { groupId, classNameId, classPK };
20938    
20939                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
20940                                    this);
20941    
20942                    if (count == null) {
20943                            StringBundler query = new StringBundler(4);
20944    
20945                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
20946    
20947                            query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
20948    
20949                            query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
20950    
20951                            query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
20952    
20953                            String sql = query.toString();
20954    
20955                            Session session = null;
20956    
20957                            try {
20958                                    session = openSession();
20959    
20960                                    Query q = session.createQuery(sql);
20961    
20962                                    QueryPos qPos = QueryPos.getInstance(q);
20963    
20964                                    qPos.add(groupId);
20965    
20966                                    qPos.add(classNameId);
20967    
20968                                    qPos.add(classPK);
20969    
20970                                    count = (Long)q.uniqueResult();
20971    
20972                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
20973                            }
20974                            catch (Exception e) {
20975                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
20976    
20977                                    throw processException(e);
20978                            }
20979                            finally {
20980                                    closeSession(session);
20981                            }
20982                    }
20983    
20984                    return count.intValue();
20985            }
20986    
20987            /**
20988             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and classPK = &#63;.
20989             *
20990             * @param groupId the group ID
20991             * @param classNameId the class name ID
20992             * @param classPK the class p k
20993             * @return the number of matching journal articles that the user has permission to view
20994             * @throws SystemException if a system exception occurred
20995             */
20996            @Override
20997            public int filterCountByG_C_C(long groupId, long classNameId, long classPK)
20998                    throws SystemException {
20999                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
21000                            return countByG_C_C(groupId, classNameId, classPK);
21001                    }
21002    
21003                    StringBundler query = new StringBundler(4);
21004    
21005                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
21006    
21007                    query.append(_FINDER_COLUMN_G_C_C_GROUPID_2);
21008    
21009                    query.append(_FINDER_COLUMN_G_C_C_CLASSNAMEID_2);
21010    
21011                    query.append(_FINDER_COLUMN_G_C_C_CLASSPK_2);
21012    
21013                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
21014                                    JournalArticle.class.getName(),
21015                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
21016    
21017                    Session session = null;
21018    
21019                    try {
21020                            session = openSession();
21021    
21022                            SQLQuery q = session.createSQLQuery(sql);
21023    
21024                            q.addScalar(COUNT_COLUMN_NAME,
21025                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
21026    
21027                            QueryPos qPos = QueryPos.getInstance(q);
21028    
21029                            qPos.add(groupId);
21030    
21031                            qPos.add(classNameId);
21032    
21033                            qPos.add(classPK);
21034    
21035                            Long count = (Long)q.uniqueResult();
21036    
21037                            return count.intValue();
21038                    }
21039                    catch (Exception e) {
21040                            throw processException(e);
21041                    }
21042                    finally {
21043                            closeSession(session);
21044                    }
21045            }
21046    
21047            private static final String _FINDER_COLUMN_G_C_C_GROUPID_2 = "journalArticle.groupId = ? AND ";
21048            private static final String _FINDER_COLUMN_G_C_C_CLASSNAMEID_2 = "journalArticle.classNameId = ? AND ";
21049            private static final String _FINDER_COLUMN_G_C_C_CLASSPK_2 = "journalArticle.classPK = ?";
21050            public static final FinderPath FINDER_PATH_FETCH_BY_G_C_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
21051                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
21052                            JournalArticleImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_C_S",
21053                            new String[] {
21054                                    Long.class.getName(), Long.class.getName(),
21055                                    String.class.getName()
21056                            },
21057                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
21058                            JournalArticleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
21059                            JournalArticleModelImpl.STRUCTUREID_COLUMN_BITMASK);
21060            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
21061                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
21062                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
21063                            new String[] {
21064                                    Long.class.getName(), Long.class.getName(),
21065                                    String.class.getName()
21066                            });
21067    
21068            /**
21069             * Returns the journal article where groupId = &#63; and classNameId = &#63; and structureId = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchArticleException} if it could not be found.
21070             *
21071             * @param groupId the group ID
21072             * @param classNameId the class name ID
21073             * @param structureId the structure ID
21074             * @return the matching journal article
21075             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
21076             * @throws SystemException if a system exception occurred
21077             */
21078            @Override
21079            public JournalArticle findByG_C_S(long groupId, long classNameId,
21080                    String structureId) throws NoSuchArticleException, SystemException {
21081                    JournalArticle journalArticle = fetchByG_C_S(groupId, classNameId,
21082                                    structureId);
21083    
21084                    if (journalArticle == null) {
21085                            StringBundler msg = new StringBundler(8);
21086    
21087                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
21088    
21089                            msg.append("groupId=");
21090                            msg.append(groupId);
21091    
21092                            msg.append(", classNameId=");
21093                            msg.append(classNameId);
21094    
21095                            msg.append(", structureId=");
21096                            msg.append(structureId);
21097    
21098                            msg.append(StringPool.CLOSE_CURLY_BRACE);
21099    
21100                            if (_log.isWarnEnabled()) {
21101                                    _log.warn(msg.toString());
21102                            }
21103    
21104                            throw new NoSuchArticleException(msg.toString());
21105                    }
21106    
21107                    return journalArticle;
21108            }
21109    
21110            /**
21111             * Returns the journal article where groupId = &#63; and classNameId = &#63; and structureId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
21112             *
21113             * @param groupId the group ID
21114             * @param classNameId the class name ID
21115             * @param structureId the structure ID
21116             * @return the matching journal article, or <code>null</code> if a matching journal article could not be found
21117             * @throws SystemException if a system exception occurred
21118             */
21119            @Override
21120            public JournalArticle fetchByG_C_S(long groupId, long classNameId,
21121                    String structureId) throws SystemException {
21122                    return fetchByG_C_S(groupId, classNameId, structureId, true);
21123            }
21124    
21125            /**
21126             * Returns the journal article where groupId = &#63; and classNameId = &#63; and structureId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
21127             *
21128             * @param groupId the group ID
21129             * @param classNameId the class name ID
21130             * @param structureId the structure ID
21131             * @param retrieveFromCache whether to use the finder cache
21132             * @return the matching journal article, or <code>null</code> if a matching journal article could not be found
21133             * @throws SystemException if a system exception occurred
21134             */
21135            @Override
21136            public JournalArticle fetchByG_C_S(long groupId, long classNameId,
21137                    String structureId, boolean retrieveFromCache)
21138                    throws SystemException {
21139                    Object[] finderArgs = new Object[] { groupId, classNameId, structureId };
21140    
21141                    Object result = null;
21142    
21143                    if (retrieveFromCache) {
21144                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_C_S,
21145                                            finderArgs, this);
21146                    }
21147    
21148                    if (result instanceof JournalArticle) {
21149                            JournalArticle journalArticle = (JournalArticle)result;
21150    
21151                            if ((groupId != journalArticle.getGroupId()) ||
21152                                            (classNameId != journalArticle.getClassNameId()) ||
21153                                            !Validator.equals(structureId,
21154                                                    journalArticle.getStructureId())) {
21155                                    result = null;
21156                            }
21157                    }
21158    
21159                    if (result == null) {
21160                            StringBundler query = new StringBundler(5);
21161    
21162                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
21163    
21164                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
21165    
21166                            query.append(_FINDER_COLUMN_G_C_S_CLASSNAMEID_2);
21167    
21168                            boolean bindStructureId = false;
21169    
21170                            if (structureId == null) {
21171                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREID_1);
21172                            }
21173                            else if (structureId.equals(StringPool.BLANK)) {
21174                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREID_3);
21175                            }
21176                            else {
21177                                    bindStructureId = true;
21178    
21179                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREID_2);
21180                            }
21181    
21182                            String sql = query.toString();
21183    
21184                            Session session = null;
21185    
21186                            try {
21187                                    session = openSession();
21188    
21189                                    Query q = session.createQuery(sql);
21190    
21191                                    QueryPos qPos = QueryPos.getInstance(q);
21192    
21193                                    qPos.add(groupId);
21194    
21195                                    qPos.add(classNameId);
21196    
21197                                    if (bindStructureId) {
21198                                            qPos.add(structureId);
21199                                    }
21200    
21201                                    List<JournalArticle> list = q.list();
21202    
21203                                    if (list.isEmpty()) {
21204                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
21205                                                    finderArgs, list);
21206                                    }
21207                                    else {
21208                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
21209                                                    _log.warn(
21210                                                            "JournalArticlePersistenceImpl.fetchByG_C_S(long, long, String, boolean) with parameters (" +
21211                                                            StringUtil.merge(finderArgs) +
21212                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
21213                                            }
21214    
21215                                            JournalArticle journalArticle = list.get(0);
21216    
21217                                            result = journalArticle;
21218    
21219                                            cacheResult(journalArticle);
21220    
21221                                            if ((journalArticle.getGroupId() != groupId) ||
21222                                                            (journalArticle.getClassNameId() != classNameId) ||
21223                                                            (journalArticle.getStructureId() == null) ||
21224                                                            !journalArticle.getStructureId().equals(structureId)) {
21225                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
21226                                                            finderArgs, journalArticle);
21227                                            }
21228                                    }
21229                            }
21230                            catch (Exception e) {
21231                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S,
21232                                            finderArgs);
21233    
21234                                    throw processException(e);
21235                            }
21236                            finally {
21237                                    closeSession(session);
21238                            }
21239                    }
21240    
21241                    if (result instanceof List<?>) {
21242                            return null;
21243                    }
21244                    else {
21245                            return (JournalArticle)result;
21246                    }
21247            }
21248    
21249            /**
21250             * Removes the journal article where groupId = &#63; and classNameId = &#63; and structureId = &#63; from the database.
21251             *
21252             * @param groupId the group ID
21253             * @param classNameId the class name ID
21254             * @param structureId the structure ID
21255             * @return the journal article that was removed
21256             * @throws SystemException if a system exception occurred
21257             */
21258            @Override
21259            public JournalArticle removeByG_C_S(long groupId, long classNameId,
21260                    String structureId) throws NoSuchArticleException, SystemException {
21261                    JournalArticle journalArticle = findByG_C_S(groupId, classNameId,
21262                                    structureId);
21263    
21264                    return remove(journalArticle);
21265            }
21266    
21267            /**
21268             * Returns the number of journal articles where groupId = &#63; and classNameId = &#63; and structureId = &#63;.
21269             *
21270             * @param groupId the group ID
21271             * @param classNameId the class name ID
21272             * @param structureId the structure ID
21273             * @return the number of matching journal articles
21274             * @throws SystemException if a system exception occurred
21275             */
21276            @Override
21277            public int countByG_C_S(long groupId, long classNameId, String structureId)
21278                    throws SystemException {
21279                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
21280    
21281                    Object[] finderArgs = new Object[] { groupId, classNameId, structureId };
21282    
21283                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
21284                                    this);
21285    
21286                    if (count == null) {
21287                            StringBundler query = new StringBundler(4);
21288    
21289                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
21290    
21291                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
21292    
21293                            query.append(_FINDER_COLUMN_G_C_S_CLASSNAMEID_2);
21294    
21295                            boolean bindStructureId = false;
21296    
21297                            if (structureId == null) {
21298                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREID_1);
21299                            }
21300                            else if (structureId.equals(StringPool.BLANK)) {
21301                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREID_3);
21302                            }
21303                            else {
21304                                    bindStructureId = true;
21305    
21306                                    query.append(_FINDER_COLUMN_G_C_S_STRUCTUREID_2);
21307                            }
21308    
21309                            String sql = query.toString();
21310    
21311                            Session session = null;
21312    
21313                            try {
21314                                    session = openSession();
21315    
21316                                    Query q = session.createQuery(sql);
21317    
21318                                    QueryPos qPos = QueryPos.getInstance(q);
21319    
21320                                    qPos.add(groupId);
21321    
21322                                    qPos.add(classNameId);
21323    
21324                                    if (bindStructureId) {
21325                                            qPos.add(structureId);
21326                                    }
21327    
21328                                    count = (Long)q.uniqueResult();
21329    
21330                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
21331                            }
21332                            catch (Exception e) {
21333                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
21334    
21335                                    throw processException(e);
21336                            }
21337                            finally {
21338                                    closeSession(session);
21339                            }
21340                    }
21341    
21342                    return count.intValue();
21343            }
21344    
21345            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "journalArticle.groupId = ? AND ";
21346            private static final String _FINDER_COLUMN_G_C_S_CLASSNAMEID_2 = "journalArticle.classNameId = ? AND ";
21347            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREID_1 = "journalArticle.structureId IS NULL";
21348            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREID_2 = "journalArticle.structureId = ?";
21349            private static final String _FINDER_COLUMN_G_C_S_STRUCTUREID_3 = "(journalArticle.structureId IS NULL OR journalArticle.structureId = '')";
21350            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
21351                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
21352                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
21353                            "findByG_C_T",
21354                            new String[] {
21355                                    Long.class.getName(), Long.class.getName(),
21356                                    String.class.getName(),
21357                                    
21358                            Integer.class.getName(), Integer.class.getName(),
21359                                    OrderByComparator.class.getName()
21360                            });
21361            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
21362                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
21363                            JournalArticleImpl.class,
21364                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
21365                            new String[] {
21366                                    Long.class.getName(), Long.class.getName(),
21367                                    String.class.getName()
21368                            },
21369                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
21370                            JournalArticleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
21371                            JournalArticleModelImpl.TEMPLATEID_COLUMN_BITMASK |
21372                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
21373                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
21374            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
21375                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
21376                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
21377                            new String[] {
21378                                    Long.class.getName(), Long.class.getName(),
21379                                    String.class.getName()
21380                            });
21381    
21382            /**
21383             * Returns all the journal articles where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21384             *
21385             * @param groupId the group ID
21386             * @param classNameId the class name ID
21387             * @param templateId the template ID
21388             * @return the matching journal articles
21389             * @throws SystemException if a system exception occurred
21390             */
21391            @Override
21392            public List<JournalArticle> findByG_C_T(long groupId, long classNameId,
21393                    String templateId) throws SystemException {
21394                    return findByG_C_T(groupId, classNameId, templateId, QueryUtil.ALL_POS,
21395                            QueryUtil.ALL_POS, null);
21396            }
21397    
21398            /**
21399             * Returns a range of all the journal articles where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21400             *
21401             * <p>
21402             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
21403             * </p>
21404             *
21405             * @param groupId the group ID
21406             * @param classNameId the class name ID
21407             * @param templateId the template ID
21408             * @param start the lower bound of the range of journal articles
21409             * @param end the upper bound of the range of journal articles (not inclusive)
21410             * @return the range of matching journal articles
21411             * @throws SystemException if a system exception occurred
21412             */
21413            @Override
21414            public List<JournalArticle> findByG_C_T(long groupId, long classNameId,
21415                    String templateId, int start, int end) throws SystemException {
21416                    return findByG_C_T(groupId, classNameId, templateId, start, end, null);
21417            }
21418    
21419            /**
21420             * Returns an ordered range of all the journal articles where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21421             *
21422             * <p>
21423             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
21424             * </p>
21425             *
21426             * @param groupId the group ID
21427             * @param classNameId the class name ID
21428             * @param templateId the template ID
21429             * @param start the lower bound of the range of journal articles
21430             * @param end the upper bound of the range of journal articles (not inclusive)
21431             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
21432             * @return the ordered range of matching journal articles
21433             * @throws SystemException if a system exception occurred
21434             */
21435            @Override
21436            public List<JournalArticle> findByG_C_T(long groupId, long classNameId,
21437                    String templateId, int start, int end,
21438                    OrderByComparator orderByComparator) throws SystemException {
21439                    boolean pagination = true;
21440                    FinderPath finderPath = null;
21441                    Object[] finderArgs = null;
21442    
21443                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
21444                                    (orderByComparator == null)) {
21445                            pagination = false;
21446                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
21447                            finderArgs = new Object[] { groupId, classNameId, templateId };
21448                    }
21449                    else {
21450                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
21451                            finderArgs = new Object[] {
21452                                            groupId, classNameId, templateId,
21453                                            
21454                                            start, end, orderByComparator
21455                                    };
21456                    }
21457    
21458                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
21459                                    finderArgs, this);
21460    
21461                    if ((list != null) && !list.isEmpty()) {
21462                            for (JournalArticle journalArticle : list) {
21463                                    if ((groupId != journalArticle.getGroupId()) ||
21464                                                    (classNameId != journalArticle.getClassNameId()) ||
21465                                                    !Validator.equals(templateId,
21466                                                            journalArticle.getTemplateId())) {
21467                                            list = null;
21468    
21469                                            break;
21470                                    }
21471                            }
21472                    }
21473    
21474                    if (list == null) {
21475                            StringBundler query = null;
21476    
21477                            if (orderByComparator != null) {
21478                                    query = new StringBundler(5 +
21479                                                    (orderByComparator.getOrderByFields().length * 3));
21480                            }
21481                            else {
21482                                    query = new StringBundler(5);
21483                            }
21484    
21485                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
21486    
21487                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
21488    
21489                            query.append(_FINDER_COLUMN_G_C_T_CLASSNAMEID_2);
21490    
21491                            boolean bindTemplateId = false;
21492    
21493                            if (templateId == null) {
21494                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_1);
21495                            }
21496                            else if (templateId.equals(StringPool.BLANK)) {
21497                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_3);
21498                            }
21499                            else {
21500                                    bindTemplateId = true;
21501    
21502                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_2);
21503                            }
21504    
21505                            if (orderByComparator != null) {
21506                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
21507                                            orderByComparator);
21508                            }
21509                            else
21510                             if (pagination) {
21511                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
21512                            }
21513    
21514                            String sql = query.toString();
21515    
21516                            Session session = null;
21517    
21518                            try {
21519                                    session = openSession();
21520    
21521                                    Query q = session.createQuery(sql);
21522    
21523                                    QueryPos qPos = QueryPos.getInstance(q);
21524    
21525                                    qPos.add(groupId);
21526    
21527                                    qPos.add(classNameId);
21528    
21529                                    if (bindTemplateId) {
21530                                            qPos.add(templateId);
21531                                    }
21532    
21533                                    if (!pagination) {
21534                                            list = (List<JournalArticle>)QueryUtil.list(q,
21535                                                            getDialect(), start, end, false);
21536    
21537                                            Collections.sort(list);
21538    
21539                                            list = new UnmodifiableList<JournalArticle>(list);
21540                                    }
21541                                    else {
21542                                            list = (List<JournalArticle>)QueryUtil.list(q,
21543                                                            getDialect(), start, end);
21544                                    }
21545    
21546                                    cacheResult(list);
21547    
21548                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
21549                            }
21550                            catch (Exception e) {
21551                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
21552    
21553                                    throw processException(e);
21554                            }
21555                            finally {
21556                                    closeSession(session);
21557                            }
21558                    }
21559    
21560                    return list;
21561            }
21562    
21563            /**
21564             * Returns the first journal article in the ordered set where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21565             *
21566             * @param groupId the group ID
21567             * @param classNameId the class name ID
21568             * @param templateId the template ID
21569             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
21570             * @return the first matching journal article
21571             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
21572             * @throws SystemException if a system exception occurred
21573             */
21574            @Override
21575            public JournalArticle findByG_C_T_First(long groupId, long classNameId,
21576                    String templateId, OrderByComparator orderByComparator)
21577                    throws NoSuchArticleException, SystemException {
21578                    JournalArticle journalArticle = fetchByG_C_T_First(groupId,
21579                                    classNameId, templateId, orderByComparator);
21580    
21581                    if (journalArticle != null) {
21582                            return journalArticle;
21583                    }
21584    
21585                    StringBundler msg = new StringBundler(8);
21586    
21587                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
21588    
21589                    msg.append("groupId=");
21590                    msg.append(groupId);
21591    
21592                    msg.append(", classNameId=");
21593                    msg.append(classNameId);
21594    
21595                    msg.append(", templateId=");
21596                    msg.append(templateId);
21597    
21598                    msg.append(StringPool.CLOSE_CURLY_BRACE);
21599    
21600                    throw new NoSuchArticleException(msg.toString());
21601            }
21602    
21603            /**
21604             * Returns the first journal article in the ordered set where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21605             *
21606             * @param groupId the group ID
21607             * @param classNameId the class name ID
21608             * @param templateId the template ID
21609             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
21610             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
21611             * @throws SystemException if a system exception occurred
21612             */
21613            @Override
21614            public JournalArticle fetchByG_C_T_First(long groupId, long classNameId,
21615                    String templateId, OrderByComparator orderByComparator)
21616                    throws SystemException {
21617                    List<JournalArticle> list = findByG_C_T(groupId, classNameId,
21618                                    templateId, 0, 1, orderByComparator);
21619    
21620                    if (!list.isEmpty()) {
21621                            return list.get(0);
21622                    }
21623    
21624                    return null;
21625            }
21626    
21627            /**
21628             * Returns the last journal article in the ordered set where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21629             *
21630             * @param groupId the group ID
21631             * @param classNameId the class name ID
21632             * @param templateId the template ID
21633             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
21634             * @return the last matching journal article
21635             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
21636             * @throws SystemException if a system exception occurred
21637             */
21638            @Override
21639            public JournalArticle findByG_C_T_Last(long groupId, long classNameId,
21640                    String templateId, OrderByComparator orderByComparator)
21641                    throws NoSuchArticleException, SystemException {
21642                    JournalArticle journalArticle = fetchByG_C_T_Last(groupId, classNameId,
21643                                    templateId, orderByComparator);
21644    
21645                    if (journalArticle != null) {
21646                            return journalArticle;
21647                    }
21648    
21649                    StringBundler msg = new StringBundler(8);
21650    
21651                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
21652    
21653                    msg.append("groupId=");
21654                    msg.append(groupId);
21655    
21656                    msg.append(", classNameId=");
21657                    msg.append(classNameId);
21658    
21659                    msg.append(", templateId=");
21660                    msg.append(templateId);
21661    
21662                    msg.append(StringPool.CLOSE_CURLY_BRACE);
21663    
21664                    throw new NoSuchArticleException(msg.toString());
21665            }
21666    
21667            /**
21668             * Returns the last journal article in the ordered set where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21669             *
21670             * @param groupId the group ID
21671             * @param classNameId the class name ID
21672             * @param templateId the template ID
21673             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
21674             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
21675             * @throws SystemException if a system exception occurred
21676             */
21677            @Override
21678            public JournalArticle fetchByG_C_T_Last(long groupId, long classNameId,
21679                    String templateId, OrderByComparator orderByComparator)
21680                    throws SystemException {
21681                    int count = countByG_C_T(groupId, classNameId, templateId);
21682    
21683                    if (count == 0) {
21684                            return null;
21685                    }
21686    
21687                    List<JournalArticle> list = findByG_C_T(groupId, classNameId,
21688                                    templateId, count - 1, count, orderByComparator);
21689    
21690                    if (!list.isEmpty()) {
21691                            return list.get(0);
21692                    }
21693    
21694                    return null;
21695            }
21696    
21697            /**
21698             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21699             *
21700             * @param id the primary key of the current journal article
21701             * @param groupId the group ID
21702             * @param classNameId the class name ID
21703             * @param templateId the template ID
21704             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
21705             * @return the previous, current, and next journal article
21706             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
21707             * @throws SystemException if a system exception occurred
21708             */
21709            @Override
21710            public JournalArticle[] findByG_C_T_PrevAndNext(long id, long groupId,
21711                    long classNameId, String templateId, OrderByComparator orderByComparator)
21712                    throws NoSuchArticleException, SystemException {
21713                    JournalArticle journalArticle = findByPrimaryKey(id);
21714    
21715                    Session session = null;
21716    
21717                    try {
21718                            session = openSession();
21719    
21720                            JournalArticle[] array = new JournalArticleImpl[3];
21721    
21722                            array[0] = getByG_C_T_PrevAndNext(session, journalArticle, groupId,
21723                                            classNameId, templateId, orderByComparator, true);
21724    
21725                            array[1] = journalArticle;
21726    
21727                            array[2] = getByG_C_T_PrevAndNext(session, journalArticle, groupId,
21728                                            classNameId, templateId, orderByComparator, false);
21729    
21730                            return array;
21731                    }
21732                    catch (Exception e) {
21733                            throw processException(e);
21734                    }
21735                    finally {
21736                            closeSession(session);
21737                    }
21738            }
21739    
21740            protected JournalArticle getByG_C_T_PrevAndNext(Session session,
21741                    JournalArticle journalArticle, long groupId, long classNameId,
21742                    String templateId, OrderByComparator orderByComparator, boolean previous) {
21743                    StringBundler query = null;
21744    
21745                    if (orderByComparator != null) {
21746                            query = new StringBundler(6 +
21747                                            (orderByComparator.getOrderByFields().length * 6));
21748                    }
21749                    else {
21750                            query = new StringBundler(3);
21751                    }
21752    
21753                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
21754    
21755                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
21756    
21757                    query.append(_FINDER_COLUMN_G_C_T_CLASSNAMEID_2);
21758    
21759                    boolean bindTemplateId = false;
21760    
21761                    if (templateId == null) {
21762                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_1);
21763                    }
21764                    else if (templateId.equals(StringPool.BLANK)) {
21765                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_3);
21766                    }
21767                    else {
21768                            bindTemplateId = true;
21769    
21770                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_2);
21771                    }
21772    
21773                    if (orderByComparator != null) {
21774                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
21775    
21776                            if (orderByConditionFields.length > 0) {
21777                                    query.append(WHERE_AND);
21778                            }
21779    
21780                            for (int i = 0; i < orderByConditionFields.length; i++) {
21781                                    query.append(_ORDER_BY_ENTITY_ALIAS);
21782                                    query.append(orderByConditionFields[i]);
21783    
21784                                    if ((i + 1) < orderByConditionFields.length) {
21785                                            if (orderByComparator.isAscending() ^ previous) {
21786                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
21787                                            }
21788                                            else {
21789                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
21790                                            }
21791                                    }
21792                                    else {
21793                                            if (orderByComparator.isAscending() ^ previous) {
21794                                                    query.append(WHERE_GREATER_THAN);
21795                                            }
21796                                            else {
21797                                                    query.append(WHERE_LESSER_THAN);
21798                                            }
21799                                    }
21800                            }
21801    
21802                            query.append(ORDER_BY_CLAUSE);
21803    
21804                            String[] orderByFields = orderByComparator.getOrderByFields();
21805    
21806                            for (int i = 0; i < orderByFields.length; i++) {
21807                                    query.append(_ORDER_BY_ENTITY_ALIAS);
21808                                    query.append(orderByFields[i]);
21809    
21810                                    if ((i + 1) < orderByFields.length) {
21811                                            if (orderByComparator.isAscending() ^ previous) {
21812                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
21813                                            }
21814                                            else {
21815                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
21816                                            }
21817                                    }
21818                                    else {
21819                                            if (orderByComparator.isAscending() ^ previous) {
21820                                                    query.append(ORDER_BY_ASC);
21821                                            }
21822                                            else {
21823                                                    query.append(ORDER_BY_DESC);
21824                                            }
21825                                    }
21826                            }
21827                    }
21828                    else {
21829                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
21830                    }
21831    
21832                    String sql = query.toString();
21833    
21834                    Query q = session.createQuery(sql);
21835    
21836                    q.setFirstResult(0);
21837                    q.setMaxResults(2);
21838    
21839                    QueryPos qPos = QueryPos.getInstance(q);
21840    
21841                    qPos.add(groupId);
21842    
21843                    qPos.add(classNameId);
21844    
21845                    if (bindTemplateId) {
21846                            qPos.add(templateId);
21847                    }
21848    
21849                    if (orderByComparator != null) {
21850                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
21851    
21852                            for (Object value : values) {
21853                                    qPos.add(value);
21854                            }
21855                    }
21856    
21857                    List<JournalArticle> list = q.list();
21858    
21859                    if (list.size() == 2) {
21860                            return list.get(1);
21861                    }
21862                    else {
21863                            return null;
21864                    }
21865            }
21866    
21867            /**
21868             * Returns all the journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21869             *
21870             * @param groupId the group ID
21871             * @param classNameId the class name ID
21872             * @param templateId the template ID
21873             * @return the matching journal articles that the user has permission to view
21874             * @throws SystemException if a system exception occurred
21875             */
21876            @Override
21877            public List<JournalArticle> filterFindByG_C_T(long groupId,
21878                    long classNameId, String templateId) throws SystemException {
21879                    return filterFindByG_C_T(groupId, classNameId, templateId,
21880                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
21881            }
21882    
21883            /**
21884             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21885             *
21886             * <p>
21887             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
21888             * </p>
21889             *
21890             * @param groupId the group ID
21891             * @param classNameId the class name ID
21892             * @param templateId the template ID
21893             * @param start the lower bound of the range of journal articles
21894             * @param end the upper bound of the range of journal articles (not inclusive)
21895             * @return the range of matching journal articles that the user has permission to view
21896             * @throws SystemException if a system exception occurred
21897             */
21898            @Override
21899            public List<JournalArticle> filterFindByG_C_T(long groupId,
21900                    long classNameId, String templateId, int start, int end)
21901                    throws SystemException {
21902                    return filterFindByG_C_T(groupId, classNameId, templateId, start, end,
21903                            null);
21904            }
21905    
21906            /**
21907             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
21908             *
21909             * <p>
21910             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
21911             * </p>
21912             *
21913             * @param groupId the group ID
21914             * @param classNameId the class name ID
21915             * @param templateId the template ID
21916             * @param start the lower bound of the range of journal articles
21917             * @param end the upper bound of the range of journal articles (not inclusive)
21918             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
21919             * @return the ordered range of matching journal articles that the user has permission to view
21920             * @throws SystemException if a system exception occurred
21921             */
21922            @Override
21923            public List<JournalArticle> filterFindByG_C_T(long groupId,
21924                    long classNameId, String templateId, int start, int end,
21925                    OrderByComparator orderByComparator) throws SystemException {
21926                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
21927                            return findByG_C_T(groupId, classNameId, templateId, start, end,
21928                                    orderByComparator);
21929                    }
21930    
21931                    StringBundler query = null;
21932    
21933                    if (orderByComparator != null) {
21934                            query = new StringBundler(5 +
21935                                            (orderByComparator.getOrderByFields().length * 3));
21936                    }
21937                    else {
21938                            query = new StringBundler(5);
21939                    }
21940    
21941                    if (getDB().isSupportsInlineDistinct()) {
21942                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
21943                    }
21944                    else {
21945                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
21946                    }
21947    
21948                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
21949    
21950                    query.append(_FINDER_COLUMN_G_C_T_CLASSNAMEID_2);
21951    
21952                    boolean bindTemplateId = false;
21953    
21954                    if (templateId == null) {
21955                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_1);
21956                    }
21957                    else if (templateId.equals(StringPool.BLANK)) {
21958                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_3);
21959                    }
21960                    else {
21961                            bindTemplateId = true;
21962    
21963                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_2);
21964                    }
21965    
21966                    if (!getDB().isSupportsInlineDistinct()) {
21967                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
21968                    }
21969    
21970                    if (orderByComparator != null) {
21971                            if (getDB().isSupportsInlineDistinct()) {
21972                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
21973                                            orderByComparator, true);
21974                            }
21975                            else {
21976                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
21977                                            orderByComparator, true);
21978                            }
21979                    }
21980                    else {
21981                            if (getDB().isSupportsInlineDistinct()) {
21982                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
21983                            }
21984                            else {
21985                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
21986                            }
21987                    }
21988    
21989                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
21990                                    JournalArticle.class.getName(),
21991                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
21992    
21993                    Session session = null;
21994    
21995                    try {
21996                            session = openSession();
21997    
21998                            SQLQuery q = session.createSQLQuery(sql);
21999    
22000                            if (getDB().isSupportsInlineDistinct()) {
22001                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
22002                            }
22003                            else {
22004                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
22005                            }
22006    
22007                            QueryPos qPos = QueryPos.getInstance(q);
22008    
22009                            qPos.add(groupId);
22010    
22011                            qPos.add(classNameId);
22012    
22013                            if (bindTemplateId) {
22014                                    qPos.add(templateId);
22015                            }
22016    
22017                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
22018                                    end);
22019                    }
22020                    catch (Exception e) {
22021                            throw processException(e);
22022                    }
22023                    finally {
22024                            closeSession(session);
22025                    }
22026            }
22027    
22028            /**
22029             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
22030             *
22031             * @param id the primary key of the current journal article
22032             * @param groupId the group ID
22033             * @param classNameId the class name ID
22034             * @param templateId the template ID
22035             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
22036             * @return the previous, current, and next journal article
22037             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
22038             * @throws SystemException if a system exception occurred
22039             */
22040            @Override
22041            public JournalArticle[] filterFindByG_C_T_PrevAndNext(long id,
22042                    long groupId, long classNameId, String templateId,
22043                    OrderByComparator orderByComparator)
22044                    throws NoSuchArticleException, SystemException {
22045                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
22046                            return findByG_C_T_PrevAndNext(id, groupId, classNameId,
22047                                    templateId, orderByComparator);
22048                    }
22049    
22050                    JournalArticle journalArticle = findByPrimaryKey(id);
22051    
22052                    Session session = null;
22053    
22054                    try {
22055                            session = openSession();
22056    
22057                            JournalArticle[] array = new JournalArticleImpl[3];
22058    
22059                            array[0] = filterGetByG_C_T_PrevAndNext(session, journalArticle,
22060                                            groupId, classNameId, templateId, orderByComparator, true);
22061    
22062                            array[1] = journalArticle;
22063    
22064                            array[2] = filterGetByG_C_T_PrevAndNext(session, journalArticle,
22065                                            groupId, classNameId, templateId, orderByComparator, false);
22066    
22067                            return array;
22068                    }
22069                    catch (Exception e) {
22070                            throw processException(e);
22071                    }
22072                    finally {
22073                            closeSession(session);
22074                    }
22075            }
22076    
22077            protected JournalArticle filterGetByG_C_T_PrevAndNext(Session session,
22078                    JournalArticle journalArticle, long groupId, long classNameId,
22079                    String templateId, OrderByComparator orderByComparator, boolean previous) {
22080                    StringBundler query = null;
22081    
22082                    if (orderByComparator != null) {
22083                            query = new StringBundler(6 +
22084                                            (orderByComparator.getOrderByFields().length * 6));
22085                    }
22086                    else {
22087                            query = new StringBundler(3);
22088                    }
22089    
22090                    if (getDB().isSupportsInlineDistinct()) {
22091                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
22092                    }
22093                    else {
22094                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
22095                    }
22096    
22097                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
22098    
22099                    query.append(_FINDER_COLUMN_G_C_T_CLASSNAMEID_2);
22100    
22101                    boolean bindTemplateId = false;
22102    
22103                    if (templateId == null) {
22104                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_1);
22105                    }
22106                    else if (templateId.equals(StringPool.BLANK)) {
22107                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_3);
22108                    }
22109                    else {
22110                            bindTemplateId = true;
22111    
22112                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_2);
22113                    }
22114    
22115                    if (!getDB().isSupportsInlineDistinct()) {
22116                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
22117                    }
22118    
22119                    if (orderByComparator != null) {
22120                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
22121    
22122                            if (orderByConditionFields.length > 0) {
22123                                    query.append(WHERE_AND);
22124                            }
22125    
22126                            for (int i = 0; i < orderByConditionFields.length; i++) {
22127                                    if (getDB().isSupportsInlineDistinct()) {
22128                                            query.append(_ORDER_BY_ENTITY_ALIAS);
22129                                    }
22130                                    else {
22131                                            query.append(_ORDER_BY_ENTITY_TABLE);
22132                                    }
22133    
22134                                    query.append(orderByConditionFields[i]);
22135    
22136                                    if ((i + 1) < orderByConditionFields.length) {
22137                                            if (orderByComparator.isAscending() ^ previous) {
22138                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
22139                                            }
22140                                            else {
22141                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
22142                                            }
22143                                    }
22144                                    else {
22145                                            if (orderByComparator.isAscending() ^ previous) {
22146                                                    query.append(WHERE_GREATER_THAN);
22147                                            }
22148                                            else {
22149                                                    query.append(WHERE_LESSER_THAN);
22150                                            }
22151                                    }
22152                            }
22153    
22154                            query.append(ORDER_BY_CLAUSE);
22155    
22156                            String[] orderByFields = orderByComparator.getOrderByFields();
22157    
22158                            for (int i = 0; i < orderByFields.length; i++) {
22159                                    if (getDB().isSupportsInlineDistinct()) {
22160                                            query.append(_ORDER_BY_ENTITY_ALIAS);
22161                                    }
22162                                    else {
22163                                            query.append(_ORDER_BY_ENTITY_TABLE);
22164                                    }
22165    
22166                                    query.append(orderByFields[i]);
22167    
22168                                    if ((i + 1) < orderByFields.length) {
22169                                            if (orderByComparator.isAscending() ^ previous) {
22170                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
22171                                            }
22172                                            else {
22173                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
22174                                            }
22175                                    }
22176                                    else {
22177                                            if (orderByComparator.isAscending() ^ previous) {
22178                                                    query.append(ORDER_BY_ASC);
22179                                            }
22180                                            else {
22181                                                    query.append(ORDER_BY_DESC);
22182                                            }
22183                                    }
22184                            }
22185                    }
22186                    else {
22187                            if (getDB().isSupportsInlineDistinct()) {
22188                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
22189                            }
22190                            else {
22191                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
22192                            }
22193                    }
22194    
22195                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
22196                                    JournalArticle.class.getName(),
22197                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
22198    
22199                    SQLQuery q = session.createSQLQuery(sql);
22200    
22201                    q.setFirstResult(0);
22202                    q.setMaxResults(2);
22203    
22204                    if (getDB().isSupportsInlineDistinct()) {
22205                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
22206                    }
22207                    else {
22208                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
22209                    }
22210    
22211                    QueryPos qPos = QueryPos.getInstance(q);
22212    
22213                    qPos.add(groupId);
22214    
22215                    qPos.add(classNameId);
22216    
22217                    if (bindTemplateId) {
22218                            qPos.add(templateId);
22219                    }
22220    
22221                    if (orderByComparator != null) {
22222                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
22223    
22224                            for (Object value : values) {
22225                                    qPos.add(value);
22226                            }
22227                    }
22228    
22229                    List<JournalArticle> list = q.list();
22230    
22231                    if (list.size() == 2) {
22232                            return list.get(1);
22233                    }
22234                    else {
22235                            return null;
22236                    }
22237            }
22238    
22239            /**
22240             * Removes all the journal articles where groupId = &#63; and classNameId = &#63; and templateId = &#63; from the database.
22241             *
22242             * @param groupId the group ID
22243             * @param classNameId the class name ID
22244             * @param templateId the template ID
22245             * @throws SystemException if a system exception occurred
22246             */
22247            @Override
22248            public void removeByG_C_T(long groupId, long classNameId, String templateId)
22249                    throws SystemException {
22250                    for (JournalArticle journalArticle : findByG_C_T(groupId, classNameId,
22251                                    templateId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
22252                            remove(journalArticle);
22253                    }
22254            }
22255    
22256            /**
22257             * Returns the number of journal articles where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
22258             *
22259             * @param groupId the group ID
22260             * @param classNameId the class name ID
22261             * @param templateId the template ID
22262             * @return the number of matching journal articles
22263             * @throws SystemException if a system exception occurred
22264             */
22265            @Override
22266            public int countByG_C_T(long groupId, long classNameId, String templateId)
22267                    throws SystemException {
22268                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
22269    
22270                    Object[] finderArgs = new Object[] { groupId, classNameId, templateId };
22271    
22272                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
22273                                    this);
22274    
22275                    if (count == null) {
22276                            StringBundler query = new StringBundler(4);
22277    
22278                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
22279    
22280                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
22281    
22282                            query.append(_FINDER_COLUMN_G_C_T_CLASSNAMEID_2);
22283    
22284                            boolean bindTemplateId = false;
22285    
22286                            if (templateId == null) {
22287                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_1);
22288                            }
22289                            else if (templateId.equals(StringPool.BLANK)) {
22290                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_3);
22291                            }
22292                            else {
22293                                    bindTemplateId = true;
22294    
22295                                    query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_2);
22296                            }
22297    
22298                            String sql = query.toString();
22299    
22300                            Session session = null;
22301    
22302                            try {
22303                                    session = openSession();
22304    
22305                                    Query q = session.createQuery(sql);
22306    
22307                                    QueryPos qPos = QueryPos.getInstance(q);
22308    
22309                                    qPos.add(groupId);
22310    
22311                                    qPos.add(classNameId);
22312    
22313                                    if (bindTemplateId) {
22314                                            qPos.add(templateId);
22315                                    }
22316    
22317                                    count = (Long)q.uniqueResult();
22318    
22319                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
22320                            }
22321                            catch (Exception e) {
22322                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
22323    
22324                                    throw processException(e);
22325                            }
22326                            finally {
22327                                    closeSession(session);
22328                            }
22329                    }
22330    
22331                    return count.intValue();
22332            }
22333    
22334            /**
22335             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and templateId = &#63;.
22336             *
22337             * @param groupId the group ID
22338             * @param classNameId the class name ID
22339             * @param templateId the template ID
22340             * @return the number of matching journal articles that the user has permission to view
22341             * @throws SystemException if a system exception occurred
22342             */
22343            @Override
22344            public int filterCountByG_C_T(long groupId, long classNameId,
22345                    String templateId) throws SystemException {
22346                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
22347                            return countByG_C_T(groupId, classNameId, templateId);
22348                    }
22349    
22350                    StringBundler query = new StringBundler(4);
22351    
22352                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
22353    
22354                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
22355    
22356                    query.append(_FINDER_COLUMN_G_C_T_CLASSNAMEID_2);
22357    
22358                    boolean bindTemplateId = false;
22359    
22360                    if (templateId == null) {
22361                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_1);
22362                    }
22363                    else if (templateId.equals(StringPool.BLANK)) {
22364                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_3);
22365                    }
22366                    else {
22367                            bindTemplateId = true;
22368    
22369                            query.append(_FINDER_COLUMN_G_C_T_TEMPLATEID_2);
22370                    }
22371    
22372                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
22373                                    JournalArticle.class.getName(),
22374                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
22375    
22376                    Session session = null;
22377    
22378                    try {
22379                            session = openSession();
22380    
22381                            SQLQuery q = session.createSQLQuery(sql);
22382    
22383                            q.addScalar(COUNT_COLUMN_NAME,
22384                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
22385    
22386                            QueryPos qPos = QueryPos.getInstance(q);
22387    
22388                            qPos.add(groupId);
22389    
22390                            qPos.add(classNameId);
22391    
22392                            if (bindTemplateId) {
22393                                    qPos.add(templateId);
22394                            }
22395    
22396                            Long count = (Long)q.uniqueResult();
22397    
22398                            return count.intValue();
22399                    }
22400                    catch (Exception e) {
22401                            throw processException(e);
22402                    }
22403                    finally {
22404                            closeSession(session);
22405                    }
22406            }
22407    
22408            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "journalArticle.groupId = ? AND ";
22409            private static final String _FINDER_COLUMN_G_C_T_CLASSNAMEID_2 = "journalArticle.classNameId = ? AND ";
22410            private static final String _FINDER_COLUMN_G_C_T_TEMPLATEID_1 = "journalArticle.templateId IS NULL";
22411            private static final String _FINDER_COLUMN_G_C_T_TEMPLATEID_2 = "journalArticle.templateId = ?";
22412            private static final String _FINDER_COLUMN_G_C_T_TEMPLATEID_3 = "(journalArticle.templateId IS NULL OR journalArticle.templateId = '')";
22413            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
22414                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
22415                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
22416                            "findByG_C_L",
22417                            new String[] {
22418                                    Long.class.getName(), Long.class.getName(),
22419                                    String.class.getName(),
22420                                    
22421                            Integer.class.getName(), Integer.class.getName(),
22422                                    OrderByComparator.class.getName()
22423                            });
22424            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
22425                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
22426                            JournalArticleImpl.class,
22427                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
22428                            new String[] {
22429                                    Long.class.getName(), Long.class.getName(),
22430                                    String.class.getName()
22431                            },
22432                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
22433                            JournalArticleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
22434                            JournalArticleModelImpl.LAYOUTUUID_COLUMN_BITMASK |
22435                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
22436                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
22437            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
22438                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
22439                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
22440                            new String[] {
22441                                    Long.class.getName(), Long.class.getName(),
22442                                    String.class.getName()
22443                            });
22444    
22445            /**
22446             * Returns all the journal articles where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22447             *
22448             * @param groupId the group ID
22449             * @param classNameId the class name ID
22450             * @param layoutUuid the layout uuid
22451             * @return the matching journal articles
22452             * @throws SystemException if a system exception occurred
22453             */
22454            @Override
22455            public List<JournalArticle> findByG_C_L(long groupId, long classNameId,
22456                    String layoutUuid) throws SystemException {
22457                    return findByG_C_L(groupId, classNameId, layoutUuid, QueryUtil.ALL_POS,
22458                            QueryUtil.ALL_POS, null);
22459            }
22460    
22461            /**
22462             * Returns a range of all the journal articles where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22463             *
22464             * <p>
22465             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
22466             * </p>
22467             *
22468             * @param groupId the group ID
22469             * @param classNameId the class name ID
22470             * @param layoutUuid the layout uuid
22471             * @param start the lower bound of the range of journal articles
22472             * @param end the upper bound of the range of journal articles (not inclusive)
22473             * @return the range of matching journal articles
22474             * @throws SystemException if a system exception occurred
22475             */
22476            @Override
22477            public List<JournalArticle> findByG_C_L(long groupId, long classNameId,
22478                    String layoutUuid, int start, int end) throws SystemException {
22479                    return findByG_C_L(groupId, classNameId, layoutUuid, start, end, null);
22480            }
22481    
22482            /**
22483             * Returns an ordered range of all the journal articles where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22484             *
22485             * <p>
22486             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
22487             * </p>
22488             *
22489             * @param groupId the group ID
22490             * @param classNameId the class name ID
22491             * @param layoutUuid the layout uuid
22492             * @param start the lower bound of the range of journal articles
22493             * @param end the upper bound of the range of journal articles (not inclusive)
22494             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
22495             * @return the ordered range of matching journal articles
22496             * @throws SystemException if a system exception occurred
22497             */
22498            @Override
22499            public List<JournalArticle> findByG_C_L(long groupId, long classNameId,
22500                    String layoutUuid, int start, int end,
22501                    OrderByComparator orderByComparator) throws SystemException {
22502                    boolean pagination = true;
22503                    FinderPath finderPath = null;
22504                    Object[] finderArgs = null;
22505    
22506                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
22507                                    (orderByComparator == null)) {
22508                            pagination = false;
22509                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
22510                            finderArgs = new Object[] { groupId, classNameId, layoutUuid };
22511                    }
22512                    else {
22513                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
22514                            finderArgs = new Object[] {
22515                                            groupId, classNameId, layoutUuid,
22516                                            
22517                                            start, end, orderByComparator
22518                                    };
22519                    }
22520    
22521                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
22522                                    finderArgs, this);
22523    
22524                    if ((list != null) && !list.isEmpty()) {
22525                            for (JournalArticle journalArticle : list) {
22526                                    if ((groupId != journalArticle.getGroupId()) ||
22527                                                    (classNameId != journalArticle.getClassNameId()) ||
22528                                                    !Validator.equals(layoutUuid,
22529                                                            journalArticle.getLayoutUuid())) {
22530                                            list = null;
22531    
22532                                            break;
22533                                    }
22534                            }
22535                    }
22536    
22537                    if (list == null) {
22538                            StringBundler query = null;
22539    
22540                            if (orderByComparator != null) {
22541                                    query = new StringBundler(5 +
22542                                                    (orderByComparator.getOrderByFields().length * 3));
22543                            }
22544                            else {
22545                                    query = new StringBundler(5);
22546                            }
22547    
22548                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
22549    
22550                            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
22551    
22552                            query.append(_FINDER_COLUMN_G_C_L_CLASSNAMEID_2);
22553    
22554                            boolean bindLayoutUuid = false;
22555    
22556                            if (layoutUuid == null) {
22557                                    query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_1);
22558                            }
22559                            else if (layoutUuid.equals(StringPool.BLANK)) {
22560                                    query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_3);
22561                            }
22562                            else {
22563                                    bindLayoutUuid = true;
22564    
22565                                    query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_2);
22566                            }
22567    
22568                            if (orderByComparator != null) {
22569                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
22570                                            orderByComparator);
22571                            }
22572                            else
22573                             if (pagination) {
22574                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
22575                            }
22576    
22577                            String sql = query.toString();
22578    
22579                            Session session = null;
22580    
22581                            try {
22582                                    session = openSession();
22583    
22584                                    Query q = session.createQuery(sql);
22585    
22586                                    QueryPos qPos = QueryPos.getInstance(q);
22587    
22588                                    qPos.add(groupId);
22589    
22590                                    qPos.add(classNameId);
22591    
22592                                    if (bindLayoutUuid) {
22593                                            qPos.add(layoutUuid);
22594                                    }
22595    
22596                                    if (!pagination) {
22597                                            list = (List<JournalArticle>)QueryUtil.list(q,
22598                                                            getDialect(), start, end, false);
22599    
22600                                            Collections.sort(list);
22601    
22602                                            list = new UnmodifiableList<JournalArticle>(list);
22603                                    }
22604                                    else {
22605                                            list = (List<JournalArticle>)QueryUtil.list(q,
22606                                                            getDialect(), start, end);
22607                                    }
22608    
22609                                    cacheResult(list);
22610    
22611                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
22612                            }
22613                            catch (Exception e) {
22614                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
22615    
22616                                    throw processException(e);
22617                            }
22618                            finally {
22619                                    closeSession(session);
22620                            }
22621                    }
22622    
22623                    return list;
22624            }
22625    
22626            /**
22627             * Returns the first journal article in the ordered set where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22628             *
22629             * @param groupId the group ID
22630             * @param classNameId the class name ID
22631             * @param layoutUuid the layout uuid
22632             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
22633             * @return the first matching journal article
22634             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
22635             * @throws SystemException if a system exception occurred
22636             */
22637            @Override
22638            public JournalArticle findByG_C_L_First(long groupId, long classNameId,
22639                    String layoutUuid, OrderByComparator orderByComparator)
22640                    throws NoSuchArticleException, SystemException {
22641                    JournalArticle journalArticle = fetchByG_C_L_First(groupId,
22642                                    classNameId, layoutUuid, orderByComparator);
22643    
22644                    if (journalArticle != null) {
22645                            return journalArticle;
22646                    }
22647    
22648                    StringBundler msg = new StringBundler(8);
22649    
22650                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
22651    
22652                    msg.append("groupId=");
22653                    msg.append(groupId);
22654    
22655                    msg.append(", classNameId=");
22656                    msg.append(classNameId);
22657    
22658                    msg.append(", layoutUuid=");
22659                    msg.append(layoutUuid);
22660    
22661                    msg.append(StringPool.CLOSE_CURLY_BRACE);
22662    
22663                    throw new NoSuchArticleException(msg.toString());
22664            }
22665    
22666            /**
22667             * Returns the first journal article in the ordered set where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22668             *
22669             * @param groupId the group ID
22670             * @param classNameId the class name ID
22671             * @param layoutUuid the layout uuid
22672             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
22673             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
22674             * @throws SystemException if a system exception occurred
22675             */
22676            @Override
22677            public JournalArticle fetchByG_C_L_First(long groupId, long classNameId,
22678                    String layoutUuid, OrderByComparator orderByComparator)
22679                    throws SystemException {
22680                    List<JournalArticle> list = findByG_C_L(groupId, classNameId,
22681                                    layoutUuid, 0, 1, orderByComparator);
22682    
22683                    if (!list.isEmpty()) {
22684                            return list.get(0);
22685                    }
22686    
22687                    return null;
22688            }
22689    
22690            /**
22691             * Returns the last journal article in the ordered set where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22692             *
22693             * @param groupId the group ID
22694             * @param classNameId the class name ID
22695             * @param layoutUuid the layout uuid
22696             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
22697             * @return the last matching journal article
22698             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
22699             * @throws SystemException if a system exception occurred
22700             */
22701            @Override
22702            public JournalArticle findByG_C_L_Last(long groupId, long classNameId,
22703                    String layoutUuid, OrderByComparator orderByComparator)
22704                    throws NoSuchArticleException, SystemException {
22705                    JournalArticle journalArticle = fetchByG_C_L_Last(groupId, classNameId,
22706                                    layoutUuid, orderByComparator);
22707    
22708                    if (journalArticle != null) {
22709                            return journalArticle;
22710                    }
22711    
22712                    StringBundler msg = new StringBundler(8);
22713    
22714                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
22715    
22716                    msg.append("groupId=");
22717                    msg.append(groupId);
22718    
22719                    msg.append(", classNameId=");
22720                    msg.append(classNameId);
22721    
22722                    msg.append(", layoutUuid=");
22723                    msg.append(layoutUuid);
22724    
22725                    msg.append(StringPool.CLOSE_CURLY_BRACE);
22726    
22727                    throw new NoSuchArticleException(msg.toString());
22728            }
22729    
22730            /**
22731             * Returns the last journal article in the ordered set where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22732             *
22733             * @param groupId the group ID
22734             * @param classNameId the class name ID
22735             * @param layoutUuid the layout uuid
22736             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
22737             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
22738             * @throws SystemException if a system exception occurred
22739             */
22740            @Override
22741            public JournalArticle fetchByG_C_L_Last(long groupId, long classNameId,
22742                    String layoutUuid, OrderByComparator orderByComparator)
22743                    throws SystemException {
22744                    int count = countByG_C_L(groupId, classNameId, layoutUuid);
22745    
22746                    if (count == 0) {
22747                            return null;
22748                    }
22749    
22750                    List<JournalArticle> list = findByG_C_L(groupId, classNameId,
22751                                    layoutUuid, count - 1, count, orderByComparator);
22752    
22753                    if (!list.isEmpty()) {
22754                            return list.get(0);
22755                    }
22756    
22757                    return null;
22758            }
22759    
22760            /**
22761             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22762             *
22763             * @param id the primary key of the current journal article
22764             * @param groupId the group ID
22765             * @param classNameId the class name ID
22766             * @param layoutUuid the layout uuid
22767             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
22768             * @return the previous, current, and next journal article
22769             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
22770             * @throws SystemException if a system exception occurred
22771             */
22772            @Override
22773            public JournalArticle[] findByG_C_L_PrevAndNext(long id, long groupId,
22774                    long classNameId, String layoutUuid, OrderByComparator orderByComparator)
22775                    throws NoSuchArticleException, SystemException {
22776                    JournalArticle journalArticle = findByPrimaryKey(id);
22777    
22778                    Session session = null;
22779    
22780                    try {
22781                            session = openSession();
22782    
22783                            JournalArticle[] array = new JournalArticleImpl[3];
22784    
22785                            array[0] = getByG_C_L_PrevAndNext(session, journalArticle, groupId,
22786                                            classNameId, layoutUuid, orderByComparator, true);
22787    
22788                            array[1] = journalArticle;
22789    
22790                            array[2] = getByG_C_L_PrevAndNext(session, journalArticle, groupId,
22791                                            classNameId, layoutUuid, orderByComparator, false);
22792    
22793                            return array;
22794                    }
22795                    catch (Exception e) {
22796                            throw processException(e);
22797                    }
22798                    finally {
22799                            closeSession(session);
22800                    }
22801            }
22802    
22803            protected JournalArticle getByG_C_L_PrevAndNext(Session session,
22804                    JournalArticle journalArticle, long groupId, long classNameId,
22805                    String layoutUuid, OrderByComparator orderByComparator, boolean previous) {
22806                    StringBundler query = null;
22807    
22808                    if (orderByComparator != null) {
22809                            query = new StringBundler(6 +
22810                                            (orderByComparator.getOrderByFields().length * 6));
22811                    }
22812                    else {
22813                            query = new StringBundler(3);
22814                    }
22815    
22816                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
22817    
22818                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
22819    
22820                    query.append(_FINDER_COLUMN_G_C_L_CLASSNAMEID_2);
22821    
22822                    boolean bindLayoutUuid = false;
22823    
22824                    if (layoutUuid == null) {
22825                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_1);
22826                    }
22827                    else if (layoutUuid.equals(StringPool.BLANK)) {
22828                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_3);
22829                    }
22830                    else {
22831                            bindLayoutUuid = true;
22832    
22833                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_2);
22834                    }
22835    
22836                    if (orderByComparator != null) {
22837                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
22838    
22839                            if (orderByConditionFields.length > 0) {
22840                                    query.append(WHERE_AND);
22841                            }
22842    
22843                            for (int i = 0; i < orderByConditionFields.length; i++) {
22844                                    query.append(_ORDER_BY_ENTITY_ALIAS);
22845                                    query.append(orderByConditionFields[i]);
22846    
22847                                    if ((i + 1) < orderByConditionFields.length) {
22848                                            if (orderByComparator.isAscending() ^ previous) {
22849                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
22850                                            }
22851                                            else {
22852                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
22853                                            }
22854                                    }
22855                                    else {
22856                                            if (orderByComparator.isAscending() ^ previous) {
22857                                                    query.append(WHERE_GREATER_THAN);
22858                                            }
22859                                            else {
22860                                                    query.append(WHERE_LESSER_THAN);
22861                                            }
22862                                    }
22863                            }
22864    
22865                            query.append(ORDER_BY_CLAUSE);
22866    
22867                            String[] orderByFields = orderByComparator.getOrderByFields();
22868    
22869                            for (int i = 0; i < orderByFields.length; i++) {
22870                                    query.append(_ORDER_BY_ENTITY_ALIAS);
22871                                    query.append(orderByFields[i]);
22872    
22873                                    if ((i + 1) < orderByFields.length) {
22874                                            if (orderByComparator.isAscending() ^ previous) {
22875                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
22876                                            }
22877                                            else {
22878                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
22879                                            }
22880                                    }
22881                                    else {
22882                                            if (orderByComparator.isAscending() ^ previous) {
22883                                                    query.append(ORDER_BY_ASC);
22884                                            }
22885                                            else {
22886                                                    query.append(ORDER_BY_DESC);
22887                                            }
22888                                    }
22889                            }
22890                    }
22891                    else {
22892                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
22893                    }
22894    
22895                    String sql = query.toString();
22896    
22897                    Query q = session.createQuery(sql);
22898    
22899                    q.setFirstResult(0);
22900                    q.setMaxResults(2);
22901    
22902                    QueryPos qPos = QueryPos.getInstance(q);
22903    
22904                    qPos.add(groupId);
22905    
22906                    qPos.add(classNameId);
22907    
22908                    if (bindLayoutUuid) {
22909                            qPos.add(layoutUuid);
22910                    }
22911    
22912                    if (orderByComparator != null) {
22913                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
22914    
22915                            for (Object value : values) {
22916                                    qPos.add(value);
22917                            }
22918                    }
22919    
22920                    List<JournalArticle> list = q.list();
22921    
22922                    if (list.size() == 2) {
22923                            return list.get(1);
22924                    }
22925                    else {
22926                            return null;
22927                    }
22928            }
22929    
22930            /**
22931             * Returns all the journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22932             *
22933             * @param groupId the group ID
22934             * @param classNameId the class name ID
22935             * @param layoutUuid the layout uuid
22936             * @return the matching journal articles that the user has permission to view
22937             * @throws SystemException if a system exception occurred
22938             */
22939            @Override
22940            public List<JournalArticle> filterFindByG_C_L(long groupId,
22941                    long classNameId, String layoutUuid) throws SystemException {
22942                    return filterFindByG_C_L(groupId, classNameId, layoutUuid,
22943                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
22944            }
22945    
22946            /**
22947             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22948             *
22949             * <p>
22950             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
22951             * </p>
22952             *
22953             * @param groupId the group ID
22954             * @param classNameId the class name ID
22955             * @param layoutUuid the layout uuid
22956             * @param start the lower bound of the range of journal articles
22957             * @param end the upper bound of the range of journal articles (not inclusive)
22958             * @return the range of matching journal articles that the user has permission to view
22959             * @throws SystemException if a system exception occurred
22960             */
22961            @Override
22962            public List<JournalArticle> filterFindByG_C_L(long groupId,
22963                    long classNameId, String layoutUuid, int start, int end)
22964                    throws SystemException {
22965                    return filterFindByG_C_L(groupId, classNameId, layoutUuid, start, end,
22966                            null);
22967            }
22968    
22969            /**
22970             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
22971             *
22972             * <p>
22973             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
22974             * </p>
22975             *
22976             * @param groupId the group ID
22977             * @param classNameId the class name ID
22978             * @param layoutUuid the layout uuid
22979             * @param start the lower bound of the range of journal articles
22980             * @param end the upper bound of the range of journal articles (not inclusive)
22981             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
22982             * @return the ordered range of matching journal articles that the user has permission to view
22983             * @throws SystemException if a system exception occurred
22984             */
22985            @Override
22986            public List<JournalArticle> filterFindByG_C_L(long groupId,
22987                    long classNameId, String layoutUuid, int start, int end,
22988                    OrderByComparator orderByComparator) throws SystemException {
22989                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
22990                            return findByG_C_L(groupId, classNameId, layoutUuid, start, end,
22991                                    orderByComparator);
22992                    }
22993    
22994                    StringBundler query = null;
22995    
22996                    if (orderByComparator != null) {
22997                            query = new StringBundler(5 +
22998                                            (orderByComparator.getOrderByFields().length * 3));
22999                    }
23000                    else {
23001                            query = new StringBundler(5);
23002                    }
23003    
23004                    if (getDB().isSupportsInlineDistinct()) {
23005                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
23006                    }
23007                    else {
23008                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
23009                    }
23010    
23011                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
23012    
23013                    query.append(_FINDER_COLUMN_G_C_L_CLASSNAMEID_2);
23014    
23015                    boolean bindLayoutUuid = false;
23016    
23017                    if (layoutUuid == null) {
23018                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_1);
23019                    }
23020                    else if (layoutUuid.equals(StringPool.BLANK)) {
23021                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_3);
23022                    }
23023                    else {
23024                            bindLayoutUuid = true;
23025    
23026                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_2);
23027                    }
23028    
23029                    if (!getDB().isSupportsInlineDistinct()) {
23030                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
23031                    }
23032    
23033                    if (orderByComparator != null) {
23034                            if (getDB().isSupportsInlineDistinct()) {
23035                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
23036                                            orderByComparator, true);
23037                            }
23038                            else {
23039                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
23040                                            orderByComparator, true);
23041                            }
23042                    }
23043                    else {
23044                            if (getDB().isSupportsInlineDistinct()) {
23045                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
23046                            }
23047                            else {
23048                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
23049                            }
23050                    }
23051    
23052                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
23053                                    JournalArticle.class.getName(),
23054                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
23055    
23056                    Session session = null;
23057    
23058                    try {
23059                            session = openSession();
23060    
23061                            SQLQuery q = session.createSQLQuery(sql);
23062    
23063                            if (getDB().isSupportsInlineDistinct()) {
23064                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
23065                            }
23066                            else {
23067                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
23068                            }
23069    
23070                            QueryPos qPos = QueryPos.getInstance(q);
23071    
23072                            qPos.add(groupId);
23073    
23074                            qPos.add(classNameId);
23075    
23076                            if (bindLayoutUuid) {
23077                                    qPos.add(layoutUuid);
23078                            }
23079    
23080                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
23081                                    end);
23082                    }
23083                    catch (Exception e) {
23084                            throw processException(e);
23085                    }
23086                    finally {
23087                            closeSession(session);
23088                    }
23089            }
23090    
23091            /**
23092             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
23093             *
23094             * @param id the primary key of the current journal article
23095             * @param groupId the group ID
23096             * @param classNameId the class name ID
23097             * @param layoutUuid the layout uuid
23098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
23099             * @return the previous, current, and next journal article
23100             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
23101             * @throws SystemException if a system exception occurred
23102             */
23103            @Override
23104            public JournalArticle[] filterFindByG_C_L_PrevAndNext(long id,
23105                    long groupId, long classNameId, String layoutUuid,
23106                    OrderByComparator orderByComparator)
23107                    throws NoSuchArticleException, SystemException {
23108                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
23109                            return findByG_C_L_PrevAndNext(id, groupId, classNameId,
23110                                    layoutUuid, orderByComparator);
23111                    }
23112    
23113                    JournalArticle journalArticle = findByPrimaryKey(id);
23114    
23115                    Session session = null;
23116    
23117                    try {
23118                            session = openSession();
23119    
23120                            JournalArticle[] array = new JournalArticleImpl[3];
23121    
23122                            array[0] = filterGetByG_C_L_PrevAndNext(session, journalArticle,
23123                                            groupId, classNameId, layoutUuid, orderByComparator, true);
23124    
23125                            array[1] = journalArticle;
23126    
23127                            array[2] = filterGetByG_C_L_PrevAndNext(session, journalArticle,
23128                                            groupId, classNameId, layoutUuid, orderByComparator, false);
23129    
23130                            return array;
23131                    }
23132                    catch (Exception e) {
23133                            throw processException(e);
23134                    }
23135                    finally {
23136                            closeSession(session);
23137                    }
23138            }
23139    
23140            protected JournalArticle filterGetByG_C_L_PrevAndNext(Session session,
23141                    JournalArticle journalArticle, long groupId, long classNameId,
23142                    String layoutUuid, OrderByComparator orderByComparator, boolean previous) {
23143                    StringBundler query = null;
23144    
23145                    if (orderByComparator != null) {
23146                            query = new StringBundler(6 +
23147                                            (orderByComparator.getOrderByFields().length * 6));
23148                    }
23149                    else {
23150                            query = new StringBundler(3);
23151                    }
23152    
23153                    if (getDB().isSupportsInlineDistinct()) {
23154                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
23155                    }
23156                    else {
23157                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
23158                    }
23159    
23160                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
23161    
23162                    query.append(_FINDER_COLUMN_G_C_L_CLASSNAMEID_2);
23163    
23164                    boolean bindLayoutUuid = false;
23165    
23166                    if (layoutUuid == null) {
23167                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_1);
23168                    }
23169                    else if (layoutUuid.equals(StringPool.BLANK)) {
23170                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_3);
23171                    }
23172                    else {
23173                            bindLayoutUuid = true;
23174    
23175                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_2);
23176                    }
23177    
23178                    if (!getDB().isSupportsInlineDistinct()) {
23179                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
23180                    }
23181    
23182                    if (orderByComparator != null) {
23183                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
23184    
23185                            if (orderByConditionFields.length > 0) {
23186                                    query.append(WHERE_AND);
23187                            }
23188    
23189                            for (int i = 0; i < orderByConditionFields.length; i++) {
23190                                    if (getDB().isSupportsInlineDistinct()) {
23191                                            query.append(_ORDER_BY_ENTITY_ALIAS);
23192                                    }
23193                                    else {
23194                                            query.append(_ORDER_BY_ENTITY_TABLE);
23195                                    }
23196    
23197                                    query.append(orderByConditionFields[i]);
23198    
23199                                    if ((i + 1) < orderByConditionFields.length) {
23200                                            if (orderByComparator.isAscending() ^ previous) {
23201                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
23202                                            }
23203                                            else {
23204                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
23205                                            }
23206                                    }
23207                                    else {
23208                                            if (orderByComparator.isAscending() ^ previous) {
23209                                                    query.append(WHERE_GREATER_THAN);
23210                                            }
23211                                            else {
23212                                                    query.append(WHERE_LESSER_THAN);
23213                                            }
23214                                    }
23215                            }
23216    
23217                            query.append(ORDER_BY_CLAUSE);
23218    
23219                            String[] orderByFields = orderByComparator.getOrderByFields();
23220    
23221                            for (int i = 0; i < orderByFields.length; i++) {
23222                                    if (getDB().isSupportsInlineDistinct()) {
23223                                            query.append(_ORDER_BY_ENTITY_ALIAS);
23224                                    }
23225                                    else {
23226                                            query.append(_ORDER_BY_ENTITY_TABLE);
23227                                    }
23228    
23229                                    query.append(orderByFields[i]);
23230    
23231                                    if ((i + 1) < orderByFields.length) {
23232                                            if (orderByComparator.isAscending() ^ previous) {
23233                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
23234                                            }
23235                                            else {
23236                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
23237                                            }
23238                                    }
23239                                    else {
23240                                            if (orderByComparator.isAscending() ^ previous) {
23241                                                    query.append(ORDER_BY_ASC);
23242                                            }
23243                                            else {
23244                                                    query.append(ORDER_BY_DESC);
23245                                            }
23246                                    }
23247                            }
23248                    }
23249                    else {
23250                            if (getDB().isSupportsInlineDistinct()) {
23251                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
23252                            }
23253                            else {
23254                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
23255                            }
23256                    }
23257    
23258                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
23259                                    JournalArticle.class.getName(),
23260                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
23261    
23262                    SQLQuery q = session.createSQLQuery(sql);
23263    
23264                    q.setFirstResult(0);
23265                    q.setMaxResults(2);
23266    
23267                    if (getDB().isSupportsInlineDistinct()) {
23268                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
23269                    }
23270                    else {
23271                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
23272                    }
23273    
23274                    QueryPos qPos = QueryPos.getInstance(q);
23275    
23276                    qPos.add(groupId);
23277    
23278                    qPos.add(classNameId);
23279    
23280                    if (bindLayoutUuid) {
23281                            qPos.add(layoutUuid);
23282                    }
23283    
23284                    if (orderByComparator != null) {
23285                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
23286    
23287                            for (Object value : values) {
23288                                    qPos.add(value);
23289                            }
23290                    }
23291    
23292                    List<JournalArticle> list = q.list();
23293    
23294                    if (list.size() == 2) {
23295                            return list.get(1);
23296                    }
23297                    else {
23298                            return null;
23299                    }
23300            }
23301    
23302            /**
23303             * Removes all the journal articles where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63; from the database.
23304             *
23305             * @param groupId the group ID
23306             * @param classNameId the class name ID
23307             * @param layoutUuid the layout uuid
23308             * @throws SystemException if a system exception occurred
23309             */
23310            @Override
23311            public void removeByG_C_L(long groupId, long classNameId, String layoutUuid)
23312                    throws SystemException {
23313                    for (JournalArticle journalArticle : findByG_C_L(groupId, classNameId,
23314                                    layoutUuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
23315                            remove(journalArticle);
23316                    }
23317            }
23318    
23319            /**
23320             * Returns the number of journal articles where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
23321             *
23322             * @param groupId the group ID
23323             * @param classNameId the class name ID
23324             * @param layoutUuid the layout uuid
23325             * @return the number of matching journal articles
23326             * @throws SystemException if a system exception occurred
23327             */
23328            @Override
23329            public int countByG_C_L(long groupId, long classNameId, String layoutUuid)
23330                    throws SystemException {
23331                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_L;
23332    
23333                    Object[] finderArgs = new Object[] { groupId, classNameId, layoutUuid };
23334    
23335                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
23336                                    this);
23337    
23338                    if (count == null) {
23339                            StringBundler query = new StringBundler(4);
23340    
23341                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
23342    
23343                            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
23344    
23345                            query.append(_FINDER_COLUMN_G_C_L_CLASSNAMEID_2);
23346    
23347                            boolean bindLayoutUuid = false;
23348    
23349                            if (layoutUuid == null) {
23350                                    query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_1);
23351                            }
23352                            else if (layoutUuid.equals(StringPool.BLANK)) {
23353                                    query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_3);
23354                            }
23355                            else {
23356                                    bindLayoutUuid = true;
23357    
23358                                    query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_2);
23359                            }
23360    
23361                            String sql = query.toString();
23362    
23363                            Session session = null;
23364    
23365                            try {
23366                                    session = openSession();
23367    
23368                                    Query q = session.createQuery(sql);
23369    
23370                                    QueryPos qPos = QueryPos.getInstance(q);
23371    
23372                                    qPos.add(groupId);
23373    
23374                                    qPos.add(classNameId);
23375    
23376                                    if (bindLayoutUuid) {
23377                                            qPos.add(layoutUuid);
23378                                    }
23379    
23380                                    count = (Long)q.uniqueResult();
23381    
23382                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
23383                            }
23384                            catch (Exception e) {
23385                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
23386    
23387                                    throw processException(e);
23388                            }
23389                            finally {
23390                                    closeSession(session);
23391                            }
23392                    }
23393    
23394                    return count.intValue();
23395            }
23396    
23397            /**
23398             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and classNameId = &#63; and layoutUuid = &#63;.
23399             *
23400             * @param groupId the group ID
23401             * @param classNameId the class name ID
23402             * @param layoutUuid the layout uuid
23403             * @return the number of matching journal articles that the user has permission to view
23404             * @throws SystemException if a system exception occurred
23405             */
23406            @Override
23407            public int filterCountByG_C_L(long groupId, long classNameId,
23408                    String layoutUuid) throws SystemException {
23409                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
23410                            return countByG_C_L(groupId, classNameId, layoutUuid);
23411                    }
23412    
23413                    StringBundler query = new StringBundler(4);
23414    
23415                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
23416    
23417                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
23418    
23419                    query.append(_FINDER_COLUMN_G_C_L_CLASSNAMEID_2);
23420    
23421                    boolean bindLayoutUuid = false;
23422    
23423                    if (layoutUuid == null) {
23424                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_1);
23425                    }
23426                    else if (layoutUuid.equals(StringPool.BLANK)) {
23427                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_3);
23428                    }
23429                    else {
23430                            bindLayoutUuid = true;
23431    
23432                            query.append(_FINDER_COLUMN_G_C_L_LAYOUTUUID_2);
23433                    }
23434    
23435                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
23436                                    JournalArticle.class.getName(),
23437                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
23438    
23439                    Session session = null;
23440    
23441                    try {
23442                            session = openSession();
23443    
23444                            SQLQuery q = session.createSQLQuery(sql);
23445    
23446                            q.addScalar(COUNT_COLUMN_NAME,
23447                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
23448    
23449                            QueryPos qPos = QueryPos.getInstance(q);
23450    
23451                            qPos.add(groupId);
23452    
23453                            qPos.add(classNameId);
23454    
23455                            if (bindLayoutUuid) {
23456                                    qPos.add(layoutUuid);
23457                            }
23458    
23459                            Long count = (Long)q.uniqueResult();
23460    
23461                            return count.intValue();
23462                    }
23463                    catch (Exception e) {
23464                            throw processException(e);
23465                    }
23466                    finally {
23467                            closeSession(session);
23468                    }
23469            }
23470    
23471            private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "journalArticle.groupId = ? AND ";
23472            private static final String _FINDER_COLUMN_G_C_L_CLASSNAMEID_2 = "journalArticle.classNameId = ? AND ";
23473            private static final String _FINDER_COLUMN_G_C_L_LAYOUTUUID_1 = "journalArticle.layoutUuid IS NULL";
23474            private static final String _FINDER_COLUMN_G_C_L_LAYOUTUUID_2 = "journalArticle.layoutUuid = ?";
23475            private static final String _FINDER_COLUMN_G_C_L_LAYOUTUUID_3 = "(journalArticle.layoutUuid IS NULL OR journalArticle.layoutUuid = '')";
23476            public static final FinderPath FINDER_PATH_FETCH_BY_G_A_V = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
23477                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
23478                            JournalArticleImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_A_V",
23479                            new String[] {
23480                                    Long.class.getName(), String.class.getName(),
23481                                    Double.class.getName()
23482                            },
23483                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
23484                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
23485                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
23486            public static final FinderPath FINDER_PATH_COUNT_BY_G_A_V = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
23487                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
23488                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A_V",
23489                            new String[] {
23490                                    Long.class.getName(), String.class.getName(),
23491                                    Double.class.getName()
23492                            });
23493    
23494            /**
23495             * Returns the journal article where groupId = &#63; and articleId = &#63; and version = &#63; or throws a {@link com.liferay.portlet.journal.NoSuchArticleException} if it could not be found.
23496             *
23497             * @param groupId the group ID
23498             * @param articleId the article ID
23499             * @param version the version
23500             * @return the matching journal article
23501             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
23502             * @throws SystemException if a system exception occurred
23503             */
23504            @Override
23505            public JournalArticle findByG_A_V(long groupId, String articleId,
23506                    double version) throws NoSuchArticleException, SystemException {
23507                    JournalArticle journalArticle = fetchByG_A_V(groupId, articleId, version);
23508    
23509                    if (journalArticle == null) {
23510                            StringBundler msg = new StringBundler(8);
23511    
23512                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
23513    
23514                            msg.append("groupId=");
23515                            msg.append(groupId);
23516    
23517                            msg.append(", articleId=");
23518                            msg.append(articleId);
23519    
23520                            msg.append(", version=");
23521                            msg.append(version);
23522    
23523                            msg.append(StringPool.CLOSE_CURLY_BRACE);
23524    
23525                            if (_log.isWarnEnabled()) {
23526                                    _log.warn(msg.toString());
23527                            }
23528    
23529                            throw new NoSuchArticleException(msg.toString());
23530                    }
23531    
23532                    return journalArticle;
23533            }
23534    
23535            /**
23536             * Returns the journal article where groupId = &#63; and articleId = &#63; and version = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
23537             *
23538             * @param groupId the group ID
23539             * @param articleId the article ID
23540             * @param version the version
23541             * @return the matching journal article, or <code>null</code> if a matching journal article could not be found
23542             * @throws SystemException if a system exception occurred
23543             */
23544            @Override
23545            public JournalArticle fetchByG_A_V(long groupId, String articleId,
23546                    double version) throws SystemException {
23547                    return fetchByG_A_V(groupId, articleId, version, true);
23548            }
23549    
23550            /**
23551             * Returns the journal article where groupId = &#63; and articleId = &#63; and version = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
23552             *
23553             * @param groupId the group ID
23554             * @param articleId the article ID
23555             * @param version the version
23556             * @param retrieveFromCache whether to use the finder cache
23557             * @return the matching journal article, or <code>null</code> if a matching journal article could not be found
23558             * @throws SystemException if a system exception occurred
23559             */
23560            @Override
23561            public JournalArticle fetchByG_A_V(long groupId, String articleId,
23562                    double version, boolean retrieveFromCache) throws SystemException {
23563                    Object[] finderArgs = new Object[] { groupId, articleId, version };
23564    
23565                    Object result = null;
23566    
23567                    if (retrieveFromCache) {
23568                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_A_V,
23569                                            finderArgs, this);
23570                    }
23571    
23572                    if (result instanceof JournalArticle) {
23573                            JournalArticle journalArticle = (JournalArticle)result;
23574    
23575                            if ((groupId != journalArticle.getGroupId()) ||
23576                                            !Validator.equals(articleId, journalArticle.getArticleId()) ||
23577                                            (version != journalArticle.getVersion())) {
23578                                    result = null;
23579                            }
23580                    }
23581    
23582                    if (result == null) {
23583                            StringBundler query = new StringBundler(5);
23584    
23585                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
23586    
23587                            query.append(_FINDER_COLUMN_G_A_V_GROUPID_2);
23588    
23589                            boolean bindArticleId = false;
23590    
23591                            if (articleId == null) {
23592                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_1);
23593                            }
23594                            else if (articleId.equals(StringPool.BLANK)) {
23595                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_3);
23596                            }
23597                            else {
23598                                    bindArticleId = true;
23599    
23600                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_2);
23601                            }
23602    
23603                            query.append(_FINDER_COLUMN_G_A_V_VERSION_2);
23604    
23605                            String sql = query.toString();
23606    
23607                            Session session = null;
23608    
23609                            try {
23610                                    session = openSession();
23611    
23612                                    Query q = session.createQuery(sql);
23613    
23614                                    QueryPos qPos = QueryPos.getInstance(q);
23615    
23616                                    qPos.add(groupId);
23617    
23618                                    if (bindArticleId) {
23619                                            qPos.add(articleId);
23620                                    }
23621    
23622                                    qPos.add(version);
23623    
23624                                    List<JournalArticle> list = q.list();
23625    
23626                                    if (list.isEmpty()) {
23627                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V,
23628                                                    finderArgs, list);
23629                                    }
23630                                    else {
23631                                            JournalArticle journalArticle = list.get(0);
23632    
23633                                            result = journalArticle;
23634    
23635                                            cacheResult(journalArticle);
23636    
23637                                            if ((journalArticle.getGroupId() != groupId) ||
23638                                                            (journalArticle.getArticleId() == null) ||
23639                                                            !journalArticle.getArticleId().equals(articleId) ||
23640                                                            (journalArticle.getVersion() != version)) {
23641                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V,
23642                                                            finderArgs, journalArticle);
23643                                            }
23644                                    }
23645                            }
23646                            catch (Exception e) {
23647                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V,
23648                                            finderArgs);
23649    
23650                                    throw processException(e);
23651                            }
23652                            finally {
23653                                    closeSession(session);
23654                            }
23655                    }
23656    
23657                    if (result instanceof List<?>) {
23658                            return null;
23659                    }
23660                    else {
23661                            return (JournalArticle)result;
23662                    }
23663            }
23664    
23665            /**
23666             * Removes the journal article where groupId = &#63; and articleId = &#63; and version = &#63; from the database.
23667             *
23668             * @param groupId the group ID
23669             * @param articleId the article ID
23670             * @param version the version
23671             * @return the journal article that was removed
23672             * @throws SystemException if a system exception occurred
23673             */
23674            @Override
23675            public JournalArticle removeByG_A_V(long groupId, String articleId,
23676                    double version) throws NoSuchArticleException, SystemException {
23677                    JournalArticle journalArticle = findByG_A_V(groupId, articleId, version);
23678    
23679                    return remove(journalArticle);
23680            }
23681    
23682            /**
23683             * Returns the number of journal articles where groupId = &#63; and articleId = &#63; and version = &#63;.
23684             *
23685             * @param groupId the group ID
23686             * @param articleId the article ID
23687             * @param version the version
23688             * @return the number of matching journal articles
23689             * @throws SystemException if a system exception occurred
23690             */
23691            @Override
23692            public int countByG_A_V(long groupId, String articleId, double version)
23693                    throws SystemException {
23694                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_A_V;
23695    
23696                    Object[] finderArgs = new Object[] { groupId, articleId, version };
23697    
23698                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
23699                                    this);
23700    
23701                    if (count == null) {
23702                            StringBundler query = new StringBundler(4);
23703    
23704                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
23705    
23706                            query.append(_FINDER_COLUMN_G_A_V_GROUPID_2);
23707    
23708                            boolean bindArticleId = false;
23709    
23710                            if (articleId == null) {
23711                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_1);
23712                            }
23713                            else if (articleId.equals(StringPool.BLANK)) {
23714                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_3);
23715                            }
23716                            else {
23717                                    bindArticleId = true;
23718    
23719                                    query.append(_FINDER_COLUMN_G_A_V_ARTICLEID_2);
23720                            }
23721    
23722                            query.append(_FINDER_COLUMN_G_A_V_VERSION_2);
23723    
23724                            String sql = query.toString();
23725    
23726                            Session session = null;
23727    
23728                            try {
23729                                    session = openSession();
23730    
23731                                    Query q = session.createQuery(sql);
23732    
23733                                    QueryPos qPos = QueryPos.getInstance(q);
23734    
23735                                    qPos.add(groupId);
23736    
23737                                    if (bindArticleId) {
23738                                            qPos.add(articleId);
23739                                    }
23740    
23741                                    qPos.add(version);
23742    
23743                                    count = (Long)q.uniqueResult();
23744    
23745                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
23746                            }
23747                            catch (Exception e) {
23748                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
23749    
23750                                    throw processException(e);
23751                            }
23752                            finally {
23753                                    closeSession(session);
23754                            }
23755                    }
23756    
23757                    return count.intValue();
23758            }
23759    
23760            private static final String _FINDER_COLUMN_G_A_V_GROUPID_2 = "journalArticle.groupId = ? AND ";
23761            private static final String _FINDER_COLUMN_G_A_V_ARTICLEID_1 = "journalArticle.articleId IS NULL AND ";
23762            private static final String _FINDER_COLUMN_G_A_V_ARTICLEID_2 = "journalArticle.articleId = ? AND ";
23763            private static final String _FINDER_COLUMN_G_A_V_ARTICLEID_3 = "(journalArticle.articleId IS NULL OR journalArticle.articleId = '') AND ";
23764            private static final String _FINDER_COLUMN_G_A_V_VERSION_2 = "journalArticle.version = ?";
23765            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
23766                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
23767                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
23768                            "findByG_A_ST",
23769                            new String[] {
23770                                    Long.class.getName(), String.class.getName(),
23771                                    Integer.class.getName(),
23772                                    
23773                            Integer.class.getName(), Integer.class.getName(),
23774                                    OrderByComparator.class.getName()
23775                            });
23776            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_ST =
23777                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
23778                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
23779                            JournalArticleImpl.class,
23780                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_A_ST",
23781                            new String[] {
23782                                    Long.class.getName(), String.class.getName(),
23783                                    Integer.class.getName()
23784                            },
23785                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
23786                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
23787                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
23788                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
23789            public static final FinderPath FINDER_PATH_COUNT_BY_G_A_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
23790                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
23791                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_A_ST",
23792                            new String[] {
23793                                    Long.class.getName(), String.class.getName(),
23794                                    Integer.class.getName()
23795                            });
23796            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_A_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
23797                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
23798                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_A_ST",
23799                            new String[] {
23800                                    Long.class.getName(), String.class.getName(),
23801                                    Integer.class.getName()
23802                            });
23803    
23804            /**
23805             * Returns all the journal articles where groupId = &#63; and articleId = &#63; and status = &#63;.
23806             *
23807             * @param groupId the group ID
23808             * @param articleId the article ID
23809             * @param status the status
23810             * @return the matching journal articles
23811             * @throws SystemException if a system exception occurred
23812             */
23813            @Override
23814            public List<JournalArticle> findByG_A_ST(long groupId, String articleId,
23815                    int status) throws SystemException {
23816                    return findByG_A_ST(groupId, articleId, status, QueryUtil.ALL_POS,
23817                            QueryUtil.ALL_POS, null);
23818            }
23819    
23820            /**
23821             * Returns a range of all the journal articles where groupId = &#63; and articleId = &#63; and status = &#63;.
23822             *
23823             * <p>
23824             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
23825             * </p>
23826             *
23827             * @param groupId the group ID
23828             * @param articleId the article ID
23829             * @param status the status
23830             * @param start the lower bound of the range of journal articles
23831             * @param end the upper bound of the range of journal articles (not inclusive)
23832             * @return the range of matching journal articles
23833             * @throws SystemException if a system exception occurred
23834             */
23835            @Override
23836            public List<JournalArticle> findByG_A_ST(long groupId, String articleId,
23837                    int status, int start, int end) throws SystemException {
23838                    return findByG_A_ST(groupId, articleId, status, start, end, null);
23839            }
23840    
23841            /**
23842             * Returns an ordered range of all the journal articles where groupId = &#63; and articleId = &#63; and status = &#63;.
23843             *
23844             * <p>
23845             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
23846             * </p>
23847             *
23848             * @param groupId the group ID
23849             * @param articleId the article ID
23850             * @param status the status
23851             * @param start the lower bound of the range of journal articles
23852             * @param end the upper bound of the range of journal articles (not inclusive)
23853             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
23854             * @return the ordered range of matching journal articles
23855             * @throws SystemException if a system exception occurred
23856             */
23857            @Override
23858            public List<JournalArticle> findByG_A_ST(long groupId, String articleId,
23859                    int status, int start, int end, OrderByComparator orderByComparator)
23860                    throws SystemException {
23861                    boolean pagination = true;
23862                    FinderPath finderPath = null;
23863                    Object[] finderArgs = null;
23864    
23865                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
23866                                    (orderByComparator == null)) {
23867                            pagination = false;
23868                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_ST;
23869                            finderArgs = new Object[] { groupId, articleId, status };
23870                    }
23871                    else {
23872                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_ST;
23873                            finderArgs = new Object[] {
23874                                            groupId, articleId, status,
23875                                            
23876                                            start, end, orderByComparator
23877                                    };
23878                    }
23879    
23880                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
23881                                    finderArgs, this);
23882    
23883                    if ((list != null) && !list.isEmpty()) {
23884                            for (JournalArticle journalArticle : list) {
23885                                    if ((groupId != journalArticle.getGroupId()) ||
23886                                                    !Validator.equals(articleId,
23887                                                            journalArticle.getArticleId()) ||
23888                                                    (status != journalArticle.getStatus())) {
23889                                            list = null;
23890    
23891                                            break;
23892                                    }
23893                            }
23894                    }
23895    
23896                    if (list == null) {
23897                            StringBundler query = null;
23898    
23899                            if (orderByComparator != null) {
23900                                    query = new StringBundler(5 +
23901                                                    (orderByComparator.getOrderByFields().length * 3));
23902                            }
23903                            else {
23904                                    query = new StringBundler(5);
23905                            }
23906    
23907                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
23908    
23909                            query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);
23910    
23911                            boolean bindArticleId = false;
23912    
23913                            if (articleId == null) {
23914                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
23915                            }
23916                            else if (articleId.equals(StringPool.BLANK)) {
23917                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
23918                            }
23919                            else {
23920                                    bindArticleId = true;
23921    
23922                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
23923                            }
23924    
23925                            query.append(_FINDER_COLUMN_G_A_ST_STATUS_2);
23926    
23927                            if (orderByComparator != null) {
23928                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
23929                                            orderByComparator);
23930                            }
23931                            else
23932                             if (pagination) {
23933                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
23934                            }
23935    
23936                            String sql = query.toString();
23937    
23938                            Session session = null;
23939    
23940                            try {
23941                                    session = openSession();
23942    
23943                                    Query q = session.createQuery(sql);
23944    
23945                                    QueryPos qPos = QueryPos.getInstance(q);
23946    
23947                                    qPos.add(groupId);
23948    
23949                                    if (bindArticleId) {
23950                                            qPos.add(articleId);
23951                                    }
23952    
23953                                    qPos.add(status);
23954    
23955                                    if (!pagination) {
23956                                            list = (List<JournalArticle>)QueryUtil.list(q,
23957                                                            getDialect(), start, end, false);
23958    
23959                                            Collections.sort(list);
23960    
23961                                            list = new UnmodifiableList<JournalArticle>(list);
23962                                    }
23963                                    else {
23964                                            list = (List<JournalArticle>)QueryUtil.list(q,
23965                                                            getDialect(), start, end);
23966                                    }
23967    
23968                                    cacheResult(list);
23969    
23970                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
23971                            }
23972                            catch (Exception e) {
23973                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
23974    
23975                                    throw processException(e);
23976                            }
23977                            finally {
23978                                    closeSession(session);
23979                            }
23980                    }
23981    
23982                    return list;
23983            }
23984    
23985            /**
23986             * Returns the first journal article in the ordered set where groupId = &#63; and articleId = &#63; and status = &#63;.
23987             *
23988             * @param groupId the group ID
23989             * @param articleId the article ID
23990             * @param status the status
23991             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
23992             * @return the first matching journal article
23993             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
23994             * @throws SystemException if a system exception occurred
23995             */
23996            @Override
23997            public JournalArticle findByG_A_ST_First(long groupId, String articleId,
23998                    int status, OrderByComparator orderByComparator)
23999                    throws NoSuchArticleException, SystemException {
24000                    JournalArticle journalArticle = fetchByG_A_ST_First(groupId, articleId,
24001                                    status, orderByComparator);
24002    
24003                    if (journalArticle != null) {
24004                            return journalArticle;
24005                    }
24006    
24007                    StringBundler msg = new StringBundler(8);
24008    
24009                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
24010    
24011                    msg.append("groupId=");
24012                    msg.append(groupId);
24013    
24014                    msg.append(", articleId=");
24015                    msg.append(articleId);
24016    
24017                    msg.append(", status=");
24018                    msg.append(status);
24019    
24020                    msg.append(StringPool.CLOSE_CURLY_BRACE);
24021    
24022                    throw new NoSuchArticleException(msg.toString());
24023            }
24024    
24025            /**
24026             * Returns the first journal article in the ordered set where groupId = &#63; and articleId = &#63; and status = &#63;.
24027             *
24028             * @param groupId the group ID
24029             * @param articleId the article ID
24030             * @param status the status
24031             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
24032             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
24033             * @throws SystemException if a system exception occurred
24034             */
24035            @Override
24036            public JournalArticle fetchByG_A_ST_First(long groupId, String articleId,
24037                    int status, OrderByComparator orderByComparator)
24038                    throws SystemException {
24039                    List<JournalArticle> list = findByG_A_ST(groupId, articleId, status, 0,
24040                                    1, orderByComparator);
24041    
24042                    if (!list.isEmpty()) {
24043                            return list.get(0);
24044                    }
24045    
24046                    return null;
24047            }
24048    
24049            /**
24050             * Returns the last journal article in the ordered set where groupId = &#63; and articleId = &#63; and status = &#63;.
24051             *
24052             * @param groupId the group ID
24053             * @param articleId the article ID
24054             * @param status the status
24055             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
24056             * @return the last matching journal article
24057             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
24058             * @throws SystemException if a system exception occurred
24059             */
24060            @Override
24061            public JournalArticle findByG_A_ST_Last(long groupId, String articleId,
24062                    int status, OrderByComparator orderByComparator)
24063                    throws NoSuchArticleException, SystemException {
24064                    JournalArticle journalArticle = fetchByG_A_ST_Last(groupId, articleId,
24065                                    status, orderByComparator);
24066    
24067                    if (journalArticle != null) {
24068                            return journalArticle;
24069                    }
24070    
24071                    StringBundler msg = new StringBundler(8);
24072    
24073                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
24074    
24075                    msg.append("groupId=");
24076                    msg.append(groupId);
24077    
24078                    msg.append(", articleId=");
24079                    msg.append(articleId);
24080    
24081                    msg.append(", status=");
24082                    msg.append(status);
24083    
24084                    msg.append(StringPool.CLOSE_CURLY_BRACE);
24085    
24086                    throw new NoSuchArticleException(msg.toString());
24087            }
24088    
24089            /**
24090             * Returns the last journal article in the ordered set where groupId = &#63; and articleId = &#63; and status = &#63;.
24091             *
24092             * @param groupId the group ID
24093             * @param articleId the article ID
24094             * @param status the status
24095             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
24096             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
24097             * @throws SystemException if a system exception occurred
24098             */
24099            @Override
24100            public JournalArticle fetchByG_A_ST_Last(long groupId, String articleId,
24101                    int status, OrderByComparator orderByComparator)
24102                    throws SystemException {
24103                    int count = countByG_A_ST(groupId, articleId, status);
24104    
24105                    if (count == 0) {
24106                            return null;
24107                    }
24108    
24109                    List<JournalArticle> list = findByG_A_ST(groupId, articleId, status,
24110                                    count - 1, count, orderByComparator);
24111    
24112                    if (!list.isEmpty()) {
24113                            return list.get(0);
24114                    }
24115    
24116                    return null;
24117            }
24118    
24119            /**
24120             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and articleId = &#63; and status = &#63;.
24121             *
24122             * @param id the primary key of the current journal article
24123             * @param groupId the group ID
24124             * @param articleId the article ID
24125             * @param status the status
24126             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
24127             * @return the previous, current, and next journal article
24128             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
24129             * @throws SystemException if a system exception occurred
24130             */
24131            @Override
24132            public JournalArticle[] findByG_A_ST_PrevAndNext(long id, long groupId,
24133                    String articleId, int status, OrderByComparator orderByComparator)
24134                    throws NoSuchArticleException, SystemException {
24135                    JournalArticle journalArticle = findByPrimaryKey(id);
24136    
24137                    Session session = null;
24138    
24139                    try {
24140                            session = openSession();
24141    
24142                            JournalArticle[] array = new JournalArticleImpl[3];
24143    
24144                            array[0] = getByG_A_ST_PrevAndNext(session, journalArticle,
24145                                            groupId, articleId, status, orderByComparator, true);
24146    
24147                            array[1] = journalArticle;
24148    
24149                            array[2] = getByG_A_ST_PrevAndNext(session, journalArticle,
24150                                            groupId, articleId, status, orderByComparator, false);
24151    
24152                            return array;
24153                    }
24154                    catch (Exception e) {
24155                            throw processException(e);
24156                    }
24157                    finally {
24158                            closeSession(session);
24159                    }
24160            }
24161    
24162            protected JournalArticle getByG_A_ST_PrevAndNext(Session session,
24163                    JournalArticle journalArticle, long groupId, String articleId,
24164                    int status, OrderByComparator orderByComparator, boolean previous) {
24165                    StringBundler query = null;
24166    
24167                    if (orderByComparator != null) {
24168                            query = new StringBundler(6 +
24169                                            (orderByComparator.getOrderByFields().length * 6));
24170                    }
24171                    else {
24172                            query = new StringBundler(3);
24173                    }
24174    
24175                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
24176    
24177                    query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);
24178    
24179                    boolean bindArticleId = false;
24180    
24181                    if (articleId == null) {
24182                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
24183                    }
24184                    else if (articleId.equals(StringPool.BLANK)) {
24185                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
24186                    }
24187                    else {
24188                            bindArticleId = true;
24189    
24190                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
24191                    }
24192    
24193                    query.append(_FINDER_COLUMN_G_A_ST_STATUS_2);
24194    
24195                    if (orderByComparator != null) {
24196                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
24197    
24198                            if (orderByConditionFields.length > 0) {
24199                                    query.append(WHERE_AND);
24200                            }
24201    
24202                            for (int i = 0; i < orderByConditionFields.length; i++) {
24203                                    query.append(_ORDER_BY_ENTITY_ALIAS);
24204                                    query.append(orderByConditionFields[i]);
24205    
24206                                    if ((i + 1) < orderByConditionFields.length) {
24207                                            if (orderByComparator.isAscending() ^ previous) {
24208                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
24209                                            }
24210                                            else {
24211                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
24212                                            }
24213                                    }
24214                                    else {
24215                                            if (orderByComparator.isAscending() ^ previous) {
24216                                                    query.append(WHERE_GREATER_THAN);
24217                                            }
24218                                            else {
24219                                                    query.append(WHERE_LESSER_THAN);
24220                                            }
24221                                    }
24222                            }
24223    
24224                            query.append(ORDER_BY_CLAUSE);
24225    
24226                            String[] orderByFields = orderByComparator.getOrderByFields();
24227    
24228                            for (int i = 0; i < orderByFields.length; i++) {
24229                                    query.append(_ORDER_BY_ENTITY_ALIAS);
24230                                    query.append(orderByFields[i]);
24231    
24232                                    if ((i + 1) < orderByFields.length) {
24233                                            if (orderByComparator.isAscending() ^ previous) {
24234                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
24235                                            }
24236                                            else {
24237                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
24238                                            }
24239                                    }
24240                                    else {
24241                                            if (orderByComparator.isAscending() ^ previous) {
24242                                                    query.append(ORDER_BY_ASC);
24243                                            }
24244                                            else {
24245                                                    query.append(ORDER_BY_DESC);
24246                                            }
24247                                    }
24248                            }
24249                    }
24250                    else {
24251                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
24252                    }
24253    
24254                    String sql = query.toString();
24255    
24256                    Query q = session.createQuery(sql);
24257    
24258                    q.setFirstResult(0);
24259                    q.setMaxResults(2);
24260    
24261                    QueryPos qPos = QueryPos.getInstance(q);
24262    
24263                    qPos.add(groupId);
24264    
24265                    if (bindArticleId) {
24266                            qPos.add(articleId);
24267                    }
24268    
24269                    qPos.add(status);
24270    
24271                    if (orderByComparator != null) {
24272                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
24273    
24274                            for (Object value : values) {
24275                                    qPos.add(value);
24276                            }
24277                    }
24278    
24279                    List<JournalArticle> list = q.list();
24280    
24281                    if (list.size() == 2) {
24282                            return list.get(1);
24283                    }
24284                    else {
24285                            return null;
24286                    }
24287            }
24288    
24289            /**
24290             * Returns all the journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = &#63;.
24291             *
24292             * @param groupId the group ID
24293             * @param articleId the article ID
24294             * @param status the status
24295             * @return the matching journal articles that the user has permission to view
24296             * @throws SystemException if a system exception occurred
24297             */
24298            @Override
24299            public List<JournalArticle> filterFindByG_A_ST(long groupId,
24300                    String articleId, int status) throws SystemException {
24301                    return filterFindByG_A_ST(groupId, articleId, status,
24302                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
24303            }
24304    
24305            /**
24306             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = &#63;.
24307             *
24308             * <p>
24309             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
24310             * </p>
24311             *
24312             * @param groupId the group ID
24313             * @param articleId the article ID
24314             * @param status the status
24315             * @param start the lower bound of the range of journal articles
24316             * @param end the upper bound of the range of journal articles (not inclusive)
24317             * @return the range of matching journal articles that the user has permission to view
24318             * @throws SystemException if a system exception occurred
24319             */
24320            @Override
24321            public List<JournalArticle> filterFindByG_A_ST(long groupId,
24322                    String articleId, int status, int start, int end)
24323                    throws SystemException {
24324                    return filterFindByG_A_ST(groupId, articleId, status, start, end, null);
24325            }
24326    
24327            /**
24328             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and articleId = &#63; and status = &#63;.
24329             *
24330             * <p>
24331             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
24332             * </p>
24333             *
24334             * @param groupId the group ID
24335             * @param articleId the article ID
24336             * @param status the status
24337             * @param start the lower bound of the range of journal articles
24338             * @param end the upper bound of the range of journal articles (not inclusive)
24339             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
24340             * @return the ordered range of matching journal articles that the user has permission to view
24341             * @throws SystemException if a system exception occurred
24342             */
24343            @Override
24344            public List<JournalArticle> filterFindByG_A_ST(long groupId,
24345                    String articleId, int status, int start, int end,
24346                    OrderByComparator orderByComparator) throws SystemException {
24347                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
24348                            return findByG_A_ST(groupId, articleId, status, start, end,
24349                                    orderByComparator);
24350                    }
24351    
24352                    StringBundler query = null;
24353    
24354                    if (orderByComparator != null) {
24355                            query = new StringBundler(5 +
24356                                            (orderByComparator.getOrderByFields().length * 3));
24357                    }
24358                    else {
24359                            query = new StringBundler(5);
24360                    }
24361    
24362                    if (getDB().isSupportsInlineDistinct()) {
24363                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
24364                    }
24365                    else {
24366                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
24367                    }
24368    
24369                    query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);
24370    
24371                    boolean bindArticleId = false;
24372    
24373                    if (articleId == null) {
24374                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
24375                    }
24376                    else if (articleId.equals(StringPool.BLANK)) {
24377                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
24378                    }
24379                    else {
24380                            bindArticleId = true;
24381    
24382                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
24383                    }
24384    
24385                    query.append(_FINDER_COLUMN_G_A_ST_STATUS_2);
24386    
24387                    if (!getDB().isSupportsInlineDistinct()) {
24388                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
24389                    }
24390    
24391                    if (orderByComparator != null) {
24392                            if (getDB().isSupportsInlineDistinct()) {
24393                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
24394                                            orderByComparator, true);
24395                            }
24396                            else {
24397                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
24398                                            orderByComparator, true);
24399                            }
24400                    }
24401                    else {
24402                            if (getDB().isSupportsInlineDistinct()) {
24403                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
24404                            }
24405                            else {
24406                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
24407                            }
24408                    }
24409    
24410                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
24411                                    JournalArticle.class.getName(),
24412                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
24413    
24414                    Session session = null;
24415    
24416                    try {
24417                            session = openSession();
24418    
24419                            SQLQuery q = session.createSQLQuery(sql);
24420    
24421                            if (getDB().isSupportsInlineDistinct()) {
24422                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
24423                            }
24424                            else {
24425                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
24426                            }
24427    
24428                            QueryPos qPos = QueryPos.getInstance(q);
24429    
24430                            qPos.add(groupId);
24431    
24432                            if (bindArticleId) {
24433                                    qPos.add(articleId);
24434                            }
24435    
24436                            qPos.add(status);
24437    
24438                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
24439                                    end);
24440                    }
24441                    catch (Exception e) {
24442                            throw processException(e);
24443                    }
24444                    finally {
24445                            closeSession(session);
24446                    }
24447            }
24448    
24449            /**
24450             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = &#63;.
24451             *
24452             * @param id the primary key of the current journal article
24453             * @param groupId the group ID
24454             * @param articleId the article ID
24455             * @param status the status
24456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
24457             * @return the previous, current, and next journal article
24458             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
24459             * @throws SystemException if a system exception occurred
24460             */
24461            @Override
24462            public JournalArticle[] filterFindByG_A_ST_PrevAndNext(long id,
24463                    long groupId, String articleId, int status,
24464                    OrderByComparator orderByComparator)
24465                    throws NoSuchArticleException, SystemException {
24466                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
24467                            return findByG_A_ST_PrevAndNext(id, groupId, articleId, status,
24468                                    orderByComparator);
24469                    }
24470    
24471                    JournalArticle journalArticle = findByPrimaryKey(id);
24472    
24473                    Session session = null;
24474    
24475                    try {
24476                            session = openSession();
24477    
24478                            JournalArticle[] array = new JournalArticleImpl[3];
24479    
24480                            array[0] = filterGetByG_A_ST_PrevAndNext(session, journalArticle,
24481                                            groupId, articleId, status, orderByComparator, true);
24482    
24483                            array[1] = journalArticle;
24484    
24485                            array[2] = filterGetByG_A_ST_PrevAndNext(session, journalArticle,
24486                                            groupId, articleId, status, orderByComparator, false);
24487    
24488                            return array;
24489                    }
24490                    catch (Exception e) {
24491                            throw processException(e);
24492                    }
24493                    finally {
24494                            closeSession(session);
24495                    }
24496            }
24497    
24498            protected JournalArticle filterGetByG_A_ST_PrevAndNext(Session session,
24499                    JournalArticle journalArticle, long groupId, String articleId,
24500                    int status, OrderByComparator orderByComparator, boolean previous) {
24501                    StringBundler query = null;
24502    
24503                    if (orderByComparator != null) {
24504                            query = new StringBundler(6 +
24505                                            (orderByComparator.getOrderByFields().length * 6));
24506                    }
24507                    else {
24508                            query = new StringBundler(3);
24509                    }
24510    
24511                    if (getDB().isSupportsInlineDistinct()) {
24512                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
24513                    }
24514                    else {
24515                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
24516                    }
24517    
24518                    query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);
24519    
24520                    boolean bindArticleId = false;
24521    
24522                    if (articleId == null) {
24523                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
24524                    }
24525                    else if (articleId.equals(StringPool.BLANK)) {
24526                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
24527                    }
24528                    else {
24529                            bindArticleId = true;
24530    
24531                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
24532                    }
24533    
24534                    query.append(_FINDER_COLUMN_G_A_ST_STATUS_2);
24535    
24536                    if (!getDB().isSupportsInlineDistinct()) {
24537                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
24538                    }
24539    
24540                    if (orderByComparator != null) {
24541                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
24542    
24543                            if (orderByConditionFields.length > 0) {
24544                                    query.append(WHERE_AND);
24545                            }
24546    
24547                            for (int i = 0; i < orderByConditionFields.length; i++) {
24548                                    if (getDB().isSupportsInlineDistinct()) {
24549                                            query.append(_ORDER_BY_ENTITY_ALIAS);
24550                                    }
24551                                    else {
24552                                            query.append(_ORDER_BY_ENTITY_TABLE);
24553                                    }
24554    
24555                                    query.append(orderByConditionFields[i]);
24556    
24557                                    if ((i + 1) < orderByConditionFields.length) {
24558                                            if (orderByComparator.isAscending() ^ previous) {
24559                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
24560                                            }
24561                                            else {
24562                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
24563                                            }
24564                                    }
24565                                    else {
24566                                            if (orderByComparator.isAscending() ^ previous) {
24567                                                    query.append(WHERE_GREATER_THAN);
24568                                            }
24569                                            else {
24570                                                    query.append(WHERE_LESSER_THAN);
24571                                            }
24572                                    }
24573                            }
24574    
24575                            query.append(ORDER_BY_CLAUSE);
24576    
24577                            String[] orderByFields = orderByComparator.getOrderByFields();
24578    
24579                            for (int i = 0; i < orderByFields.length; i++) {
24580                                    if (getDB().isSupportsInlineDistinct()) {
24581                                            query.append(_ORDER_BY_ENTITY_ALIAS);
24582                                    }
24583                                    else {
24584                                            query.append(_ORDER_BY_ENTITY_TABLE);
24585                                    }
24586    
24587                                    query.append(orderByFields[i]);
24588    
24589                                    if ((i + 1) < orderByFields.length) {
24590                                            if (orderByComparator.isAscending() ^ previous) {
24591                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
24592                                            }
24593                                            else {
24594                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
24595                                            }
24596                                    }
24597                                    else {
24598                                            if (orderByComparator.isAscending() ^ previous) {
24599                                                    query.append(ORDER_BY_ASC);
24600                                            }
24601                                            else {
24602                                                    query.append(ORDER_BY_DESC);
24603                                            }
24604                                    }
24605                            }
24606                    }
24607                    else {
24608                            if (getDB().isSupportsInlineDistinct()) {
24609                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
24610                            }
24611                            else {
24612                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
24613                            }
24614                    }
24615    
24616                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
24617                                    JournalArticle.class.getName(),
24618                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
24619    
24620                    SQLQuery q = session.createSQLQuery(sql);
24621    
24622                    q.setFirstResult(0);
24623                    q.setMaxResults(2);
24624    
24625                    if (getDB().isSupportsInlineDistinct()) {
24626                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
24627                    }
24628                    else {
24629                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
24630                    }
24631    
24632                    QueryPos qPos = QueryPos.getInstance(q);
24633    
24634                    qPos.add(groupId);
24635    
24636                    if (bindArticleId) {
24637                            qPos.add(articleId);
24638                    }
24639    
24640                    qPos.add(status);
24641    
24642                    if (orderByComparator != null) {
24643                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
24644    
24645                            for (Object value : values) {
24646                                    qPos.add(value);
24647                            }
24648                    }
24649    
24650                    List<JournalArticle> list = q.list();
24651    
24652                    if (list.size() == 2) {
24653                            return list.get(1);
24654                    }
24655                    else {
24656                            return null;
24657                    }
24658            }
24659    
24660            /**
24661             * Returns all the journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = any &#63;.
24662             *
24663             * @param groupId the group ID
24664             * @param articleId the article ID
24665             * @param statuses the statuses
24666             * @return the matching journal articles that the user has permission to view
24667             * @throws SystemException if a system exception occurred
24668             */
24669            @Override
24670            public List<JournalArticle> filterFindByG_A_ST(long groupId,
24671                    String articleId, int[] statuses) throws SystemException {
24672                    return filterFindByG_A_ST(groupId, articleId, statuses,
24673                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
24674            }
24675    
24676            /**
24677             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = any &#63;.
24678             *
24679             * <p>
24680             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
24681             * </p>
24682             *
24683             * @param groupId the group ID
24684             * @param articleId the article ID
24685             * @param statuses the statuses
24686             * @param start the lower bound of the range of journal articles
24687             * @param end the upper bound of the range of journal articles (not inclusive)
24688             * @return the range of matching journal articles that the user has permission to view
24689             * @throws SystemException if a system exception occurred
24690             */
24691            @Override
24692            public List<JournalArticle> filterFindByG_A_ST(long groupId,
24693                    String articleId, int[] statuses, int start, int end)
24694                    throws SystemException {
24695                    return filterFindByG_A_ST(groupId, articleId, statuses, start, end, null);
24696            }
24697    
24698            /**
24699             * Returns an ordered range of all the journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = any &#63;.
24700             *
24701             * <p>
24702             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
24703             * </p>
24704             *
24705             * @param groupId the group ID
24706             * @param articleId the article ID
24707             * @param statuses the statuses
24708             * @param start the lower bound of the range of journal articles
24709             * @param end the upper bound of the range of journal articles (not inclusive)
24710             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
24711             * @return the ordered range of matching journal articles that the user has permission to view
24712             * @throws SystemException if a system exception occurred
24713             */
24714            @Override
24715            public List<JournalArticle> filterFindByG_A_ST(long groupId,
24716                    String articleId, int[] statuses, int start, int end,
24717                    OrderByComparator orderByComparator) throws SystemException {
24718                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
24719                            return findByG_A_ST(groupId, articleId, statuses, start, end,
24720                                    orderByComparator);
24721                    }
24722    
24723                    StringBundler query = new StringBundler();
24724    
24725                    if (getDB().isSupportsInlineDistinct()) {
24726                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
24727                    }
24728                    else {
24729                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
24730                    }
24731    
24732                    boolean conjunctionable = false;
24733    
24734                    if (conjunctionable) {
24735                            query.append(WHERE_AND);
24736                    }
24737    
24738                    query.append(_FINDER_COLUMN_G_A_ST_GROUPID_5);
24739    
24740                    conjunctionable = true;
24741    
24742                    if (conjunctionable) {
24743                            query.append(WHERE_AND);
24744                    }
24745    
24746                    if (articleId == null) {
24747                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_4);
24748                    }
24749                    else if (articleId.equals(StringPool.BLANK)) {
24750                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_6);
24751                    }
24752                    else {
24753                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_5);
24754                    }
24755    
24756                    conjunctionable = true;
24757    
24758                    if ((statuses == null) || (statuses.length > 0)) {
24759                            if (conjunctionable) {
24760                                    query.append(WHERE_AND);
24761                            }
24762    
24763                            query.append(StringPool.OPEN_PARENTHESIS);
24764    
24765                            for (int i = 0; i < statuses.length; i++) {
24766                                    query.append(_FINDER_COLUMN_G_A_ST_STATUS_5);
24767    
24768                                    if ((i + 1) < statuses.length) {
24769                                            query.append(WHERE_OR);
24770                                    }
24771                            }
24772    
24773                            query.append(StringPool.CLOSE_PARENTHESIS);
24774    
24775                            conjunctionable = true;
24776                    }
24777    
24778                    if (!getDB().isSupportsInlineDistinct()) {
24779                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
24780                    }
24781    
24782                    if (orderByComparator != null) {
24783                            if (getDB().isSupportsInlineDistinct()) {
24784                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
24785                                            orderByComparator, true);
24786                            }
24787                            else {
24788                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
24789                                            orderByComparator, true);
24790                            }
24791                    }
24792                    else {
24793                            if (getDB().isSupportsInlineDistinct()) {
24794                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
24795                            }
24796                            else {
24797                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
24798                            }
24799                    }
24800    
24801                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
24802                                    JournalArticle.class.getName(),
24803                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
24804    
24805                    Session session = null;
24806    
24807                    try {
24808                            session = openSession();
24809    
24810                            SQLQuery q = session.createSQLQuery(sql);
24811    
24812                            if (getDB().isSupportsInlineDistinct()) {
24813                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
24814                            }
24815                            else {
24816                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
24817                            }
24818    
24819                            QueryPos qPos = QueryPos.getInstance(q);
24820    
24821                            qPos.add(groupId);
24822    
24823                            if (articleId != null) {
24824                                    qPos.add(articleId);
24825                            }
24826    
24827                            if (statuses != null) {
24828                                    qPos.add(statuses);
24829                            }
24830    
24831                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
24832                                    end);
24833                    }
24834                    catch (Exception e) {
24835                            throw processException(e);
24836                    }
24837                    finally {
24838                            closeSession(session);
24839                    }
24840            }
24841    
24842            /**
24843             * Returns all the journal articles where groupId = &#63; and articleId = &#63; and status = any &#63;.
24844             *
24845             * <p>
24846             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
24847             * </p>
24848             *
24849             * @param groupId the group ID
24850             * @param articleId the article ID
24851             * @param statuses the statuses
24852             * @return the matching journal articles
24853             * @throws SystemException if a system exception occurred
24854             */
24855            @Override
24856            public List<JournalArticle> findByG_A_ST(long groupId, String articleId,
24857                    int[] statuses) throws SystemException {
24858                    return findByG_A_ST(groupId, articleId, statuses, QueryUtil.ALL_POS,
24859                            QueryUtil.ALL_POS, null);
24860            }
24861    
24862            /**
24863             * Returns a range of all the journal articles where groupId = &#63; and articleId = &#63; and status = any &#63;.
24864             *
24865             * <p>
24866             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
24867             * </p>
24868             *
24869             * @param groupId the group ID
24870             * @param articleId the article ID
24871             * @param statuses the statuses
24872             * @param start the lower bound of the range of journal articles
24873             * @param end the upper bound of the range of journal articles (not inclusive)
24874             * @return the range of matching journal articles
24875             * @throws SystemException if a system exception occurred
24876             */
24877            @Override
24878            public List<JournalArticle> findByG_A_ST(long groupId, String articleId,
24879                    int[] statuses, int start, int end) throws SystemException {
24880                    return findByG_A_ST(groupId, articleId, statuses, start, end, null);
24881            }
24882    
24883            /**
24884             * Returns an ordered range of all the journal articles where groupId = &#63; and articleId = &#63; and status = any &#63;.
24885             *
24886             * <p>
24887             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
24888             * </p>
24889             *
24890             * @param groupId the group ID
24891             * @param articleId the article ID
24892             * @param statuses the statuses
24893             * @param start the lower bound of the range of journal articles
24894             * @param end the upper bound of the range of journal articles (not inclusive)
24895             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
24896             * @return the ordered range of matching journal articles
24897             * @throws SystemException if a system exception occurred
24898             */
24899            @Override
24900            public List<JournalArticle> findByG_A_ST(long groupId, String articleId,
24901                    int[] statuses, int start, int end, OrderByComparator orderByComparator)
24902                    throws SystemException {
24903                    if ((statuses != null) && (statuses.length == 1)) {
24904                            return findByG_A_ST(groupId, articleId, statuses[0], start, end,
24905                                    orderByComparator);
24906                    }
24907    
24908                    boolean pagination = true;
24909                    Object[] finderArgs = null;
24910    
24911                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
24912                                    (orderByComparator == null)) {
24913                            pagination = false;
24914                            finderArgs = new Object[] {
24915                                            groupId, articleId, StringUtil.merge(statuses)
24916                                    };
24917                    }
24918                    else {
24919                            finderArgs = new Object[] {
24920                                            groupId, articleId, StringUtil.merge(statuses),
24921                                            
24922                                            start, end, orderByComparator
24923                                    };
24924                    }
24925    
24926                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_ST,
24927                                    finderArgs, this);
24928    
24929                    if ((list != null) && !list.isEmpty()) {
24930                            for (JournalArticle journalArticle : list) {
24931                                    if ((groupId != journalArticle.getGroupId()) ||
24932                                                    !Validator.equals(articleId,
24933                                                            journalArticle.getArticleId()) ||
24934                                                    !ArrayUtil.contains(statuses, journalArticle.getStatus())) {
24935                                            list = null;
24936    
24937                                            break;
24938                                    }
24939                            }
24940                    }
24941    
24942                    if (list == null) {
24943                            StringBundler query = new StringBundler();
24944    
24945                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
24946    
24947                            boolean conjunctionable = false;
24948    
24949                            if (conjunctionable) {
24950                                    query.append(WHERE_AND);
24951                            }
24952    
24953                            query.append(_FINDER_COLUMN_G_A_ST_GROUPID_5);
24954    
24955                            conjunctionable = true;
24956    
24957                            if (conjunctionable) {
24958                                    query.append(WHERE_AND);
24959                            }
24960    
24961                            if (articleId == null) {
24962                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_4);
24963                            }
24964                            else if (articleId.equals(StringPool.BLANK)) {
24965                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_6);
24966                            }
24967                            else {
24968                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_5);
24969                            }
24970    
24971                            conjunctionable = true;
24972    
24973                            if ((statuses == null) || (statuses.length > 0)) {
24974                                    if (conjunctionable) {
24975                                            query.append(WHERE_AND);
24976                                    }
24977    
24978                                    query.append(StringPool.OPEN_PARENTHESIS);
24979    
24980                                    for (int i = 0; i < statuses.length; i++) {
24981                                            query.append(_FINDER_COLUMN_G_A_ST_STATUS_5);
24982    
24983                                            if ((i + 1) < statuses.length) {
24984                                                    query.append(WHERE_OR);
24985                                            }
24986                                    }
24987    
24988                                    query.append(StringPool.CLOSE_PARENTHESIS);
24989    
24990                                    conjunctionable = true;
24991                            }
24992    
24993                            if (orderByComparator != null) {
24994                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
24995                                            orderByComparator);
24996                            }
24997                            else
24998                             if (pagination) {
24999                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
25000                            }
25001    
25002                            String sql = query.toString();
25003    
25004                            Session session = null;
25005    
25006                            try {
25007                                    session = openSession();
25008    
25009                                    Query q = session.createQuery(sql);
25010    
25011                                    QueryPos qPos = QueryPos.getInstance(q);
25012    
25013                                    qPos.add(groupId);
25014    
25015                                    if (articleId != null) {
25016                                            qPos.add(articleId);
25017                                    }
25018    
25019                                    if (statuses != null) {
25020                                            qPos.add(statuses);
25021                                    }
25022    
25023                                    if (!pagination) {
25024                                            list = (List<JournalArticle>)QueryUtil.list(q,
25025                                                            getDialect(), start, end, false);
25026    
25027                                            Collections.sort(list);
25028    
25029                                            list = new UnmodifiableList<JournalArticle>(list);
25030                                    }
25031                                    else {
25032                                            list = (List<JournalArticle>)QueryUtil.list(q,
25033                                                            getDialect(), start, end);
25034                                    }
25035    
25036                                    cacheResult(list);
25037    
25038                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_ST,
25039                                            finderArgs, list);
25040                            }
25041                            catch (Exception e) {
25042                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_ST,
25043                                            finderArgs);
25044    
25045                                    throw processException(e);
25046                            }
25047                            finally {
25048                                    closeSession(session);
25049                            }
25050                    }
25051    
25052                    return list;
25053            }
25054    
25055            /**
25056             * Removes all the journal articles where groupId = &#63; and articleId = &#63; and status = &#63; from the database.
25057             *
25058             * @param groupId the group ID
25059             * @param articleId the article ID
25060             * @param status the status
25061             * @throws SystemException if a system exception occurred
25062             */
25063            @Override
25064            public void removeByG_A_ST(long groupId, String articleId, int status)
25065                    throws SystemException {
25066                    for (JournalArticle journalArticle : findByG_A_ST(groupId, articleId,
25067                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
25068                            remove(journalArticle);
25069                    }
25070            }
25071    
25072            /**
25073             * Returns the number of journal articles where groupId = &#63; and articleId = &#63; and status = &#63;.
25074             *
25075             * @param groupId the group ID
25076             * @param articleId the article ID
25077             * @param status the status
25078             * @return the number of matching journal articles
25079             * @throws SystemException if a system exception occurred
25080             */
25081            @Override
25082            public int countByG_A_ST(long groupId, String articleId, int status)
25083                    throws SystemException {
25084                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_A_ST;
25085    
25086                    Object[] finderArgs = new Object[] { groupId, articleId, status };
25087    
25088                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
25089                                    this);
25090    
25091                    if (count == null) {
25092                            StringBundler query = new StringBundler(4);
25093    
25094                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
25095    
25096                            query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);
25097    
25098                            boolean bindArticleId = false;
25099    
25100                            if (articleId == null) {
25101                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
25102                            }
25103                            else if (articleId.equals(StringPool.BLANK)) {
25104                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
25105                            }
25106                            else {
25107                                    bindArticleId = true;
25108    
25109                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
25110                            }
25111    
25112                            query.append(_FINDER_COLUMN_G_A_ST_STATUS_2);
25113    
25114                            String sql = query.toString();
25115    
25116                            Session session = null;
25117    
25118                            try {
25119                                    session = openSession();
25120    
25121                                    Query q = session.createQuery(sql);
25122    
25123                                    QueryPos qPos = QueryPos.getInstance(q);
25124    
25125                                    qPos.add(groupId);
25126    
25127                                    if (bindArticleId) {
25128                                            qPos.add(articleId);
25129                                    }
25130    
25131                                    qPos.add(status);
25132    
25133                                    count = (Long)q.uniqueResult();
25134    
25135                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
25136                            }
25137                            catch (Exception e) {
25138                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
25139    
25140                                    throw processException(e);
25141                            }
25142                            finally {
25143                                    closeSession(session);
25144                            }
25145                    }
25146    
25147                    return count.intValue();
25148            }
25149    
25150            /**
25151             * Returns the number of journal articles where groupId = &#63; and articleId = &#63; and status = any &#63;.
25152             *
25153             * @param groupId the group ID
25154             * @param articleId the article ID
25155             * @param statuses the statuses
25156             * @return the number of matching journal articles
25157             * @throws SystemException if a system exception occurred
25158             */
25159            @Override
25160            public int countByG_A_ST(long groupId, String articleId, int[] statuses)
25161                    throws SystemException {
25162                    Object[] finderArgs = new Object[] {
25163                                    groupId, articleId, StringUtil.merge(statuses)
25164                            };
25165    
25166                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_A_ST,
25167                                    finderArgs, this);
25168    
25169                    if (count == null) {
25170                            StringBundler query = new StringBundler();
25171    
25172                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
25173    
25174                            boolean conjunctionable = false;
25175    
25176                            if (conjunctionable) {
25177                                    query.append(WHERE_AND);
25178                            }
25179    
25180                            query.append(_FINDER_COLUMN_G_A_ST_GROUPID_5);
25181    
25182                            conjunctionable = true;
25183    
25184                            if (conjunctionable) {
25185                                    query.append(WHERE_AND);
25186                            }
25187    
25188                            if (articleId == null) {
25189                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_4);
25190                            }
25191                            else if (articleId.equals(StringPool.BLANK)) {
25192                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_6);
25193                            }
25194                            else {
25195                                    query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_5);
25196                            }
25197    
25198                            conjunctionable = true;
25199    
25200                            if ((statuses == null) || (statuses.length > 0)) {
25201                                    if (conjunctionable) {
25202                                            query.append(WHERE_AND);
25203                                    }
25204    
25205                                    query.append(StringPool.OPEN_PARENTHESIS);
25206    
25207                                    for (int i = 0; i < statuses.length; i++) {
25208                                            query.append(_FINDER_COLUMN_G_A_ST_STATUS_5);
25209    
25210                                            if ((i + 1) < statuses.length) {
25211                                                    query.append(WHERE_OR);
25212                                            }
25213                                    }
25214    
25215                                    query.append(StringPool.CLOSE_PARENTHESIS);
25216    
25217                                    conjunctionable = true;
25218                            }
25219    
25220                            String sql = query.toString();
25221    
25222                            Session session = null;
25223    
25224                            try {
25225                                    session = openSession();
25226    
25227                                    Query q = session.createQuery(sql);
25228    
25229                                    QueryPos qPos = QueryPos.getInstance(q);
25230    
25231                                    qPos.add(groupId);
25232    
25233                                    if (articleId != null) {
25234                                            qPos.add(articleId);
25235                                    }
25236    
25237                                    if (statuses != null) {
25238                                            qPos.add(statuses);
25239                                    }
25240    
25241                                    count = (Long)q.uniqueResult();
25242    
25243                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_A_ST,
25244                                            finderArgs, count);
25245                            }
25246                            catch (Exception e) {
25247                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_A_ST,
25248                                            finderArgs);
25249    
25250                                    throw processException(e);
25251                            }
25252                            finally {
25253                                    closeSession(session);
25254                            }
25255                    }
25256    
25257                    return count.intValue();
25258            }
25259    
25260            /**
25261             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = &#63;.
25262             *
25263             * @param groupId the group ID
25264             * @param articleId the article ID
25265             * @param status the status
25266             * @return the number of matching journal articles that the user has permission to view
25267             * @throws SystemException if a system exception occurred
25268             */
25269            @Override
25270            public int filterCountByG_A_ST(long groupId, String articleId, int status)
25271                    throws SystemException {
25272                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
25273                            return countByG_A_ST(groupId, articleId, status);
25274                    }
25275    
25276                    StringBundler query = new StringBundler(4);
25277    
25278                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
25279    
25280                    query.append(_FINDER_COLUMN_G_A_ST_GROUPID_2);
25281    
25282                    boolean bindArticleId = false;
25283    
25284                    if (articleId == null) {
25285                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_1);
25286                    }
25287                    else if (articleId.equals(StringPool.BLANK)) {
25288                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_3);
25289                    }
25290                    else {
25291                            bindArticleId = true;
25292    
25293                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_2);
25294                    }
25295    
25296                    query.append(_FINDER_COLUMN_G_A_ST_STATUS_2);
25297    
25298                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
25299                                    JournalArticle.class.getName(),
25300                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
25301    
25302                    Session session = null;
25303    
25304                    try {
25305                            session = openSession();
25306    
25307                            SQLQuery q = session.createSQLQuery(sql);
25308    
25309                            q.addScalar(COUNT_COLUMN_NAME,
25310                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
25311    
25312                            QueryPos qPos = QueryPos.getInstance(q);
25313    
25314                            qPos.add(groupId);
25315    
25316                            if (bindArticleId) {
25317                                    qPos.add(articleId);
25318                            }
25319    
25320                            qPos.add(status);
25321    
25322                            Long count = (Long)q.uniqueResult();
25323    
25324                            return count.intValue();
25325                    }
25326                    catch (Exception e) {
25327                            throw processException(e);
25328                    }
25329                    finally {
25330                            closeSession(session);
25331                    }
25332            }
25333    
25334            /**
25335             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and articleId = &#63; and status = any &#63;.
25336             *
25337             * @param groupId the group ID
25338             * @param articleId the article ID
25339             * @param statuses the statuses
25340             * @return the number of matching journal articles that the user has permission to view
25341             * @throws SystemException if a system exception occurred
25342             */
25343            @Override
25344            public int filterCountByG_A_ST(long groupId, String articleId,
25345                    int[] statuses) throws SystemException {
25346                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
25347                            return countByG_A_ST(groupId, articleId, statuses);
25348                    }
25349    
25350                    StringBundler query = new StringBundler();
25351    
25352                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
25353    
25354                    boolean conjunctionable = false;
25355    
25356                    if (conjunctionable) {
25357                            query.append(WHERE_AND);
25358                    }
25359    
25360                    query.append(_FINDER_COLUMN_G_A_ST_GROUPID_5);
25361    
25362                    conjunctionable = true;
25363    
25364                    if (conjunctionable) {
25365                            query.append(WHERE_AND);
25366                    }
25367    
25368                    if (articleId == null) {
25369                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_4);
25370                    }
25371                    else if (articleId.equals(StringPool.BLANK)) {
25372                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_6);
25373                    }
25374                    else {
25375                            query.append(_FINDER_COLUMN_G_A_ST_ARTICLEID_5);
25376                    }
25377    
25378                    conjunctionable = true;
25379    
25380                    if ((statuses == null) || (statuses.length > 0)) {
25381                            if (conjunctionable) {
25382                                    query.append(WHERE_AND);
25383                            }
25384    
25385                            query.append(StringPool.OPEN_PARENTHESIS);
25386    
25387                            for (int i = 0; i < statuses.length; i++) {
25388                                    query.append(_FINDER_COLUMN_G_A_ST_STATUS_5);
25389    
25390                                    if ((i + 1) < statuses.length) {
25391                                            query.append(WHERE_OR);
25392                                    }
25393                            }
25394    
25395                            query.append(StringPool.CLOSE_PARENTHESIS);
25396    
25397                            conjunctionable = true;
25398                    }
25399    
25400                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
25401                                    JournalArticle.class.getName(),
25402                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
25403    
25404                    Session session = null;
25405    
25406                    try {
25407                            session = openSession();
25408    
25409                            SQLQuery q = session.createSQLQuery(sql);
25410    
25411                            q.addScalar(COUNT_COLUMN_NAME,
25412                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
25413    
25414                            QueryPos qPos = QueryPos.getInstance(q);
25415    
25416                            qPos.add(groupId);
25417    
25418                            if (articleId != null) {
25419                                    qPos.add(articleId);
25420                            }
25421    
25422                            if (statuses != null) {
25423                                    qPos.add(statuses);
25424                            }
25425    
25426                            Long count = (Long)q.uniqueResult();
25427    
25428                            return count.intValue();
25429                    }
25430                    catch (Exception e) {
25431                            throw processException(e);
25432                    }
25433                    finally {
25434                            closeSession(session);
25435                    }
25436            }
25437    
25438            private static final String _FINDER_COLUMN_G_A_ST_GROUPID_2 = "journalArticle.groupId = ? AND ";
25439            private static final String _FINDER_COLUMN_G_A_ST_GROUPID_5 = "(" +
25440                    removeConjunction(_FINDER_COLUMN_G_A_ST_GROUPID_2) + ")";
25441            private static final String _FINDER_COLUMN_G_A_ST_ARTICLEID_1 = "journalArticle.articleId IS NULL AND ";
25442            private static final String _FINDER_COLUMN_G_A_ST_ARTICLEID_2 = "journalArticle.articleId = ? AND ";
25443            private static final String _FINDER_COLUMN_G_A_ST_ARTICLEID_3 = "(journalArticle.articleId IS NULL OR journalArticle.articleId = '') AND ";
25444            private static final String _FINDER_COLUMN_G_A_ST_ARTICLEID_4 = "(" +
25445                    removeConjunction(_FINDER_COLUMN_G_A_ST_ARTICLEID_1) + ")";
25446            private static final String _FINDER_COLUMN_G_A_ST_ARTICLEID_5 = "(" +
25447                    removeConjunction(_FINDER_COLUMN_G_A_ST_ARTICLEID_2) + ")";
25448            private static final String _FINDER_COLUMN_G_A_ST_ARTICLEID_6 = "(" +
25449                    removeConjunction(_FINDER_COLUMN_G_A_ST_ARTICLEID_3) + ")";
25450            private static final String _FINDER_COLUMN_G_A_ST_STATUS_2 = "journalArticle.status = ?";
25451            private static final String _FINDER_COLUMN_G_A_ST_STATUS_5 = "(" +
25452                    removeConjunction(_FINDER_COLUMN_G_A_ST_STATUS_2) + ")";
25453            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_UT_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
25454                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
25455                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
25456                            "findByG_UT_ST",
25457                            new String[] {
25458                                    Long.class.getName(), String.class.getName(),
25459                                    Integer.class.getName(),
25460                                    
25461                            Integer.class.getName(), Integer.class.getName(),
25462                                    OrderByComparator.class.getName()
25463                            });
25464            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT_ST =
25465                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
25466                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
25467                            JournalArticleImpl.class,
25468                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_UT_ST",
25469                            new String[] {
25470                                    Long.class.getName(), String.class.getName(),
25471                                    Integer.class.getName()
25472                            },
25473                            JournalArticleModelImpl.GROUPID_COLUMN_BITMASK |
25474                            JournalArticleModelImpl.URLTITLE_COLUMN_BITMASK |
25475                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
25476                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK |
25477                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK);
25478            public static final FinderPath FINDER_PATH_COUNT_BY_G_UT_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
25479                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
25480                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_UT_ST",
25481                            new String[] {
25482                                    Long.class.getName(), String.class.getName(),
25483                                    Integer.class.getName()
25484                            });
25485    
25486            /**
25487             * Returns all the journal articles where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25488             *
25489             * @param groupId the group ID
25490             * @param urlTitle the url title
25491             * @param status the status
25492             * @return the matching journal articles
25493             * @throws SystemException if a system exception occurred
25494             */
25495            @Override
25496            public List<JournalArticle> findByG_UT_ST(long groupId, String urlTitle,
25497                    int status) throws SystemException {
25498                    return findByG_UT_ST(groupId, urlTitle, status, QueryUtil.ALL_POS,
25499                            QueryUtil.ALL_POS, null);
25500            }
25501    
25502            /**
25503             * Returns a range of all the journal articles where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25504             *
25505             * <p>
25506             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
25507             * </p>
25508             *
25509             * @param groupId the group ID
25510             * @param urlTitle the url title
25511             * @param status the status
25512             * @param start the lower bound of the range of journal articles
25513             * @param end the upper bound of the range of journal articles (not inclusive)
25514             * @return the range of matching journal articles
25515             * @throws SystemException if a system exception occurred
25516             */
25517            @Override
25518            public List<JournalArticle> findByG_UT_ST(long groupId, String urlTitle,
25519                    int status, int start, int end) throws SystemException {
25520                    return findByG_UT_ST(groupId, urlTitle, status, start, end, null);
25521            }
25522    
25523            /**
25524             * Returns an ordered range of all the journal articles where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25525             *
25526             * <p>
25527             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
25528             * </p>
25529             *
25530             * @param groupId the group ID
25531             * @param urlTitle the url title
25532             * @param status the status
25533             * @param start the lower bound of the range of journal articles
25534             * @param end the upper bound of the range of journal articles (not inclusive)
25535             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
25536             * @return the ordered range of matching journal articles
25537             * @throws SystemException if a system exception occurred
25538             */
25539            @Override
25540            public List<JournalArticle> findByG_UT_ST(long groupId, String urlTitle,
25541                    int status, int start, int end, OrderByComparator orderByComparator)
25542                    throws SystemException {
25543                    boolean pagination = true;
25544                    FinderPath finderPath = null;
25545                    Object[] finderArgs = null;
25546    
25547                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
25548                                    (orderByComparator == null)) {
25549                            pagination = false;
25550                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT_ST;
25551                            finderArgs = new Object[] { groupId, urlTitle, status };
25552                    }
25553                    else {
25554                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_UT_ST;
25555                            finderArgs = new Object[] {
25556                                            groupId, urlTitle, status,
25557                                            
25558                                            start, end, orderByComparator
25559                                    };
25560                    }
25561    
25562                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
25563                                    finderArgs, this);
25564    
25565                    if ((list != null) && !list.isEmpty()) {
25566                            for (JournalArticle journalArticle : list) {
25567                                    if ((groupId != journalArticle.getGroupId()) ||
25568                                                    !Validator.equals(urlTitle, journalArticle.getUrlTitle()) ||
25569                                                    (status != journalArticle.getStatus())) {
25570                                            list = null;
25571    
25572                                            break;
25573                                    }
25574                            }
25575                    }
25576    
25577                    if (list == null) {
25578                            StringBundler query = null;
25579    
25580                            if (orderByComparator != null) {
25581                                    query = new StringBundler(5 +
25582                                                    (orderByComparator.getOrderByFields().length * 3));
25583                            }
25584                            else {
25585                                    query = new StringBundler(5);
25586                            }
25587    
25588                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
25589    
25590                            query.append(_FINDER_COLUMN_G_UT_ST_GROUPID_2);
25591    
25592                            boolean bindUrlTitle = false;
25593    
25594                            if (urlTitle == null) {
25595                                    query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_1);
25596                            }
25597                            else if (urlTitle.equals(StringPool.BLANK)) {
25598                                    query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_3);
25599                            }
25600                            else {
25601                                    bindUrlTitle = true;
25602    
25603                                    query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_2);
25604                            }
25605    
25606                            query.append(_FINDER_COLUMN_G_UT_ST_STATUS_2);
25607    
25608                            if (orderByComparator != null) {
25609                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
25610                                            orderByComparator);
25611                            }
25612                            else
25613                             if (pagination) {
25614                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
25615                            }
25616    
25617                            String sql = query.toString();
25618    
25619                            Session session = null;
25620    
25621                            try {
25622                                    session = openSession();
25623    
25624                                    Query q = session.createQuery(sql);
25625    
25626                                    QueryPos qPos = QueryPos.getInstance(q);
25627    
25628                                    qPos.add(groupId);
25629    
25630                                    if (bindUrlTitle) {
25631                                            qPos.add(urlTitle);
25632                                    }
25633    
25634                                    qPos.add(status);
25635    
25636                                    if (!pagination) {
25637                                            list = (List<JournalArticle>)QueryUtil.list(q,
25638                                                            getDialect(), start, end, false);
25639    
25640                                            Collections.sort(list);
25641    
25642                                            list = new UnmodifiableList<JournalArticle>(list);
25643                                    }
25644                                    else {
25645                                            list = (List<JournalArticle>)QueryUtil.list(q,
25646                                                            getDialect(), start, end);
25647                                    }
25648    
25649                                    cacheResult(list);
25650    
25651                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
25652                            }
25653                            catch (Exception e) {
25654                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
25655    
25656                                    throw processException(e);
25657                            }
25658                            finally {
25659                                    closeSession(session);
25660                            }
25661                    }
25662    
25663                    return list;
25664            }
25665    
25666            /**
25667             * Returns the first journal article in the ordered set where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25668             *
25669             * @param groupId the group ID
25670             * @param urlTitle the url title
25671             * @param status the status
25672             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
25673             * @return the first matching journal article
25674             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
25675             * @throws SystemException if a system exception occurred
25676             */
25677            @Override
25678            public JournalArticle findByG_UT_ST_First(long groupId, String urlTitle,
25679                    int status, OrderByComparator orderByComparator)
25680                    throws NoSuchArticleException, SystemException {
25681                    JournalArticle journalArticle = fetchByG_UT_ST_First(groupId, urlTitle,
25682                                    status, orderByComparator);
25683    
25684                    if (journalArticle != null) {
25685                            return journalArticle;
25686                    }
25687    
25688                    StringBundler msg = new StringBundler(8);
25689    
25690                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
25691    
25692                    msg.append("groupId=");
25693                    msg.append(groupId);
25694    
25695                    msg.append(", urlTitle=");
25696                    msg.append(urlTitle);
25697    
25698                    msg.append(", status=");
25699                    msg.append(status);
25700    
25701                    msg.append(StringPool.CLOSE_CURLY_BRACE);
25702    
25703                    throw new NoSuchArticleException(msg.toString());
25704            }
25705    
25706            /**
25707             * Returns the first journal article in the ordered set where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25708             *
25709             * @param groupId the group ID
25710             * @param urlTitle the url title
25711             * @param status the status
25712             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
25713             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
25714             * @throws SystemException if a system exception occurred
25715             */
25716            @Override
25717            public JournalArticle fetchByG_UT_ST_First(long groupId, String urlTitle,
25718                    int status, OrderByComparator orderByComparator)
25719                    throws SystemException {
25720                    List<JournalArticle> list = findByG_UT_ST(groupId, urlTitle, status, 0,
25721                                    1, orderByComparator);
25722    
25723                    if (!list.isEmpty()) {
25724                            return list.get(0);
25725                    }
25726    
25727                    return null;
25728            }
25729    
25730            /**
25731             * Returns the last journal article in the ordered set where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25732             *
25733             * @param groupId the group ID
25734             * @param urlTitle the url title
25735             * @param status the status
25736             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
25737             * @return the last matching journal article
25738             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
25739             * @throws SystemException if a system exception occurred
25740             */
25741            @Override
25742            public JournalArticle findByG_UT_ST_Last(long groupId, String urlTitle,
25743                    int status, OrderByComparator orderByComparator)
25744                    throws NoSuchArticleException, SystemException {
25745                    JournalArticle journalArticle = fetchByG_UT_ST_Last(groupId, urlTitle,
25746                                    status, orderByComparator);
25747    
25748                    if (journalArticle != null) {
25749                            return journalArticle;
25750                    }
25751    
25752                    StringBundler msg = new StringBundler(8);
25753    
25754                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
25755    
25756                    msg.append("groupId=");
25757                    msg.append(groupId);
25758    
25759                    msg.append(", urlTitle=");
25760                    msg.append(urlTitle);
25761    
25762                    msg.append(", status=");
25763                    msg.append(status);
25764    
25765                    msg.append(StringPool.CLOSE_CURLY_BRACE);
25766    
25767                    throw new NoSuchArticleException(msg.toString());
25768            }
25769    
25770            /**
25771             * Returns the last journal article in the ordered set where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25772             *
25773             * @param groupId the group ID
25774             * @param urlTitle the url title
25775             * @param status the status
25776             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
25777             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
25778             * @throws SystemException if a system exception occurred
25779             */
25780            @Override
25781            public JournalArticle fetchByG_UT_ST_Last(long groupId, String urlTitle,
25782                    int status, OrderByComparator orderByComparator)
25783                    throws SystemException {
25784                    int count = countByG_UT_ST(groupId, urlTitle, status);
25785    
25786                    if (count == 0) {
25787                            return null;
25788                    }
25789    
25790                    List<JournalArticle> list = findByG_UT_ST(groupId, urlTitle, status,
25791                                    count - 1, count, orderByComparator);
25792    
25793                    if (!list.isEmpty()) {
25794                            return list.get(0);
25795                    }
25796    
25797                    return null;
25798            }
25799    
25800            /**
25801             * Returns the journal articles before and after the current journal article in the ordered set where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25802             *
25803             * @param id the primary key of the current journal article
25804             * @param groupId the group ID
25805             * @param urlTitle the url title
25806             * @param status the status
25807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
25808             * @return the previous, current, and next journal article
25809             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
25810             * @throws SystemException if a system exception occurred
25811             */
25812            @Override
25813            public JournalArticle[] findByG_UT_ST_PrevAndNext(long id, long groupId,
25814                    String urlTitle, int status, OrderByComparator orderByComparator)
25815                    throws NoSuchArticleException, SystemException {
25816                    JournalArticle journalArticle = findByPrimaryKey(id);
25817    
25818                    Session session = null;
25819    
25820                    try {
25821                            session = openSession();
25822    
25823                            JournalArticle[] array = new JournalArticleImpl[3];
25824    
25825                            array[0] = getByG_UT_ST_PrevAndNext(session, journalArticle,
25826                                            groupId, urlTitle, status, orderByComparator, true);
25827    
25828                            array[1] = journalArticle;
25829    
25830                            array[2] = getByG_UT_ST_PrevAndNext(session, journalArticle,
25831                                            groupId, urlTitle, status, orderByComparator, false);
25832    
25833                            return array;
25834                    }
25835                    catch (Exception e) {
25836                            throw processException(e);
25837                    }
25838                    finally {
25839                            closeSession(session);
25840                    }
25841            }
25842    
25843            protected JournalArticle getByG_UT_ST_PrevAndNext(Session session,
25844                    JournalArticle journalArticle, long groupId, String urlTitle,
25845                    int status, OrderByComparator orderByComparator, boolean previous) {
25846                    StringBundler query = null;
25847    
25848                    if (orderByComparator != null) {
25849                            query = new StringBundler(6 +
25850                                            (orderByComparator.getOrderByFields().length * 6));
25851                    }
25852                    else {
25853                            query = new StringBundler(3);
25854                    }
25855    
25856                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
25857    
25858                    query.append(_FINDER_COLUMN_G_UT_ST_GROUPID_2);
25859    
25860                    boolean bindUrlTitle = false;
25861    
25862                    if (urlTitle == null) {
25863                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_1);
25864                    }
25865                    else if (urlTitle.equals(StringPool.BLANK)) {
25866                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_3);
25867                    }
25868                    else {
25869                            bindUrlTitle = true;
25870    
25871                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_2);
25872                    }
25873    
25874                    query.append(_FINDER_COLUMN_G_UT_ST_STATUS_2);
25875    
25876                    if (orderByComparator != null) {
25877                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
25878    
25879                            if (orderByConditionFields.length > 0) {
25880                                    query.append(WHERE_AND);
25881                            }
25882    
25883                            for (int i = 0; i < orderByConditionFields.length; i++) {
25884                                    query.append(_ORDER_BY_ENTITY_ALIAS);
25885                                    query.append(orderByConditionFields[i]);
25886    
25887                                    if ((i + 1) < orderByConditionFields.length) {
25888                                            if (orderByComparator.isAscending() ^ previous) {
25889                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
25890                                            }
25891                                            else {
25892                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
25893                                            }
25894                                    }
25895                                    else {
25896                                            if (orderByComparator.isAscending() ^ previous) {
25897                                                    query.append(WHERE_GREATER_THAN);
25898                                            }
25899                                            else {
25900                                                    query.append(WHERE_LESSER_THAN);
25901                                            }
25902                                    }
25903                            }
25904    
25905                            query.append(ORDER_BY_CLAUSE);
25906    
25907                            String[] orderByFields = orderByComparator.getOrderByFields();
25908    
25909                            for (int i = 0; i < orderByFields.length; i++) {
25910                                    query.append(_ORDER_BY_ENTITY_ALIAS);
25911                                    query.append(orderByFields[i]);
25912    
25913                                    if ((i + 1) < orderByFields.length) {
25914                                            if (orderByComparator.isAscending() ^ previous) {
25915                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
25916                                            }
25917                                            else {
25918                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
25919                                            }
25920                                    }
25921                                    else {
25922                                            if (orderByComparator.isAscending() ^ previous) {
25923                                                    query.append(ORDER_BY_ASC);
25924                                            }
25925                                            else {
25926                                                    query.append(ORDER_BY_DESC);
25927                                            }
25928                                    }
25929                            }
25930                    }
25931                    else {
25932                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
25933                    }
25934    
25935                    String sql = query.toString();
25936    
25937                    Query q = session.createQuery(sql);
25938    
25939                    q.setFirstResult(0);
25940                    q.setMaxResults(2);
25941    
25942                    QueryPos qPos = QueryPos.getInstance(q);
25943    
25944                    qPos.add(groupId);
25945    
25946                    if (bindUrlTitle) {
25947                            qPos.add(urlTitle);
25948                    }
25949    
25950                    qPos.add(status);
25951    
25952                    if (orderByComparator != null) {
25953                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
25954    
25955                            for (Object value : values) {
25956                                    qPos.add(value);
25957                            }
25958                    }
25959    
25960                    List<JournalArticle> list = q.list();
25961    
25962                    if (list.size() == 2) {
25963                            return list.get(1);
25964                    }
25965                    else {
25966                            return null;
25967                    }
25968            }
25969    
25970            /**
25971             * Returns all the journal articles that the user has permission to view where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25972             *
25973             * @param groupId the group ID
25974             * @param urlTitle the url title
25975             * @param status the status
25976             * @return the matching journal articles that the user has permission to view
25977             * @throws SystemException if a system exception occurred
25978             */
25979            @Override
25980            public List<JournalArticle> filterFindByG_UT_ST(long groupId,
25981                    String urlTitle, int status) throws SystemException {
25982                    return filterFindByG_UT_ST(groupId, urlTitle, status,
25983                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
25984            }
25985    
25986            /**
25987             * Returns a range of all the journal articles that the user has permission to view where groupId = &#63; and urlTitle = &#63; and status = &#63;.
25988             *
25989             * <p>
25990             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
25991             * </p>
25992             *
25993             * @param groupId the group ID
25994             * @param urlTitle the url title
25995             * @param status the status
25996             * @param start the lower bound of the range of journal articles
25997             * @param end the upper bound of the range of journal articles (not inclusive)
25998             * @return the range of matching journal articles that the user has permission to view
25999             * @throws SystemException if a system exception occurred
26000             */
26001            @Override
26002            public List<JournalArticle> filterFindByG_UT_ST(long groupId,
26003                    String urlTitle, int status, int start, int end)
26004                    throws SystemException {
26005                    return filterFindByG_UT_ST(groupId, urlTitle, status, start, end, null);
26006            }
26007    
26008            /**
26009             * Returns an ordered range of all the journal articles that the user has permissions to view where groupId = &#63; and urlTitle = &#63; and status = &#63;.
26010             *
26011             * <p>
26012             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
26013             * </p>
26014             *
26015             * @param groupId the group ID
26016             * @param urlTitle the url title
26017             * @param status the status
26018             * @param start the lower bound of the range of journal articles
26019             * @param end the upper bound of the range of journal articles (not inclusive)
26020             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
26021             * @return the ordered range of matching journal articles that the user has permission to view
26022             * @throws SystemException if a system exception occurred
26023             */
26024            @Override
26025            public List<JournalArticle> filterFindByG_UT_ST(long groupId,
26026                    String urlTitle, int status, int start, int end,
26027                    OrderByComparator orderByComparator) throws SystemException {
26028                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
26029                            return findByG_UT_ST(groupId, urlTitle, status, start, end,
26030                                    orderByComparator);
26031                    }
26032    
26033                    StringBundler query = null;
26034    
26035                    if (orderByComparator != null) {
26036                            query = new StringBundler(5 +
26037                                            (orderByComparator.getOrderByFields().length * 3));
26038                    }
26039                    else {
26040                            query = new StringBundler(5);
26041                    }
26042    
26043                    if (getDB().isSupportsInlineDistinct()) {
26044                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
26045                    }
26046                    else {
26047                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
26048                    }
26049    
26050                    query.append(_FINDER_COLUMN_G_UT_ST_GROUPID_2);
26051    
26052                    boolean bindUrlTitle = false;
26053    
26054                    if (urlTitle == null) {
26055                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_1);
26056                    }
26057                    else if (urlTitle.equals(StringPool.BLANK)) {
26058                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_3);
26059                    }
26060                    else {
26061                            bindUrlTitle = true;
26062    
26063                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_2);
26064                    }
26065    
26066                    query.append(_FINDER_COLUMN_G_UT_ST_STATUS_2);
26067    
26068                    if (!getDB().isSupportsInlineDistinct()) {
26069                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
26070                    }
26071    
26072                    if (orderByComparator != null) {
26073                            if (getDB().isSupportsInlineDistinct()) {
26074                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
26075                                            orderByComparator, true);
26076                            }
26077                            else {
26078                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
26079                                            orderByComparator, true);
26080                            }
26081                    }
26082                    else {
26083                            if (getDB().isSupportsInlineDistinct()) {
26084                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
26085                            }
26086                            else {
26087                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
26088                            }
26089                    }
26090    
26091                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
26092                                    JournalArticle.class.getName(),
26093                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
26094    
26095                    Session session = null;
26096    
26097                    try {
26098                            session = openSession();
26099    
26100                            SQLQuery q = session.createSQLQuery(sql);
26101    
26102                            if (getDB().isSupportsInlineDistinct()) {
26103                                    q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
26104                            }
26105                            else {
26106                                    q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
26107                            }
26108    
26109                            QueryPos qPos = QueryPos.getInstance(q);
26110    
26111                            qPos.add(groupId);
26112    
26113                            if (bindUrlTitle) {
26114                                    qPos.add(urlTitle);
26115                            }
26116    
26117                            qPos.add(status);
26118    
26119                            return (List<JournalArticle>)QueryUtil.list(q, getDialect(), start,
26120                                    end);
26121                    }
26122                    catch (Exception e) {
26123                            throw processException(e);
26124                    }
26125                    finally {
26126                            closeSession(session);
26127                    }
26128            }
26129    
26130            /**
26131             * Returns the journal articles before and after the current journal article in the ordered set of journal articles that the user has permission to view where groupId = &#63; and urlTitle = &#63; and status = &#63;.
26132             *
26133             * @param id the primary key of the current journal article
26134             * @param groupId the group ID
26135             * @param urlTitle the url title
26136             * @param status the status
26137             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
26138             * @return the previous, current, and next journal article
26139             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
26140             * @throws SystemException if a system exception occurred
26141             */
26142            @Override
26143            public JournalArticle[] filterFindByG_UT_ST_PrevAndNext(long id,
26144                    long groupId, String urlTitle, int status,
26145                    OrderByComparator orderByComparator)
26146                    throws NoSuchArticleException, SystemException {
26147                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
26148                            return findByG_UT_ST_PrevAndNext(id, groupId, urlTitle, status,
26149                                    orderByComparator);
26150                    }
26151    
26152                    JournalArticle journalArticle = findByPrimaryKey(id);
26153    
26154                    Session session = null;
26155    
26156                    try {
26157                            session = openSession();
26158    
26159                            JournalArticle[] array = new JournalArticleImpl[3];
26160    
26161                            array[0] = filterGetByG_UT_ST_PrevAndNext(session, journalArticle,
26162                                            groupId, urlTitle, status, orderByComparator, true);
26163    
26164                            array[1] = journalArticle;
26165    
26166                            array[2] = filterGetByG_UT_ST_PrevAndNext(session, journalArticle,
26167                                            groupId, urlTitle, status, orderByComparator, false);
26168    
26169                            return array;
26170                    }
26171                    catch (Exception e) {
26172                            throw processException(e);
26173                    }
26174                    finally {
26175                            closeSession(session);
26176                    }
26177            }
26178    
26179            protected JournalArticle filterGetByG_UT_ST_PrevAndNext(Session session,
26180                    JournalArticle journalArticle, long groupId, String urlTitle,
26181                    int status, OrderByComparator orderByComparator, boolean previous) {
26182                    StringBundler query = null;
26183    
26184                    if (orderByComparator != null) {
26185                            query = new StringBundler(6 +
26186                                            (orderByComparator.getOrderByFields().length * 6));
26187                    }
26188                    else {
26189                            query = new StringBundler(3);
26190                    }
26191    
26192                    if (getDB().isSupportsInlineDistinct()) {
26193                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_WHERE);
26194                    }
26195                    else {
26196                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1);
26197                    }
26198    
26199                    query.append(_FINDER_COLUMN_G_UT_ST_GROUPID_2);
26200    
26201                    boolean bindUrlTitle = false;
26202    
26203                    if (urlTitle == null) {
26204                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_1);
26205                    }
26206                    else if (urlTitle.equals(StringPool.BLANK)) {
26207                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_3);
26208                    }
26209                    else {
26210                            bindUrlTitle = true;
26211    
26212                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_2);
26213                    }
26214    
26215                    query.append(_FINDER_COLUMN_G_UT_ST_STATUS_2);
26216    
26217                    if (!getDB().isSupportsInlineDistinct()) {
26218                            query.append(_FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2);
26219                    }
26220    
26221                    if (orderByComparator != null) {
26222                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
26223    
26224                            if (orderByConditionFields.length > 0) {
26225                                    query.append(WHERE_AND);
26226                            }
26227    
26228                            for (int i = 0; i < orderByConditionFields.length; i++) {
26229                                    if (getDB().isSupportsInlineDistinct()) {
26230                                            query.append(_ORDER_BY_ENTITY_ALIAS);
26231                                    }
26232                                    else {
26233                                            query.append(_ORDER_BY_ENTITY_TABLE);
26234                                    }
26235    
26236                                    query.append(orderByConditionFields[i]);
26237    
26238                                    if ((i + 1) < orderByConditionFields.length) {
26239                                            if (orderByComparator.isAscending() ^ previous) {
26240                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
26241                                            }
26242                                            else {
26243                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
26244                                            }
26245                                    }
26246                                    else {
26247                                            if (orderByComparator.isAscending() ^ previous) {
26248                                                    query.append(WHERE_GREATER_THAN);
26249                                            }
26250                                            else {
26251                                                    query.append(WHERE_LESSER_THAN);
26252                                            }
26253                                    }
26254                            }
26255    
26256                            query.append(ORDER_BY_CLAUSE);
26257    
26258                            String[] orderByFields = orderByComparator.getOrderByFields();
26259    
26260                            for (int i = 0; i < orderByFields.length; i++) {
26261                                    if (getDB().isSupportsInlineDistinct()) {
26262                                            query.append(_ORDER_BY_ENTITY_ALIAS);
26263                                    }
26264                                    else {
26265                                            query.append(_ORDER_BY_ENTITY_TABLE);
26266                                    }
26267    
26268                                    query.append(orderByFields[i]);
26269    
26270                                    if ((i + 1) < orderByFields.length) {
26271                                            if (orderByComparator.isAscending() ^ previous) {
26272                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
26273                                            }
26274                                            else {
26275                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
26276                                            }
26277                                    }
26278                                    else {
26279                                            if (orderByComparator.isAscending() ^ previous) {
26280                                                    query.append(ORDER_BY_ASC);
26281                                            }
26282                                            else {
26283                                                    query.append(ORDER_BY_DESC);
26284                                            }
26285                                    }
26286                            }
26287                    }
26288                    else {
26289                            if (getDB().isSupportsInlineDistinct()) {
26290                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
26291                            }
26292                            else {
26293                                    query.append(JournalArticleModelImpl.ORDER_BY_SQL);
26294                            }
26295                    }
26296    
26297                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
26298                                    JournalArticle.class.getName(),
26299                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
26300    
26301                    SQLQuery q = session.createSQLQuery(sql);
26302    
26303                    q.setFirstResult(0);
26304                    q.setMaxResults(2);
26305    
26306                    if (getDB().isSupportsInlineDistinct()) {
26307                            q.addEntity(_FILTER_ENTITY_ALIAS, JournalArticleImpl.class);
26308                    }
26309                    else {
26310                            q.addEntity(_FILTER_ENTITY_TABLE, JournalArticleImpl.class);
26311                    }
26312    
26313                    QueryPos qPos = QueryPos.getInstance(q);
26314    
26315                    qPos.add(groupId);
26316    
26317                    if (bindUrlTitle) {
26318                            qPos.add(urlTitle);
26319                    }
26320    
26321                    qPos.add(status);
26322    
26323                    if (orderByComparator != null) {
26324                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
26325    
26326                            for (Object value : values) {
26327                                    qPos.add(value);
26328                            }
26329                    }
26330    
26331                    List<JournalArticle> list = q.list();
26332    
26333                    if (list.size() == 2) {
26334                            return list.get(1);
26335                    }
26336                    else {
26337                            return null;
26338                    }
26339            }
26340    
26341            /**
26342             * Removes all the journal articles where groupId = &#63; and urlTitle = &#63; and status = &#63; from the database.
26343             *
26344             * @param groupId the group ID
26345             * @param urlTitle the url title
26346             * @param status the status
26347             * @throws SystemException if a system exception occurred
26348             */
26349            @Override
26350            public void removeByG_UT_ST(long groupId, String urlTitle, int status)
26351                    throws SystemException {
26352                    for (JournalArticle journalArticle : findByG_UT_ST(groupId, urlTitle,
26353                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
26354                            remove(journalArticle);
26355                    }
26356            }
26357    
26358            /**
26359             * Returns the number of journal articles where groupId = &#63; and urlTitle = &#63; and status = &#63;.
26360             *
26361             * @param groupId the group ID
26362             * @param urlTitle the url title
26363             * @param status the status
26364             * @return the number of matching journal articles
26365             * @throws SystemException if a system exception occurred
26366             */
26367            @Override
26368            public int countByG_UT_ST(long groupId, String urlTitle, int status)
26369                    throws SystemException {
26370                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_UT_ST;
26371    
26372                    Object[] finderArgs = new Object[] { groupId, urlTitle, status };
26373    
26374                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
26375                                    this);
26376    
26377                    if (count == null) {
26378                            StringBundler query = new StringBundler(4);
26379    
26380                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
26381    
26382                            query.append(_FINDER_COLUMN_G_UT_ST_GROUPID_2);
26383    
26384                            boolean bindUrlTitle = false;
26385    
26386                            if (urlTitle == null) {
26387                                    query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_1);
26388                            }
26389                            else if (urlTitle.equals(StringPool.BLANK)) {
26390                                    query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_3);
26391                            }
26392                            else {
26393                                    bindUrlTitle = true;
26394    
26395                                    query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_2);
26396                            }
26397    
26398                            query.append(_FINDER_COLUMN_G_UT_ST_STATUS_2);
26399    
26400                            String sql = query.toString();
26401    
26402                            Session session = null;
26403    
26404                            try {
26405                                    session = openSession();
26406    
26407                                    Query q = session.createQuery(sql);
26408    
26409                                    QueryPos qPos = QueryPos.getInstance(q);
26410    
26411                                    qPos.add(groupId);
26412    
26413                                    if (bindUrlTitle) {
26414                                            qPos.add(urlTitle);
26415                                    }
26416    
26417                                    qPos.add(status);
26418    
26419                                    count = (Long)q.uniqueResult();
26420    
26421                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
26422                            }
26423                            catch (Exception e) {
26424                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
26425    
26426                                    throw processException(e);
26427                            }
26428                            finally {
26429                                    closeSession(session);
26430                            }
26431                    }
26432    
26433                    return count.intValue();
26434            }
26435    
26436            /**
26437             * Returns the number of journal articles that the user has permission to view where groupId = &#63; and urlTitle = &#63; and status = &#63;.
26438             *
26439             * @param groupId the group ID
26440             * @param urlTitle the url title
26441             * @param status the status
26442             * @return the number of matching journal articles that the user has permission to view
26443             * @throws SystemException if a system exception occurred
26444             */
26445            @Override
26446            public int filterCountByG_UT_ST(long groupId, String urlTitle, int status)
26447                    throws SystemException {
26448                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
26449                            return countByG_UT_ST(groupId, urlTitle, status);
26450                    }
26451    
26452                    StringBundler query = new StringBundler(4);
26453    
26454                    query.append(_FILTER_SQL_COUNT_JOURNALARTICLE_WHERE);
26455    
26456                    query.append(_FINDER_COLUMN_G_UT_ST_GROUPID_2);
26457    
26458                    boolean bindUrlTitle = false;
26459    
26460                    if (urlTitle == null) {
26461                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_1);
26462                    }
26463                    else if (urlTitle.equals(StringPool.BLANK)) {
26464                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_3);
26465                    }
26466                    else {
26467                            bindUrlTitle = true;
26468    
26469                            query.append(_FINDER_COLUMN_G_UT_ST_URLTITLE_2);
26470                    }
26471    
26472                    query.append(_FINDER_COLUMN_G_UT_ST_STATUS_2);
26473    
26474                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
26475                                    JournalArticle.class.getName(),
26476                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
26477    
26478                    Session session = null;
26479    
26480                    try {
26481                            session = openSession();
26482    
26483                            SQLQuery q = session.createSQLQuery(sql);
26484    
26485                            q.addScalar(COUNT_COLUMN_NAME,
26486                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
26487    
26488                            QueryPos qPos = QueryPos.getInstance(q);
26489    
26490                            qPos.add(groupId);
26491    
26492                            if (bindUrlTitle) {
26493                                    qPos.add(urlTitle);
26494                            }
26495    
26496                            qPos.add(status);
26497    
26498                            Long count = (Long)q.uniqueResult();
26499    
26500                            return count.intValue();
26501                    }
26502                    catch (Exception e) {
26503                            throw processException(e);
26504                    }
26505                    finally {
26506                            closeSession(session);
26507                    }
26508            }
26509    
26510            private static final String _FINDER_COLUMN_G_UT_ST_GROUPID_2 = "journalArticle.groupId = ? AND ";
26511            private static final String _FINDER_COLUMN_G_UT_ST_URLTITLE_1 = "journalArticle.urlTitle IS NULL AND ";
26512            private static final String _FINDER_COLUMN_G_UT_ST_URLTITLE_2 = "journalArticle.urlTitle = ? AND ";
26513            private static final String _FINDER_COLUMN_G_UT_ST_URLTITLE_3 = "(journalArticle.urlTitle IS NULL OR journalArticle.urlTitle = '') AND ";
26514            private static final String _FINDER_COLUMN_G_UT_ST_STATUS_2 = "journalArticle.status = ?";
26515            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_V_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
26516                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
26517                            JournalArticleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
26518                            "findByC_V_ST",
26519                            new String[] {
26520                                    Long.class.getName(), Double.class.getName(),
26521                                    Integer.class.getName(),
26522                                    
26523                            Integer.class.getName(), Integer.class.getName(),
26524                                    OrderByComparator.class.getName()
26525                            });
26526            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V_ST =
26527                    new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
26528                            JournalArticleModelImpl.FINDER_CACHE_ENABLED,
26529                            JournalArticleImpl.class,
26530                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_V_ST",
26531                            new String[] {
26532                                    Long.class.getName(), Double.class.getName(),
26533                                    Integer.class.getName()
26534                            },
26535                            JournalArticleModelImpl.COMPANYID_COLUMN_BITMASK |
26536                            JournalArticleModelImpl.VERSION_COLUMN_BITMASK |
26537                            JournalArticleModelImpl.STATUS_COLUMN_BITMASK |
26538                            JournalArticleModelImpl.ARTICLEID_COLUMN_BITMASK);
26539            public static final FinderPath FINDER_PATH_COUNT_BY_C_V_ST = new FinderPath(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
26540                            JournalArticleModelImpl.FINDER_CACHE_ENABLED, Long.class,
26541                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_V_ST",
26542                            new String[] {
26543                                    Long.class.getName(), Double.class.getName(),
26544                                    Integer.class.getName()
26545                            });
26546    
26547            /**
26548             * Returns all the journal articles where companyId = &#63; and version = &#63; and status = &#63;.
26549             *
26550             * @param companyId the company ID
26551             * @param version the version
26552             * @param status the status
26553             * @return the matching journal articles
26554             * @throws SystemException if a system exception occurred
26555             */
26556            @Override
26557            public List<JournalArticle> findByC_V_ST(long companyId, double version,
26558                    int status) throws SystemException {
26559                    return findByC_V_ST(companyId, version, status, QueryUtil.ALL_POS,
26560                            QueryUtil.ALL_POS, null);
26561            }
26562    
26563            /**
26564             * Returns a range of all the journal articles where companyId = &#63; and version = &#63; and status = &#63;.
26565             *
26566             * <p>
26567             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
26568             * </p>
26569             *
26570             * @param companyId the company ID
26571             * @param version the version
26572             * @param status the status
26573             * @param start the lower bound of the range of journal articles
26574             * @param end the upper bound of the range of journal articles (not inclusive)
26575             * @return the range of matching journal articles
26576             * @throws SystemException if a system exception occurred
26577             */
26578            @Override
26579            public List<JournalArticle> findByC_V_ST(long companyId, double version,
26580                    int status, int start, int end) throws SystemException {
26581                    return findByC_V_ST(companyId, version, status, start, end, null);
26582            }
26583    
26584            /**
26585             * Returns an ordered range of all the journal articles where companyId = &#63; and version = &#63; and status = &#63;.
26586             *
26587             * <p>
26588             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
26589             * </p>
26590             *
26591             * @param companyId the company ID
26592             * @param version the version
26593             * @param status the status
26594             * @param start the lower bound of the range of journal articles
26595             * @param end the upper bound of the range of journal articles (not inclusive)
26596             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
26597             * @return the ordered range of matching journal articles
26598             * @throws SystemException if a system exception occurred
26599             */
26600            @Override
26601            public List<JournalArticle> findByC_V_ST(long companyId, double version,
26602                    int status, int start, int end, OrderByComparator orderByComparator)
26603                    throws SystemException {
26604                    boolean pagination = true;
26605                    FinderPath finderPath = null;
26606                    Object[] finderArgs = null;
26607    
26608                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
26609                                    (orderByComparator == null)) {
26610                            pagination = false;
26611                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V_ST;
26612                            finderArgs = new Object[] { companyId, version, status };
26613                    }
26614                    else {
26615                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_V_ST;
26616                            finderArgs = new Object[] {
26617                                            companyId, version, status,
26618                                            
26619                                            start, end, orderByComparator
26620                                    };
26621                    }
26622    
26623                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
26624                                    finderArgs, this);
26625    
26626                    if ((list != null) && !list.isEmpty()) {
26627                            for (JournalArticle journalArticle : list) {
26628                                    if ((companyId != journalArticle.getCompanyId()) ||
26629                                                    (version != journalArticle.getVersion()) ||
26630                                                    (status != journalArticle.getStatus())) {
26631                                            list = null;
26632    
26633                                            break;
26634                                    }
26635                            }
26636                    }
26637    
26638                    if (list == null) {
26639                            StringBundler query = null;
26640    
26641                            if (orderByComparator != null) {
26642                                    query = new StringBundler(5 +
26643                                                    (orderByComparator.getOrderByFields().length * 3));
26644                            }
26645                            else {
26646                                    query = new StringBundler(5);
26647                            }
26648    
26649                            query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
26650    
26651                            query.append(_FINDER_COLUMN_C_V_ST_COMPANYID_2);
26652    
26653                            query.append(_FINDER_COLUMN_C_V_ST_VERSION_2);
26654    
26655                            query.append(_FINDER_COLUMN_C_V_ST_STATUS_2);
26656    
26657                            if (orderByComparator != null) {
26658                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
26659                                            orderByComparator);
26660                            }
26661                            else
26662                             if (pagination) {
26663                                    query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
26664                            }
26665    
26666                            String sql = query.toString();
26667    
26668                            Session session = null;
26669    
26670                            try {
26671                                    session = openSession();
26672    
26673                                    Query q = session.createQuery(sql);
26674    
26675                                    QueryPos qPos = QueryPos.getInstance(q);
26676    
26677                                    qPos.add(companyId);
26678    
26679                                    qPos.add(version);
26680    
26681                                    qPos.add(status);
26682    
26683                                    if (!pagination) {
26684                                            list = (List<JournalArticle>)QueryUtil.list(q,
26685                                                            getDialect(), start, end, false);
26686    
26687                                            Collections.sort(list);
26688    
26689                                            list = new UnmodifiableList<JournalArticle>(list);
26690                                    }
26691                                    else {
26692                                            list = (List<JournalArticle>)QueryUtil.list(q,
26693                                                            getDialect(), start, end);
26694                                    }
26695    
26696                                    cacheResult(list);
26697    
26698                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
26699                            }
26700                            catch (Exception e) {
26701                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
26702    
26703                                    throw processException(e);
26704                            }
26705                            finally {
26706                                    closeSession(session);
26707                            }
26708                    }
26709    
26710                    return list;
26711            }
26712    
26713            /**
26714             * Returns the first journal article in the ordered set where companyId = &#63; and version = &#63; and status = &#63;.
26715             *
26716             * @param companyId the company ID
26717             * @param version the version
26718             * @param status the status
26719             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
26720             * @return the first matching journal article
26721             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
26722             * @throws SystemException if a system exception occurred
26723             */
26724            @Override
26725            public JournalArticle findByC_V_ST_First(long companyId, double version,
26726                    int status, OrderByComparator orderByComparator)
26727                    throws NoSuchArticleException, SystemException {
26728                    JournalArticle journalArticle = fetchByC_V_ST_First(companyId, version,
26729                                    status, orderByComparator);
26730    
26731                    if (journalArticle != null) {
26732                            return journalArticle;
26733                    }
26734    
26735                    StringBundler msg = new StringBundler(8);
26736    
26737                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
26738    
26739                    msg.append("companyId=");
26740                    msg.append(companyId);
26741    
26742                    msg.append(", version=");
26743                    msg.append(version);
26744    
26745                    msg.append(", status=");
26746                    msg.append(status);
26747    
26748                    msg.append(StringPool.CLOSE_CURLY_BRACE);
26749    
26750                    throw new NoSuchArticleException(msg.toString());
26751            }
26752    
26753            /**
26754             * Returns the first journal article in the ordered set where companyId = &#63; and version = &#63; and status = &#63;.
26755             *
26756             * @param companyId the company ID
26757             * @param version the version
26758             * @param status the status
26759             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
26760             * @return the first matching journal article, or <code>null</code> if a matching journal article could not be found
26761             * @throws SystemException if a system exception occurred
26762             */
26763            @Override
26764            public JournalArticle fetchByC_V_ST_First(long companyId, double version,
26765                    int status, OrderByComparator orderByComparator)
26766                    throws SystemException {
26767                    List<JournalArticle> list = findByC_V_ST(companyId, version, status, 0,
26768                                    1, orderByComparator);
26769    
26770                    if (!list.isEmpty()) {
26771                            return list.get(0);
26772                    }
26773    
26774                    return null;
26775            }
26776    
26777            /**
26778             * Returns the last journal article in the ordered set where companyId = &#63; and version = &#63; and status = &#63;.
26779             *
26780             * @param companyId the company ID
26781             * @param version the version
26782             * @param status the status
26783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
26784             * @return the last matching journal article
26785             * @throws com.liferay.portlet.journal.NoSuchArticleException if a matching journal article could not be found
26786             * @throws SystemException if a system exception occurred
26787             */
26788            @Override
26789            public JournalArticle findByC_V_ST_Last(long companyId, double version,
26790                    int status, OrderByComparator orderByComparator)
26791                    throws NoSuchArticleException, SystemException {
26792                    JournalArticle journalArticle = fetchByC_V_ST_Last(companyId, version,
26793                                    status, orderByComparator);
26794    
26795                    if (journalArticle != null) {
26796                            return journalArticle;
26797                    }
26798    
26799                    StringBundler msg = new StringBundler(8);
26800    
26801                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
26802    
26803                    msg.append("companyId=");
26804                    msg.append(companyId);
26805    
26806                    msg.append(", version=");
26807                    msg.append(version);
26808    
26809                    msg.append(", status=");
26810                    msg.append(status);
26811    
26812                    msg.append(StringPool.CLOSE_CURLY_BRACE);
26813    
26814                    throw new NoSuchArticleException(msg.toString());
26815            }
26816    
26817            /**
26818             * Returns the last journal article in the ordered set where companyId = &#63; and version = &#63; and status = &#63;.
26819             *
26820             * @param companyId the company ID
26821             * @param version the version
26822             * @param status the status
26823             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
26824             * @return the last matching journal article, or <code>null</code> if a matching journal article could not be found
26825             * @throws SystemException if a system exception occurred
26826             */
26827            @Override
26828            public JournalArticle fetchByC_V_ST_Last(long companyId, double version,
26829                    int status, OrderByComparator orderByComparator)
26830                    throws SystemException {
26831                    int count = countByC_V_ST(companyId, version, status);
26832    
26833                    if (count == 0) {
26834                            return null;
26835                    }
26836    
26837                    List<JournalArticle> list = findByC_V_ST(companyId, version, status,
26838                                    count - 1, count, orderByComparator);
26839    
26840                    if (!list.isEmpty()) {
26841                            return list.get(0);
26842                    }
26843    
26844                    return null;
26845            }
26846    
26847            /**
26848             * Returns the journal articles before and after the current journal article in the ordered set where companyId = &#63; and version = &#63; and status = &#63;.
26849             *
26850             * @param id the primary key of the current journal article
26851             * @param companyId the company ID
26852             * @param version the version
26853             * @param status the status
26854             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
26855             * @return the previous, current, and next journal article
26856             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
26857             * @throws SystemException if a system exception occurred
26858             */
26859            @Override
26860            public JournalArticle[] findByC_V_ST_PrevAndNext(long id, long companyId,
26861                    double version, int status, OrderByComparator orderByComparator)
26862                    throws NoSuchArticleException, SystemException {
26863                    JournalArticle journalArticle = findByPrimaryKey(id);
26864    
26865                    Session session = null;
26866    
26867                    try {
26868                            session = openSession();
26869    
26870                            JournalArticle[] array = new JournalArticleImpl[3];
26871    
26872                            array[0] = getByC_V_ST_PrevAndNext(session, journalArticle,
26873                                            companyId, version, status, orderByComparator, true);
26874    
26875                            array[1] = journalArticle;
26876    
26877                            array[2] = getByC_V_ST_PrevAndNext(session, journalArticle,
26878                                            companyId, version, status, orderByComparator, false);
26879    
26880                            return array;
26881                    }
26882                    catch (Exception e) {
26883                            throw processException(e);
26884                    }
26885                    finally {
26886                            closeSession(session);
26887                    }
26888            }
26889    
26890            protected JournalArticle getByC_V_ST_PrevAndNext(Session session,
26891                    JournalArticle journalArticle, long companyId, double version,
26892                    int status, OrderByComparator orderByComparator, boolean previous) {
26893                    StringBundler query = null;
26894    
26895                    if (orderByComparator != null) {
26896                            query = new StringBundler(6 +
26897                                            (orderByComparator.getOrderByFields().length * 6));
26898                    }
26899                    else {
26900                            query = new StringBundler(3);
26901                    }
26902    
26903                    query.append(_SQL_SELECT_JOURNALARTICLE_WHERE);
26904    
26905                    query.append(_FINDER_COLUMN_C_V_ST_COMPANYID_2);
26906    
26907                    query.append(_FINDER_COLUMN_C_V_ST_VERSION_2);
26908    
26909                    query.append(_FINDER_COLUMN_C_V_ST_STATUS_2);
26910    
26911                    if (orderByComparator != null) {
26912                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
26913    
26914                            if (orderByConditionFields.length > 0) {
26915                                    query.append(WHERE_AND);
26916                            }
26917    
26918                            for (int i = 0; i < orderByConditionFields.length; i++) {
26919                                    query.append(_ORDER_BY_ENTITY_ALIAS);
26920                                    query.append(orderByConditionFields[i]);
26921    
26922                                    if ((i + 1) < orderByConditionFields.length) {
26923                                            if (orderByComparator.isAscending() ^ previous) {
26924                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
26925                                            }
26926                                            else {
26927                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
26928                                            }
26929                                    }
26930                                    else {
26931                                            if (orderByComparator.isAscending() ^ previous) {
26932                                                    query.append(WHERE_GREATER_THAN);
26933                                            }
26934                                            else {
26935                                                    query.append(WHERE_LESSER_THAN);
26936                                            }
26937                                    }
26938                            }
26939    
26940                            query.append(ORDER_BY_CLAUSE);
26941    
26942                            String[] orderByFields = orderByComparator.getOrderByFields();
26943    
26944                            for (int i = 0; i < orderByFields.length; i++) {
26945                                    query.append(_ORDER_BY_ENTITY_ALIAS);
26946                                    query.append(orderByFields[i]);
26947    
26948                                    if ((i + 1) < orderByFields.length) {
26949                                            if (orderByComparator.isAscending() ^ previous) {
26950                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
26951                                            }
26952                                            else {
26953                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
26954                                            }
26955                                    }
26956                                    else {
26957                                            if (orderByComparator.isAscending() ^ previous) {
26958                                                    query.append(ORDER_BY_ASC);
26959                                            }
26960                                            else {
26961                                                    query.append(ORDER_BY_DESC);
26962                                            }
26963                                    }
26964                            }
26965                    }
26966                    else {
26967                            query.append(JournalArticleModelImpl.ORDER_BY_JPQL);
26968                    }
26969    
26970                    String sql = query.toString();
26971    
26972                    Query q = session.createQuery(sql);
26973    
26974                    q.setFirstResult(0);
26975                    q.setMaxResults(2);
26976    
26977                    QueryPos qPos = QueryPos.getInstance(q);
26978    
26979                    qPos.add(companyId);
26980    
26981                    qPos.add(version);
26982    
26983                    qPos.add(status);
26984    
26985                    if (orderByComparator != null) {
26986                            Object[] values = orderByComparator.getOrderByConditionValues(journalArticle);
26987    
26988                            for (Object value : values) {
26989                                    qPos.add(value);
26990                            }
26991                    }
26992    
26993                    List<JournalArticle> list = q.list();
26994    
26995                    if (list.size() == 2) {
26996                            return list.get(1);
26997                    }
26998                    else {
26999                            return null;
27000                    }
27001            }
27002    
27003            /**
27004             * Removes all the journal articles where companyId = &#63; and version = &#63; and status = &#63; from the database.
27005             *
27006             * @param companyId the company ID
27007             * @param version the version
27008             * @param status the status
27009             * @throws SystemException if a system exception occurred
27010             */
27011            @Override
27012            public void removeByC_V_ST(long companyId, double version, int status)
27013                    throws SystemException {
27014                    for (JournalArticle journalArticle : findByC_V_ST(companyId, version,
27015                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
27016                            remove(journalArticle);
27017                    }
27018            }
27019    
27020            /**
27021             * Returns the number of journal articles where companyId = &#63; and version = &#63; and status = &#63;.
27022             *
27023             * @param companyId the company ID
27024             * @param version the version
27025             * @param status the status
27026             * @return the number of matching journal articles
27027             * @throws SystemException if a system exception occurred
27028             */
27029            @Override
27030            public int countByC_V_ST(long companyId, double version, int status)
27031                    throws SystemException {
27032                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_V_ST;
27033    
27034                    Object[] finderArgs = new Object[] { companyId, version, status };
27035    
27036                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
27037                                    this);
27038    
27039                    if (count == null) {
27040                            StringBundler query = new StringBundler(4);
27041    
27042                            query.append(_SQL_COUNT_JOURNALARTICLE_WHERE);
27043    
27044                            query.append(_FINDER_COLUMN_C_V_ST_COMPANYID_2);
27045    
27046                            query.append(_FINDER_COLUMN_C_V_ST_VERSION_2);
27047    
27048                            query.append(_FINDER_COLUMN_C_V_ST_STATUS_2);
27049    
27050                            String sql = query.toString();
27051    
27052                            Session session = null;
27053    
27054                            try {
27055                                    session = openSession();
27056    
27057                                    Query q = session.createQuery(sql);
27058    
27059                                    QueryPos qPos = QueryPos.getInstance(q);
27060    
27061                                    qPos.add(companyId);
27062    
27063                                    qPos.add(version);
27064    
27065                                    qPos.add(status);
27066    
27067                                    count = (Long)q.uniqueResult();
27068    
27069                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
27070                            }
27071                            catch (Exception e) {
27072                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
27073    
27074                                    throw processException(e);
27075                            }
27076                            finally {
27077                                    closeSession(session);
27078                            }
27079                    }
27080    
27081                    return count.intValue();
27082            }
27083    
27084            private static final String _FINDER_COLUMN_C_V_ST_COMPANYID_2 = "journalArticle.companyId = ? AND ";
27085            private static final String _FINDER_COLUMN_C_V_ST_VERSION_2 = "journalArticle.version = ? AND ";
27086            private static final String _FINDER_COLUMN_C_V_ST_STATUS_2 = "journalArticle.status = ?";
27087    
27088            public JournalArticlePersistenceImpl() {
27089                    setModelClass(JournalArticle.class);
27090            }
27091    
27092            /**
27093             * Caches the journal article in the entity cache if it is enabled.
27094             *
27095             * @param journalArticle the journal article
27096             */
27097            @Override
27098            public void cacheResult(JournalArticle journalArticle) {
27099                    EntityCacheUtil.putResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
27100                            JournalArticleImpl.class, journalArticle.getPrimaryKey(),
27101                            journalArticle);
27102    
27103                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
27104                            new Object[] { journalArticle.getUuid(), journalArticle.getGroupId() },
27105                            journalArticle);
27106    
27107                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S,
27108                            new Object[] {
27109                                    journalArticle.getGroupId(), journalArticle.getClassNameId(),
27110                                    journalArticle.getStructureId()
27111                            }, journalArticle);
27112    
27113                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V,
27114                            new Object[] {
27115                                    journalArticle.getGroupId(), journalArticle.getArticleId(),
27116                                    journalArticle.getVersion()
27117                            }, journalArticle);
27118    
27119                    journalArticle.resetOriginalValues();
27120            }
27121    
27122            /**
27123             * Caches the journal articles in the entity cache if it is enabled.
27124             *
27125             * @param journalArticles the journal articles
27126             */
27127            @Override
27128            public void cacheResult(List<JournalArticle> journalArticles) {
27129                    for (JournalArticle journalArticle : journalArticles) {
27130                            if (EntityCacheUtil.getResult(
27131                                                    JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
27132                                                    JournalArticleImpl.class, journalArticle.getPrimaryKey()) == null) {
27133                                    cacheResult(journalArticle);
27134                            }
27135                            else {
27136                                    journalArticle.resetOriginalValues();
27137                            }
27138                    }
27139            }
27140    
27141            /**
27142             * Clears the cache for all journal articles.
27143             *
27144             * <p>
27145             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
27146             * </p>
27147             */
27148            @Override
27149            public void clearCache() {
27150                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
27151                            CacheRegistryUtil.clear(JournalArticleImpl.class.getName());
27152                    }
27153    
27154                    EntityCacheUtil.clearCache(JournalArticleImpl.class.getName());
27155    
27156                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
27157                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
27158                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
27159            }
27160    
27161            /**
27162             * Clears the cache for the journal article.
27163             *
27164             * <p>
27165             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
27166             * </p>
27167             */
27168            @Override
27169            public void clearCache(JournalArticle journalArticle) {
27170                    EntityCacheUtil.removeResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
27171                            JournalArticleImpl.class, journalArticle.getPrimaryKey());
27172    
27173                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
27174                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
27175    
27176                    clearUniqueFindersCache(journalArticle);
27177            }
27178    
27179            @Override
27180            public void clearCache(List<JournalArticle> journalArticles) {
27181                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
27182                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
27183    
27184                    for (JournalArticle journalArticle : journalArticles) {
27185                            EntityCacheUtil.removeResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
27186                                    JournalArticleImpl.class, journalArticle.getPrimaryKey());
27187    
27188                            clearUniqueFindersCache(journalArticle);
27189                    }
27190            }
27191    
27192            protected void cacheUniqueFindersCache(JournalArticle journalArticle) {
27193                    if (journalArticle.isNew()) {
27194                            Object[] args = new Object[] {
27195                                            journalArticle.getUuid(), journalArticle.getGroupId()
27196                                    };
27197    
27198                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
27199                                    Long.valueOf(1));
27200                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
27201                                    journalArticle);
27202    
27203                            args = new Object[] {
27204                                            journalArticle.getGroupId(), journalArticle.getClassNameId(),
27205                                            journalArticle.getStructureId()
27206                                    };
27207    
27208                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S, args,
27209                                    Long.valueOf(1));
27210                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S, args,
27211                                    journalArticle);
27212    
27213                            args = new Object[] {
27214                                            journalArticle.getGroupId(), journalArticle.getArticleId(),
27215                                            journalArticle.getVersion()
27216                                    };
27217    
27218                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A_V, args,
27219                                    Long.valueOf(1));
27220                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V, args,
27221                                    journalArticle);
27222                    }
27223                    else {
27224                            JournalArticleModelImpl journalArticleModelImpl = (JournalArticleModelImpl)journalArticle;
27225    
27226                            if ((journalArticleModelImpl.getColumnBitmask() &
27227                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
27228                                    Object[] args = new Object[] {
27229                                                    journalArticle.getUuid(), journalArticle.getGroupId()
27230                                            };
27231    
27232                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
27233                                            Long.valueOf(1));
27234                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
27235                                            journalArticle);
27236                            }
27237    
27238                            if ((journalArticleModelImpl.getColumnBitmask() &
27239                                            FINDER_PATH_FETCH_BY_G_C_S.getColumnBitmask()) != 0) {
27240                                    Object[] args = new Object[] {
27241                                                    journalArticle.getGroupId(),
27242                                                    journalArticle.getClassNameId(),
27243                                                    journalArticle.getStructureId()
27244                                            };
27245    
27246                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S, args,
27247                                            Long.valueOf(1));
27248                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_C_S, args,
27249                                            journalArticle);
27250                            }
27251    
27252                            if ((journalArticleModelImpl.getColumnBitmask() &
27253                                            FINDER_PATH_FETCH_BY_G_A_V.getColumnBitmask()) != 0) {
27254                                    Object[] args = new Object[] {
27255                                                    journalArticle.getGroupId(),
27256                                                    journalArticle.getArticleId(),
27257                                                    journalArticle.getVersion()
27258                                            };
27259    
27260                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_A_V, args,
27261                                            Long.valueOf(1));
27262                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_A_V, args,
27263                                            journalArticle);
27264                            }
27265                    }
27266            }
27267    
27268            protected void clearUniqueFindersCache(JournalArticle journalArticle) {
27269                    JournalArticleModelImpl journalArticleModelImpl = (JournalArticleModelImpl)journalArticle;
27270    
27271                    Object[] args = new Object[] {
27272                                    journalArticle.getUuid(), journalArticle.getGroupId()
27273                            };
27274    
27275                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
27276                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
27277    
27278                    if ((journalArticleModelImpl.getColumnBitmask() &
27279                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
27280                            args = new Object[] {
27281                                            journalArticleModelImpl.getOriginalUuid(),
27282                                            journalArticleModelImpl.getOriginalGroupId()
27283                                    };
27284    
27285                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
27286                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
27287                    }
27288    
27289                    args = new Object[] {
27290                                    journalArticle.getGroupId(), journalArticle.getClassNameId(),
27291                                    journalArticle.getStructureId()
27292                            };
27293    
27294                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
27295                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S, args);
27296    
27297                    if ((journalArticleModelImpl.getColumnBitmask() &
27298                                    FINDER_PATH_FETCH_BY_G_C_S.getColumnBitmask()) != 0) {
27299                            args = new Object[] {
27300                                            journalArticleModelImpl.getOriginalGroupId(),
27301                                            journalArticleModelImpl.getOriginalClassNameId(),
27302                                            journalArticleModelImpl.getOriginalStructureId()
27303                                    };
27304    
27305                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
27306                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_C_S, args);
27307                    }
27308    
27309                    args = new Object[] {
27310                                    journalArticle.getGroupId(), journalArticle.getArticleId(),
27311                                    journalArticle.getVersion()
27312                            };
27313    
27314                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V, args);
27315                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V, args);
27316    
27317                    if ((journalArticleModelImpl.getColumnBitmask() &
27318                                    FINDER_PATH_FETCH_BY_G_A_V.getColumnBitmask()) != 0) {
27319                            args = new Object[] {
27320                                            journalArticleModelImpl.getOriginalGroupId(),
27321                                            journalArticleModelImpl.getOriginalArticleId(),
27322                                            journalArticleModelImpl.getOriginalVersion()
27323                                    };
27324    
27325                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_V, args);
27326                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_A_V, args);
27327                    }
27328            }
27329    
27330            /**
27331             * Creates a new journal article with the primary key. Does not add the journal article to the database.
27332             *
27333             * @param id the primary key for the new journal article
27334             * @return the new journal article
27335             */
27336            @Override
27337            public JournalArticle create(long id) {
27338                    JournalArticle journalArticle = new JournalArticleImpl();
27339    
27340                    journalArticle.setNew(true);
27341                    journalArticle.setPrimaryKey(id);
27342    
27343                    String uuid = PortalUUIDUtil.generate();
27344    
27345                    journalArticle.setUuid(uuid);
27346    
27347                    return journalArticle;
27348            }
27349    
27350            /**
27351             * Removes the journal article with the primary key from the database. Also notifies the appropriate model listeners.
27352             *
27353             * @param id the primary key of the journal article
27354             * @return the journal article that was removed
27355             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
27356             * @throws SystemException if a system exception occurred
27357             */
27358            @Override
27359            public JournalArticle remove(long id)
27360                    throws NoSuchArticleException, SystemException {
27361                    return remove((Serializable)id);
27362            }
27363    
27364            /**
27365             * Removes the journal article with the primary key from the database. Also notifies the appropriate model listeners.
27366             *
27367             * @param primaryKey the primary key of the journal article
27368             * @return the journal article that was removed
27369             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
27370             * @throws SystemException if a system exception occurred
27371             */
27372            @Override
27373            public JournalArticle remove(Serializable primaryKey)
27374                    throws NoSuchArticleException, SystemException {
27375                    Session session = null;
27376    
27377                    try {
27378                            session = openSession();
27379    
27380                            JournalArticle journalArticle = (JournalArticle)session.get(JournalArticleImpl.class,
27381                                            primaryKey);
27382    
27383                            if (journalArticle == null) {
27384                                    if (_log.isWarnEnabled()) {
27385                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
27386                                    }
27387    
27388                                    throw new NoSuchArticleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
27389                                            primaryKey);
27390                            }
27391    
27392                            return remove(journalArticle);
27393                    }
27394                    catch (NoSuchArticleException nsee) {
27395                            throw nsee;
27396                    }
27397                    catch (Exception e) {
27398                            throw processException(e);
27399                    }
27400                    finally {
27401                            closeSession(session);
27402                    }
27403            }
27404    
27405            @Override
27406            protected JournalArticle removeImpl(JournalArticle journalArticle)
27407                    throws SystemException {
27408                    journalArticle = toUnwrappedModel(journalArticle);
27409    
27410                    Session session = null;
27411    
27412                    try {
27413                            session = openSession();
27414    
27415                            if (!session.contains(journalArticle)) {
27416                                    journalArticle = (JournalArticle)session.get(JournalArticleImpl.class,
27417                                                    journalArticle.getPrimaryKeyObj());
27418                            }
27419    
27420                            if (journalArticle != null) {
27421                                    session.delete(journalArticle);
27422                            }
27423                    }
27424                    catch (Exception e) {
27425                            throw processException(e);
27426                    }
27427                    finally {
27428                            closeSession(session);
27429                    }
27430    
27431                    if (journalArticle != null) {
27432                            clearCache(journalArticle);
27433                    }
27434    
27435                    return journalArticle;
27436            }
27437    
27438            @Override
27439            public JournalArticle updateImpl(
27440                    com.liferay.portlet.journal.model.JournalArticle journalArticle)
27441                    throws SystemException {
27442                    journalArticle = toUnwrappedModel(journalArticle);
27443    
27444                    boolean isNew = journalArticle.isNew();
27445    
27446                    JournalArticleModelImpl journalArticleModelImpl = (JournalArticleModelImpl)journalArticle;
27447    
27448                    if (Validator.isNull(journalArticle.getUuid())) {
27449                            String uuid = PortalUUIDUtil.generate();
27450    
27451                            journalArticle.setUuid(uuid);
27452                    }
27453    
27454                    Session session = null;
27455    
27456                    try {
27457                            session = openSession();
27458    
27459                            if (journalArticle.isNew()) {
27460                                    session.save(journalArticle);
27461    
27462                                    journalArticle.setNew(false);
27463                            }
27464                            else {
27465                                    session.merge(journalArticle);
27466                            }
27467                    }
27468                    catch (Exception e) {
27469                            throw processException(e);
27470                    }
27471                    finally {
27472                            closeSession(session);
27473                    }
27474    
27475                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
27476    
27477                    if (isNew || !JournalArticleModelImpl.COLUMN_BITMASK_ENABLED) {
27478                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
27479                    }
27480    
27481                    else {
27482                            if ((journalArticleModelImpl.getColumnBitmask() &
27483                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
27484                                    Object[] args = new Object[] {
27485                                                    journalArticleModelImpl.getOriginalUuid()
27486                                            };
27487    
27488                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
27489                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
27490                                            args);
27491    
27492                                    args = new Object[] { journalArticleModelImpl.getUuid() };
27493    
27494                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
27495                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
27496                                            args);
27497                            }
27498    
27499                            if ((journalArticleModelImpl.getColumnBitmask() &
27500                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
27501                                    Object[] args = new Object[] {
27502                                                    journalArticleModelImpl.getOriginalUuid(),
27503                                                    journalArticleModelImpl.getOriginalCompanyId()
27504                                            };
27505    
27506                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
27507                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
27508                                            args);
27509    
27510                                    args = new Object[] {
27511                                                    journalArticleModelImpl.getUuid(),
27512                                                    journalArticleModelImpl.getCompanyId()
27513                                            };
27514    
27515                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
27516                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
27517                                            args);
27518                            }
27519    
27520                            if ((journalArticleModelImpl.getColumnBitmask() &
27521                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY.getColumnBitmask()) != 0) {
27522                                    Object[] args = new Object[] {
27523                                                    journalArticleModelImpl.getOriginalResourcePrimKey()
27524                                            };
27525    
27526                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY,
27527                                            args);
27528                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY,
27529                                            args);
27530    
27531                                    args = new Object[] { journalArticleModelImpl.getResourcePrimKey() };
27532    
27533                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEPRIMKEY,
27534                                            args);
27535                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEPRIMKEY,
27536                                            args);
27537                            }
27538    
27539                            if ((journalArticleModelImpl.getColumnBitmask() &
27540                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
27541                                    Object[] args = new Object[] {
27542                                                    journalArticleModelImpl.getOriginalGroupId()
27543                                            };
27544    
27545                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
27546                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
27547                                            args);
27548    
27549                                    args = new Object[] { journalArticleModelImpl.getGroupId() };
27550    
27551                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
27552                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
27553                                            args);
27554                            }
27555    
27556                            if ((journalArticleModelImpl.getColumnBitmask() &
27557                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
27558                                    Object[] args = new Object[] {
27559                                                    journalArticleModelImpl.getOriginalCompanyId()
27560                                            };
27561    
27562                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
27563                                            args);
27564                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
27565                                            args);
27566    
27567                                    args = new Object[] { journalArticleModelImpl.getCompanyId() };
27568    
27569                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
27570                                            args);
27571                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
27572                                            args);
27573                            }
27574    
27575                            if ((journalArticleModelImpl.getColumnBitmask() &
27576                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID.getColumnBitmask()) != 0) {
27577                                    Object[] args = new Object[] {
27578                                                    journalArticleModelImpl.getOriginalStructureId()
27579                                            };
27580    
27581                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
27582                                            args);
27583                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
27584                                            args);
27585    
27586                                    args = new Object[] { journalArticleModelImpl.getStructureId() };
27587    
27588                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_STRUCTUREID,
27589                                            args);
27590                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_STRUCTUREID,
27591                                            args);
27592                            }
27593    
27594                            if ((journalArticleModelImpl.getColumnBitmask() &
27595                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID.getColumnBitmask()) != 0) {
27596                                    Object[] args = new Object[] {
27597                                                    journalArticleModelImpl.getOriginalTemplateId()
27598                                            };
27599    
27600                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
27601                                            args);
27602                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
27603                                            args);
27604    
27605                                    args = new Object[] { journalArticleModelImpl.getTemplateId() };
27606    
27607                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TEMPLATEID,
27608                                            args);
27609                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TEMPLATEID,
27610                                            args);
27611                            }
27612    
27613                            if ((journalArticleModelImpl.getColumnBitmask() &
27614                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID.getColumnBitmask()) != 0) {
27615                                    Object[] args = new Object[] {
27616                                                    journalArticleModelImpl.getOriginalLayoutUuid()
27617                                            };
27618    
27619                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTUUID,
27620                                            args);
27621                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID,
27622                                            args);
27623    
27624                                    args = new Object[] { journalArticleModelImpl.getLayoutUuid() };
27625    
27626                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LAYOUTUUID,
27627                                            args);
27628                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_LAYOUTUUID,
27629                                            args);
27630                            }
27631    
27632                            if ((journalArticleModelImpl.getColumnBitmask() &
27633                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SMALLIMAGEID.getColumnBitmask()) != 0) {
27634                                    Object[] args = new Object[] {
27635                                                    journalArticleModelImpl.getOriginalSmallImageId()
27636                                            };
27637    
27638                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
27639                                            args);
27640                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SMALLIMAGEID,
27641                                            args);
27642    
27643                                    args = new Object[] { journalArticleModelImpl.getSmallImageId() };
27644    
27645                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SMALLIMAGEID,
27646                                            args);
27647                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SMALLIMAGEID,
27648                                            args);
27649                            }
27650    
27651                            if ((journalArticleModelImpl.getColumnBitmask() &
27652                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_ST.getColumnBitmask()) != 0) {
27653                                    Object[] args = new Object[] {
27654                                                    journalArticleModelImpl.getOriginalResourcePrimKey(),
27655                                                    journalArticleModelImpl.getOriginalStatus()
27656                                            };
27657    
27658                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_ST, args);
27659                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_ST,
27660                                            args);
27661    
27662                                    args = new Object[] {
27663                                                    journalArticleModelImpl.getResourcePrimKey(),
27664                                                    journalArticleModelImpl.getStatus()
27665                                            };
27666    
27667                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_ST, args);
27668                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_ST,
27669                                            args);
27670                            }
27671    
27672                            if ((journalArticleModelImpl.getColumnBitmask() &
27673                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
27674                                    Object[] args = new Object[] {
27675                                                    journalArticleModelImpl.getOriginalGroupId(),
27676                                                    journalArticleModelImpl.getOriginalUserId()
27677                                            };
27678    
27679                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
27680                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
27681                                            args);
27682    
27683                                    args = new Object[] {
27684                                                    journalArticleModelImpl.getGroupId(),
27685                                                    journalArticleModelImpl.getUserId()
27686                                            };
27687    
27688                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
27689                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
27690                                            args);
27691                            }
27692    
27693                            if ((journalArticleModelImpl.getColumnBitmask() &
27694                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F.getColumnBitmask()) != 0) {
27695                                    Object[] args = new Object[] {
27696                                                    journalArticleModelImpl.getOriginalGroupId(),
27697                                                    journalArticleModelImpl.getOriginalFolderId()
27698                                            };
27699    
27700                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F, args);
27701                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F,
27702                                            args);
27703    
27704                                    args = new Object[] {
27705                                                    journalArticleModelImpl.getGroupId(),
27706                                                    journalArticleModelImpl.getFolderId()
27707                                            };
27708    
27709                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F, args);
27710                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F,
27711                                            args);
27712                            }
27713    
27714                            if ((journalArticleModelImpl.getColumnBitmask() &
27715                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A.getColumnBitmask()) != 0) {
27716                                    Object[] args = new Object[] {
27717                                                    journalArticleModelImpl.getOriginalGroupId(),
27718                                                    journalArticleModelImpl.getOriginalArticleId()
27719                                            };
27720    
27721                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A, args);
27722                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A,
27723                                            args);
27724    
27725                                    args = new Object[] {
27726                                                    journalArticleModelImpl.getGroupId(),
27727                                                    journalArticleModelImpl.getArticleId()
27728                                            };
27729    
27730                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A, args);
27731                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A,
27732                                            args);
27733                            }
27734    
27735                            if ((journalArticleModelImpl.getColumnBitmask() &
27736                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT.getColumnBitmask()) != 0) {
27737                                    Object[] args = new Object[] {
27738                                                    journalArticleModelImpl.getOriginalGroupId(),
27739                                                    journalArticleModelImpl.getOriginalUrlTitle()
27740                                            };
27741    
27742                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_UT, args);
27743                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT,
27744                                            args);
27745    
27746                                    args = new Object[] {
27747                                                    journalArticleModelImpl.getGroupId(),
27748                                                    journalArticleModelImpl.getUrlTitle()
27749                                            };
27750    
27751                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_UT, args);
27752                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT,
27753                                            args);
27754                            }
27755    
27756                            if ((journalArticleModelImpl.getColumnBitmask() &
27757                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
27758                                    Object[] args = new Object[] {
27759                                                    journalArticleModelImpl.getOriginalGroupId(),
27760                                                    journalArticleModelImpl.getOriginalStructureId()
27761                                            };
27762    
27763                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
27764                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
27765                                            args);
27766    
27767                                    args = new Object[] {
27768                                                    journalArticleModelImpl.getGroupId(),
27769                                                    journalArticleModelImpl.getStructureId()
27770                                            };
27771    
27772                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
27773                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
27774                                            args);
27775                            }
27776    
27777                            if ((journalArticleModelImpl.getColumnBitmask() &
27778                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T.getColumnBitmask()) != 0) {
27779                                    Object[] args = new Object[] {
27780                                                    journalArticleModelImpl.getOriginalGroupId(),
27781                                                    journalArticleModelImpl.getOriginalTemplateId()
27782                                            };
27783    
27784                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
27785                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T,
27786                                            args);
27787    
27788                                    args = new Object[] {
27789                                                    journalArticleModelImpl.getGroupId(),
27790                                                    journalArticleModelImpl.getTemplateId()
27791                                            };
27792    
27793                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_T, args);
27794                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_T,
27795                                            args);
27796                            }
27797    
27798                            if ((journalArticleModelImpl.getColumnBitmask() &
27799                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_L.getColumnBitmask()) != 0) {
27800                                    Object[] args = new Object[] {
27801                                                    journalArticleModelImpl.getOriginalGroupId(),
27802                                                    journalArticleModelImpl.getOriginalLayoutUuid()
27803                                            };
27804    
27805                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_L, args);
27806                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_L,
27807                                            args);
27808    
27809                                    args = new Object[] {
27810                                                    journalArticleModelImpl.getGroupId(),
27811                                                    journalArticleModelImpl.getLayoutUuid()
27812                                            };
27813    
27814                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_L, args);
27815                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_L,
27816                                            args);
27817                            }
27818    
27819                            if ((journalArticleModelImpl.getColumnBitmask() &
27820                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_ST.getColumnBitmask()) != 0) {
27821                                    Object[] args = new Object[] {
27822                                                    journalArticleModelImpl.getOriginalGroupId(),
27823                                                    journalArticleModelImpl.getOriginalStatus()
27824                                            };
27825    
27826                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_ST, args);
27827                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_ST,
27828                                            args);
27829    
27830                                    args = new Object[] {
27831                                                    journalArticleModelImpl.getGroupId(),
27832                                                    journalArticleModelImpl.getStatus()
27833                                            };
27834    
27835                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_ST, args);
27836                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_ST,
27837                                            args);
27838                            }
27839    
27840                            if ((journalArticleModelImpl.getColumnBitmask() &
27841                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V.getColumnBitmask()) != 0) {
27842                                    Object[] args = new Object[] {
27843                                                    journalArticleModelImpl.getOriginalCompanyId(),
27844                                                    journalArticleModelImpl.getOriginalVersion()
27845                                            };
27846    
27847                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_V, args);
27848                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V,
27849                                            args);
27850    
27851                                    args = new Object[] {
27852                                                    journalArticleModelImpl.getCompanyId(),
27853                                                    journalArticleModelImpl.getVersion()
27854                                            };
27855    
27856                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_V, args);
27857                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V,
27858                                            args);
27859                            }
27860    
27861                            if ((journalArticleModelImpl.getColumnBitmask() &
27862                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_ST.getColumnBitmask()) != 0) {
27863                                    Object[] args = new Object[] {
27864                                                    journalArticleModelImpl.getOriginalCompanyId(),
27865                                                    journalArticleModelImpl.getOriginalStatus()
27866                                            };
27867    
27868                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_ST, args);
27869                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_ST,
27870                                            args);
27871    
27872                                    args = new Object[] {
27873                                                    journalArticleModelImpl.getCompanyId(),
27874                                                    journalArticleModelImpl.getStatus()
27875                                            };
27876    
27877                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_ST, args);
27878                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_ST,
27879                                            args);
27880                            }
27881    
27882                            if ((journalArticleModelImpl.getColumnBitmask() &
27883                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_I_S.getColumnBitmask()) != 0) {
27884                                    Object[] args = new Object[] {
27885                                                    journalArticleModelImpl.getOriginalResourcePrimKey(),
27886                                                    journalArticleModelImpl.getOriginalIndexable(),
27887                                                    journalArticleModelImpl.getOriginalStatus()
27888                                            };
27889    
27890                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_I_S, args);
27891                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_I_S,
27892                                            args);
27893    
27894                                    args = new Object[] {
27895                                                    journalArticleModelImpl.getResourcePrimKey(),
27896                                                    journalArticleModelImpl.getIndexable(),
27897                                                    journalArticleModelImpl.getStatus()
27898                                            };
27899    
27900                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_I_S, args);
27901                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_I_S,
27902                                            args);
27903                            }
27904    
27905                            if ((journalArticleModelImpl.getColumnBitmask() &
27906                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C.getColumnBitmask()) != 0) {
27907                                    Object[] args = new Object[] {
27908                                                    journalArticleModelImpl.getOriginalGroupId(),
27909                                                    journalArticleModelImpl.getOriginalUserId(),
27910                                                    journalArticleModelImpl.getOriginalClassNameId()
27911                                            };
27912    
27913                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C, args);
27914                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C,
27915                                            args);
27916    
27917                                    args = new Object[] {
27918                                                    journalArticleModelImpl.getGroupId(),
27919                                                    journalArticleModelImpl.getUserId(),
27920                                                    journalArticleModelImpl.getClassNameId()
27921                                            };
27922    
27923                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C, args);
27924                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C,
27925                                            args);
27926                            }
27927    
27928                            if ((journalArticleModelImpl.getColumnBitmask() &
27929                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_ST.getColumnBitmask()) != 0) {
27930                                    Object[] args = new Object[] {
27931                                                    journalArticleModelImpl.getOriginalGroupId(),
27932                                                    journalArticleModelImpl.getOriginalFolderId(),
27933                                                    journalArticleModelImpl.getOriginalStatus()
27934                                            };
27935    
27936                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_ST, args);
27937                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_ST,
27938                                            args);
27939    
27940                                    args = new Object[] {
27941                                                    journalArticleModelImpl.getGroupId(),
27942                                                    journalArticleModelImpl.getFolderId(),
27943                                                    journalArticleModelImpl.getStatus()
27944                                            };
27945    
27946                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_F_ST, args);
27947                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_F_ST,
27948                                            args);
27949                            }
27950    
27951                            if ((journalArticleModelImpl.getColumnBitmask() &
27952                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C.getColumnBitmask()) != 0) {
27953                                    Object[] args = new Object[] {
27954                                                    journalArticleModelImpl.getOriginalGroupId(),
27955                                                    journalArticleModelImpl.getOriginalClassNameId(),
27956                                                    journalArticleModelImpl.getOriginalClassPK()
27957                                            };
27958    
27959                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
27960                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
27961                                            args);
27962    
27963                                    args = new Object[] {
27964                                                    journalArticleModelImpl.getGroupId(),
27965                                                    journalArticleModelImpl.getClassNameId(),
27966                                                    journalArticleModelImpl.getClassPK()
27967                                            };
27968    
27969                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_C, args);
27970                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_C,
27971                                            args);
27972                            }
27973    
27974                            if ((journalArticleModelImpl.getColumnBitmask() &
27975                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
27976                                    Object[] args = new Object[] {
27977                                                    journalArticleModelImpl.getOriginalGroupId(),
27978                                                    journalArticleModelImpl.getOriginalClassNameId(),
27979                                                    journalArticleModelImpl.getOriginalTemplateId()
27980                                            };
27981    
27982                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
27983                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
27984                                            args);
27985    
27986                                    args = new Object[] {
27987                                                    journalArticleModelImpl.getGroupId(),
27988                                                    journalArticleModelImpl.getClassNameId(),
27989                                                    journalArticleModelImpl.getTemplateId()
27990                                            };
27991    
27992                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
27993                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
27994                                            args);
27995                            }
27996    
27997                            if ((journalArticleModelImpl.getColumnBitmask() &
27998                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
27999                                    Object[] args = new Object[] {
28000                                                    journalArticleModelImpl.getOriginalGroupId(),
28001                                                    journalArticleModelImpl.getOriginalClassNameId(),
28002                                                    journalArticleModelImpl.getOriginalLayoutUuid()
28003                                            };
28004    
28005                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
28006                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
28007                                            args);
28008    
28009                                    args = new Object[] {
28010                                                    journalArticleModelImpl.getGroupId(),
28011                                                    journalArticleModelImpl.getClassNameId(),
28012                                                    journalArticleModelImpl.getLayoutUuid()
28013                                            };
28014    
28015                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
28016                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
28017                                            args);
28018                            }
28019    
28020                            if ((journalArticleModelImpl.getColumnBitmask() &
28021                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_ST.getColumnBitmask()) != 0) {
28022                                    Object[] args = new Object[] {
28023                                                    journalArticleModelImpl.getOriginalGroupId(),
28024                                                    journalArticleModelImpl.getOriginalArticleId(),
28025                                                    journalArticleModelImpl.getOriginalStatus()
28026                                            };
28027    
28028                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_ST, args);
28029                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_ST,
28030                                            args);
28031    
28032                                    args = new Object[] {
28033                                                    journalArticleModelImpl.getGroupId(),
28034                                                    journalArticleModelImpl.getArticleId(),
28035                                                    journalArticleModelImpl.getStatus()
28036                                            };
28037    
28038                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_A_ST, args);
28039                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_A_ST,
28040                                            args);
28041                            }
28042    
28043                            if ((journalArticleModelImpl.getColumnBitmask() &
28044                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT_ST.getColumnBitmask()) != 0) {
28045                                    Object[] args = new Object[] {
28046                                                    journalArticleModelImpl.getOriginalGroupId(),
28047                                                    journalArticleModelImpl.getOriginalUrlTitle(),
28048                                                    journalArticleModelImpl.getOriginalStatus()
28049                                            };
28050    
28051                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_UT_ST, args);
28052                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT_ST,
28053                                            args);
28054    
28055                                    args = new Object[] {
28056                                                    journalArticleModelImpl.getGroupId(),
28057                                                    journalArticleModelImpl.getUrlTitle(),
28058                                                    journalArticleModelImpl.getStatus()
28059                                            };
28060    
28061                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_UT_ST, args);
28062                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_UT_ST,
28063                                            args);
28064                            }
28065    
28066                            if ((journalArticleModelImpl.getColumnBitmask() &
28067                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V_ST.getColumnBitmask()) != 0) {
28068                                    Object[] args = new Object[] {
28069                                                    journalArticleModelImpl.getOriginalCompanyId(),
28070                                                    journalArticleModelImpl.getOriginalVersion(),
28071                                                    journalArticleModelImpl.getOriginalStatus()
28072                                            };
28073    
28074                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_V_ST, args);
28075                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V_ST,
28076                                            args);
28077    
28078                                    args = new Object[] {
28079                                                    journalArticleModelImpl.getCompanyId(),
28080                                                    journalArticleModelImpl.getVersion(),
28081                                                    journalArticleModelImpl.getStatus()
28082                                            };
28083    
28084                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_V_ST, args);
28085                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_V_ST,
28086                                            args);
28087                            }
28088                    }
28089    
28090                    EntityCacheUtil.putResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
28091                            JournalArticleImpl.class, journalArticle.getPrimaryKey(),
28092                            journalArticle);
28093    
28094                    clearUniqueFindersCache(journalArticle);
28095                    cacheUniqueFindersCache(journalArticle);
28096    
28097                    return journalArticle;
28098            }
28099    
28100            protected JournalArticle toUnwrappedModel(JournalArticle journalArticle) {
28101                    if (journalArticle instanceof JournalArticleImpl) {
28102                            return journalArticle;
28103                    }
28104    
28105                    JournalArticleImpl journalArticleImpl = new JournalArticleImpl();
28106    
28107                    journalArticleImpl.setNew(journalArticle.isNew());
28108                    journalArticleImpl.setPrimaryKey(journalArticle.getPrimaryKey());
28109    
28110                    journalArticleImpl.setUuid(journalArticle.getUuid());
28111                    journalArticleImpl.setId(journalArticle.getId());
28112                    journalArticleImpl.setResourcePrimKey(journalArticle.getResourcePrimKey());
28113                    journalArticleImpl.setGroupId(journalArticle.getGroupId());
28114                    journalArticleImpl.setCompanyId(journalArticle.getCompanyId());
28115                    journalArticleImpl.setUserId(journalArticle.getUserId());
28116                    journalArticleImpl.setUserName(journalArticle.getUserName());
28117                    journalArticleImpl.setCreateDate(journalArticle.getCreateDate());
28118                    journalArticleImpl.setModifiedDate(journalArticle.getModifiedDate());
28119                    journalArticleImpl.setFolderId(journalArticle.getFolderId());
28120                    journalArticleImpl.setClassNameId(journalArticle.getClassNameId());
28121                    journalArticleImpl.setClassPK(journalArticle.getClassPK());
28122                    journalArticleImpl.setTreePath(journalArticle.getTreePath());
28123                    journalArticleImpl.setArticleId(journalArticle.getArticleId());
28124                    journalArticleImpl.setVersion(journalArticle.getVersion());
28125                    journalArticleImpl.setTitle(journalArticle.getTitle());
28126                    journalArticleImpl.setUrlTitle(journalArticle.getUrlTitle());
28127                    journalArticleImpl.setDescription(journalArticle.getDescription());
28128                    journalArticleImpl.setContent(journalArticle.getContent());
28129                    journalArticleImpl.setType(journalArticle.getType());
28130                    journalArticleImpl.setStructureId(journalArticle.getStructureId());
28131                    journalArticleImpl.setTemplateId(journalArticle.getTemplateId());
28132                    journalArticleImpl.setLayoutUuid(journalArticle.getLayoutUuid());
28133                    journalArticleImpl.setDisplayDate(journalArticle.getDisplayDate());
28134                    journalArticleImpl.setExpirationDate(journalArticle.getExpirationDate());
28135                    journalArticleImpl.setReviewDate(journalArticle.getReviewDate());
28136                    journalArticleImpl.setIndexable(journalArticle.isIndexable());
28137                    journalArticleImpl.setSmallImage(journalArticle.isSmallImage());
28138                    journalArticleImpl.setSmallImageId(journalArticle.getSmallImageId());
28139                    journalArticleImpl.setSmallImageURL(journalArticle.getSmallImageURL());
28140                    journalArticleImpl.setStatus(journalArticle.getStatus());
28141                    journalArticleImpl.setStatusByUserId(journalArticle.getStatusByUserId());
28142                    journalArticleImpl.setStatusByUserName(journalArticle.getStatusByUserName());
28143                    journalArticleImpl.setStatusDate(journalArticle.getStatusDate());
28144    
28145                    return journalArticleImpl;
28146            }
28147    
28148            /**
28149             * Returns the journal article with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
28150             *
28151             * @param primaryKey the primary key of the journal article
28152             * @return the journal article
28153             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
28154             * @throws SystemException if a system exception occurred
28155             */
28156            @Override
28157            public JournalArticle findByPrimaryKey(Serializable primaryKey)
28158                    throws NoSuchArticleException, SystemException {
28159                    JournalArticle journalArticle = fetchByPrimaryKey(primaryKey);
28160    
28161                    if (journalArticle == null) {
28162                            if (_log.isWarnEnabled()) {
28163                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
28164                            }
28165    
28166                            throw new NoSuchArticleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
28167                                    primaryKey);
28168                    }
28169    
28170                    return journalArticle;
28171            }
28172    
28173            /**
28174             * Returns the journal article with the primary key or throws a {@link com.liferay.portlet.journal.NoSuchArticleException} if it could not be found.
28175             *
28176             * @param id the primary key of the journal article
28177             * @return the journal article
28178             * @throws com.liferay.portlet.journal.NoSuchArticleException if a journal article with the primary key could not be found
28179             * @throws SystemException if a system exception occurred
28180             */
28181            @Override
28182            public JournalArticle findByPrimaryKey(long id)
28183                    throws NoSuchArticleException, SystemException {
28184                    return findByPrimaryKey((Serializable)id);
28185            }
28186    
28187            /**
28188             * Returns the journal article with the primary key or returns <code>null</code> if it could not be found.
28189             *
28190             * @param primaryKey the primary key of the journal article
28191             * @return the journal article, or <code>null</code> if a journal article with the primary key could not be found
28192             * @throws SystemException if a system exception occurred
28193             */
28194            @Override
28195            public JournalArticle fetchByPrimaryKey(Serializable primaryKey)
28196                    throws SystemException {
28197                    JournalArticle journalArticle = (JournalArticle)EntityCacheUtil.getResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
28198                                    JournalArticleImpl.class, primaryKey);
28199    
28200                    if (journalArticle == _nullJournalArticle) {
28201                            return null;
28202                    }
28203    
28204                    if (journalArticle == null) {
28205                            Session session = null;
28206    
28207                            try {
28208                                    session = openSession();
28209    
28210                                    journalArticle = (JournalArticle)session.get(JournalArticleImpl.class,
28211                                                    primaryKey);
28212    
28213                                    if (journalArticle != null) {
28214                                            cacheResult(journalArticle);
28215                                    }
28216                                    else {
28217                                            EntityCacheUtil.putResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
28218                                                    JournalArticleImpl.class, primaryKey,
28219                                                    _nullJournalArticle);
28220                                    }
28221                            }
28222                            catch (Exception e) {
28223                                    EntityCacheUtil.removeResult(JournalArticleModelImpl.ENTITY_CACHE_ENABLED,
28224                                            JournalArticleImpl.class, primaryKey);
28225    
28226                                    throw processException(e);
28227                            }
28228                            finally {
28229                                    closeSession(session);
28230                            }
28231                    }
28232    
28233                    return journalArticle;
28234            }
28235    
28236            /**
28237             * Returns the journal article with the primary key or returns <code>null</code> if it could not be found.
28238             *
28239             * @param id the primary key of the journal article
28240             * @return the journal article, or <code>null</code> if a journal article with the primary key could not be found
28241             * @throws SystemException if a system exception occurred
28242             */
28243            @Override
28244            public JournalArticle fetchByPrimaryKey(long id) throws SystemException {
28245                    return fetchByPrimaryKey((Serializable)id);
28246            }
28247    
28248            /**
28249             * Returns all the journal articles.
28250             *
28251             * @return the journal articles
28252             * @throws SystemException if a system exception occurred
28253             */
28254            @Override
28255            public List<JournalArticle> findAll() throws SystemException {
28256                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
28257            }
28258    
28259            /**
28260             * Returns a range of all the journal articles.
28261             *
28262             * <p>
28263             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
28264             * </p>
28265             *
28266             * @param start the lower bound of the range of journal articles
28267             * @param end the upper bound of the range of journal articles (not inclusive)
28268             * @return the range of journal articles
28269             * @throws SystemException if a system exception occurred
28270             */
28271            @Override
28272            public List<JournalArticle> findAll(int start, int end)
28273                    throws SystemException {
28274                    return findAll(start, end, null);
28275            }
28276    
28277            /**
28278             * Returns an ordered range of all the journal articles.
28279             *
28280             * <p>
28281             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.journal.model.impl.JournalArticleModelImpl}. 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.
28282             * </p>
28283             *
28284             * @param start the lower bound of the range of journal articles
28285             * @param end the upper bound of the range of journal articles (not inclusive)
28286             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
28287             * @return the ordered range of journal articles
28288             * @throws SystemException if a system exception occurred
28289             */
28290            @Override
28291            public List<JournalArticle> findAll(int start, int end,
28292                    OrderByComparator orderByComparator) throws SystemException {
28293                    boolean pagination = true;
28294                    FinderPath finderPath = null;
28295                    Object[] finderArgs = null;
28296    
28297                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
28298                                    (orderByComparator == null)) {
28299                            pagination = false;
28300                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
28301                            finderArgs = FINDER_ARGS_EMPTY;
28302                    }
28303                    else {
28304                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
28305                            finderArgs = new Object[] { start, end, orderByComparator };
28306                    }
28307    
28308                    List<JournalArticle> list = (List<JournalArticle>)FinderCacheUtil.getResult(finderPath,
28309                                    finderArgs, this);
28310    
28311                    if (list == null) {
28312                            StringBundler query = null;
28313                            String sql = null;
28314    
28315                            if (orderByComparator != null) {
28316                                    query = new StringBundler(2 +
28317                                                    (orderByComparator.getOrderByFields().length * 3));
28318    
28319                                    query.append(_SQL_SELECT_JOURNALARTICLE);
28320    
28321                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
28322                                            orderByComparator);
28323    
28324                                    sql = query.toString();
28325                            }
28326                            else {
28327                                    sql = _SQL_SELECT_JOURNALARTICLE;
28328    
28329                                    if (pagination) {
28330                                            sql = sql.concat(JournalArticleModelImpl.ORDER_BY_JPQL);
28331                                    }
28332                            }
28333    
28334                            Session session = null;
28335    
28336                            try {
28337                                    session = openSession();
28338    
28339                                    Query q = session.createQuery(sql);
28340    
28341                                    if (!pagination) {
28342                                            list = (List<JournalArticle>)QueryUtil.list(q,
28343                                                            getDialect(), start, end, false);
28344    
28345                                            Collections.sort(list);
28346    
28347                                            list = new UnmodifiableList<JournalArticle>(list);
28348                                    }
28349                                    else {
28350                                            list = (List<JournalArticle>)QueryUtil.list(q,
28351                                                            getDialect(), start, end);
28352                                    }
28353    
28354                                    cacheResult(list);
28355    
28356                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
28357                            }
28358                            catch (Exception e) {
28359                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
28360    
28361                                    throw processException(e);
28362                            }
28363                            finally {
28364                                    closeSession(session);
28365                            }
28366                    }
28367    
28368                    return list;
28369            }
28370    
28371            /**
28372             * Removes all the journal articles from the database.
28373             *
28374             * @throws SystemException if a system exception occurred
28375             */
28376            @Override
28377            public void removeAll() throws SystemException {
28378                    for (JournalArticle journalArticle : findAll()) {
28379                            remove(journalArticle);
28380                    }
28381            }
28382    
28383            /**
28384             * Returns the number of journal articles.
28385             *
28386             * @return the number of journal articles
28387             * @throws SystemException if a system exception occurred
28388             */
28389            @Override
28390            public int countAll() throws SystemException {
28391                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
28392                                    FINDER_ARGS_EMPTY, this);
28393    
28394                    if (count == null) {
28395                            Session session = null;
28396    
28397                            try {
28398                                    session = openSession();
28399    
28400                                    Query q = session.createQuery(_SQL_COUNT_JOURNALARTICLE);
28401    
28402                                    count = (Long)q.uniqueResult();
28403    
28404                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
28405                                            FINDER_ARGS_EMPTY, count);
28406                            }
28407                            catch (Exception e) {
28408                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
28409                                            FINDER_ARGS_EMPTY);
28410    
28411                                    throw processException(e);
28412                            }
28413                            finally {
28414                                    closeSession(session);
28415                            }
28416                    }
28417    
28418                    return count.intValue();
28419            }
28420    
28421            @Override
28422            protected Set<String> getBadColumnNames() {
28423                    return _badColumnNames;
28424            }
28425    
28426            /**
28427             * Initializes the journal article persistence.
28428             */
28429            public void afterPropertiesSet() {
28430                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
28431                                            com.liferay.portal.util.PropsUtil.get(
28432                                                    "value.object.listener.com.liferay.portlet.journal.model.JournalArticle")));
28433    
28434                    if (listenerClassNames.length > 0) {
28435                            try {
28436                                    List<ModelListener<JournalArticle>> listenersList = new ArrayList<ModelListener<JournalArticle>>();
28437    
28438                                    for (String listenerClassName : listenerClassNames) {
28439                                            listenersList.add((ModelListener<JournalArticle>)InstanceFactory.newInstance(
28440                                                            getClassLoader(), listenerClassName));
28441                                    }
28442    
28443                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
28444                            }
28445                            catch (Exception e) {
28446                                    _log.error(e);
28447                            }
28448                    }
28449            }
28450    
28451            public void destroy() {
28452                    EntityCacheUtil.removeCache(JournalArticleImpl.class.getName());
28453                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
28454                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
28455                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
28456            }
28457    
28458            private static final String _SQL_SELECT_JOURNALARTICLE = "SELECT journalArticle FROM JournalArticle journalArticle";
28459            private static final String _SQL_SELECT_JOURNALARTICLE_WHERE = "SELECT journalArticle FROM JournalArticle journalArticle WHERE ";
28460            private static final String _SQL_COUNT_JOURNALARTICLE = "SELECT COUNT(journalArticle) FROM JournalArticle journalArticle";
28461            private static final String _SQL_COUNT_JOURNALARTICLE_WHERE = "SELECT COUNT(journalArticle) FROM JournalArticle journalArticle WHERE ";
28462            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "journalArticle.resourcePrimKey";
28463            private static final String _FILTER_SQL_SELECT_JOURNALARTICLE_WHERE = "SELECT DISTINCT {journalArticle.*} FROM JournalArticle journalArticle WHERE ";
28464            private static final String _FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_1 =
28465                    "SELECT {JournalArticle.*} FROM (SELECT DISTINCT journalArticle.id_ FROM JournalArticle journalArticle WHERE ";
28466            private static final String _FILTER_SQL_SELECT_JOURNALARTICLE_NO_INLINE_DISTINCT_WHERE_2 =
28467                    ") TEMP_TABLE INNER JOIN JournalArticle ON TEMP_TABLE.id_ = JournalArticle.id_";
28468            private static final String _FILTER_SQL_COUNT_JOURNALARTICLE_WHERE = "SELECT COUNT(DISTINCT journalArticle.id_) AS COUNT_VALUE FROM JournalArticle journalArticle WHERE ";
28469            private static final String _FILTER_ENTITY_ALIAS = "journalArticle";
28470            private static final String _FILTER_ENTITY_TABLE = "JournalArticle";
28471            private static final String _ORDER_BY_ENTITY_ALIAS = "journalArticle.";
28472            private static final String _ORDER_BY_ENTITY_TABLE = "JournalArticle.";
28473            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No JournalArticle exists with the primary key ";
28474            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No JournalArticle exists with the key {";
28475            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
28476            private static Log _log = LogFactoryUtil.getLog(JournalArticlePersistenceImpl.class);
28477            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
28478                                    "uuid", "id", "type"
28479                            });
28480            private static JournalArticle _nullJournalArticle = new JournalArticleImpl() {
28481                            @Override
28482                            public Object clone() {
28483                                    return this;
28484                            }
28485    
28486                            @Override
28487                            public CacheModel<JournalArticle> toCacheModel() {
28488                                    return _nullJournalArticleCacheModel;
28489                            }
28490                    };
28491    
28492            private static CacheModel<JournalArticle> _nullJournalArticleCacheModel = new CacheModel<JournalArticle>() {
28493                            @Override
28494                            public JournalArticle toEntityModel() {
28495                                    return _nullJournalArticle;
28496                            }
28497                    };
28498    }